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 "fcc.h" |
---|
31 | } |
---|
32 | |
---|
33 | FCCrystalModel :: FCCrystalModel() { |
---|
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 FCCrystalModel :: 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 = FCC_ParaCrystal(dp, q) * pow(weights_rad[i].value,3); |
---|
82 | // This FIXES a singualrity 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 FCCrystalModel :: operator()(double qx, double qy) { |
---|
108 | FCParameters 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 | double pi = 4.0*atan(1.0); |
---|
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 | * fc_analytical_2DXY(&dp, qx, qy); |
---|
161 | //* pow(weights_rad[i].value,3.0); |
---|
162 | // Consider when there is infinte or nan. |
---|
163 | if ( _ptvalue == INFINITY || _ptvalue == NAN){ |
---|
164 | _ptvalue = 0.0; |
---|
165 | } |
---|
166 | if (weights_theta.size()>1) { |
---|
167 | _ptvalue *= fabs(sin(weights_theta[j].value*pi/180.0)); |
---|
168 | } |
---|
169 | sum += _ptvalue; |
---|
170 | // This model dose not need the volume of spheres correction!!! |
---|
171 | norm += weights_rad[i].weight |
---|
172 | * weights_theta[j].weight |
---|
173 | * weights_phi[k].weight |
---|
174 | * weights_psi[l].weight; |
---|
175 | } |
---|
176 | } |
---|
177 | } |
---|
178 | } |
---|
179 | // Averaging in theta needs an extra normalization |
---|
180 | // factor to account for the sin(theta) term in the |
---|
181 | // integration (see documentation). |
---|
182 | if (weights_theta.size()>1) norm = norm / asin(1.0); |
---|
183 | |
---|
184 | if (vol != 0.0 && norm_vol != 0.0) { |
---|
185 | //Re-normalize by avg volume |
---|
186 | sum = sum/(vol/norm_vol);} |
---|
187 | |
---|
188 | return sum/norm + background(); |
---|
189 | } |
---|
190 | |
---|
191 | /** |
---|
192 | * Function to evaluate 2D scattering function |
---|
193 | * @param pars: parameters of the FCCCrystal |
---|
194 | * @param q: q-value |
---|
195 | * @param phi: angle phi |
---|
196 | * @return: function value |
---|
197 | */ |
---|
198 | double FCCrystalModel :: evaluate_rphi(double q, double phi) { |
---|
199 | return (*this).operator()(q); |
---|
200 | } |
---|
201 | |
---|
202 | /** |
---|
203 | * Function to calculate effective radius |
---|
204 | * @return: effective radius value |
---|
205 | */ |
---|
206 | double FCCrystalModel :: calculate_ER() { |
---|
207 | //NOT implemented yet!!! |
---|
208 | } |
---|