source: sasview/sansmodels/src/sans/models/c_models/parallelepiped.cpp @ 15f52f8

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 15f52f8 was f9bf661, checked in by Jae Cho <jhjcho@…>, 15 years ago

updated documents

  • Property mode set to 100644
File size: 8.5 KB
Line 
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 function
22 */
23
24#include <math.h>
25#include "models.hh"
26#include "parameters.hh"
27#include <stdio.h>
28using namespace std;
29
30extern "C" {
31        #include "libCylinder.h"
32        #include "libStructureFactor.h"
33        #include "parallelepiped.h"
34}
35
36ParallelepipedModel :: ParallelepipedModel() {
37        scale      = Parameter(1.0);
38        short_a     = Parameter(35.0, true);
39        short_a.set_min(1.0);
40        short_b     = Parameter(75.0, true);
41        short_b.set_min(1.0);
42        long_c     = Parameter(400.0, true);
43        long_c.set_min(1.0);
44        contrast   = Parameter(53.e-7);
45        background = Parameter(0.0);
46        parallel_theta  = Parameter(0.0, true);
47        parallel_phi    = Parameter(0.0, true);
48        parallel_psi    = Parameter(0.0, true);
49}
50
51/**
52 * Function to evaluate 1D scattering function
53 * The NIST IGOR library is used for the actual calculation.
54 * @param q: q-value
55 * @return: function value
56 */
57double ParallelepipedModel :: operator()(double q) {
58        double dp[6];
59
60        // Fill parameter array for IGOR library
61        // Add the background after averaging
62        dp[0] = scale();
63        dp[1] = short_a();
64        dp[2] = short_b();
65        dp[3] = long_c();
66        dp[4] = contrast();
67        dp[5] = 0.0;
68
69        // Get the dispersion points for the short_edgeA
70        vector<WeightPoint> weights_short_a;
71        short_a.get_weights(weights_short_a);
72
73        // Get the dispersion points for the longer_edgeB
74        vector<WeightPoint> weights_short_b;
75        short_b.get_weights(weights_short_b);
76
77        // Get the dispersion points for the longuest_edgeC
78        vector<WeightPoint> weights_long_c;
79        long_c.get_weights(weights_long_c);
80
81
82
83        // Perform the computation, with all weight points
84        double sum = 0.0;
85        double norm = 0.0;
86
87        // Loop over short_edgeA weight points
88        for(int i=0; i< (int)weights_short_a.size(); i++) {
89                dp[1] = weights_short_a[i].value;
90
91                // Loop over longer_edgeB weight points
92                for(int j=0; j< (int)weights_short_b.size(); j++) {
93                        dp[2] = weights_short_b[j].value;
94
95                        // Loop over longuest_edgeC weight points
96                        for(int k=0; k< (int)weights_long_c.size(); k++) {
97                                dp[3] = weights_long_c[k].value;
98                                sum += weights_short_a[i].weight * weights_short_b[j].weight
99                                        * weights_long_c[k].weight * Parallelepiped(dp, q);
100
101                                norm += weights_short_a[i].weight
102                                         * weights_short_b[j].weight * weights_long_c[k].weight;
103                        }
104                }
105        }
106
107        return sum/norm + background();
108}
109/**
110 * Function to evaluate 2D scattering function
111 * @param q_x: value of Q along x
112 * @param q_y: value of Q along y
113 * @return: function value
114 */
115double ParallelepipedModel :: operator()(double qx, double qy) {
116        ParallelepipedParameters dp;
117        // Fill parameter array
118        dp.scale      = scale();
119        dp.short_a   = short_a();
120        dp.short_b   = short_b();
121        dp.long_c  = long_c();
122        dp.contrast   = contrast();
123        dp.background = 0.0;
124        //dp.background = background();
125        dp.parallel_theta  = parallel_theta();
126        dp.parallel_phi    = parallel_phi();
127        dp.parallel_psi    = parallel_psi();
128
129
130        // Get the dispersion points for the short_edgeA
131        vector<WeightPoint> weights_short_a;
132        short_a.get_weights(weights_short_a);
133
134        // Get the dispersion points for the longer_edgeB
135        vector<WeightPoint> weights_short_b;
136        short_b.get_weights(weights_short_b);
137
138        // Get angular averaging for the longuest_edgeC
139        vector<WeightPoint> weights_long_c;
140        long_c.get_weights(weights_long_c);
141
142        // Get angular averaging for theta
143        vector<WeightPoint> weights_parallel_theta;
144        parallel_theta.get_weights(weights_parallel_theta);
145
146        // Get angular averaging for phi
147        vector<WeightPoint> weights_parallel_phi;
148        parallel_phi.get_weights(weights_parallel_phi);
149
150        // Get angular averaging for psi
151        vector<WeightPoint> weights_parallel_psi;
152        parallel_psi.get_weights(weights_parallel_psi);
153
154        // Perform the computation, with all weight points
155        double sum = 0.0;
156        double norm = 0.0;
157
158        // Loop over radius weight points
159        for(int i=0; i< (int)weights_short_a.size(); i++) {
160                dp.short_a = weights_short_a[i].value;
161
162                // Loop over longer_edgeB weight points
163                for(int j=0; j< (int)weights_short_b.size(); j++) {
164                        dp.short_b = weights_short_b[j].value;
165
166                        // Average over longuest_edgeC distribution
167                        for(int k=0; k< (int)weights_long_c.size(); k++) {
168                                dp.long_c = weights_long_c[k].value;
169
170                                // Average over theta distribution
171                                for(int l=0; l< (int)weights_parallel_theta.size(); l++) {
172                                dp.parallel_theta = weights_parallel_theta[l].value;
173
174                                        // Average over phi distribution
175                                        for(int m=0; m< (int)weights_parallel_phi.size(); m++) {
176                                                dp.parallel_phi = weights_parallel_phi[m].value;
177
178                                                // Average over phi distribution
179                                                for(int n=0; n< (int)weights_parallel_psi.size(); n++) {
180                                                        dp.parallel_psi = weights_parallel_psi[n].value;
181
182                                                        double _ptvalue = weights_short_a[i].weight
183                                                                * weights_short_b[j].weight
184                                                                * weights_long_c[k].weight
185                                                                * weights_parallel_theta[l].weight
186                                                                * weights_parallel_phi[m].weight
187                                                                * weights_parallel_psi[n].weight
188                                                                * parallelepiped_analytical_2DXY(&dp, qx, qy);
189                                                        if (weights_parallel_theta.size()>1) {
190                                                                _ptvalue *= sin(weights_parallel_theta[l].value);
191                                                        }
192                                                        sum += _ptvalue;
193
194                                                        norm += weights_short_a[i].weight
195                                                                * weights_short_b[j].weight
196                                                                * weights_long_c[k].weight
197                                                                * weights_parallel_theta[l].weight
198                                                                * weights_parallel_phi[m].weight
199                                                                * weights_parallel_psi[n].weight;
200                                                }
201                                        }
202
203                                }
204                        }
205                }
206        }
207        // Averaging in theta needs an extra normalization
208        // factor to account for the sin(theta) term in the
209        // integration (see documentation).
210        if (weights_parallel_theta.size()>1) norm = norm / asin(1.0);
211        return sum/norm + background();
212}
213
214
215/**
216 * Function to evaluate 2D scattering function
217 * @param pars: parameters of the cylinder
218 * @param q: q-value
219 * @param phi: angle phi
220 * @return: function value
221 */
222double ParallelepipedModel :: evaluate_rphi(double q, double phi) {
223        double qx = q*cos(phi);
224        double qy = q*sin(phi);
225        return (*this).operator()(qx, qy);
226}
227/**
228 * Function to calculate effective radius
229 * @return: effective radius value
230 */
231double ParallelepipedModel :: calculate_ER() {
232        ParallelepipedParameters dp;
233        dp.short_a   = short_a();
234        dp.short_b   = short_b();
235        dp.long_c  = long_c();
236        double rad_out = 0.0;
237        double pi = 4.0*atan(1.0);
238        double suf_rad = sqrt(dp.short_a*dp.short_b/pi);
239
240        // Perform the computation, with all weight points
241        double sum = 0.0;
242        double norm = 0.0;
243
244        // Get the dispersion points for the short_edgeA
245        vector<WeightPoint> weights_short_a;
246        short_a.get_weights(weights_short_a);
247
248        // Get the dispersion points for the longer_edgeB
249        vector<WeightPoint> weights_short_b;
250        short_b.get_weights(weights_short_b);
251
252        // Get angular averaging for the longuest_edgeC
253        vector<WeightPoint> weights_long_c;
254        long_c.get_weights(weights_long_c);
255
256        // Loop over radius weight points
257        for(int i=0; i< (int)weights_short_a.size(); i++) {
258                dp.short_a = weights_short_a[i].value;
259
260                // Loop over longer_edgeB weight points
261                for(int j=0; j< (int)weights_short_b.size(); j++) {
262                        dp.short_b = weights_short_b[j].value;
263
264                        // Average over longuest_edgeC distribution
265                        for(int k=0; k< (int)weights_long_c.size(); k++) {
266                                dp.long_c = weights_long_c[k].value;
267                                //Calculate surface averaged radius
268                                //This is rough approximation.
269                                suf_rad = sqrt(dp.short_a*dp.short_b/pi);
270
271                                //Note: output of "DiamCyl(dp.length,dp.radius)" is DIAMETER.
272                                sum +=weights_short_a[i].weight* weights_short_b[j].weight
273                                        * weights_long_c[k].weight*DiamCyl(dp.long_c, suf_rad)/2.0;
274                                norm += weights_short_a[i].weight* weights_short_b[j].weight*weights_long_c[k].weight;
275                        }
276                }
277        }
278
279        if (norm != 0){
280                //return the averaged value
281                rad_out =  sum/norm;}
282        else{
283                //return normal value
284                //Note: output of "DiamCyl(length,radius)" is DIAMETER.
285                rad_out = DiamCyl(dp.long_c, suf_rad)/2.0;}
286        return rad_out;
287
288}
Note: See TracBrowser for help on using the repository browser.