[ae3ce4e] | 1 | /** |
---|
| 2 | * Scattering model for an ellipsoid |
---|
| 3 | * @author: Mathieu Doucet / UTK |
---|
| 4 | */ |
---|
| 5 | |
---|
| 6 | #include "ellipsoid.h" |
---|
| 7 | #include "libCylinder.h" |
---|
| 8 | #include <math.h> |
---|
| 9 | #include <stdio.h> |
---|
| 10 | |
---|
| 11 | /** |
---|
| 12 | * Test kernel for validation |
---|
[44aa1ed] | 13 | * |
---|
[ae3ce4e] | 14 | * @param q: q-value |
---|
| 15 | * @param r_small: small axis length |
---|
| 16 | * @param r_long: rotation axis length |
---|
| 17 | * @param angle: angle between rotation axis and q vector |
---|
| 18 | * @return: oriented kernel value |
---|
| 19 | */ |
---|
| 20 | double kernel(double q, double r_small, double r_long, double angle) { |
---|
| 21 | double length; |
---|
| 22 | double sin_alpha; |
---|
| 23 | double cos_alpha; |
---|
| 24 | double sph_func; |
---|
[44aa1ed] | 25 | |
---|
[ae3ce4e] | 26 | sin_alpha = sin(angle); |
---|
| 27 | cos_alpha = cos(angle); |
---|
[44aa1ed] | 28 | |
---|
[ae3ce4e] | 29 | // Modified length for phase |
---|
[44aa1ed] | 30 | length = r_small*sqrt(sin_alpha*sin_alpha + |
---|
[ae3ce4e] | 31 | r_long*r_long/(r_small*r_small)*cos_alpha*cos_alpha); |
---|
[44aa1ed] | 32 | |
---|
[ae3ce4e] | 33 | // Spherical scattering ampliture, with modified length for ellipsoid |
---|
[8f20419d] | 34 | sph_func = 3.0*( sin(q*length) - q*length*cos(q*length) ) / (q*q*q*length*length*length); |
---|
[44aa1ed] | 35 | |
---|
[ae3ce4e] | 36 | return sph_func*sph_func; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | /** |
---|
| 40 | * Function to evaluate 1D scattering function |
---|
| 41 | * @param pars: parameters of the ellipsoid |
---|
| 42 | * @param q: q-value |
---|
| 43 | * @return: function value |
---|
| 44 | */ |
---|
| 45 | double ellipsoid_analytical_1D(EllipsoidParameters *pars, double q) { |
---|
[f10063e] | 46 | double dp[6]; |
---|
[44aa1ed] | 47 | |
---|
[ae3ce4e] | 48 | dp[0] = pars->scale; |
---|
| 49 | dp[1] = pars->radius_a; |
---|
| 50 | dp[2] = pars->radius_b; |
---|
[f10063e] | 51 | dp[3] = pars->sldEll; |
---|
| 52 | dp[4] = pars->sldSolv; |
---|
| 53 | dp[5] = pars->background; |
---|
[44aa1ed] | 54 | |
---|
[ae3ce4e] | 55 | return EllipsoidForm(dp, q); |
---|
| 56 | } |
---|
[44aa1ed] | 57 | |
---|
[ae3ce4e] | 58 | /** |
---|
| 59 | * Function to evaluate 2D scattering function |
---|
| 60 | * @param pars: parameters of the ellipsoid |
---|
| 61 | * @param q: q-value |
---|
| 62 | * @return: function value |
---|
| 63 | */ |
---|
| 64 | double ellipsoid_analytical_2DXY(EllipsoidParameters *pars, double qx, double qy) { |
---|
| 65 | double q; |
---|
| 66 | q = sqrt(qx*qx+qy*qy); |
---|
| 67 | return ellipsoid_analytical_2D_scaled(pars, q, qx/q, qy/q); |
---|
[44aa1ed] | 68 | } |
---|
[ae3ce4e] | 69 | |
---|
| 70 | /** |
---|
| 71 | * Function to evaluate 2D scattering function |
---|
| 72 | * @param pars: parameters of the ellipsoid |
---|
| 73 | * @param q: q-value |
---|
| 74 | * @param phi: angle phi |
---|
| 75 | * @return: function value |
---|
| 76 | */ |
---|
| 77 | double ellipsoid_analytical_2D(EllipsoidParameters *pars, double q, double phi) { |
---|
| 78 | return ellipsoid_analytical_2D_scaled(pars, q, cos(phi), sin(phi)); |
---|
[44aa1ed] | 79 | } |
---|
[ae3ce4e] | 80 | |
---|
| 81 | /** |
---|
| 82 | * Function to evaluate 2D scattering function |
---|
| 83 | * @param pars: parameters of the ellipsoid |
---|
| 84 | * @param q: q-value |
---|
| 85 | * @param q_x: q_x / q |
---|
| 86 | * @param q_y: q_y / q |
---|
| 87 | * @return: function value |
---|
| 88 | */ |
---|
| 89 | double ellipsoid_analytical_2D_scaled(EllipsoidParameters *pars, double q, double q_x, double q_y) { |
---|
| 90 | double cyl_x, cyl_y, cyl_z; |
---|
| 91 | double q_z, lenq; |
---|
| 92 | double theta, alpha, f, vol, sin_val, cos_val; |
---|
| 93 | double answer; |
---|
[44aa1ed] | 94 | |
---|
[ae3ce4e] | 95 | // Ellipsoid orientation |
---|
| 96 | cyl_x = sin(pars->axis_theta) * cos(pars->axis_phi); |
---|
| 97 | cyl_y = sin(pars->axis_theta) * sin(pars->axis_phi); |
---|
| 98 | cyl_z = cos(pars->axis_theta); |
---|
[44aa1ed] | 99 | |
---|
[ae3ce4e] | 100 | // q vector |
---|
[8f20419d] | 101 | q_z = 0.0; |
---|
[44aa1ed] | 102 | |
---|
[ae3ce4e] | 103 | // Compute the angle btw vector q and the |
---|
| 104 | // axis of the cylinder |
---|
| 105 | cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; |
---|
[44aa1ed] | 106 | |
---|
[ae3ce4e] | 107 | // The following test should always pass |
---|
| 108 | if (fabs(cos_val)>1.0) { |
---|
| 109 | printf("ellipsoid_ana_2D: Unexpected error: cos(alpha)>1\n"); |
---|
| 110 | return 0; |
---|
| 111 | } |
---|
[44aa1ed] | 112 | |
---|
[ae3ce4e] | 113 | // Angle between rotation axis and q vector |
---|
| 114 | alpha = acos( cos_val ); |
---|
[44aa1ed] | 115 | |
---|
[ae3ce4e] | 116 | // Call the IGOR library function to get the kernel |
---|
[df4702f] | 117 | answer = EllipsoidKernel(q, pars->radius_b, pars->radius_a, cos_val); |
---|
[44aa1ed] | 118 | |
---|
[ae3ce4e] | 119 | // Multiply by contrast^2 |
---|
[f10063e] | 120 | answer *= (pars->sldEll - pars->sldSolv) * (pars->sldEll - pars->sldSolv); |
---|
[44aa1ed] | 121 | |
---|
[ae3ce4e] | 122 | //normalize by cylinder volume |
---|
| 123 | vol = 4.0/3.0 * acos(-1.0) * pars->radius_b * pars->radius_b * pars->radius_a; |
---|
| 124 | answer *= vol; |
---|
[44aa1ed] | 125 | |
---|
[ae3ce4e] | 126 | //convert to [cm-1] |
---|
| 127 | answer *= 1.0e8; |
---|
[44aa1ed] | 128 | |
---|
[ae3ce4e] | 129 | //Scale |
---|
| 130 | answer *= pars->scale; |
---|
[44aa1ed] | 131 | |
---|
[ae3ce4e] | 132 | // add in the background |
---|
| 133 | answer += pars->background; |
---|
[44aa1ed] | 134 | |
---|
[ae3ce4e] | 135 | return answer; |
---|
| 136 | } |
---|