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 "hollow_cylinder.h" |
---|
33 | } |
---|
34 | |
---|
35 | HollowCylinderModel :: HollowCylinderModel() { |
---|
36 | scale = Parameter(1.0); |
---|
37 | core_radius = Parameter(20.0, true); |
---|
38 | core_radius.set_min(0.0); |
---|
39 | radius = Parameter(30.0, true); |
---|
40 | radius.set_min(0.0); |
---|
41 | length = Parameter(400.0, true); |
---|
42 | length.set_min(0.0); |
---|
43 | contrast = Parameter(5.3e-6); |
---|
44 | background = Parameter(0.0); |
---|
45 | axis_theta = Parameter(0.0, true); |
---|
46 | axis_phi = Parameter(0.0, true); |
---|
47 | } |
---|
48 | |
---|
49 | /** |
---|
50 | * Function to evaluate 1D scattering function |
---|
51 | * The NIST IGOR library is used for the actual calculation. |
---|
52 | * @param q: q-value |
---|
53 | * @return: function value |
---|
54 | */ |
---|
55 | double HollowCylinderModel :: operator()(double q) { |
---|
56 | double dp[6]; |
---|
57 | |
---|
58 | dp[0] = scale(); |
---|
59 | dp[1] = core_radius(); |
---|
60 | dp[2] = radius(); |
---|
61 | dp[3] = length(); |
---|
62 | dp[4] = contrast(); |
---|
63 | dp[5] = 0.0; |
---|
64 | |
---|
65 | // Get the dispersion points for the core radius |
---|
66 | vector<WeightPoint> weights_core_radius; |
---|
67 | core_radius.get_weights(weights_core_radius); |
---|
68 | |
---|
69 | // Get the dispersion points for the shell radius |
---|
70 | vector<WeightPoint> weights_radius; |
---|
71 | radius.get_weights(weights_radius); |
---|
72 | |
---|
73 | // Get the dispersion points for the length |
---|
74 | vector<WeightPoint> weights_length; |
---|
75 | length.get_weights(weights_length); |
---|
76 | |
---|
77 | // Perform the computation, with all weight points |
---|
78 | double sum = 0.0; |
---|
79 | double norm = 0.0; |
---|
80 | |
---|
81 | // Loop over core radius weight points |
---|
82 | for(int i=0; i< (int)weights_core_radius.size(); i++) { |
---|
83 | dp[1] = weights_core_radius[i].value; |
---|
84 | |
---|
85 | // Loop over length weight points |
---|
86 | for(int j=0; j< (int)weights_length.size(); j++) { |
---|
87 | dp[3] = weights_length[j].value; |
---|
88 | |
---|
89 | // Loop over shell radius weight points |
---|
90 | for(int k=0; k< (int)weights_radius.size(); k++) { |
---|
91 | dp[2] = weights_radius[k].value; |
---|
92 | |
---|
93 | sum += weights_core_radius[i].weight |
---|
94 | * weights_length[j].weight |
---|
95 | * weights_radius[k].weight |
---|
96 | * HollowCylinder(dp, q); |
---|
97 | norm += weights_core_radius[i].weight |
---|
98 | * weights_length[j].weight |
---|
99 | * weights_radius[k].weight; |
---|
100 | } |
---|
101 | } |
---|
102 | } |
---|
103 | return sum/norm + background(); |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | * Function to evaluate 2D scattering function |
---|
108 | * @param q_x: value of Q along x |
---|
109 | * @param q_y: value of Q along y |
---|
110 | * @return: function value |
---|
111 | */ |
---|
112 | double HollowCylinderModel :: operator()(double qx, double qy) { |
---|
113 | HollowCylinderParameters dp; |
---|
114 | // Fill parameter array |
---|
115 | dp.scale = scale(); |
---|
116 | dp.core_radius = core_radius(); |
---|
117 | dp.radius = radius(); |
---|
118 | dp.length = length(); |
---|
119 | dp.contrast = contrast(); |
---|
120 | dp.background = 0.0; |
---|
121 | dp.axis_theta = axis_theta(); |
---|
122 | dp.axis_phi = axis_phi(); |
---|
123 | |
---|
124 | // Get the dispersion points for the core radius |
---|
125 | vector<WeightPoint> weights_core_radius; |
---|
126 | core_radius.get_weights(weights_core_radius); |
---|
127 | |
---|
128 | // Get the dispersion points for the shell radius |
---|
129 | vector<WeightPoint> weights_radius; |
---|
130 | radius.get_weights(weights_radius); |
---|
131 | |
---|
132 | // Get the dispersion points for the length |
---|
133 | vector<WeightPoint> weights_length; |
---|
134 | length.get_weights(weights_length); |
---|
135 | |
---|
136 | // Get angular averaging for theta |
---|
137 | vector<WeightPoint> weights_theta; |
---|
138 | axis_theta.get_weights(weights_theta); |
---|
139 | |
---|
140 | // Get angular averaging for phi |
---|
141 | vector<WeightPoint> weights_phi; |
---|
142 | axis_phi.get_weights(weights_phi); |
---|
143 | |
---|
144 | // Perform the computation, with all weight points |
---|
145 | double sum = 0.0; |
---|
146 | double norm = 0.0; |
---|
147 | |
---|
148 | // Loop over core radius weight points |
---|
149 | for(int i=0; i<(int)weights_core_radius.size(); i++) { |
---|
150 | dp.core_radius = weights_core_radius[i].value; |
---|
151 | |
---|
152 | |
---|
153 | // Loop over length weight points |
---|
154 | for(int j=0; j<(int)weights_length.size(); j++) { |
---|
155 | dp.length = weights_length[j].value; |
---|
156 | |
---|
157 | // Loop over shell radius weight points |
---|
158 | for(int m=0; m< (int)weights_radius.size(); m++) { |
---|
159 | dp.radius = weights_radius[m].value; |
---|
160 | |
---|
161 | // Average over theta distribution |
---|
162 | for(int k=0; k< (int)weights_theta.size(); k++) { |
---|
163 | dp.axis_theta = weights_theta[k].value; |
---|
164 | |
---|
165 | // Average over phi distribution |
---|
166 | for(int l=0; l< (int)weights_phi.size(); l++) { |
---|
167 | dp.axis_phi = weights_phi[l].value; |
---|
168 | |
---|
169 | double _ptvalue = weights_core_radius[i].weight |
---|
170 | * weights_length[j].weight |
---|
171 | * weights_radius[m].weight |
---|
172 | * weights_theta[k].weight |
---|
173 | * weights_phi[l].weight |
---|
174 | * hollow_cylinder_analytical_2DXY(&dp, qx, qy); |
---|
175 | if (weights_theta.size()>1) { |
---|
176 | _ptvalue *= sin(weights_theta[k].value); |
---|
177 | } |
---|
178 | sum += _ptvalue; |
---|
179 | |
---|
180 | norm += weights_core_radius[i].weight |
---|
181 | * weights_length[j].weight |
---|
182 | * weights_radius[m].weight |
---|
183 | * weights_theta[k].weight |
---|
184 | * weights_phi[l].weight; |
---|
185 | |
---|
186 | } |
---|
187 | } |
---|
188 | } |
---|
189 | } |
---|
190 | } |
---|
191 | // Averaging in theta needs an extra normalization |
---|
192 | // factor to account for the sin(theta) term in the |
---|
193 | // integration (see documentation). |
---|
194 | if (weights_theta.size()>1) norm = norm / asin(1.0); |
---|
195 | return sum/norm + background(); |
---|
196 | } |
---|
197 | |
---|
198 | /** |
---|
199 | * Function to evaluate 2D scattering function |
---|
200 | * @param pars: parameters of the cylinder |
---|
201 | * @param q: q-value |
---|
202 | * @param phi: angle phi |
---|
203 | * @return: function value |
---|
204 | */ |
---|
205 | double HollowCylinderModel :: evaluate_rphi(double q, double phi) { |
---|
206 | double qx = q*cos(phi); |
---|
207 | double qy = q*sin(phi); |
---|
208 | return (*this).operator()(qx, qy); |
---|
209 | } |
---|
210 | /** |
---|
211 | * Function to calculate effective radius |
---|
212 | * @return: effective radius value |
---|
213 | */ |
---|
214 | double HollowCylinderModel :: calculate_ER() { |
---|
215 | HollowCylinderParameters dp; |
---|
216 | |
---|
217 | dp.radius = radius(); |
---|
218 | dp.length = length(); |
---|
219 | |
---|
220 | double rad_out = 0.0; |
---|
221 | |
---|
222 | // Perform the computation, with all weight points |
---|
223 | double sum = 0.0; |
---|
224 | double norm = 0.0; |
---|
225 | |
---|
226 | // Get the dispersion points for the major shell |
---|
227 | vector<WeightPoint> weights_length; |
---|
228 | length.get_weights(weights_length); |
---|
229 | |
---|
230 | // Get the dispersion points for the minor shell |
---|
231 | vector<WeightPoint> weights_radius ; |
---|
232 | radius.get_weights(weights_radius); |
---|
233 | |
---|
234 | // Loop over major shell weight points |
---|
235 | for(int i=0; i< (int)weights_length.size(); i++) { |
---|
236 | dp.length = weights_length[i].value; |
---|
237 | for(int k=0; k< (int)weights_radius.size(); k++) { |
---|
238 | dp.radius = weights_radius[k].value; |
---|
239 | //Note: output of "DiamCyl(dp.length,dp.radius)" is DIAMETER. |
---|
240 | sum +=weights_length[i].weight |
---|
241 | * weights_radius[k].weight*DiamCyl(dp.length,dp.radius)/2.0; |
---|
242 | norm += weights_length[i].weight* weights_radius[k].weight; |
---|
243 | } |
---|
244 | } |
---|
245 | if (norm != 0){ |
---|
246 | //return the averaged value |
---|
247 | rad_out = sum/norm;} |
---|
248 | else{ |
---|
249 | //return normal value |
---|
250 | //Note: output of "DiamCyl(dp.length,dp.radius)" is DIAMETER. |
---|
251 | rad_out = DiamCyl(dp.length,dp.radius)/2.0;} |
---|
252 | |
---|
253 | return rad_out; |
---|
254 | } |
---|