1 | /** |
---|
2 | This software was developed by the University of Tennessee as part of the |
---|
3 | Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
4 | project funded by the US National Science Foundation. |
---|
5 | |
---|
6 | If you use DANSE applications to do scientific research that leads to |
---|
7 | publication, we ask that you acknowledge the use of the software with the |
---|
8 | following sentence: |
---|
9 | |
---|
10 | "This work benefited from DANSE software developed under NSF award DMR-0520547." |
---|
11 | |
---|
12 | copyright 2008, University of Tennessee |
---|
13 | */ |
---|
14 | |
---|
15 | /** |
---|
16 | * Scattering model classes |
---|
17 | * The classes use the IGOR library found in |
---|
18 | * sansmodels/src/libigor |
---|
19 | * |
---|
20 | * TODO: refactor so that we pull in the old sansmodels.c_extensions |
---|
21 | */ |
---|
22 | |
---|
23 | #include <math.h> |
---|
24 | #include "models.hh" |
---|
25 | #include "parameters.hh" |
---|
26 | #include <stdio.h> |
---|
27 | using namespace std; |
---|
28 | |
---|
29 | extern "C" { |
---|
30 | #include "libCylinder.h" |
---|
31 | #include "libStructureFactor.h" |
---|
32 | #include "core_shell_cylinder.h" |
---|
33 | } |
---|
34 | |
---|
35 | CoreShellCylinderModel :: CoreShellCylinderModel() { |
---|
36 | scale = Parameter(1.0); |
---|
37 | radius = Parameter(20.0, true); |
---|
38 | radius.set_min(0.0); |
---|
39 | thickness = Parameter(10.0, true); |
---|
40 | thickness.set_min(0.0); |
---|
41 | length = Parameter(400.0, true); |
---|
42 | length.set_min(0.0); |
---|
43 | core_sld = Parameter(1.e-6); |
---|
44 | shell_sld = Parameter(4.e-6); |
---|
45 | solvent_sld= Parameter(1.e-6); |
---|
46 | background = Parameter(0.0); |
---|
47 | axis_theta = Parameter(0.0, true); |
---|
48 | axis_phi = Parameter(0.0, true); |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | * Function to evaluate 1D scattering function |
---|
53 | * The NIST IGOR library is used for the actual calculation. |
---|
54 | * @param q: q-value |
---|
55 | * @return: function value |
---|
56 | */ |
---|
57 | double CoreShellCylinderModel :: operator()(double q) { |
---|
58 | double dp[8]; |
---|
59 | |
---|
60 | dp[0] = scale(); |
---|
61 | dp[1] = radius(); |
---|
62 | dp[2] = thickness(); |
---|
63 | dp[3] = length(); |
---|
64 | dp[4] = core_sld(); |
---|
65 | dp[5] = shell_sld(); |
---|
66 | dp[6] = solvent_sld(); |
---|
67 | dp[7] = 0.0; |
---|
68 | |
---|
69 | // Get the dispersion points for the radius |
---|
70 | vector<WeightPoint> weights_rad; |
---|
71 | radius.get_weights(weights_rad); |
---|
72 | |
---|
73 | // Get the dispersion points for the thickness |
---|
74 | vector<WeightPoint> weights_thick; |
---|
75 | thickness.get_weights(weights_thick); |
---|
76 | |
---|
77 | // Get the dispersion points for the length |
---|
78 | vector<WeightPoint> weights_len; |
---|
79 | length.get_weights(weights_len); |
---|
80 | |
---|
81 | // Perform the computation, with all weight points |
---|
82 | double sum = 0.0; |
---|
83 | double norm = 0.0; |
---|
84 | |
---|
85 | // Loop over radius weight points |
---|
86 | for(int i=0; i<weights_rad.size(); i++) { |
---|
87 | dp[1] = weights_rad[i].value; |
---|
88 | |
---|
89 | // Loop over length weight points |
---|
90 | for(int j=0; j<weights_len.size(); j++) { |
---|
91 | dp[3] = weights_len[j].value; |
---|
92 | |
---|
93 | // Loop over thickness weight points |
---|
94 | for(int k=0; k<weights_thick.size(); k++) { |
---|
95 | dp[2] = weights_thick[k].value; |
---|
96 | |
---|
97 | sum += weights_rad[i].weight |
---|
98 | * weights_len[j].weight |
---|
99 | * weights_thick[k].weight |
---|
100 | * CoreShellCylinder(dp, q); |
---|
101 | norm += weights_rad[i].weight |
---|
102 | * weights_len[j].weight |
---|
103 | * weights_thick[k].weight; |
---|
104 | } |
---|
105 | } |
---|
106 | } |
---|
107 | return sum/norm + background(); |
---|
108 | } |
---|
109 | |
---|
110 | /** |
---|
111 | * Function to evaluate 2D scattering function |
---|
112 | * @param q_x: value of Q along x |
---|
113 | * @param q_y: value of Q along y |
---|
114 | * @return: function value |
---|
115 | */ |
---|
116 | double CoreShellCylinderModel :: operator()(double qx, double qy) { |
---|
117 | CoreShellCylinderParameters dp; |
---|
118 | // Fill parameter array |
---|
119 | dp.scale = scale(); |
---|
120 | dp.radius = radius(); |
---|
121 | dp.thickness = thickness(); |
---|
122 | dp.length = length(); |
---|
123 | dp.core_sld = core_sld(); |
---|
124 | dp.shell_sld = shell_sld(); |
---|
125 | dp.solvent_sld= solvent_sld(); |
---|
126 | dp.background = 0.0; |
---|
127 | dp.axis_theta = axis_theta(); |
---|
128 | dp.axis_phi = axis_phi(); |
---|
129 | |
---|
130 | // Get the dispersion points for the radius |
---|
131 | vector<WeightPoint> weights_rad; |
---|
132 | radius.get_weights(weights_rad); |
---|
133 | |
---|
134 | // Get the dispersion points for the thickness |
---|
135 | vector<WeightPoint> weights_thick; |
---|
136 | thickness.get_weights(weights_thick); |
---|
137 | |
---|
138 | // Get the dispersion points for the length |
---|
139 | vector<WeightPoint> weights_len; |
---|
140 | length.get_weights(weights_len); |
---|
141 | |
---|
142 | // Get angular averaging for theta |
---|
143 | vector<WeightPoint> weights_theta; |
---|
144 | axis_theta.get_weights(weights_theta); |
---|
145 | |
---|
146 | // Get angular averaging for phi |
---|
147 | vector<WeightPoint> weights_phi; |
---|
148 | axis_phi.get_weights(weights_phi); |
---|
149 | |
---|
150 | // Perform the computation, with all weight points |
---|
151 | double sum = 0.0; |
---|
152 | double norm = 0.0; |
---|
153 | |
---|
154 | // Loop over radius weight points |
---|
155 | for(int i=0; i<weights_rad.size(); i++) { |
---|
156 | dp.radius = weights_rad[i].value; |
---|
157 | |
---|
158 | |
---|
159 | // Loop over length weight points |
---|
160 | for(int j=0; j<weights_len.size(); j++) { |
---|
161 | dp.length = weights_len[j].value; |
---|
162 | |
---|
163 | // Loop over thickness weight points |
---|
164 | for(int m=0; m<weights_thick.size(); m++) { |
---|
165 | dp.thickness = weights_thick[m].value; |
---|
166 | |
---|
167 | // Average over theta distribution |
---|
168 | for(int k=0; k<weights_theta.size(); k++) { |
---|
169 | dp.axis_theta = weights_theta[k].value; |
---|
170 | |
---|
171 | // Average over phi distribution |
---|
172 | for(int l=0; l<weights_phi.size(); l++) { |
---|
173 | dp.axis_phi = weights_phi[l].value; |
---|
174 | |
---|
175 | double _ptvalue = weights_rad[i].weight |
---|
176 | * weights_len[j].weight |
---|
177 | * weights_thick[m].weight |
---|
178 | * weights_theta[k].weight |
---|
179 | * weights_phi[l].weight |
---|
180 | * core_shell_cylinder_analytical_2DXY(&dp, qx, qy); |
---|
181 | if (weights_theta.size()>1) { |
---|
182 | _ptvalue *= sin(weights_theta[k].value); |
---|
183 | } |
---|
184 | sum += _ptvalue; |
---|
185 | |
---|
186 | norm += weights_rad[i].weight |
---|
187 | * weights_len[j].weight |
---|
188 | * weights_thick[m].weight |
---|
189 | * weights_theta[k].weight |
---|
190 | * weights_phi[l].weight; |
---|
191 | |
---|
192 | } |
---|
193 | } |
---|
194 | } |
---|
195 | } |
---|
196 | } |
---|
197 | // Averaging in theta needs an extra normalization |
---|
198 | // factor to account for the sin(theta) term in the |
---|
199 | // integration (see documentation). |
---|
200 | if (weights_theta.size()>1) norm = norm / asin(1.0); |
---|
201 | return sum/norm + background(); |
---|
202 | } |
---|
203 | |
---|
204 | /** |
---|
205 | * Function to evaluate 2D scattering function |
---|
206 | * @param pars: parameters of the cylinder |
---|
207 | * @param q: q-value |
---|
208 | * @param phi: angle phi |
---|
209 | * @return: function value |
---|
210 | */ |
---|
211 | double CoreShellCylinderModel :: evaluate_rphi(double q, double phi) { |
---|
212 | double qx = q*cos(phi); |
---|
213 | double qy = q*sin(phi); |
---|
214 | return (*this).operator()(qx, qy); |
---|
215 | } |
---|
216 | /** |
---|
217 | * Function to calculate effective radius |
---|
218 | * @return: effective radius value |
---|
219 | */ |
---|
220 | double CoreShellCylinderModel :: calculate_ER() { |
---|
221 | CoreShellCylinderParameters dp; |
---|
222 | |
---|
223 | dp.radius = radius(); |
---|
224 | dp.thickness = thickness(); |
---|
225 | dp.length = length(); |
---|
226 | double rad_out = 0.0; |
---|
227 | |
---|
228 | // Perform the computation, with all weight points |
---|
229 | double sum = 0.0; |
---|
230 | double norm = 0.0; |
---|
231 | |
---|
232 | // Get the dispersion points for the length |
---|
233 | vector<WeightPoint> weights_length; |
---|
234 | length.get_weights(weights_length); |
---|
235 | |
---|
236 | // Get the dispersion points for the thickness |
---|
237 | vector<WeightPoint> weights_thickness; |
---|
238 | thickness.get_weights(weights_thickness); |
---|
239 | |
---|
240 | // Get the dispersion points for the radius |
---|
241 | vector<WeightPoint> weights_radius ; |
---|
242 | radius.get_weights(weights_radius); |
---|
243 | |
---|
244 | // Loop over major shell weight points |
---|
245 | for(int i=0; i< (int)weights_length.size(); i++) { |
---|
246 | dp.length = weights_length[i].value; |
---|
247 | for(int j=0; j< (int)weights_thickness.size(); j++) { |
---|
248 | dp.thickness = weights_thickness[j].value; |
---|
249 | for(int k=0; k< (int)weights_radius.size(); k++) { |
---|
250 | dp.radius = weights_radius[k].value; |
---|
251 | //Note: output of "DiamCyl( )" is DIAMETER. |
---|
252 | sum +=weights_length[i].weight * weights_thickness[j].weight |
---|
253 | * weights_radius[k].weight*DiamCyl(dp.length+2.0*dp.thickness,dp.radius+dp.thickness)/2.0; |
---|
254 | norm += weights_length[i].weight* weights_thickness[j].weight* weights_radius[k].weight; |
---|
255 | } |
---|
256 | } |
---|
257 | } |
---|
258 | if (norm != 0){ |
---|
259 | //return the averaged value |
---|
260 | rad_out = sum/norm;} |
---|
261 | else{ |
---|
262 | //return normal value |
---|
263 | //Note: output of "DiamCyl()" is DIAMETER. |
---|
264 | rad_out = DiamCyl(dp.length+2.0*dp.thickness,dp.radius+dp.thickness)/2.0;} |
---|
265 | |
---|
266 | return rad_out; |
---|
267 | } |
---|