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 | */ |
---|
22 | |
---|
23 | #include <math.h> |
---|
24 | #include "models.hh" |
---|
25 | #include "parameters.hh" |
---|
26 | #include <stdio.h> |
---|
27 | using namespace std; |
---|
28 | |
---|
29 | extern "C" { |
---|
30 | #include "libStructureFactor.h" |
---|
31 | #include "HayterMSA.h" |
---|
32 | } |
---|
33 | |
---|
34 | HayterMSAStructure :: HayterMSAStructure() { |
---|
35 | effect_radius = Parameter(20.75, true); |
---|
36 | effect_radius.set_min(0.0); |
---|
37 | charge = Parameter(19.0, true); |
---|
38 | volfraction = Parameter(0.0192, true); |
---|
39 | volfraction.set_min(0.0); |
---|
40 | temperature = Parameter(318.16, true); |
---|
41 | temperature.set_min(0.0); |
---|
42 | saltconc = Parameter(0.0); |
---|
43 | dielectconst = Parameter(71.08); |
---|
44 | } |
---|
45 | |
---|
46 | /** |
---|
47 | * Function to evaluate 1D scattering function |
---|
48 | * The NIST IGOR library is used for the actual calculation. |
---|
49 | * @param q: q-value |
---|
50 | * @return: function value |
---|
51 | */ |
---|
52 | double HayterMSAStructure :: operator()(double q) { |
---|
53 | double dp[6]; |
---|
54 | |
---|
55 | // Fill parameter array for IGOR library |
---|
56 | // Add the background after averaging |
---|
57 | dp[0] = 2.0*effect_radius(); |
---|
58 | dp[1] = fabs(charge()); |
---|
59 | dp[2] = volfraction(); |
---|
60 | dp[3] = temperature(); |
---|
61 | dp[4] = saltconc(); |
---|
62 | dp[5] = dielectconst(); |
---|
63 | |
---|
64 | // Get the dispersion points for the radius |
---|
65 | vector<WeightPoint> weights_rad; |
---|
66 | effect_radius.get_weights(weights_rad); |
---|
67 | |
---|
68 | // Perform the computation, with all weight points |
---|
69 | double sum = 0.0; |
---|
70 | double norm = 0.0; |
---|
71 | |
---|
72 | // Loop over radius weight points |
---|
73 | for(int i=0; i<weights_rad.size(); i++) { |
---|
74 | dp[0] = 2.0*weights_rad[i].value; |
---|
75 | |
---|
76 | sum += weights_rad[i].weight |
---|
77 | * HayterPenfoldMSA(dp, q); |
---|
78 | norm += weights_rad[i].weight; |
---|
79 | } |
---|
80 | return sum/norm ; |
---|
81 | } |
---|
82 | |
---|
83 | /** |
---|
84 | * Function to evaluate 2D scattering function |
---|
85 | * @param q_x: value of Q along x |
---|
86 | * @param q_y: value of Q along y |
---|
87 | * @return: function value |
---|
88 | */ |
---|
89 | double HayterMSAStructure :: operator()(double qx, double qy) { |
---|
90 | double q = sqrt(qx*qx + qy*qy); |
---|
91 | return (*this).operator()(q); |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | * Function to evaluate 2D scattering function |
---|
96 | * @param pars: parameters of the cylinder |
---|
97 | * @param q: q-value |
---|
98 | * @param phi: angle phi |
---|
99 | * @return: function value |
---|
100 | */ |
---|
101 | double HayterMSAStructure :: evaluate_rphi(double q, double phi) { |
---|
102 | double qx = q*cos(phi); |
---|
103 | double qy = q*sin(phi); |
---|
104 | return (*this).operator()(qx, qy); |
---|
105 | } |
---|
106 | /** |
---|
107 | * Function to calculate effective radius |
---|
108 | * @return: effective radius value |
---|
109 | */ |
---|
110 | double HayterMSAStructure :: calculate_ER() { |
---|
111 | //NOT implemented yet!!! |
---|
112 | } |
---|
113 | |
---|
114 | // Testing code |
---|
115 | /* |
---|
116 | int main(void) |
---|
117 | { |
---|
118 | SquareWellModel c = SquareWellModel(); |
---|
119 | |
---|
120 | printf("I(Qx=%g,Qy=%g) = %g\n", 0.001, 0.001, c(0.001, 0.001)); |
---|
121 | printf("I(Q=%g) = %g\n", 0.001, c(0.001)); |
---|
122 | c.radius.dispersion = new GaussianDispersion(); |
---|
123 | c.radius.dispersion->npts = 100; |
---|
124 | c.radius.dispersion->width = 5; |
---|
125 | |
---|
126 | //c.length.dispersion = GaussianDispersion(); |
---|
127 | //c.length.dispersion.npts = 20; |
---|
128 | //c.length.dispersion.width = 65; |
---|
129 | |
---|
130 | printf("I(Q=%g) = %g\n", 0.001, c(0.001)); |
---|
131 | printf("I(Q=%g) = %g\n", 0.001, c(0.001)); |
---|
132 | printf("I(Qx=%g, Qy=%g) = %g\n", 0.001, 0.001, c(0.001, 0.001)); |
---|
133 | printf("I(Q=%g, Phi=%g) = %g\n", 0.00447, .7854, c.evaluate_rphi(sqrt(0.00002), .7854)); |
---|
134 | |
---|
135 | |
---|
136 | |
---|
137 | double i_avg = c(0.01, 0.01); |
---|
138 | double i_1d = c(sqrt(0.0002)); |
---|
139 | |
---|
140 | printf("\nI(Qx=%g, Qy=%g) = %g\n", 0.01, 0.01, i_avg); |
---|
141 | printf("I(Q=%g) = %g\n", sqrt(0.0002), i_1d); |
---|
142 | printf("ratio %g %g\n", i_avg/i_1d, i_1d/i_avg); |
---|
143 | |
---|
144 | |
---|
145 | return 0; |
---|
146 | } |
---|
147 | */ |
---|