source: sasview/sansmodels/src/sans/models/c_models/oblate.cpp @ b341b16

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 b341b16 was 27a0771, checked in by Gervaise Alina <gervyh@…>, 15 years ago

add more models

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