source: sasview/sansmodels/src/sans/models/c_models/coreshellcylinder.cpp @ 8809e48

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 8809e48 was 0f5bc9f, checked in by Mathieu Doucet <doucetm@…>, 16 years ago

Update of all C models to the new style of C++ models

  • Property mode set to 100644
File size: 5.8 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 "core_shell_cylinder.h"
32}
33
34CoreShellCylinderModel :: CoreShellCylinderModel() {
35        scale      = Parameter(1.0);
36        radius     = Parameter(20.0, true);
37        radius.set_min(0.0);
38        thickness  = Parameter(10.0, true);
39        thickness.set_min(0.0);
40        length     = Parameter(400.0, true);
41        length.set_min(0.0);
42        core_sld   = Parameter(1.e-6);
43        shell_sld  = Parameter(4.e-6);
44        solvent_sld= Parameter(1.e-6);
45        background = Parameter(0.0);
46        axis_theta = Parameter(0.0, true);
47        axis_phi   = Parameter(0.0, true);
48}
49
50/**
51 * Function to evaluate 1D scattering function
52 * The NIST IGOR library is used for the actual calculation.
53 * @param q: q-value
54 * @return: function value
55 */
56double CoreShellCylinderModel :: operator()(double q) {
57        double dp[8];
58
59        dp[0] = scale();
60        dp[1] = radius();
61        dp[2] = thickness();
62        dp[3] = length();
63        dp[4] = core_sld();
64        dp[5] = shell_sld();
65        dp[6] = solvent_sld();
66        dp[7] = 0.0;
67
68        // Get the dispersion points for the radius
69        vector<WeightPoint> weights_rad;
70        radius.get_weights(weights_rad);
71
72        // Get the dispersion points for the thickness
73        vector<WeightPoint> weights_thick;
74        thickness.get_weights(weights_thick);
75
76        // Get the dispersion points for the length
77        vector<WeightPoint> weights_len;
78        length.get_weights(weights_len);
79
80        // Perform the computation, with all weight points
81        double sum = 0.0;
82        double norm = 0.0;
83
84        // Loop over radius weight points
85        for(int i=0; i<weights_rad.size(); i++) {
86                dp[1] = weights_rad[i].value;
87
88                // Loop over length weight points
89                for(int j=0; j<weights_len.size(); j++) {
90                        dp[3] = weights_len[j].value;
91
92                        // Loop over thickness weight points
93                        for(int k=0; k<weights_thick.size(); k++) {
94                                dp[2] = weights_thick[k].value;
95
96                                sum += weights_rad[i].weight
97                                        * weights_len[j].weight
98                                        * weights_thick[k].weight
99                                        * CoreShellCylinder(dp, q);
100                                norm += weights_rad[i].weight
101                                * weights_len[j].weight
102                                * weights_thick[k].weight;
103                        }
104                }
105        }
106        return sum/norm + background();
107}
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 CoreShellCylinderModel :: operator()(double qx, double qy) {
116        CoreShellCylinderParameters dp;
117        // Fill parameter array
118        dp.scale      = scale();
119        dp.radius     = radius();
120        dp.thickness  = thickness();
121        dp.length     = length();
122        dp.core_sld   = core_sld();
123        dp.shell_sld  = shell_sld();
124        dp.solvent_sld= solvent_sld();
125        dp.background = 0.0;
126        dp.axis_theta = axis_theta();
127        dp.axis_phi   = axis_phi();
128
129        // Get the dispersion points for the radius
130        vector<WeightPoint> weights_rad;
131        radius.get_weights(weights_rad);
132
133        // Get the dispersion points for the thickness
134        vector<WeightPoint> weights_thick;
135        thickness.get_weights(weights_thick);
136
137        // Get the dispersion points for the length
138        vector<WeightPoint> weights_len;
139        length.get_weights(weights_len);
140
141        // Get angular averaging for theta
142        vector<WeightPoint> weights_theta;
143        axis_theta.get_weights(weights_theta);
144
145        // Get angular averaging for phi
146        vector<WeightPoint> weights_phi;
147        axis_phi.get_weights(weights_phi);
148
149        // Perform the computation, with all weight points
150        double sum = 0.0;
151        double norm = 0.0;
152
153        // Loop over radius weight points
154        for(int i=0; i<weights_rad.size(); i++) {
155                dp.radius = weights_rad[i].value;
156
157
158                // Loop over length weight points
159                for(int j=0; j<weights_len.size(); j++) {
160                        dp.length = weights_len[j].value;
161
162                        // Loop over thickness weight points
163                        for(int m=0; m<weights_thick.size(); m++) {
164                                dp.thickness = weights_thick[m].value;
165
166                        // Average over theta distribution
167                        for(int k=0; k<weights_theta.size(); k++) {
168                                dp.axis_theta = weights_theta[k].value;
169
170                                // Average over phi distribution
171                                for(int l=0; l<weights_phi.size(); l++) {
172                                        dp.axis_phi = weights_phi[l].value;
173
174                                        double _ptvalue = weights_rad[i].weight
175                                                * weights_len[j].weight
176                                                * weights_thick[m].weight
177                                                * weights_theta[k].weight
178                                                * weights_phi[l].weight
179                                                * core_shell_cylinder_analytical_2DXY(&dp, qx, qy);
180                                        if (weights_theta.size()>1) {
181                                                _ptvalue *= sin(weights_theta[k].value);
182                                        }
183                                        sum += _ptvalue;
184
185                                        norm += weights_rad[i].weight
186                                                * weights_len[j].weight
187                                                * weights_thick[m].weight
188                                                * weights_theta[k].weight
189                                                * weights_phi[l].weight;
190
191                                }
192                        }
193                        }
194                }
195        }
196        // Averaging in theta needs an extra normalization
197        // factor to account for the sin(theta) term in the
198        // integration (see documentation).
199        if (weights_theta.size()>1) norm = norm / asin(1.0);
200        return sum/norm + background();
201}
202
203/**
204 * Function to evaluate 2D scattering function
205 * @param pars: parameters of the cylinder
206 * @param q: q-value
207 * @param phi: angle phi
208 * @return: function value
209 */
210double CoreShellCylinderModel :: evaluate_rphi(double q, double phi) {
211        double qx = q*cos(phi);
212        double qy = q*sin(phi);
213        return (*this).operator()(qx, qy);
214}
Note: See TracBrowser for help on using the repository browser.