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 "bcc.h" |
---|
31 | } |
---|
32 | |
---|
33 | BCCrystalModel :: BCCrystalModel() { |
---|
34 | scale = Parameter(1.0); |
---|
35 | dnn = Parameter(220.0); |
---|
36 | d_factor = Parameter(0.06); |
---|
37 | radius = Parameter(40.0, true); |
---|
38 | radius.set_min(0.0); |
---|
39 | sldSph = Parameter(3.0e-6); |
---|
40 | sldSolv = Parameter(6.3e-6); |
---|
41 | background = Parameter(0.0); |
---|
42 | theta = Parameter(0.0, true); |
---|
43 | phi = Parameter(0.0, true); |
---|
44 | psi = Parameter(0.0, true); |
---|
45 | } |
---|
46 | |
---|
47 | /** |
---|
48 | * Function to evaluate 1D scattering function |
---|
49 | * The NIST IGOR library is used for the actual calculation. |
---|
50 | * @param q: q-value |
---|
51 | * @return: function value |
---|
52 | */ |
---|
53 | double BCCrystalModel :: operator()(double q) { |
---|
54 | double dp[7]; |
---|
55 | |
---|
56 | // Fill parameter array for IGOR library |
---|
57 | // Add the background after averaging |
---|
58 | dp[0] = scale(); |
---|
59 | dp[1] = dnn(); |
---|
60 | dp[2] = d_factor(); |
---|
61 | dp[3] = radius(); |
---|
62 | dp[4] = sldSph(); |
---|
63 | dp[5] = sldSolv(); |
---|
64 | dp[6] = 0.0; |
---|
65 | |
---|
66 | // Get the dispersion points for the radius |
---|
67 | vector<WeightPoint> weights_rad; |
---|
68 | radius.get_weights(weights_rad); |
---|
69 | |
---|
70 | // Perform the computation, with all weight points |
---|
71 | double sum = 0.0; |
---|
72 | double norm = 0.0; |
---|
73 | double vol = 0.0; |
---|
74 | double result; |
---|
75 | |
---|
76 | // Loop over radius weight points |
---|
77 | for(int i=0; i<weights_rad.size(); i++) { |
---|
78 | dp[3] = weights_rad[i].value; |
---|
79 | |
---|
80 | //Un-normalize SphereForm by volume |
---|
81 | result = BCC_ParaCrystal(dp, q) * pow(weights_rad[i].value,3); |
---|
82 | // This FIXES a singualrity in the kernel in libigor. |
---|
83 | if ( result == INFINITY || result == NAN){ |
---|
84 | result = 0.0; |
---|
85 | } |
---|
86 | sum += weights_rad[i].weight |
---|
87 | * result; |
---|
88 | //Find average volume |
---|
89 | vol += weights_rad[i].weight |
---|
90 | * pow(weights_rad[i].value,3); |
---|
91 | |
---|
92 | norm += weights_rad[i].weight; |
---|
93 | } |
---|
94 | |
---|
95 | if (vol != 0.0 && norm != 0.0) { |
---|
96 | //Re-normalize by avg volume |
---|
97 | sum = sum/(vol/norm);} |
---|
98 | return sum/norm + background(); |
---|
99 | } |
---|
100 | |
---|
101 | /** |
---|
102 | * Function to evaluate 2D scattering function |
---|
103 | * @param q_x: value of Q along x |
---|
104 | * @param q_y: value of Q along y |
---|
105 | * @return: function value |
---|
106 | */ |
---|
107 | double BCCrystalModel :: operator()(double qx, double qy) { |
---|
108 | BCParameters dp; |
---|
109 | double q = sqrt(qx*qx + qy*qy); |
---|
110 | dp.scale = scale(); |
---|
111 | dp.dnn = dnn(); |
---|
112 | dp.d_factor = d_factor(); |
---|
113 | dp.radius = radius(); |
---|
114 | dp.sldSph = sldSph(); |
---|
115 | dp.sldSolv = sldSolv(); |
---|
116 | dp.background = 0.0; |
---|
117 | dp.theta = theta(); |
---|
118 | dp.phi = phi(); |
---|
119 | dp.psi = psi(); |
---|
120 | |
---|
121 | // Get the dispersion points for the radius |
---|
122 | vector<WeightPoint> weights_rad; |
---|
123 | radius.get_weights(weights_rad); |
---|
124 | |
---|
125 | // Get angular averaging for theta |
---|
126 | vector<WeightPoint> weights_theta; |
---|
127 | theta.get_weights(weights_theta); |
---|
128 | |
---|
129 | // Get angular averaging for phi |
---|
130 | vector<WeightPoint> weights_phi; |
---|
131 | phi.get_weights(weights_phi); |
---|
132 | |
---|
133 | // Get angular averaging for psi |
---|
134 | vector<WeightPoint> weights_psi; |
---|
135 | psi.get_weights(weights_psi); |
---|
136 | |
---|
137 | // Perform the computation, with all weight points |
---|
138 | double sum = 0.0; |
---|
139 | double norm = 0.0; |
---|
140 | double norm_vol = 0.0; |
---|
141 | double vol = 0.0; |
---|
142 | |
---|
143 | // Loop over radius weight points |
---|
144 | for(int i=0; i<weights_rad.size(); i++) { |
---|
145 | dp.radius = weights_rad[i].value; |
---|
146 | // Average over theta distribution |
---|
147 | for(int j=0; j< weights_theta.size(); j++) { |
---|
148 | dp.theta = weights_theta[j].value; |
---|
149 | // Average over phi distribution |
---|
150 | for(int k=0; k< weights_phi.size(); k++) { |
---|
151 | dp.phi = weights_phi[k].value; |
---|
152 | // Average over phi distribution |
---|
153 | for(int l=0; l< weights_psi.size(); l++) { |
---|
154 | dp.psi = weights_psi[l].value; |
---|
155 | //Un-normalize SphereForm by volume |
---|
156 | double _ptvalue = weights_rad[i].weight |
---|
157 | * weights_theta[j].weight |
---|
158 | * weights_phi[k].weight |
---|
159 | * weights_psi[l].weight |
---|
160 | * bc_analytical_2DXY(&dp, qx, qy); |
---|
161 | //* pow(weights_rad[i].value,3.0); |
---|
162 | // Consider when there is infinity or nan. |
---|
163 | // Actual value for this singular point are typically zero. |
---|
164 | if ( _ptvalue == INFINITY || _ptvalue == NAN){ |
---|
165 | _ptvalue = 0.0; |
---|
166 | } |
---|
167 | if (weights_theta.size()>1) { |
---|
168 | _ptvalue *= sin(weights_theta[j].value); |
---|
169 | } |
---|
170 | sum += _ptvalue; |
---|
171 | // This model dose not need the volume of spheres correction!!! |
---|
172 | norm += weights_rad[i].weight |
---|
173 | * weights_theta[j].weight |
---|
174 | * weights_phi[k].weight |
---|
175 | * weights_psi[l].weight; |
---|
176 | } |
---|
177 | } |
---|
178 | } |
---|
179 | } |
---|
180 | // Averaging in theta needs an extra normalization |
---|
181 | // factor to account for the sin(theta) term in the |
---|
182 | // integration (see documentation). |
---|
183 | if (weights_theta.size()>1) norm = norm / asin(1.0); |
---|
184 | |
---|
185 | if (vol != 0.0 && norm_vol != 0.0) { |
---|
186 | //Re-normalize by avg volume |
---|
187 | sum = sum/(vol/norm_vol);} |
---|
188 | |
---|
189 | return sum/norm + background(); |
---|
190 | } |
---|
191 | |
---|
192 | /** |
---|
193 | * Function to evaluate 2D scattering function |
---|
194 | * @param pars: parameters of the BCCCrystal |
---|
195 | * @param q: q-value |
---|
196 | * @param phi: angle phi |
---|
197 | * @return: function value |
---|
198 | */ |
---|
199 | double BCCrystalModel :: evaluate_rphi(double q, double phi) { |
---|
200 | return (*this).operator()(q); |
---|
201 | } |
---|
202 | |
---|
203 | /** |
---|
204 | * Function to calculate effective radius |
---|
205 | * @return: effective radius value |
---|
206 | */ |
---|
207 | double BCCrystalModel :: calculate_ER() { |
---|
208 | //NOT implemented yet!!! |
---|
209 | } |
---|