[8a48713] | 1 | /** |
---|
| 2 | * Scattering model for a parallelepiped |
---|
| 3 | * TODO: Add 2D analysis |
---|
| 4 | */ |
---|
| 5 | |
---|
| 6 | #include "parallelepiped.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 |
---|
[5068697] | 15 | * @param pars: parameters of the parallelepiped |
---|
[8a48713] | 16 | * @param q: q-value |
---|
| 17 | * @return: function value |
---|
| 18 | */ |
---|
| 19 | double parallelepiped_analytical_1D(ParallelepipedParameters *pars, double q) { |
---|
| 20 | double dp[6]; |
---|
[975ec8e] | 21 | |
---|
[8a48713] | 22 | // Fill paramater array |
---|
| 23 | dp[0] = pars->scale; |
---|
[2cb89e7] | 24 | dp[1] = pars->short_a; |
---|
[8e36cdd] | 25 | dp[2] = pars->short_b; |
---|
| 26 | dp[3] = pars->long_c; |
---|
[8a48713] | 27 | dp[4] = pars->contrast; |
---|
| 28 | dp[5] = pars->background; |
---|
| 29 | |
---|
| 30 | // Call library function to evaluate model |
---|
[975ec8e] | 31 | return Parallelepiped(dp, q); |
---|
[8a48713] | 32 | } |
---|
[975ec8e] | 33 | |
---|
| 34 | |
---|
| 35 | double pkernel(double a, double b,double c, double ala, double alb, double alc){ |
---|
| 36 | // mu passed in is really mu*sqrt(1-sig^2) |
---|
| 37 | double argA,argB,argC,tmp1,tmp2,tmp3; //local variables |
---|
| 38 | |
---|
| 39 | //handle arg=0 separately, as sin(t)/t -> 1 as t->0 |
---|
[2cb89e7] | 40 | argA = a*ala/2; |
---|
| 41 | argB = b*alb/2; |
---|
| 42 | argC = c*alc/2; |
---|
[975ec8e] | 43 | if(argA==0.0) { |
---|
| 44 | tmp1 = 1.0; |
---|
| 45 | } else { |
---|
| 46 | tmp1 = sin(argA)*sin(argA)/argA/argA; |
---|
| 47 | } |
---|
| 48 | if (argB==0.0) { |
---|
| 49 | tmp2 = 1.0; |
---|
| 50 | } else { |
---|
| 51 | tmp2 = sin(argB)*sin(argB)/argB/argB; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | if (argC==0.0) { |
---|
| 55 | tmp3 = 1.0; |
---|
| 56 | } else { |
---|
| 57 | tmp3 = sin(argC)*sin(argC)/argC/argC; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | return (tmp1*tmp2*tmp3); |
---|
| 61 | |
---|
| 62 | }//Function pkernel() |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | |
---|
[8a48713] | 67 | /** |
---|
| 68 | * Function to evaluate 2D scattering function |
---|
[5068697] | 69 | * @param pars: parameters of the parallelepiped |
---|
[8a48713] | 70 | * @param q: q-value |
---|
| 71 | * @return: function value |
---|
| 72 | */ |
---|
| 73 | double parallelepiped_analytical_2DXY(ParallelepipedParameters *pars, double qx, double qy) { |
---|
| 74 | double q; |
---|
| 75 | q = sqrt(qx*qx+qy*qy); |
---|
| 76 | return parallelepiped_analytical_2D_scaled(pars, q, qx/q, qy/q); |
---|
[975ec8e] | 77 | } |
---|
[8a48713] | 78 | |
---|
| 79 | |
---|
| 80 | /** |
---|
| 81 | * Function to evaluate 2D scattering function |
---|
| 82 | * @param pars: parameters of the Parallelepiped |
---|
| 83 | * @param q: q-value |
---|
| 84 | * @param phi: angle phi |
---|
| 85 | * @return: function value |
---|
| 86 | */ |
---|
| 87 | double parallelepiped_analytical_2D(ParallelepipedParameters *pars, double q, double phi) { |
---|
| 88 | return parallelepiped_analytical_2D_scaled(pars, q, cos(phi), sin(phi)); |
---|
[975ec8e] | 89 | } |
---|
| 90 | |
---|
[8a48713] | 91 | /** |
---|
| 92 | * Function to evaluate 2D scattering function |
---|
| 93 | * @param pars: parameters of the parallelepiped |
---|
| 94 | * @param q: q-value |
---|
| 95 | * @param q_x: q_x / q |
---|
| 96 | * @param q_y: q_y / q |
---|
| 97 | * @return: function value |
---|
| 98 | */ |
---|
| 99 | double parallelepiped_analytical_2D_scaled(ParallelepipedParameters *pars, double q, double q_x, double q_y) { |
---|
[8e36cdd] | 100 | double cparallel_x, cparallel_y, cparallel_z, bparallel_x, bparallel_y, parallel_x, parallel_y, parallel_z; |
---|
[8a48713] | 101 | double q_z; |
---|
[975ec8e] | 102 | double alpha, vol, cos_val_c, cos_val_b, cos_val_a, edgeA, edgeB, edgeC; |
---|
| 103 | |
---|
[8a48713] | 104 | double answer; |
---|
[975ec8e] | 105 | double pi = 4.0*atan(1.0); |
---|
| 106 | |
---|
[2cb89e7] | 107 | edgeA = pars->short_a; |
---|
[8e36cdd] | 108 | edgeB = pars->short_b; |
---|
| 109 | edgeC = pars->long_c; |
---|
[975ec8e] | 110 | |
---|
| 111 | |
---|
| 112 | // parallelepiped c axis orientation |
---|
[8e36cdd] | 113 | cparallel_x = sin(pars->parallel_theta) * cos(pars->parallel_phi); |
---|
| 114 | cparallel_y = sin(pars->parallel_theta) * sin(pars->parallel_phi); |
---|
| 115 | cparallel_z = cos(pars->parallel_theta); |
---|
[975ec8e] | 116 | |
---|
[8a48713] | 117 | // q vector |
---|
| 118 | q_z = 0; |
---|
[975ec8e] | 119 | |
---|
[8a48713] | 120 | // Compute the angle btw vector q and the |
---|
| 121 | // axis of the parallelepiped |
---|
[8e36cdd] | 122 | cos_val_c = cparallel_x*q_x + cparallel_y*q_y + cparallel_z*q_z; |
---|
[975ec8e] | 123 | alpha = acos(cos_val_c); |
---|
| 124 | |
---|
| 125 | // parallelepiped a axis orientation |
---|
[8e36cdd] | 126 | parallel_x = sin(pars->parallel_psi);//cos(pars->parallel_theta) * sin(pars->parallel_phi)*sin(pars->parallel_psi); |
---|
| 127 | parallel_y = cos(pars->parallel_psi);//cos(pars->parallel_theta) * cos(pars->parallel_phi)*cos(pars->parallel_psi); |
---|
[3c102d4] | 128 | |
---|
[8e36cdd] | 129 | cos_val_a = parallel_x*q_x + parallel_y*q_y; |
---|
[975ec8e] | 130 | |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | // parallelepiped b axis orientation |
---|
[8e36cdd] | 134 | bparallel_x = sqrt(1-sin(pars->parallel_theta)*cos(pars->parallel_phi))*cos(pars->parallel_psi);//cos(pars->parallel_theta) * cos(pars->parallel_phi)* cos(pars->parallel_psi); |
---|
| 135 | bparallel_y = sqrt(1-sin(pars->parallel_theta)*cos(pars->parallel_phi))*sin(pars->parallel_psi);//cos(pars->parallel_theta) * sin(pars->parallel_phi)* sin(pars->parallel_psi); |
---|
[975ec8e] | 136 | // axis of the parallelepiped |
---|
[8e36cdd] | 137 | cos_val_b = sin(acos(cos_val_a)) ; |
---|
[975ec8e] | 138 | |
---|
| 139 | |
---|
| 140 | |
---|
[8a48713] | 141 | // The following test should always pass |
---|
[975ec8e] | 142 | if (fabs(cos_val_c)>1.0) { |
---|
[8a48713] | 143 | printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); |
---|
| 144 | return 0; |
---|
| 145 | } |
---|
[975ec8e] | 146 | |
---|
[8a48713] | 147 | // Call the IGOR library function to get the kernel |
---|
[8e36cdd] | 148 | answer = pkernel( q*edgeA, q*edgeB, q*edgeC, sin(alpha)*cos_val_a,sin(alpha)*cos_val_b,cos_val_c); |
---|
[975ec8e] | 149 | |
---|
[8a48713] | 150 | // Multiply by contrast^2 |
---|
| 151 | answer *= pars->contrast*pars->contrast; |
---|
[975ec8e] | 152 | |
---|
[8a48713] | 153 | //normalize by cylinder volume |
---|
| 154 | //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vparallel |
---|
[2cb89e7] | 155 | vol = edgeA* edgeB * edgeC; |
---|
[8a48713] | 156 | answer *= vol; |
---|
[975ec8e] | 157 | |
---|
[8a48713] | 158 | //convert to [cm-1] |
---|
| 159 | answer *= 1.0e8; |
---|
[975ec8e] | 160 | |
---|
[8a48713] | 161 | //Scale |
---|
| 162 | answer *= pars->scale; |
---|
[975ec8e] | 163 | |
---|
[8a48713] | 164 | // add in the background |
---|
| 165 | answer += pars->background; |
---|
[975ec8e] | 166 | |
---|
[8a48713] | 167 | return answer; |
---|
| 168 | } |
---|
| 169 | |
---|