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

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 4deaec6 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: 5.2 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
83        // Loop over radius weight points
84        for(int i=0; i< (int)weights_core_radius.size(); i++) {
85                dp[1] = weights_core_radius[i].value;
86                for(int j=0; j< (int)weights_s_thickness.size(); j++){
87                        dp[2] = weights_s_thickness[j].value;
88                        for(int k=0; k< (int)weights_w_thickness.size(); k++){
89                                dp[3] = weights_w_thickness[k].value;
90
91                                sum += weights_core_radius[i].weight*weights_s_thickness[j].weight
92                                        *weights_w_thickness[k].weight* MultiShell(dp, q);
93                                norm += weights_core_radius[i].weight*weights_s_thickness[j].weight
94                                        *weights_w_thickness[k].weight;
95                        }
96                }
97        }
98        return sum/norm + background();
99}
100
101/**
102 * Function to evaluate 2D scattering function
103 * @param q_x: value of Q along x
104 * @param q_y: value of Q along y
105 * @return: function value
106 */
107double MultiShellModel :: operator()(double qx, double qy) {
108        double q = sqrt(qx*qx + qy*qy);
109        return (*this).operator()(q);
110}
111
112/**
113 * Function to evaluate 2D scattering function
114 * @param pars: parameters of the multishell
115 * @param q: q-value
116 * @param phi: angle phi
117 * @return: function value
118 */
119double MultiShellModel :: evaluate_rphi(double q, double phi) {
120        return (*this).operator()(q);
121}
122/**
123 * Function to calculate effective radius
124 * @param pars: parameters of the sphere
125 * @return: effective radius value
126 */
127double MultiShellModel :: calculate_ER() {
128        MultiShellParameters dp;
129
130        dp.core_radius     = core_radius();
131        dp.s_thickness  = s_thickness();
132        dp.w_thickness  = w_thickness();
133        dp.n_pairs = n_pairs();
134
135        double rad_out = 0.0;
136
137        // Perform the computation, with all weight points
138        double sum = 0.0;
139        double norm = 0.0;
140        if (dp.n_pairs <= 0.0 ){
141                dp.n_pairs = 0.0;
142        }
143
144        // Get the dispersion points for the core radius
145        vector<WeightPoint> weights_core_radius;
146        core_radius.get_weights(weights_core_radius);
147
148        // Get the dispersion points for the s_thickness
149        vector<WeightPoint> weights_s_thickness;
150        s_thickness.get_weights(weights_s_thickness);
151
152        // Get the dispersion points for the w_thickness
153        vector<WeightPoint> weights_w_thickness;
154        w_thickness.get_weights(weights_w_thickness);
155
156        // Loop over major shell weight points
157        for(int i=0; i< (int)weights_s_thickness.size(); i++) {
158                dp.s_thickness = weights_s_thickness[i].value;
159                for(int j=0; j< (int)weights_w_thickness.size(); j++) {
160                        dp.w_thickness = weights_w_thickness[j].value;
161                        for(int k=0; k< (int)weights_core_radius.size(); k++) {
162                                dp.core_radius = weights_core_radius[k].value;
163                                sum += weights_s_thickness[i].weight*weights_w_thickness[j].weight
164                                        * weights_core_radius[k].weight*(dp.core_radius+dp.n_pairs*dp.s_thickness+(dp.n_pairs-1.0)*dp.w_thickness);
165                                norm += weights_s_thickness[i].weight*weights_w_thickness[j].weight* weights_core_radius[k].weight;
166                        }
167                }
168        }
169        if (norm != 0){
170                //return the averaged value
171                rad_out =  sum/norm;}
172        else{
173                //return normal value
174                rad_out = (dp.core_radius+dp.n_pairs*dp.s_thickness+(dp.n_pairs-1.0)*dp.w_thickness);}
175
176        return rad_out;
177}
Note: See TracBrowser for help on using the repository browser.