1 | static double |
---|
2 | sc_Zq(double qa, double qb, double qc, double dnn, double d_factor) |
---|
3 | { |
---|
4 | // Rewriting equations for efficiency, accuracy and readability, and so |
---|
5 | // code is reusable between 1D and 2D models. |
---|
6 | #if 1 // SC |
---|
7 | const double a1 = qa; |
---|
8 | const double a2 = qb; |
---|
9 | const double a3 = qc; |
---|
10 | #elif 1 // BCC |
---|
11 | const double a1 = (+qa + qb + qc)/2.; |
---|
12 | const double a2 = (-qa - qb + qc)/2.; |
---|
13 | const double a3 = (-qa + qb - qc)/2.; |
---|
14 | #elif 1 // FCC |
---|
15 | const double a1 = ( qa + qb)/2.0; |
---|
16 | const double a2 = (-qa + qc)/2.0; |
---|
17 | const double a3 = (-qa + qb)/2.0; |
---|
18 | #endif |
---|
19 | |
---|
20 | const double arg = -0.5*square(dnn*d_factor)*(a1*a1 + a2*a2 + a3*a3); |
---|
21 | |
---|
22 | // Numerator: (1 - exp(a)^2)^3 |
---|
23 | // => (-(exp(2a) - 1))^3 |
---|
24 | // => -expm1(2a)^3 |
---|
25 | // Denominator: prod(1 - 2 cos(xk) exp(a) + exp(a)^2) |
---|
26 | // => exp(a)^2 - 2 cos(xk) exp(a) + 1 |
---|
27 | // => (exp(a) - 2 cos(xk)) * exp(a) + 1 |
---|
28 | const double exp_arg = exp(arg); |
---|
29 | const double Zq = -cube(expm1(2.0*arg)) |
---|
30 | / ( ((exp_arg - 2.0*cos(dnn*a1))*exp_arg + 1.0) |
---|
31 | * ((exp_arg - 2.0*cos(dnn*a2))*exp_arg + 1.0) |
---|
32 | * ((exp_arg - 2.0*cos(dnn*a3))*exp_arg + 1.0)); |
---|
33 | |
---|
34 | return Zq; |
---|
35 | } |
---|
36 | |
---|
37 | // occupied volume fraction calculated from lattice symmetry and sphere radius |
---|
38 | static double |
---|
39 | sc_volume_fraction(double radius, double dnn) |
---|
40 | { |
---|
41 | return sphere_volume(radius/dnn); |
---|
42 | } |
---|
43 | |
---|
44 | static double |
---|
45 | form_volume(double radius) |
---|
46 | { |
---|
47 | return sphere_volume(radius); |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | static double Iq(double q, double dnn, |
---|
52 | double d_factor, double radius, |
---|
53 | double sld, double solvent_sld, |
---|
54 | double n, double sym) |
---|
55 | { |
---|
56 | double phi_m, phi_b, theta_m, theta_b; |
---|
57 | if (sym>0.) { |
---|
58 | // translate a point in [-1,1] to a point in [0, 2 pi] |
---|
59 | phi_m = M_PI_4; |
---|
60 | phi_b = M_PI_4; |
---|
61 | // translate a point in [-1,1] to a point in [0, pi] |
---|
62 | theta_m = M_PI_4; |
---|
63 | theta_b = M_PI_4; |
---|
64 | } else { |
---|
65 | // translate a point in [-1,1] to a point in [0, 2 pi] |
---|
66 | phi_m = M_PI; |
---|
67 | phi_b = M_PI; |
---|
68 | // translate a point in [-1,1] to a point in [0, pi] |
---|
69 | theta_m = M_PI_2; |
---|
70 | theta_b = M_PI_2; |
---|
71 | } |
---|
72 | |
---|
73 | #if 0 |
---|
74 | double outer_sum = 0.0; |
---|
75 | for(int i=0; i<150; i++) { |
---|
76 | double inner_sum = 0.0; |
---|
77 | const double theta = Gauss150Z[i]*theta_m + theta_b; |
---|
78 | double sin_theta, cos_theta; |
---|
79 | SINCOS(theta, sin_theta, cos_theta); |
---|
80 | const double qc = q*cos_theta; |
---|
81 | const double qab = q*sin_theta; |
---|
82 | for(int j=0;j<150;j++) { |
---|
83 | const double phi = Gauss150Z[j]*phi_m + phi_b; |
---|
84 | double sin_phi, cos_phi; |
---|
85 | SINCOS(phi, sin_phi, cos_phi); |
---|
86 | const double qa = qab*cos_phi; |
---|
87 | const double qb = qab*sin_phi; |
---|
88 | const double fq = _sq_sc(qa, qb, qc, dnn, d_factor); |
---|
89 | inner_sum += Gauss150Wt[j] * fq; |
---|
90 | } |
---|
91 | inner_sum *= phi_m; // sum(f(x)dx) = sum(f(x)) dx |
---|
92 | outer_sum += Gauss150Wt[i] * inner_sum * sin_theta; |
---|
93 | } |
---|
94 | outer_sum *= theta_m; |
---|
95 | #else |
---|
96 | double outer_sum = 0.0; |
---|
97 | for(int i=0; i<(int)n; i++) { |
---|
98 | double inner_sum = 0.0; |
---|
99 | const double theta = (i*2./n-1.)*theta_m + theta_b; |
---|
100 | double sin_theta, cos_theta; |
---|
101 | SINCOS(theta, sin_theta, cos_theta); |
---|
102 | const double qc = q*cos_theta; |
---|
103 | const double qab = q*sin_theta; |
---|
104 | for(int j=0;j<(int)n;j++) { |
---|
105 | const double phi = (j*2./n-1.)*phi_m + phi_b; |
---|
106 | double sin_phi, cos_phi; |
---|
107 | SINCOS(phi, sin_phi, cos_phi); |
---|
108 | const double qa = qab*cos_phi; |
---|
109 | const double qb = qab*sin_phi; |
---|
110 | const double form = sc_Zq(qa, qb, qc, dnn, d_factor); |
---|
111 | inner_sum += form; |
---|
112 | } |
---|
113 | inner_sum *= phi_m; // sum(f(x)dx) = sum(f(x)) dx |
---|
114 | outer_sum += inner_sum * sin_theta; |
---|
115 | } |
---|
116 | outer_sum *= theta_m/(n*n); |
---|
117 | #endif |
---|
118 | double Zq; |
---|
119 | if (sym > 0.) { |
---|
120 | Zq = outer_sum/M_PI_2; |
---|
121 | } else { |
---|
122 | Zq = outer_sum/(4.0*M_PI); |
---|
123 | } |
---|
124 | |
---|
125 | //return Zq; |
---|
126 | const double Pq = sphere_form(q, radius, sld, solvent_sld); |
---|
127 | return sc_volume_fraction(radius, dnn) * Pq * Zq; |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | static double Iqxy(double qx, double qy, |
---|
132 | double dnn, double d_factor, double radius, |
---|
133 | double sld, double solvent_sld, |
---|
134 | double n, double sym, |
---|
135 | double theta, double phi, double psi) |
---|
136 | { |
---|
137 | double q, zhat, yhat, xhat; |
---|
138 | ORIENT_ASYMMETRIC(qx, qy, theta, phi, psi, q, xhat, yhat, zhat); |
---|
139 | const double qa = q*xhat; |
---|
140 | const double qb = q*yhat; |
---|
141 | const double qc = q*zhat; |
---|
142 | |
---|
143 | q = sqrt(qa*qa + qb*qb + qc*qc); |
---|
144 | const double Pq = sphere_form(q, radius, sld, solvent_sld); |
---|
145 | const double Zq = sc_Zq(qa, qb, qc, dnn, d_factor); |
---|
146 | return Zq; |
---|
147 | return sc_volume_fraction(radius, dnn) * Pq * Zq; |
---|
148 | } |
---|