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