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 | */ |
---|
21 | |
---|
22 | #include <math.h> |
---|
23 | #include "parameters.hh" |
---|
24 | #include <stdio.h> |
---|
25 | using namespace std; |
---|
26 | #include "corefourshell.h" |
---|
27 | |
---|
28 | extern "C" { |
---|
29 | #include "libSphere.h" |
---|
30 | } |
---|
31 | |
---|
32 | typedef struct { |
---|
33 | double scale; |
---|
34 | double rad_core0; |
---|
35 | double sld_core0; |
---|
36 | double thick_shell1; |
---|
37 | double sld_shell1; |
---|
38 | double thick_shell2; |
---|
39 | double sld_shell2; |
---|
40 | double thick_shell3; |
---|
41 | double sld_shell3; |
---|
42 | double thick_shell4; |
---|
43 | double sld_shell4; |
---|
44 | double sld_solv; |
---|
45 | double background; |
---|
46 | } CoreFourShellParameters; |
---|
47 | |
---|
48 | CoreFourShellModel :: CoreFourShellModel() { |
---|
49 | scale = Parameter(1.0); |
---|
50 | rad_core0 = Parameter(60.0, true); |
---|
51 | rad_core0.set_min(0.0); |
---|
52 | sld_core0 = Parameter(6.4e-6); |
---|
53 | thick_shell1 = Parameter(10.0, true); |
---|
54 | thick_shell1.set_min(0.0); |
---|
55 | sld_shell1 = Parameter(1.0e-6); |
---|
56 | thick_shell2 = Parameter(10.0, true); |
---|
57 | thick_shell2.set_min(0.0); |
---|
58 | sld_shell2 = Parameter(2.0e-6); |
---|
59 | thick_shell3 = Parameter(10.0, true); |
---|
60 | thick_shell3.set_min(0.0); |
---|
61 | sld_shell3 = Parameter(3.0e-6); |
---|
62 | thick_shell4 = Parameter(10.0, true); |
---|
63 | thick_shell4.set_min(0.0); |
---|
64 | sld_shell4 = Parameter(4.0e-6); |
---|
65 | sld_solv = Parameter(6.4e-6); |
---|
66 | background = Parameter(0.001); |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * Function to evaluate 1D scattering function |
---|
71 | * The NIST IGOR library is used for the actual calculation. |
---|
72 | * @param q: q-value |
---|
73 | * @return: function value |
---|
74 | */ |
---|
75 | double CoreFourShellModel :: operator()(double q) { |
---|
76 | double dp[13]; |
---|
77 | |
---|
78 | // Fill parameter array for IGOR library |
---|
79 | // Add the background after averaging |
---|
80 | dp[0] = scale(); |
---|
81 | dp[1] = rad_core0(); |
---|
82 | dp[2] = sld_core0(); |
---|
83 | dp[3] = thick_shell1(); |
---|
84 | dp[4] = sld_shell1(); |
---|
85 | dp[5] = thick_shell2(); |
---|
86 | dp[6] = sld_shell2(); |
---|
87 | dp[7] = thick_shell3(); |
---|
88 | dp[8] = sld_shell3(); |
---|
89 | dp[9] = thick_shell4(); |
---|
90 | dp[10] = sld_shell4(); |
---|
91 | dp[11] = sld_solv(); |
---|
92 | dp[12] = 0.0; |
---|
93 | |
---|
94 | // Get the dispersion points for the radius |
---|
95 | vector<WeightPoint> weights_rad; |
---|
96 | rad_core0.get_weights(weights_rad); |
---|
97 | |
---|
98 | // Get the dispersion points for the thick 1 |
---|
99 | vector<WeightPoint> weights_s1; |
---|
100 | thick_shell1.get_weights(weights_s1); |
---|
101 | |
---|
102 | // Get the dispersion points for the thick 2 |
---|
103 | vector<WeightPoint> weights_s2; |
---|
104 | thick_shell2.get_weights(weights_s2); |
---|
105 | |
---|
106 | // Get the dispersion points for the thick 3 |
---|
107 | vector<WeightPoint> weights_s3; |
---|
108 | thick_shell3.get_weights(weights_s3); |
---|
109 | |
---|
110 | // Get the dispersion points for the thick 4 |
---|
111 | vector<WeightPoint> weights_s4; |
---|
112 | thick_shell4.get_weights(weights_s4); |
---|
113 | |
---|
114 | // Perform the computation, with all weight points |
---|
115 | double sum = 0.0; |
---|
116 | double norm = 0.0; |
---|
117 | double vol = 0.0; |
---|
118 | |
---|
119 | // Loop over radius weight points |
---|
120 | for(size_t i=0; i<weights_rad.size(); i++) { |
---|
121 | dp[1] = weights_rad[i].value; |
---|
122 | // Loop over radius weight points |
---|
123 | for(size_t j=0; j<weights_s1.size(); j++) { |
---|
124 | dp[3] = weights_s1[j].value; |
---|
125 | // Loop over radius weight points |
---|
126 | for(size_t k=0; k<weights_s2.size(); k++) { |
---|
127 | dp[5] = weights_s2[k].value; |
---|
128 | // Loop over radius weight points |
---|
129 | for(size_t l=0; l<weights_s3.size(); l++) { |
---|
130 | dp[7] = weights_s3[l].value; |
---|
131 | // Loop over radius weight points |
---|
132 | for(size_t m=0; m<weights_s4.size(); m++) { |
---|
133 | dp[9] = weights_s4[m].value; |
---|
134 | //Un-normalize FourShell by volume |
---|
135 | sum += weights_rad[i].weight*weights_s1[j].weight*weights_s2[k].weight*weights_s3[l].weight*weights_s4[m].weight |
---|
136 | * FourShell(dp, q) * pow((weights_rad[i].value+weights_s1[j].value+weights_s2[k].value+weights_s3[l].value+weights_s4[m].value),3); |
---|
137 | //Find average volume |
---|
138 | vol += weights_rad[i].weight*weights_s1[j].weight*weights_s2[k].weight*weights_s3[l].weight*weights_s4[m].weight |
---|
139 | * pow((weights_rad[i].value+weights_s1[j].value+weights_s2[k].value+weights_s3[l].value+weights_s4[m].value),3); |
---|
140 | |
---|
141 | norm += weights_rad[i].weight*weights_s1[j].weight*weights_s2[k].weight*weights_s3[l].weight*weights_s4[m].weight; |
---|
142 | } |
---|
143 | } |
---|
144 | } |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | if (vol != 0.0 && norm != 0.0) { |
---|
149 | //Re-normalize by avg volume |
---|
150 | sum = sum/(vol/norm);} |
---|
151 | return sum/norm + background(); |
---|
152 | } |
---|
153 | |
---|
154 | /** |
---|
155 | * Function to evaluate 2D scattering function |
---|
156 | * @param q_x: value of Q along x |
---|
157 | * @param q_y: value of Q along y |
---|
158 | * @return: function value |
---|
159 | */ |
---|
160 | double CoreFourShellModel :: operator()(double qx, double qy) { |
---|
161 | double q = sqrt(qx*qx + qy*qy); |
---|
162 | return (*this).operator()(q); |
---|
163 | } |
---|
164 | |
---|
165 | /** |
---|
166 | * Function to evaluate 2D scattering function |
---|
167 | * @param pars: parameters of the sphere |
---|
168 | * @param q: q-value |
---|
169 | * @param phi: angle phi |
---|
170 | * @return: function value |
---|
171 | */ |
---|
172 | double CoreFourShellModel :: evaluate_rphi(double q, double phi) { |
---|
173 | return (*this).operator()(q); |
---|
174 | } |
---|
175 | |
---|
176 | /** |
---|
177 | * Function to calculate effective radius |
---|
178 | * @return: effective radius value |
---|
179 | */ |
---|
180 | double CoreFourShellModel :: calculate_ER() { |
---|
181 | CoreFourShellParameters dp; |
---|
182 | |
---|
183 | dp.scale = scale(); |
---|
184 | dp.rad_core0 = rad_core0(); |
---|
185 | dp.sld_core0 = sld_core0(); |
---|
186 | dp.thick_shell1 = thick_shell1(); |
---|
187 | dp.sld_shell1 = sld_shell1(); |
---|
188 | dp.thick_shell2 = thick_shell2(); |
---|
189 | dp.sld_shell2 = sld_shell2(); |
---|
190 | dp.thick_shell3 = thick_shell3(); |
---|
191 | dp.sld_shell3 = sld_shell3(); |
---|
192 | dp.thick_shell4 = thick_shell4(); |
---|
193 | dp.sld_shell4 = sld_shell4(); |
---|
194 | dp.sld_solv = sld_solv(); |
---|
195 | dp.background = 0.0; |
---|
196 | |
---|
197 | // Get the dispersion points for the radius |
---|
198 | vector<WeightPoint> weights_rad; |
---|
199 | rad_core0.get_weights(weights_rad); |
---|
200 | |
---|
201 | // Get the dispersion points for the thick 1 |
---|
202 | vector<WeightPoint> weights_s1; |
---|
203 | thick_shell1.get_weights(weights_s1); |
---|
204 | |
---|
205 | // Get the dispersion points for the thick 2 |
---|
206 | vector<WeightPoint> weights_s2; |
---|
207 | thick_shell2.get_weights(weights_s2); |
---|
208 | |
---|
209 | // Get the dispersion points for the thick 3 |
---|
210 | vector<WeightPoint> weights_s3; |
---|
211 | thick_shell3.get_weights(weights_s3); |
---|
212 | |
---|
213 | // Get the dispersion points for the thick 4 |
---|
214 | vector<WeightPoint> weights_s4; |
---|
215 | thick_shell4.get_weights(weights_s4); |
---|
216 | |
---|
217 | double rad_out = 0.0; |
---|
218 | // Perform the computation, with all weight points |
---|
219 | double sum = 0.0; |
---|
220 | double norm = 0.0; |
---|
221 | |
---|
222 | // Loop over radius weight points |
---|
223 | for(size_t i=0; i<weights_rad.size(); i++) { |
---|
224 | dp.rad_core0 = weights_rad[i].value; |
---|
225 | // Loop over radius weight points |
---|
226 | for(size_t j=0; j<weights_s1.size(); j++) { |
---|
227 | dp.thick_shell1 = weights_s1[j].value; |
---|
228 | // Loop over radius weight points |
---|
229 | for(size_t k=0; k<weights_s2.size(); k++) { |
---|
230 | dp.thick_shell2 = weights_s2[k].value; |
---|
231 | // Loop over radius weight points |
---|
232 | for(size_t l=0; l<weights_s3.size(); l++) { |
---|
233 | dp.thick_shell3 = weights_s3[l].value; |
---|
234 | // Loop over radius weight points |
---|
235 | for(size_t m=0; m<weights_s4.size(); m++) { |
---|
236 | dp.thick_shell4 = weights_s4[m].value; |
---|
237 | //Un-normalize FourShell by volume |
---|
238 | sum += weights_rad[i].weight*weights_s1[j].weight*weights_s2[k].weight*weights_s3[l].weight*weights_s4[m].weight |
---|
239 | * (dp.rad_core0+dp.thick_shell1+dp.thick_shell2+dp.thick_shell3+dp.thick_shell4); |
---|
240 | norm += weights_rad[i].weight*weights_s1[j].weight*weights_s2[k].weight*weights_s3[l].weight*weights_s4[m].weight; |
---|
241 | } |
---|
242 | } |
---|
243 | } |
---|
244 | } |
---|
245 | } |
---|
246 | if (norm != 0){ |
---|
247 | //return the averaged value |
---|
248 | rad_out = sum/norm;} |
---|
249 | else{ |
---|
250 | //return normal value |
---|
251 | rad_out = dp.rad_core0+dp.thick_shell1+dp.thick_shell2+dp.thick_shell3+dp.thick_shell4;} |
---|
252 | |
---|
253 | return rad_out; |
---|
254 | } |
---|