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

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

updated documents

  • Property mode set to 100644
File size: 5.1 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 * @return: effective radius value
125 */
126double MultiShellModel :: calculate_ER() {
127        MultiShellParameters dp;
128
129        dp.core_radius     = core_radius();
130        dp.s_thickness  = s_thickness();
131        dp.w_thickness  = w_thickness();
132        dp.n_pairs = n_pairs();
133
134        double rad_out = 0.0;
135
136        // Perform the computation, with all weight points
137        double sum = 0.0;
138        double norm = 0.0;
139        if (dp.n_pairs <= 0.0 ){
140                dp.n_pairs = 0.0;
141        }
142
143        // Get the dispersion points for the core radius
144        vector<WeightPoint> weights_core_radius;
145        core_radius.get_weights(weights_core_radius);
146
147        // Get the dispersion points for the s_thickness
148        vector<WeightPoint> weights_s_thickness;
149        s_thickness.get_weights(weights_s_thickness);
150
151        // Get the dispersion points for the w_thickness
152        vector<WeightPoint> weights_w_thickness;
153        w_thickness.get_weights(weights_w_thickness);
154
155        // Loop over major shell weight points
156        for(int i=0; i< (int)weights_s_thickness.size(); i++) {
157                dp.s_thickness = weights_s_thickness[i].value;
158                for(int j=0; j< (int)weights_w_thickness.size(); j++) {
159                        dp.w_thickness = weights_w_thickness[j].value;
160                        for(int k=0; k< (int)weights_core_radius.size(); k++) {
161                                dp.core_radius = weights_core_radius[k].value;
162                                sum += weights_s_thickness[i].weight*weights_w_thickness[j].weight
163                                        * weights_core_radius[k].weight*(dp.core_radius+dp.n_pairs*dp.s_thickness+(dp.n_pairs-1.0)*dp.w_thickness);
164                                norm += weights_s_thickness[i].weight*weights_w_thickness[j].weight* weights_core_radius[k].weight;
165                        }
166                }
167        }
168        if (norm != 0){
169                //return the averaged value
170                rad_out =  sum/norm;}
171        else{
172                //return normal value
173                rad_out = (dp.core_radius+dp.n_pairs*dp.s_thickness+(dp.n_pairs-1.0)*dp.w_thickness);}
174
175        return rad_out;
176}
Note: See TracBrowser for help on using the repository browser.