1 | /* |
---|
2 | * Scattering model for a SC_ParaCrystal |
---|
3 | */ |
---|
4 | #include "fcc.h" |
---|
5 | #include "libSphere.h" |
---|
6 | #include <math.h> |
---|
7 | |
---|
8 | |
---|
9 | /** |
---|
10 | * Function to evaluate 1D scattering function |
---|
11 | * @param pars: parameters of the FCC_ParaCrystal |
---|
12 | * @param q: q-value |
---|
13 | * @return: function value |
---|
14 | */ |
---|
15 | double fcc_analytical_1D(FCParameters *pars, double q) { |
---|
16 | double dp[7]; |
---|
17 | double result; |
---|
18 | |
---|
19 | dp[0] = pars->scale; |
---|
20 | dp[1] = pars->dnn; |
---|
21 | dp[2] = pars->d_factor; |
---|
22 | dp[3] = pars->radius; |
---|
23 | dp[4] = pars->sldSph; |
---|
24 | dp[5] = pars->sldSolv; |
---|
25 | dp[6] = pars->background; |
---|
26 | |
---|
27 | result = FCC_ParaCrystal(dp, q); |
---|
28 | // This FIXES a singualrity the kernel in libigor. |
---|
29 | if ( result == INFINITY || result == NAN){ |
---|
30 | result = pars->background; |
---|
31 | } |
---|
32 | return result; |
---|
33 | } |
---|
34 | |
---|
35 | /** |
---|
36 | * Function to evaluate 2D scattering function |
---|
37 | * @param pars: parameters of the FCC_ParaCrystal |
---|
38 | * @param q: q-value |
---|
39 | * @return: function value |
---|
40 | */ |
---|
41 | double fc_analytical_2DXY(FCParameters *pars, double qx, double qy){ |
---|
42 | double q; |
---|
43 | q = sqrt(qx*qx+qy*qy); |
---|
44 | return fc_analytical_2D_scaled(pars, q, qx/q, qy/q); |
---|
45 | } |
---|
46 | |
---|
47 | double fc_analytical_2D(FCParameters *pars, double q, double phi) { |
---|
48 | return fc_analytical_2D_scaled(pars, q, cos(phi), sin(phi)); |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | * Function to evaluate 2D scattering function |
---|
53 | * @param pars: parameters of the FCCCrystalModel |
---|
54 | * @param q: q-value |
---|
55 | * @param q_x: q_x / q |
---|
56 | * @param q_y: q_y / q |
---|
57 | * @return: function value |
---|
58 | */ |
---|
59 | double fc_analytical_2D_scaled(FCParameters *pars, double q, double q_x, double q_y) { |
---|
60 | double a3_x, a3_y, a3_z, a2_x, a2_y, a1_x, a1_y; |
---|
61 | double b3_x, b3_y, b3_z, b2_x, b2_y, b1_x, b1_y; |
---|
62 | double q_z; |
---|
63 | double alpha, vol, cos_val_a3, cos_val_a2, cos_val_a1; |
---|
64 | double a1_dot_q, a2_dot_q,a3_dot_q; |
---|
65 | double answer; |
---|
66 | double Pi = 4.0*atan(1.0); |
---|
67 | double aa, Da, qDa_2, latticeScale, Zq, Fkq, Fkq_2,contrast; |
---|
68 | |
---|
69 | double dp[5]; |
---|
70 | dp[0] = 1.0; |
---|
71 | dp[1] = pars->radius; |
---|
72 | dp[2] = pars->sldSph; |
---|
73 | dp[3] = pars->sldSolv; |
---|
74 | dp[4] = 0.0; |
---|
75 | |
---|
76 | aa = pars->dnn; |
---|
77 | Da = pars->d_factor*aa; |
---|
78 | qDa_2 = pow(q*Da,2.0); |
---|
79 | contrast = pars->sldSph - pars->sldSolv; |
---|
80 | |
---|
81 | latticeScale = 4.0*(4.0/3.0)*Pi*(dp[1]*dp[1]*dp[1])/pow(aa*sqrt(2.0),3.0); |
---|
82 | |
---|
83 | /// Angles here are respect to detector coordinate |
---|
84 | /// instead of against q coordinate(PRB 36(46), 3(6), 1754(3854)) |
---|
85 | // b3 axis orientation |
---|
86 | b3_x = sin(pars->theta) * cos(pars->phi);//negative sign here??? |
---|
87 | b3_y = sin(pars->theta) * sin(pars->phi); |
---|
88 | b3_z = cos(pars->theta); |
---|
89 | // b1 axis orientation |
---|
90 | b1_x = sin(pars->psi); |
---|
91 | b1_y = cos(pars->psi); |
---|
92 | // b2 axis orientation |
---|
93 | b2_x = sqrt(1-sin(pars->theta)*cos(pars->phi))*cos(pars->psi); |
---|
94 | b2_y = sqrt(1-sin(pars->theta)*cos(pars->phi))*sin(pars->psi); |
---|
95 | |
---|
96 | // a3 axis orientation |
---|
97 | a3_x = 0.5*(b2_x + b1_x); |
---|
98 | a3_y = 0.5*(b2_y + b1_y); |
---|
99 | a3_z = 0.0; |
---|
100 | // a1 axis orientation |
---|
101 | a1_x = 0.5*(b3_x + b2_x); |
---|
102 | a1_y = 0.5*(b3_y + b2_y); |
---|
103 | // a2 axis orientation |
---|
104 | a2_x = 0.5*(b3_x + b1_x); |
---|
105 | a2_y = 0.5*(b3_y + b1_y); |
---|
106 | |
---|
107 | // q vector |
---|
108 | q_z = 0.0; // for SANS; assuming qz is negligible |
---|
109 | |
---|
110 | // Compute the angle btw vector q and the a3 axis |
---|
111 | cos_val_a3 = a3_x*q_x + a3_y*q_y + a3_z*q_z; |
---|
112 | a3_dot_q = aa*q*cos_val_a3; |
---|
113 | |
---|
114 | // a1 axis |
---|
115 | cos_val_a1 = a1_x*q_x + a1_y*q_y; |
---|
116 | a1_dot_q = aa*q*cos_val_a1; |
---|
117 | |
---|
118 | // a2 axis |
---|
119 | cos_val_a2 = a2_x*q_x + a2_y*q_y; //sin(acos(cos_val_a1)) ; |
---|
120 | a2_dot_q = aa*q*cos_val_a2; |
---|
121 | |
---|
122 | // The following test should always pass |
---|
123 | if (fabs(cos_val_a3)>1.0) { |
---|
124 | printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); |
---|
125 | return 0; |
---|
126 | } |
---|
127 | // Get Fkq and Fkq_2 |
---|
128 | Fkq = exp(-0.5*pow(Da/aa,2.0)*(a1_dot_q*a1_dot_q+a2_dot_q*a2_dot_q+a3_dot_q*a3_dot_q)); |
---|
129 | Fkq_2 = Fkq*Fkq; |
---|
130 | // Call Zq=Z1*Z2*Z3 |
---|
131 | Zq = (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a1_dot_q)+Fkq_2); |
---|
132 | Zq = Zq * (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a2_dot_q)+Fkq_2); |
---|
133 | Zq = Zq * (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a3_dot_q)+Fkq_2); |
---|
134 | |
---|
135 | // Use SphereForm directly from libigor |
---|
136 | answer = SphereForm_Paracrystal(pars->radius,contrast,q)*Zq; |
---|
137 | |
---|
138 | //consider scales |
---|
139 | answer *= latticeScale * pars->scale; |
---|
140 | |
---|
141 | // This FIXES a singualrity the kernel in libigor. |
---|
142 | if ( answer == INFINITY || answer == NAN){ |
---|
143 | answer = 0.0; |
---|
144 | } |
---|
145 | |
---|
146 | // add background |
---|
147 | answer += pars->background; |
---|
148 | |
---|
149 | return answer; |
---|
150 | } |
---|