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 | * TODO: add 2d |
---|
22 | */ |
---|
23 | |
---|
24 | #include <math.h> |
---|
25 | #include "models.hh" |
---|
26 | #include "parameters.hh" |
---|
27 | #include <stdio.h> |
---|
28 | using namespace std; |
---|
29 | |
---|
30 | extern "C" { |
---|
31 | #include "libCylinder.h" |
---|
32 | #include "stacked_disks.h" |
---|
33 | } |
---|
34 | |
---|
35 | StackedDisksModel :: StackedDisksModel() { |
---|
36 | scale = Parameter(1.0); |
---|
37 | radius = Parameter(3000.0, true); |
---|
38 | radius.set_min(0.0); |
---|
39 | length = Parameter(10.0, true); |
---|
40 | length.set_min(0.0); |
---|
41 | thickness = Parameter(15.0); |
---|
42 | thickness.set_min(0.0); |
---|
43 | core_sld = Parameter(4.0e-6); |
---|
44 | layer_sld = Parameter(-4.0e-7); |
---|
45 | solvent_sld = Parameter(5.0e-6); |
---|
46 | nlayers = Parameter(1); |
---|
47 | spacing = Parameter(0); |
---|
48 | background = Parameter(0.001); |
---|
49 | axis_theta = Parameter(0.0, true); |
---|
50 | axis_phi = Parameter(0.0, true); |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * Function to evaluate 1D scattering function |
---|
55 | * The NIST IGOR library is used for the actual calculation. |
---|
56 | * @param q: q-value |
---|
57 | * @return: function value |
---|
58 | */ |
---|
59 | double StackedDisksModel :: operator()(double q) { |
---|
60 | double dp[10]; |
---|
61 | |
---|
62 | // Fill parameter array for IGOR library |
---|
63 | // Add the background after averaging |
---|
64 | dp[0] = scale(); |
---|
65 | dp[1] = radius(); |
---|
66 | dp[2] = length(); |
---|
67 | dp[3] = thickness(); |
---|
68 | dp[4] = core_sld(); |
---|
69 | dp[5] = layer_sld(); |
---|
70 | dp[6] = solvent_sld(); |
---|
71 | dp[7] = nlayers(); |
---|
72 | dp[8] = spacing(); |
---|
73 | dp[9] = background(); |
---|
74 | |
---|
75 | // Get the dispersion points for the length |
---|
76 | vector<WeightPoint> weights_length; |
---|
77 | length.get_weights(weights_length); |
---|
78 | |
---|
79 | // Get the dispersion points for the radius |
---|
80 | vector<WeightPoint> weights_radius; |
---|
81 | radius.get_weights(weights_radius); |
---|
82 | |
---|
83 | // Get the dispersion points for the thickness |
---|
84 | vector<WeightPoint> weights_thickness; |
---|
85 | thickness.get_weights(weights_thickness); |
---|
86 | |
---|
87 | // Perform the computation, with all weight points |
---|
88 | double sum = 0.0; |
---|
89 | double norm = 0.0; |
---|
90 | |
---|
91 | // Loop over length weight points |
---|
92 | for(int i=0; i< (int)weights_length.size(); i++) { |
---|
93 | dp[1] = weights_length[i].value; |
---|
94 | |
---|
95 | // Loop over radius weight points |
---|
96 | for(int j=0; j< (int)weights_radius.size(); j++) { |
---|
97 | dp[2] = weights_radius[j].value; |
---|
98 | |
---|
99 | // Loop over thickness weight points |
---|
100 | for(int k=0; k< (int)weights_radius.size(); k++) { |
---|
101 | dp[3] = weights_radius[k].value; |
---|
102 | |
---|
103 | sum += weights_length[i].weight |
---|
104 | * weights_radius[j].weight * weights_thickness[k].weight* StackedDiscs(dp, q); |
---|
105 | norm += weights_length[i].weight |
---|
106 | * weights_radius[j].weight* weights_thickness[k].weight; |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|
110 | return sum/norm + background(); |
---|
111 | } |
---|
112 | |
---|
113 | /** |
---|
114 | * Function to evaluate 2D scattering function |
---|
115 | * @param q_x: value of Q along x |
---|
116 | * @param q_y: value of Q along y |
---|
117 | * @return: function value |
---|
118 | */ |
---|
119 | double StackedDisksModel :: operator()(double qx, double qy) { |
---|
120 | StackedDisksParameters dp; |
---|
121 | // Fill parameter array |
---|
122 | dp.scale = scale(); |
---|
123 | dp.length = length(); |
---|
124 | dp.radius = radius(); |
---|
125 | dp.thickness = thickness(); |
---|
126 | dp.core_sld = core_sld(); |
---|
127 | dp.layer_sld = layer_sld(); |
---|
128 | dp.solvent_sld= solvent_sld(); |
---|
129 | dp.nlayers = nlayers(); |
---|
130 | dp.spacing = spacing(); |
---|
131 | dp.background = background(); |
---|
132 | dp.axis_theta = axis_theta(); |
---|
133 | dp.axis_phi = axis_phi(); |
---|
134 | |
---|
135 | // Get the dispersion points for the length |
---|
136 | vector<WeightPoint> weights_length; |
---|
137 | length.get_weights(weights_length); |
---|
138 | |
---|
139 | // Get the dispersion points for the radius |
---|
140 | vector<WeightPoint> weights_radius; |
---|
141 | radius.get_weights(weights_radius); |
---|
142 | |
---|
143 | // Get the dispersion points for the thickness |
---|
144 | vector<WeightPoint> weights_thickness; |
---|
145 | thickness.get_weights(weights_thickness); |
---|
146 | |
---|
147 | // Get angular averaging for theta |
---|
148 | vector<WeightPoint> weights_theta; |
---|
149 | axis_theta.get_weights(weights_theta); |
---|
150 | |
---|
151 | // Get angular averaging for phi |
---|
152 | vector<WeightPoint> weights_phi; |
---|
153 | axis_phi.get_weights(weights_phi); |
---|
154 | |
---|
155 | // Perform the computation, with all weight points |
---|
156 | double sum = 0.0; |
---|
157 | double norm = 0.0; |
---|
158 | |
---|
159 | // Loop over length weight points |
---|
160 | for(int i=0; i< (int)weights_length.size(); i++) { |
---|
161 | dp.length = weights_length[i].value; |
---|
162 | |
---|
163 | // Loop over radius weight points |
---|
164 | for(int j=0; j< (int)weights_radius.size(); j++) { |
---|
165 | dp.radius = weights_radius[j].value; |
---|
166 | |
---|
167 | // Loop over thickness weight points |
---|
168 | for(int k=0; k< (int)weights_thickness.size(); k++) { |
---|
169 | dp.thickness = weights_thickness[k].value; |
---|
170 | |
---|
171 | for(int l=0; l< (int)weights_theta.size(); l++) { |
---|
172 | dp.axis_theta = weights_theta[l].value; |
---|
173 | |
---|
174 | // Average over phi distribution |
---|
175 | for(int m=0; m <(int)weights_phi.size(); m++) { |
---|
176 | dp.axis_phi = weights_phi[m].value; |
---|
177 | |
---|
178 | double _ptvalue = weights_length[i].weight |
---|
179 | * weights_radius[j].weight |
---|
180 | * weights_thickness[k].weight |
---|
181 | * weights_theta[l].weight |
---|
182 | * weights_phi[m].weight |
---|
183 | * stacked_disks_analytical_2DXY(&dp, qx, qy); |
---|
184 | if (weights_theta.size()>1) { |
---|
185 | _ptvalue *= sin(weights_theta[l].value); |
---|
186 | } |
---|
187 | sum += _ptvalue; |
---|
188 | |
---|
189 | norm += weights_length[i].weight |
---|
190 | * weights_radius[j].weight |
---|
191 | * weights_thickness[k].weight |
---|
192 | * weights_theta[l].weight |
---|
193 | * weights_phi[m].weight; |
---|
194 | } |
---|
195 | } |
---|
196 | } |
---|
197 | } |
---|
198 | } |
---|
199 | // Averaging in theta needs an extra normalization |
---|
200 | // factor to account for the sin(theta) term in the |
---|
201 | // integration (see documentation). |
---|
202 | if (weights_theta.size()>1) norm = norm / asin(1.0); |
---|
203 | return sum/norm + background(); |
---|
204 | } |
---|
205 | |
---|
206 | /** |
---|
207 | * Function to evaluate 2D scattering function |
---|
208 | * @param pars: parameters of the triaxial ellipsoid |
---|
209 | * @param q: q-value |
---|
210 | * @param phi: angle phi |
---|
211 | * @return: function value |
---|
212 | */ |
---|
213 | double StackedDisksModel :: evaluate_rphi(double q, double phi) { |
---|
214 | double qx = q*cos(phi); |
---|
215 | double qy = q*sin(phi); |
---|
216 | return (*this).operator()(qx, qy); |
---|
217 | } |
---|