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> |
---|
26 | using namespace std; |
---|
27 | |
---|
28 | extern "C" { |
---|
29 | #include "libSphere.h" |
---|
30 | #include "core_shell.h" |
---|
31 | } |
---|
32 | |
---|
33 | CoreShellModel :: CoreShellModel() { |
---|
34 | scale = Parameter(1.0); |
---|
35 | radius = Parameter(60.0, true); |
---|
36 | radius.set_min(0.0); |
---|
37 | thickness = Parameter(10.0, true); |
---|
38 | thickness.set_min(0.0); |
---|
39 | core_sld = Parameter(1.e-6); |
---|
40 | shell_sld = Parameter(2.e-6); |
---|
41 | solvent_sld = Parameter(3.e-6); |
---|
42 | background = Parameter(0.0); |
---|
43 | } |
---|
44 | |
---|
45 | /** |
---|
46 | * Function to evaluate 1D scattering function |
---|
47 | * The NIST IGOR library is used for the actual calculation. |
---|
48 | * @param q: q-value |
---|
49 | * @return: function value |
---|
50 | */ |
---|
51 | double CoreShellModel :: operator()(double q) { |
---|
52 | double dp[7]; |
---|
53 | |
---|
54 | // Fill parameter array for IGOR library |
---|
55 | // Add the background after averaging |
---|
56 | |
---|
57 | dp[0] = scale(); |
---|
58 | dp[1] = radius(); |
---|
59 | dp[2] = thickness(); |
---|
60 | dp[3] = core_sld(); |
---|
61 | dp[4] = shell_sld(); |
---|
62 | dp[5] = solvent_sld(); |
---|
63 | dp[6] = 0.0; |
---|
64 | |
---|
65 | |
---|
66 | // Get the dispersion points for the radius |
---|
67 | vector<WeightPoint> weights_rad; |
---|
68 | radius.get_weights(weights_rad); |
---|
69 | |
---|
70 | // Get the dispersion points for the thickness |
---|
71 | vector<WeightPoint> weights_thick; |
---|
72 | thickness.get_weights(weights_thick); |
---|
73 | |
---|
74 | // Perform the computation, with all weight points |
---|
75 | double sum = 0.0; |
---|
76 | double norm = 0.0; |
---|
77 | |
---|
78 | // Loop over radius weight points |
---|
79 | for(int i=0; i<weights_rad.size(); i++) { |
---|
80 | dp[1] = weights_rad[i].value; |
---|
81 | |
---|
82 | // Loop over thickness weight points |
---|
83 | for(int j=0; j<weights_thick.size(); j++) { |
---|
84 | dp[2] = weights_thick[j].value; |
---|
85 | |
---|
86 | sum += weights_rad[i].weight |
---|
87 | * weights_thick[j].weight * CoreShellForm(dp, q); |
---|
88 | norm += weights_rad[i].weight |
---|
89 | * weights_thick[j].weight; |
---|
90 | } |
---|
91 | } |
---|
92 | return sum/norm + background(); |
---|
93 | } |
---|
94 | |
---|
95 | /** |
---|
96 | * Function to evaluate 2D scattering function |
---|
97 | * @param q_x: value of Q along x |
---|
98 | * @param q_y: value of Q along y |
---|
99 | * @return: function value |
---|
100 | */ |
---|
101 | double CoreShellModel :: operator()(double qx, double qy) { |
---|
102 | double q = sqrt(qx*qx + qy*qy); |
---|
103 | return (*this).operator()(q); |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | * Function to evaluate 2D scattering function |
---|
108 | * @param pars: parameters of the sphere |
---|
109 | * @param q: q-value |
---|
110 | * @param phi: angle phi |
---|
111 | * @return: function value |
---|
112 | */ |
---|
113 | double CoreShellModel :: evaluate_rphi(double q, double phi) { |
---|
114 | return (*this).operator()(q); |
---|
115 | } |
---|
116 | /** |
---|
117 | * Function to calculate effective radius |
---|
118 | * @return: effective radius value |
---|
119 | */ |
---|
120 | double CoreShellModel :: calculate_ER() { |
---|
121 | CoreShellParameters dp; |
---|
122 | |
---|
123 | dp.radius = radius(); |
---|
124 | dp.thickness = thickness(); |
---|
125 | |
---|
126 | double rad_out = 0.0; |
---|
127 | |
---|
128 | // Perform the computation, with all weight points |
---|
129 | double sum = 0.0; |
---|
130 | double norm = 0.0; |
---|
131 | |
---|
132 | |
---|
133 | // Get the dispersion points for the major shell |
---|
134 | vector<WeightPoint> weights_thickness; |
---|
135 | thickness.get_weights(weights_thickness); |
---|
136 | |
---|
137 | // Get the dispersion points for the minor shell |
---|
138 | vector<WeightPoint> weights_radius ; |
---|
139 | radius.get_weights(weights_radius); |
---|
140 | |
---|
141 | // Loop over major shell weight points |
---|
142 | for(int j=0; j< (int)weights_thickness.size(); j++) { |
---|
143 | dp.thickness = weights_thickness[j].value; |
---|
144 | for(int k=0; k< (int)weights_radius.size(); k++) { |
---|
145 | dp.radius = weights_radius[k].value; |
---|
146 | sum += weights_thickness[j].weight |
---|
147 | * weights_radius[k].weight*(dp.radius+dp.thickness); |
---|
148 | norm += weights_thickness[j].weight* weights_radius[k].weight; |
---|
149 | } |
---|
150 | } |
---|
151 | if (norm != 0){ |
---|
152 | //return the averaged value |
---|
153 | rad_out = sum/norm;} |
---|
154 | else{ |
---|
155 | //return normal value |
---|
156 | rad_out = (dp.radius+dp.thickness);} |
---|
157 | |
---|
158 | return rad_out; |
---|
159 | } |
---|