source: sasview/sansmodels/src/sans/models/c_models/stackeddisks.cpp @ 27953d1

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 27953d1 was 975ec8e, checked in by Jae Cho <jhjcho@…>, 15 years ago

working on 2D models. Still need smore corrections and unit tests.

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