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