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