source: sasview/sansmodels/src/sans/models/c_models/ellipsoid.cpp @ 4deaec6

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 4deaec6 was 5eb9154, checked in by Jae Cho <jhjcho@…>, 15 years ago

calculation of the effective radius are added

  • Property mode set to 100644
File size: 6.2 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 "libStructureFactor.h"
32        #include "ellipsoid.h"
33}
34
35EllipsoidModel :: EllipsoidModel() {
36        scale      = Parameter(1.0);
37        radius_a   = Parameter(20.0, true);
38        radius_a.set_min(0.0);
39        radius_b   = Parameter(400.0, true);
40        radius_b.set_min(0.0);
41        contrast   = Parameter(3.e-6);
42        background = Parameter(0.0);
43        axis_theta  = Parameter(1.57, true);
44        axis_phi    = 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 */
53double EllipsoidModel :: operator()(double q) {
54        double dp[5];
55
56        // Fill parameter array for IGOR library
57        // Add the background after averaging
58        dp[0] = scale();
59        dp[1] = radius_a();
60        dp[2] = radius_b();
61        dp[3] = contrast();
62        dp[4] = 0.0;
63
64        // Get the dispersion points for the radius_a
65        vector<WeightPoint> weights_rad_a;
66        radius_a.get_weights(weights_rad_a);
67
68        // Get the dispersion points for the radius_b
69        vector<WeightPoint> weights_rad_b;
70        radius_b.get_weights(weights_rad_b);
71
72        // Perform the computation, with all weight points
73        double sum = 0.0;
74        double norm = 0.0;
75
76        // Loop over radius_a weight points
77        for(int i=0; i<weights_rad_a.size(); i++) {
78                dp[1] = weights_rad_a[i].value;
79
80                // Loop over radius_b weight points
81                for(int j=0; j<weights_rad_b.size(); j++) {
82                        dp[2] = weights_rad_b[j].value;
83
84                        sum += weights_rad_a[i].weight
85                                * weights_rad_b[j].weight * EllipsoidForm(dp, q);
86                        norm += weights_rad_a[i].weight
87                                * weights_rad_b[j].weight;
88                }
89        }
90        return sum/norm + background();
91}
92
93/**
94 * Function to evaluate 2D scattering function
95 * @param q_x: value of Q along x
96 * @param q_y: value of Q along y
97 * @return: function value
98 */
99double EllipsoidModel :: operator()(double qx, double qy) {
100        EllipsoidParameters dp;
101        // Fill parameter array
102        dp.scale      = scale();
103        dp.radius_a   = radius_a();
104        dp.radius_b   = radius_b();
105        dp.contrast   = contrast();
106        dp.background = 0.0;
107        dp.axis_theta = axis_theta();
108        dp.axis_phi   = axis_phi();
109
110        // Get the dispersion points for the radius_a
111        vector<WeightPoint> weights_rad_a;
112        radius_a.get_weights(weights_rad_a);
113
114        // Get the dispersion points for the radius_b
115        vector<WeightPoint> weights_rad_b;
116        radius_b.get_weights(weights_rad_b);
117
118        // Get angular averaging for theta
119        vector<WeightPoint> weights_theta;
120        axis_theta.get_weights(weights_theta);
121
122        // Get angular averaging for phi
123        vector<WeightPoint> weights_phi;
124        axis_phi.get_weights(weights_phi);
125
126        // Perform the computation, with all weight points
127        double sum = 0.0;
128        double norm = 0.0;
129
130        // Loop over radius weight points
131        for(int i=0; i<weights_rad_a.size(); i++) {
132                dp.radius_a = weights_rad_a[i].value;
133
134
135                // Loop over length weight points
136                for(int j=0; j<weights_rad_b.size(); j++) {
137                        dp.radius_b = weights_rad_b[j].value;
138
139                        // Average over theta distribution
140                        for(int k=0; k<weights_theta.size(); k++) {
141                                dp.axis_theta = weights_theta[k].value;
142
143                                // Average over phi distribution
144                                for(int l=0; l<weights_phi.size(); l++) {
145                                        dp.axis_phi = weights_phi[l].value;
146
147                                        double _ptvalue = weights_rad_a[i].weight
148                                                * weights_rad_b[j].weight
149                                                * weights_theta[k].weight
150                                                * weights_phi[l].weight
151                                                * ellipsoid_analytical_2DXY(&dp, qx, qy);
152                                        if (weights_theta.size()>1) {
153                                                _ptvalue *= sin(weights_theta[k].value);
154                                        }
155                                        sum += _ptvalue;
156
157                                        norm += weights_rad_a[i].weight
158                                                * weights_rad_b[j].weight
159                                                * weights_theta[k].weight
160                                                * weights_phi[l].weight;
161
162                                }
163                        }
164                }
165        }
166        // Averaging in theta needs an extra normalization
167        // factor to account for the sin(theta) term in the
168        // integration (see documentation).
169        if (weights_theta.size()>1) norm = norm / asin(1.0);
170        return sum/norm + background();
171}
172
173/**
174 * Function to evaluate 2D scattering function
175 * @param pars: parameters of the cylinder
176 * @param q: q-value
177 * @param phi: angle phi
178 * @return: function value
179 */
180double EllipsoidModel :: evaluate_rphi(double q, double phi) {
181        double qx = q*cos(phi);
182        double qy = q*sin(phi);
183        return (*this).operator()(qx, qy);
184}
185
186/**
187 * Function to calculate effective radius
188 * @param pars: parameters of the sphere
189 * @return: effective radius value
190 */
191double EllipsoidModel :: calculate_ER() {
192        EllipsoidParameters dp;
193
194        dp.radius_a = radius_a();
195        dp.radius_b = radius_b();
196
197        double rad_out = 0.0;
198
199        // Perform the computation, with all weight points
200        double sum = 0.0;
201        double norm = 0.0;
202
203        // Get the dispersion points for the major shell
204        vector<WeightPoint> weights_radius_a;
205        radius_a.get_weights(weights_radius_a);
206
207        // Get the dispersion points for the minor shell
208        vector<WeightPoint> weights_radius_b;
209        radius_b.get_weights(weights_radius_b);
210
211        // Loop over major shell weight points
212        for(int i=0; i< (int)weights_radius_b.size(); i++) {
213                dp.radius_b = weights_radius_b[i].value;
214                for(int k=0; k< (int)weights_radius_a.size(); k++) {
215                        dp.radius_a = weights_radius_a[k].value;
216                        sum +=weights_radius_b[i].weight
217                                * weights_radius_a[k].weight*DiamEllip(dp.radius_a,dp.radius_b)/2.0;
218                        norm += weights_radius_b[i].weight* weights_radius_a[k].weight;
219                }
220        }
221        if (norm != 0){
222                //return the averaged value
223                rad_out =  sum/norm;}
224        else{
225                //return normal value
226                rad_out = DiamEllip(dp.radius_a,dp.radius_b)/2.0;}
227
228        return rad_out;
229}
Note: See TracBrowser for help on using the repository browser.