source: sasview/sansmodels/src/sans/models/c_models/hollowcylinder.cpp @ 72f719b

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 72f719b 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: 7.2 KB
RevLine 
[27fea3f]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"
[5eb9154]31        #include "libStructureFactor.h"
[27fea3f]32        #include "hollow_cylinder.h"
33}
34
35HollowCylinderModel :: HollowCylinderModel() {
36        scale      = Parameter(1.0);
37        core_radius = Parameter(20.0, true);
38        core_radius.set_min(0.0);
[e2afadf]39        radius  = Parameter(30.0, true);
40        radius.set_min(0.0);
[27fea3f]41        length     = Parameter(400.0, true);
42        length.set_min(0.0);
43        contrast  = Parameter(5.3e-6);
44        background = Parameter(0.0);
45        axis_theta = Parameter(0.0, true);
46        axis_phi   = Parameter(0.0, true);
47}
48
49/**
50 * Function to evaluate 1D scattering function
51 * The NIST IGOR library is used for the actual calculation.
52 * @param q: q-value
53 * @return: function value
54 */
55double HollowCylinderModel :: operator()(double q) {
56        double dp[6];
57
58        dp[0] = scale();
59        dp[1] = core_radius();
[e2afadf]60        dp[2] = radius();
[27fea3f]61        dp[3] = length();
62        dp[4] = contrast();
[9188cc1]63        dp[5] = 0.0;
[27fea3f]64
65        // Get the dispersion points for the core radius
66        vector<WeightPoint> weights_core_radius;
67        core_radius.get_weights(weights_core_radius);
68
69        // Get the dispersion points for the shell radius
[e2afadf]70        vector<WeightPoint> weights_radius;
71        radius.get_weights(weights_radius);
[27fea3f]72
73        // Get the dispersion points for the length
74        vector<WeightPoint> weights_length;
75        length.get_weights(weights_length);
76
77        // Perform the computation, with all weight points
78        double sum = 0.0;
79        double norm = 0.0;
80
81        // Loop over core radius weight points
82        for(int i=0; i< (int)weights_core_radius.size(); i++) {
83                dp[1] = weights_core_radius[i].value;
84
85                // Loop over length weight points
86                for(int j=0; j< (int)weights_length.size(); j++) {
87                        dp[3] = weights_length[j].value;
88
89                        // Loop over shell radius weight points
[e2afadf]90                        for(int k=0; k< (int)weights_radius.size(); k++) {
91                                dp[2] = weights_radius[k].value;
[27fea3f]92
93                                sum += weights_core_radius[i].weight
94                                        * weights_length[j].weight
[e2afadf]95                                        * weights_radius[k].weight
[27fea3f]96                                        * HollowCylinder(dp, q);
97                                norm += weights_core_radius[i].weight
98                                * weights_length[j].weight
[e2afadf]99                                * weights_radius[k].weight;
[27fea3f]100                        }
101                }
102        }
103        return sum/norm + background();
104}
105
106/**
107 * Function to evaluate 2D scattering function
108 * @param q_x: value of Q along x
109 * @param q_y: value of Q along y
110 * @return: function value
111 */
112double HollowCylinderModel :: operator()(double qx, double qy) {
113        HollowCylinderParameters dp;
114        // Fill parameter array
115        dp.scale      = scale();
116        dp.core_radius     = core_radius();
[e2afadf]117        dp.radius  = radius();
[27fea3f]118        dp.length     = length();
119        dp.contrast   = contrast();
[9188cc1]120        dp.background = 0.0;
[27fea3f]121        dp.axis_theta = axis_theta();
122        dp.axis_phi   = axis_phi();
123
124        // Get the dispersion points for the core radius
125        vector<WeightPoint> weights_core_radius;
126        core_radius.get_weights(weights_core_radius);
127
128        // Get the dispersion points for the shell radius
[e2afadf]129        vector<WeightPoint> weights_radius;
130        radius.get_weights(weights_radius);
[27fea3f]131
132        // Get the dispersion points for the length
133        vector<WeightPoint> weights_length;
134        length.get_weights(weights_length);
135
136        // Get angular averaging for theta
137        vector<WeightPoint> weights_theta;
138        axis_theta.get_weights(weights_theta);
139
140        // Get angular averaging for phi
141        vector<WeightPoint> weights_phi;
142        axis_phi.get_weights(weights_phi);
143
144        // Perform the computation, with all weight points
145        double sum = 0.0;
146        double norm = 0.0;
147
148        // Loop over core radius weight points
149        for(int i=0; i<(int)weights_core_radius.size(); i++) {
150                dp.core_radius = weights_core_radius[i].value;
151
152
153                // Loop over length weight points
154                for(int j=0; j<(int)weights_length.size(); j++) {
155                        dp.length = weights_length[j].value;
156
157                        // Loop over shell radius weight points
[e2afadf]158                        for(int m=0; m< (int)weights_radius.size(); m++) {
159                                dp.radius = weights_radius[m].value;
[27fea3f]160
161                        // Average over theta distribution
162                        for(int k=0; k< (int)weights_theta.size(); k++) {
163                                dp.axis_theta = weights_theta[k].value;
164
165                                // Average over phi distribution
166                                for(int l=0; l< (int)weights_phi.size(); l++) {
167                                        dp.axis_phi = weights_phi[l].value;
168
169                                        double _ptvalue = weights_core_radius[i].weight
170                                                * weights_length[j].weight
[e2afadf]171                                                * weights_radius[m].weight
[27fea3f]172                                                * weights_theta[k].weight
173                                                * weights_phi[l].weight
174                                                * hollow_cylinder_analytical_2DXY(&dp, qx, qy);
175                                        if (weights_theta.size()>1) {
176                                                _ptvalue *= sin(weights_theta[k].value);
177                                        }
178                                        sum += _ptvalue;
179
180                                        norm += weights_core_radius[i].weight
181                                                * weights_length[j].weight
[e2afadf]182                                                * weights_radius[m].weight
[27fea3f]183                                                * weights_theta[k].weight
184                                                * weights_phi[l].weight;
185
186                                }
187                        }
188                        }
189                }
190        }
191        // Averaging in theta needs an extra normalization
192        // factor to account for the sin(theta) term in the
193        // integration (see documentation).
194        if (weights_theta.size()>1) norm = norm / asin(1.0);
195        return sum/norm + background();
196}
197
198/**
199 * Function to evaluate 2D scattering function
200 * @param pars: parameters of the  cylinder
201 * @param q: q-value
202 * @param phi: angle phi
203 * @return: function value
204 */
205double HollowCylinderModel :: evaluate_rphi(double q, double phi) {
206        double qx = q*cos(phi);
207        double qy = q*sin(phi);
208        return (*this).operator()(qx, qy);
209}
[5eb9154]210/**
211 * Function to calculate effective radius
212 * @param pars: parameters of the sphere
213 * @return: effective radius value
214 */
215double HollowCylinderModel :: calculate_ER() {
216        HollowCylinderParameters dp;
217
218        dp.radius  = radius();
219        dp.length     = length();
220
221        double rad_out = 0.0;
222
223        // Perform the computation, with all weight points
224        double sum = 0.0;
225        double norm = 0.0;
226
227        // Get the dispersion points for the major shell
228        vector<WeightPoint> weights_length;
229        length.get_weights(weights_length);
230
231        // Get the dispersion points for the minor shell
232        vector<WeightPoint> weights_radius ;
233        radius.get_weights(weights_radius);
234
235        // Loop over major shell weight points
236        for(int i=0; i< (int)weights_length.size(); i++) {
237                dp.length = weights_length[i].value;
238                for(int k=0; k< (int)weights_radius.size(); k++) {
239                        dp.radius = weights_radius[k].value;
240                        //Note: output of "DiamCyl(dp.length,dp.radius)" is DIAMETER.
241                        sum +=weights_length[i].weight
242                                * weights_radius[k].weight*DiamCyl(dp.length,dp.radius)/2.0;
243                        norm += weights_length[i].weight* weights_radius[k].weight;
244                }
245        }
246        if (norm != 0){
247                //return the averaged value
248                rad_out =  sum/norm;}
249        else{
250                //return normal value
251                //Note: output of "DiamCyl(dp.length,dp.radius)" is DIAMETER.
252                rad_out = DiamCyl(dp.length,dp.radius)/2.0;}
253
254        return rad_out;
255}
Note: See TracBrowser for help on using the repository browser.