source: sasview/sansmodels/src/sans/models/c_models/multishell.cpp @ b1a65b6

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 b1a65b6 was c451be9, checked in by Jae Cho <jhjcho@…>, 15 years ago

corrections on the definition of polydispersity as suggested by steve K: should be normalized by average volume

  • Property mode set to 100644
File size: 5.6 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 */
21
22#include <math.h>
23#include "models.hh"
24#include "parameters.hh"
25#include <stdio.h>
26using namespace std;
27
28extern "C" {
29        #include "libSphere.h"
30        #include "multishell.h"
31}
32
33MultiShellModel :: MultiShellModel() {
34        scale      = Parameter(1.0);
35        core_radius     = Parameter(60.0, true);
36        core_radius.set_min(0.0);
37        s_thickness  = Parameter(10.0, true);
38        s_thickness.set_min(0.0);
39        w_thickness   = Parameter(10.0, true);
40        w_thickness.set_min(0.0);
41        core_sld   = Parameter(6.4e-6);
42        shell_sld   = Parameter(4.0e-7);
43        n_pairs   = Parameter(2);
44        background = Parameter(0.0);
45}
46
47/**
48 * Function to evaluate 1D scattering function
49 * The NIST IGOR library is used for the actual calculation.
50 * @param q: q-value
51 * @return: function value
52 */
53double MultiShellModel :: operator()(double q) {
54        double dp[8];
55
56        // Fill parameter array for IGOR library
57        // Add the background after averaging
58        dp[0] = scale();
59        dp[1] = core_radius();
60        dp[2] = s_thickness();
61        dp[3] = w_thickness();
62        dp[4] = core_sld();
63        dp[5] = shell_sld();
64        dp[6] = n_pairs();
65        dp[7] = 0.0;
66
67        // Get the dispersion points for the core radius
68        vector<WeightPoint> weights_core_radius;
69        core_radius.get_weights(weights_core_radius);
70
71        // Get the dispersion points for the s_thickness
72        vector<WeightPoint> weights_s_thickness;
73        s_thickness.get_weights(weights_s_thickness);
74
75        // Get the dispersion points for the w_thickness
76        vector<WeightPoint> weights_w_thickness;
77        w_thickness.get_weights(weights_w_thickness);
78
79        // Perform the computation, with all weight points
80        double sum = 0.0;
81        double norm = 0.0;
82        double vol = 0.0;
83
84        // Loop over radius weight points
85        for(int i=0; i< (int)weights_core_radius.size(); i++) {
86                dp[1] = weights_core_radius[i].value;
87                for(int j=0; j< (int)weights_s_thickness.size(); j++){
88                        dp[2] = weights_s_thickness[j].value;
89                        for(int k=0; k< (int)weights_w_thickness.size(); k++){
90                                dp[3] = weights_w_thickness[k].value;
91                                //Un-normalize SphereForm by volume
92                                sum += weights_core_radius[i].weight*weights_s_thickness[j].weight
93                                        *weights_w_thickness[k].weight* MultiShell(dp, q)
94                                        *pow(weights_core_radius[i].value+dp[6]*weights_s_thickness[j].value+(dp[6]-1)*weights_w_thickness[k].value,3);
95                                //Find average volume
96                                vol += weights_core_radius[i].weight*weights_s_thickness[j].weight
97                                        *weights_w_thickness[k].weight
98                                        *pow(weights_core_radius[i].value+dp[6]*weights_s_thickness[j].value+(dp[6]-1)*weights_w_thickness[k].value,3);
99                                norm += weights_core_radius[i].weight*weights_s_thickness[j].weight
100                                        *weights_w_thickness[k].weight;
101                        }
102                }
103        }
104        if (vol != 0.0 && norm != 0.0) {
105                //Re-normalize by avg volume
106                sum = sum/(vol/norm);}
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 MultiShellModel :: operator()(double qx, double qy) {
117        double q = sqrt(qx*qx + qy*qy);
118        return (*this).operator()(q);
119}
120
121/**
122 * Function to evaluate 2D scattering function
123 * @param pars: parameters of the multishell
124 * @param q: q-value
125 * @param phi: angle phi
126 * @return: function value
127 */
128double MultiShellModel :: evaluate_rphi(double q, double phi) {
129        return (*this).operator()(q);
130}
131/**
132 * Function to calculate effective radius
133 * @return: effective radius value
134 */
135double MultiShellModel :: calculate_ER() {
136        MultiShellParameters dp;
137
138        dp.core_radius     = core_radius();
139        dp.s_thickness  = s_thickness();
140        dp.w_thickness  = w_thickness();
141        dp.n_pairs = n_pairs();
142
143        double rad_out = 0.0;
144
145        // Perform the computation, with all weight points
146        double sum = 0.0;
147        double norm = 0.0;
148        if (dp.n_pairs <= 0.0 ){
149                dp.n_pairs = 0.0;
150        }
151
152        // Get the dispersion points for the core radius
153        vector<WeightPoint> weights_core_radius;
154        core_radius.get_weights(weights_core_radius);
155
156        // Get the dispersion points for the s_thickness
157        vector<WeightPoint> weights_s_thickness;
158        s_thickness.get_weights(weights_s_thickness);
159
160        // Get the dispersion points for the w_thickness
161        vector<WeightPoint> weights_w_thickness;
162        w_thickness.get_weights(weights_w_thickness);
163
164        // Loop over major shell weight points
165        for(int i=0; i< (int)weights_s_thickness.size(); i++) {
166                dp.s_thickness = weights_s_thickness[i].value;
167                for(int j=0; j< (int)weights_w_thickness.size(); j++) {
168                        dp.w_thickness = weights_w_thickness[j].value;
169                        for(int k=0; k< (int)weights_core_radius.size(); k++) {
170                                dp.core_radius = weights_core_radius[k].value;
171                                sum += weights_s_thickness[i].weight*weights_w_thickness[j].weight
172                                        * weights_core_radius[k].weight*(dp.core_radius+dp.n_pairs*dp.s_thickness+(dp.n_pairs-1.0)*dp.w_thickness);
173                                norm += weights_s_thickness[i].weight*weights_w_thickness[j].weight* weights_core_radius[k].weight;
174                        }
175                }
176        }
177        if (norm != 0){
178                //return the averaged value
179                rad_out =  sum/norm;}
180        else{
181                //return normal value
182                rad_out = (dp.core_radius+dp.n_pairs*dp.s_thickness+(dp.n_pairs-1.0)*dp.w_thickness);}
183
184        return rad_out;
185}
Note: See TracBrowser for help on using the repository browser.