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 | * TODO: add 2D function |
---|
22 | */ |
---|
23 | |
---|
24 | #include <math.h> |
---|
25 | #include "models.hh" |
---|
26 | #include "parameters.hh" |
---|
27 | #include <stdio.h> |
---|
28 | using namespace std; |
---|
29 | |
---|
30 | extern "C" { |
---|
31 | #include "libCylinder.h" |
---|
32 | #include "lamellarPS_HG.h" |
---|
33 | } |
---|
34 | |
---|
35 | LamellarPSHGModel :: LamellarPSHGModel() { |
---|
36 | scale = Parameter(1.0); |
---|
37 | spacing = Parameter(40.0, true); |
---|
38 | spacing.set_min(0.0); |
---|
39 | deltaT = Parameter(10.0, true); |
---|
40 | deltaT.set_min(0.0); |
---|
41 | deltaH = Parameter(2.0, true); |
---|
42 | deltaH.set_min(0.0); |
---|
43 | sld_tail = Parameter(4e-7); |
---|
44 | sld_head = Parameter(2e-6); |
---|
45 | sld_solvent = Parameter(6e-6); |
---|
46 | n_plates = Parameter(30); |
---|
47 | caille = Parameter(0.001); |
---|
48 | background = Parameter(0.001); |
---|
49 | |
---|
50 | } |
---|
51 | |
---|
52 | /** |
---|
53 | * Function to evaluate 1D scattering function |
---|
54 | * The NIST IGOR library is used for the actual calculation. |
---|
55 | * @param q: q-value |
---|
56 | * @return: function value |
---|
57 | */ |
---|
58 | double LamellarPSHGModel :: operator()(double q) { |
---|
59 | double dp[10]; |
---|
60 | |
---|
61 | // Fill parameter array for IGOR library |
---|
62 | // Add the background after averaging |
---|
63 | dp[0] = scale(); |
---|
64 | dp[1] = spacing(); |
---|
65 | dp[2] = deltaT(); |
---|
66 | dp[3] = deltaH(); |
---|
67 | dp[4] = sld_tail(); |
---|
68 | dp[5] = sld_head(); |
---|
69 | dp[6] = sld_solvent(); |
---|
70 | dp[7] = n_plates(); |
---|
71 | dp[8] = caille(); |
---|
72 | dp[9] = 0.0; |
---|
73 | |
---|
74 | |
---|
75 | // Get the dispersion points for (deltaT) thickness of the tail |
---|
76 | vector<WeightPoint> weights_deltaT; |
---|
77 | deltaT.get_weights(weights_deltaT); |
---|
78 | |
---|
79 | // Get the dispersion points for (deltaH) thickness of the head |
---|
80 | vector<WeightPoint> weights_deltaH; |
---|
81 | deltaH.get_weights(weights_deltaH); |
---|
82 | |
---|
83 | // Get the dispersion points for spacing |
---|
84 | vector<WeightPoint> weights_spacing; |
---|
85 | spacing.get_weights(weights_spacing); |
---|
86 | |
---|
87 | // Perform the computation, with all weight points |
---|
88 | double sum = 0.0; |
---|
89 | double norm = 0.0; |
---|
90 | |
---|
91 | // Loop over deltaT weight points |
---|
92 | for(int i=0; i< (int)weights_deltaT.size(); i++) { |
---|
93 | dp[2] = weights_deltaT[i].value; |
---|
94 | |
---|
95 | // Loop over deltaH weight points |
---|
96 | for(int j=0; j< (int)weights_deltaH.size(); j++) { |
---|
97 | dp[3] = weights_deltaH[j].value; |
---|
98 | // Loop over spacing weight points |
---|
99 | for(int k=0; k< (int)weights_spacing.size(); k++) { |
---|
100 | dp[1] = weights_spacing[k].value; |
---|
101 | |
---|
102 | sum += weights_deltaT[i].weight * weights_deltaH[j].weight *weights_spacing[k].weight |
---|
103 | *LamellarPS_HG(dp, q); |
---|
104 | norm += weights_deltaT[i].weight * weights_deltaH[j].weight * weights_spacing[k].weight; |
---|
105 | } |
---|
106 | } |
---|
107 | } |
---|
108 | return sum/norm + background(); |
---|
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 | */ |
---|
116 | double LamellarPSHGModel :: 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 lamellarPS_HG |
---|
124 | * @param q: q-value |
---|
125 | * @param phi: angle phi |
---|
126 | * @return: function value |
---|
127 | */ |
---|
128 | double LamellarPSHGModel :: evaluate_rphi(double q, double phi) { |
---|
129 | return (*this).operator()(q); |
---|
130 | } |
---|
131 | |
---|
132 | /* |
---|
133 | double LamellarPSHGModel :: operator()(double qx, double qy) { |
---|
134 | LamellarPSHGParameters dp; |
---|
135 | // Fill parameter array |
---|
136 | dp.scale = scale(); |
---|
137 | dp.spacing = spacing(); |
---|
138 | dp.deltaT = deltaT(); |
---|
139 | dp.deltaH = deltaH(); |
---|
140 | dp.sld_tail = sld_tail(); |
---|
141 | dp.sld_head = sld_head(); |
---|
142 | dp.sld_solvent = sld_solvent(); |
---|
143 | dp.n_plates = n_plates(); |
---|
144 | dp.caille = caille(); |
---|
145 | dp.background = background(); |
---|
146 | |
---|
147 | // Get the dispersion points for the deltaT |
---|
148 | vector<WeightPoint> weights_deltaT; |
---|
149 | deltaT.get_weights(weights_deltaT); |
---|
150 | |
---|
151 | // Get the dispersion points for the deltaH |
---|
152 | vector<WeightPoint> weights_deltaH; |
---|
153 | deltaH.get_weights(weights_deltaH); |
---|
154 | |
---|
155 | // Perform the computation, with all weight points |
---|
156 | double sum = 0.0; |
---|
157 | double norm = 0.0; |
---|
158 | |
---|
159 | // Loop over deltaT weight points |
---|
160 | for(int i=0; i< (int)weights_deltaT.size(); i++) { |
---|
161 | dp.deltaT = weights_deltaT[i].value; |
---|
162 | |
---|
163 | // Loop over deltaH weight points |
---|
164 | for(int j=0; j< (int)weights_deltaH.size(); j++) { |
---|
165 | dp.deltaH = weights_deltaH[j].value; |
---|
166 | |
---|
167 | sum += weights_deltaT[i].weight *weights_deltaH[j].weight *lamellarPS_HG_analytical_2DXY(&dp, qx, qy); |
---|
168 | norm += weights_deltaT[i].weight * weights_deltaH[j].weight; |
---|
169 | } |
---|
170 | } |
---|
171 | return sum/norm + background(); |
---|
172 | } |
---|
173 | */ |
---|
174 | |
---|
175 | |
---|