source: sasview/sansmodels/src/sans/models/c_models/triaxialellipsoid.cpp @ 7f81665

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 7f81665 was 9188cc1, checked in by Jae Cho <jhjcho@…>, 15 years ago

corrected bkg values for polydispersity cal and add doc

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