[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 |
---|
| 34 | sph_func = 3*( 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) { |
---|
| 46 | double dp[5]; |
---|
[44aa1ed] | 47 | |
---|
[ae3ce4e] | 48 | dp[0] = pars->scale; |
---|
| 49 | dp[1] = pars->radius_a; |
---|
| 50 | dp[2] = pars->radius_b; |
---|
| 51 | dp[3] = pars->contrast; |
---|
| 52 | dp[4] = pars->background; |
---|
[44aa1ed] | 53 | |
---|
[ae3ce4e] | 54 | return EllipsoidForm(dp, q); |
---|
| 55 | } |
---|
[44aa1ed] | 56 | |
---|
[ae3ce4e] | 57 | /** |
---|
| 58 | * Function to evaluate 2D scattering function |
---|
| 59 | * @param pars: parameters of the ellipsoid |
---|
| 60 | * @param q: q-value |
---|
| 61 | * @return: function value |
---|
| 62 | */ |
---|
| 63 | double ellipsoid_analytical_2DXY(EllipsoidParameters *pars, double qx, double qy) { |
---|
| 64 | double q; |
---|
| 65 | q = sqrt(qx*qx+qy*qy); |
---|
| 66 | return ellipsoid_analytical_2D_scaled(pars, q, qx/q, qy/q); |
---|
[44aa1ed] | 67 | } |
---|
[ae3ce4e] | 68 | |
---|
| 69 | /** |
---|
| 70 | * Function to evaluate 2D scattering function |
---|
| 71 | * @param pars: parameters of the ellipsoid |
---|
| 72 | * @param q: q-value |
---|
| 73 | * @param phi: angle phi |
---|
| 74 | * @return: function value |
---|
| 75 | */ |
---|
| 76 | double ellipsoid_analytical_2D(EllipsoidParameters *pars, double q, double phi) { |
---|
| 77 | return ellipsoid_analytical_2D_scaled(pars, q, cos(phi), sin(phi)); |
---|
[44aa1ed] | 78 | } |
---|
[ae3ce4e] | 79 | |
---|
| 80 | /** |
---|
| 81 | * Function to evaluate 2D scattering function |
---|
| 82 | * @param pars: parameters of the ellipsoid |
---|
| 83 | * @param q: q-value |
---|
| 84 | * @param q_x: q_x / q |
---|
| 85 | * @param q_y: q_y / q |
---|
| 86 | * @return: function value |
---|
| 87 | */ |
---|
| 88 | double ellipsoid_analytical_2D_scaled(EllipsoidParameters *pars, double q, double q_x, double q_y) { |
---|
| 89 | double cyl_x, cyl_y, cyl_z; |
---|
| 90 | double q_z, lenq; |
---|
| 91 | double theta, alpha, f, vol, sin_val, cos_val; |
---|
| 92 | double answer; |
---|
[44aa1ed] | 93 | |
---|
[ae3ce4e] | 94 | // Ellipsoid orientation |
---|
| 95 | cyl_x = sin(pars->axis_theta) * cos(pars->axis_phi); |
---|
| 96 | cyl_y = sin(pars->axis_theta) * sin(pars->axis_phi); |
---|
| 97 | cyl_z = cos(pars->axis_theta); |
---|
[44aa1ed] | 98 | |
---|
[ae3ce4e] | 99 | // q vector |
---|
| 100 | q_z = 0; |
---|
[44aa1ed] | 101 | |
---|
[ae3ce4e] | 102 | // Compute the angle btw vector q and the |
---|
| 103 | // axis of the cylinder |
---|
| 104 | cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; |
---|
[44aa1ed] | 105 | |
---|
[ae3ce4e] | 106 | // The following test should always pass |
---|
| 107 | if (fabs(cos_val)>1.0) { |
---|
| 108 | printf("ellipsoid_ana_2D: Unexpected error: cos(alpha)>1\n"); |
---|
| 109 | return 0; |
---|
| 110 | } |
---|
[44aa1ed] | 111 | |
---|
[ae3ce4e] | 112 | // Angle between rotation axis and q vector |
---|
| 113 | alpha = acos( cos_val ); |
---|
[44aa1ed] | 114 | |
---|
[ae3ce4e] | 115 | // Call the IGOR library function to get the kernel |
---|
[44aa1ed] | 116 | answer = EllipsoidKernel(q, pars->radius_a, pars->radius_b, cos_val); |
---|
| 117 | |
---|
[ae3ce4e] | 118 | // Multiply by contrast^2 |
---|
| 119 | answer *= pars->contrast*pars->contrast; |
---|
[44aa1ed] | 120 | |
---|
[ae3ce4e] | 121 | //normalize by cylinder volume |
---|
| 122 | vol = 4.0/3.0 * acos(-1.0) * pars->radius_b * pars->radius_b * pars->radius_a; |
---|
| 123 | answer *= vol; |
---|
[44aa1ed] | 124 | |
---|
[ae3ce4e] | 125 | //convert to [cm-1] |
---|
| 126 | answer *= 1.0e8; |
---|
[44aa1ed] | 127 | |
---|
[ae3ce4e] | 128 | //Scale |
---|
| 129 | answer *= pars->scale; |
---|
[44aa1ed] | 130 | |
---|
[ae3ce4e] | 131 | // add in the background |
---|
| 132 | answer += pars->background; |
---|
[44aa1ed] | 133 | |
---|
[ae3ce4e] | 134 | return answer; |
---|
| 135 | } |
---|