[ae3ce4e] | 1 | /** |
---|
| 2 | * Scattering model for a cylinder |
---|
| 3 | * @author: Mathieu Doucet / UTK |
---|
| 4 | */ |
---|
| 5 | |
---|
| 6 | #include "cylinder.h" |
---|
| 7 | #include <math.h> |
---|
| 8 | #include "libCylinder.h" |
---|
| 9 | #include <stdio.h> |
---|
| 10 | #include <stdlib.h> |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | /** |
---|
| 14 | * Function to evaluate 1D scattering function |
---|
| 15 | * @param pars: parameters of the cylinder |
---|
| 16 | * @param q: q-value |
---|
| 17 | * @return: function value |
---|
| 18 | */ |
---|
| 19 | double cylinder_analytical_1D(CylinderParameters *pars, double q) { |
---|
[f10063e] | 20 | double dp[6]; |
---|
| 21 | |
---|
[ae3ce4e] | 22 | // Fill paramater array |
---|
| 23 | dp[0] = pars->scale; |
---|
| 24 | dp[1] = pars->radius; |
---|
| 25 | dp[2] = pars->length; |
---|
[f10063e] | 26 | dp[3] = pars->sldCyl; |
---|
| 27 | dp[4] = pars->sldSolv; |
---|
| 28 | dp[5] = pars->background; |
---|
| 29 | |
---|
[ae3ce4e] | 30 | // Call library function to evaluate model |
---|
[f10063e] | 31 | return CylinderForm(dp, q); |
---|
[ae3ce4e] | 32 | } |
---|
| 33 | |
---|
| 34 | /** |
---|
| 35 | * Function to evaluate 2D scattering function |
---|
| 36 | * @param pars: parameters of the cylinder |
---|
| 37 | * @param q: q-value |
---|
| 38 | * @return: function value |
---|
| 39 | */ |
---|
| 40 | double cylinder_analytical_2DXY(CylinderParameters *pars, double qx, double qy) { |
---|
| 41 | double q; |
---|
| 42 | q = sqrt(qx*qx+qy*qy); |
---|
| 43 | return cylinder_analytical_2D_scaled(pars, q, qx/q, qy/q); |
---|
[f10063e] | 44 | } |
---|
[ae3ce4e] | 45 | |
---|
| 46 | |
---|
| 47 | /** |
---|
| 48 | * Function to evaluate 2D scattering function |
---|
| 49 | * @param pars: parameters of the cylinder |
---|
| 50 | * @param q: q-value |
---|
| 51 | * @param phi: angle phi |
---|
| 52 | * @return: function value |
---|
| 53 | */ |
---|
| 54 | double cylinder_analytical_2D(CylinderParameters *pars, double q, double phi) { |
---|
| 55 | return cylinder_analytical_2D_scaled(pars, q, cos(phi), sin(phi)); |
---|
[f10063e] | 56 | } |
---|
| 57 | |
---|
[ae3ce4e] | 58 | /** |
---|
| 59 | * Function to evaluate 2D scattering function |
---|
| 60 | * @param pars: parameters of the cylinder |
---|
| 61 | * @param q: q-value |
---|
| 62 | * @param q_x: q_x / q |
---|
| 63 | * @param q_y: q_y / q |
---|
| 64 | * @return: function value |
---|
| 65 | */ |
---|
| 66 | double cylinder_analytical_2D_scaled(CylinderParameters *pars, double q, double q_x, double q_y) { |
---|
| 67 | double cyl_x, cyl_y, cyl_z; |
---|
| 68 | double q_z; |
---|
| 69 | double alpha, vol, cos_val; |
---|
| 70 | double answer; |
---|
[4628e31] | 71 | //convert angle degree to radian |
---|
| 72 | double pi = 4.0*atan(1.0); |
---|
| 73 | double theta = pars->cyl_theta * pi/180.0; |
---|
| 74 | double phi = pars->cyl_phi * pi/180.0; |
---|
[f10063e] | 75 | |
---|
[ae3ce4e] | 76 | // Cylinder orientation |
---|
[4628e31] | 77 | cyl_x = sin(theta) * cos(phi); |
---|
| 78 | cyl_y = sin(theta) * sin(phi); |
---|
| 79 | cyl_z = cos(theta); |
---|
[f10063e] | 80 | |
---|
[ae3ce4e] | 81 | // q vector |
---|
| 82 | q_z = 0; |
---|
[f10063e] | 83 | |
---|
[ae3ce4e] | 84 | // Compute the angle btw vector q and the |
---|
| 85 | // axis of the cylinder |
---|
| 86 | cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; |
---|
[f10063e] | 87 | |
---|
[ae3ce4e] | 88 | // The following test should always pass |
---|
| 89 | if (fabs(cos_val)>1.0) { |
---|
| 90 | printf("cyl_ana_2D: Unexpected error: cos(alpha)>1\n"); |
---|
| 91 | return 0; |
---|
| 92 | } |
---|
[f10063e] | 93 | |
---|
[ae3ce4e] | 94 | // Note: cos(alpha) = 0 and 1 will get an |
---|
| 95 | // undefined value from CylKernel |
---|
| 96 | alpha = acos( cos_val ); |
---|
[f10063e] | 97 | |
---|
[ae3ce4e] | 98 | // Call the IGOR library function to get the kernel |
---|
| 99 | answer = CylKernel(q, pars->radius, pars->length/2.0, alpha) / sin(alpha); |
---|
[f10063e] | 100 | |
---|
[ae3ce4e] | 101 | // Multiply by contrast^2 |
---|
[f10063e] | 102 | answer *= (pars->sldCyl - pars->sldSolv)*(pars->sldCyl - pars->sldSolv); |
---|
| 103 | |
---|
[ae3ce4e] | 104 | //normalize by cylinder volume |
---|
| 105 | //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl |
---|
| 106 | vol = acos(-1.0) * pars->radius * pars->radius * pars->length; |
---|
| 107 | answer *= vol; |
---|
[f10063e] | 108 | |
---|
[ae3ce4e] | 109 | //convert to [cm-1] |
---|
| 110 | answer *= 1.0e8; |
---|
[f10063e] | 111 | |
---|
[ae3ce4e] | 112 | //Scale |
---|
| 113 | answer *= pars->scale; |
---|
[f10063e] | 114 | |
---|
[ae3ce4e] | 115 | // add in the background |
---|
| 116 | answer += pars->background; |
---|
[f10063e] | 117 | |
---|
[ae3ce4e] | 118 | return answer; |
---|
| 119 | } |
---|
[f10063e] | 120 | |
---|