[8a48713] | 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 "parallelepiped.h" |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | ParallelepipedModel :: ParallelepipedModel() { |
---|
| 36 | scale = Parameter(1.0); |
---|
[3c102d4] | 37 | short_a = Parameter(35.0, true); |
---|
| 38 | short_a.set_max(1.0); |
---|
| 39 | long_b = Parameter(75.0, true); |
---|
| 40 | long_b.set_min(1.0); |
---|
| 41 | longer_c = Parameter(400.0, true); |
---|
| 42 | longer_c.set_min(1.0); |
---|
[8a48713] | 43 | contrast = Parameter(53.e-7); |
---|
| 44 | background = Parameter(0.0); |
---|
| 45 | parallel_theta = Parameter(0.0, true); |
---|
| 46 | parallel_phi = Parameter(0.0, true); |
---|
[975ec8e] | 47 | parallel_psi = Parameter(0.0, true); |
---|
[8a48713] | 48 | } |
---|
| 49 | |
---|
| 50 | /** |
---|
| 51 | * Function to evaluate 1D scattering function |
---|
| 52 | * The NIST IGOR library is used for the actual calculation. |
---|
| 53 | * @param q: q-value |
---|
| 54 | * @return: function value |
---|
| 55 | */ |
---|
| 56 | double ParallelepipedModel :: operator()(double q) { |
---|
[975ec8e] | 57 | double dp[6]; |
---|
[8a48713] | 58 | |
---|
| 59 | // Fill parameter array for IGOR library |
---|
| 60 | // Add the background after averaging |
---|
| 61 | dp[0] = scale(); |
---|
[3c102d4] | 62 | dp[1] = short_a(); |
---|
| 63 | dp[2] = long_b(); |
---|
| 64 | dp[3] = longer_c(); |
---|
[8a48713] | 65 | dp[4] = contrast(); |
---|
| 66 | dp[5] = 0.0; |
---|
| 67 | |
---|
| 68 | // Get the dispersion points for the short_edgeA |
---|
[3c102d4] | 69 | vector<WeightPoint> weights_short_a; |
---|
| 70 | short_a.get_weights(weights_short_a); |
---|
[975ec8e] | 71 | |
---|
[8a48713] | 72 | // Get the dispersion points for the longer_edgeB |
---|
[3c102d4] | 73 | vector<WeightPoint> weights_long_b; |
---|
| 74 | long_b.get_weights(weights_long_b); |
---|
[8a48713] | 75 | |
---|
| 76 | // Get the dispersion points for the longuest_edgeC |
---|
[3c102d4] | 77 | vector<WeightPoint> weights_longer_c; |
---|
| 78 | longer_c.get_weights(weights_longer_c); |
---|
[8a48713] | 79 | |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | // Perform the computation, with all weight points |
---|
| 83 | double sum = 0.0; |
---|
| 84 | double norm = 0.0; |
---|
[975ec8e] | 85 | |
---|
[8a48713] | 86 | // Loop over short_edgeA weight points |
---|
[3c102d4] | 87 | for(int i=0; i< (int)weights_short_a.size(); i++) { |
---|
| 88 | dp[1] = weights_short_a[i].value; |
---|
[8a48713] | 89 | |
---|
| 90 | // Loop over longer_edgeB weight points |
---|
[3c102d4] | 91 | for(int j=0; j< (int)weights_long_b.size(); j++) { |
---|
| 92 | dp[2] = weights_long_b[j].value; |
---|
[8a48713] | 93 | |
---|
| 94 | // Loop over longuest_edgeC weight points |
---|
[3c102d4] | 95 | for(int k=0; k< (int)weights_longer_c.size(); k++) { |
---|
| 96 | dp[3] = weights_longer_c[k].value; |
---|
[8a48713] | 97 | |
---|
[3c102d4] | 98 | sum += weights_short_a[i].weight * weights_long_b[j].weight |
---|
| 99 | * weights_longer_c[k].weight * Parallelepiped(dp, q); |
---|
[8a48713] | 100 | |
---|
[3c102d4] | 101 | norm += weights_short_a[i].weight |
---|
| 102 | * weights_long_b[j].weight * weights_longer_c[k].weight; |
---|
[8a48713] | 103 | } |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | return sum/norm + background(); |
---|
| 107 | } |
---|
| 108 | /** |
---|
| 109 | * Function to evaluate 2D scattering function |
---|
| 110 | * @param q_x: value of Q along x |
---|
| 111 | * @param q_y: value of Q along y |
---|
| 112 | * @return: function value |
---|
| 113 | */ |
---|
| 114 | double ParallelepipedModel :: operator()(double qx, double qy) { |
---|
| 115 | ParallelepipedParameters dp; |
---|
| 116 | // Fill parameter array |
---|
| 117 | dp.scale = scale(); |
---|
[3c102d4] | 118 | dp.short_a = short_a(); |
---|
| 119 | dp.long_b = long_b(); |
---|
| 120 | dp.longer_c = longer_c(); |
---|
[8a48713] | 121 | dp.contrast = contrast(); |
---|
| 122 | dp.background = 0.0; |
---|
| 123 | //dp.background = background(); |
---|
| 124 | dp.parallel_theta = parallel_theta(); |
---|
| 125 | dp.parallel_phi = parallel_phi(); |
---|
[975ec8e] | 126 | dp.parallel_psi = parallel_psi(); |
---|
| 127 | |
---|
[8a48713] | 128 | |
---|
| 129 | // Get the dispersion points for the short_edgeA |
---|
[3c102d4] | 130 | vector<WeightPoint> weights_short_a; |
---|
| 131 | short_a.get_weights(weights_short_a); |
---|
[8a48713] | 132 | |
---|
| 133 | // Get the dispersion points for the longer_edgeB |
---|
[3c102d4] | 134 | vector<WeightPoint> weights_long_b; |
---|
| 135 | long_b.get_weights(weights_long_b); |
---|
[8a48713] | 136 | |
---|
| 137 | // Get angular averaging for the longuest_edgeC |
---|
[3c102d4] | 138 | vector<WeightPoint> weights_longer_c; |
---|
| 139 | longer_c.get_weights(weights_longer_c); |
---|
[8a48713] | 140 | |
---|
| 141 | // Get angular averaging for theta |
---|
| 142 | vector<WeightPoint> weights_parallel_theta; |
---|
| 143 | parallel_theta.get_weights(weights_parallel_theta); |
---|
| 144 | |
---|
| 145 | // Get angular averaging for phi |
---|
| 146 | vector<WeightPoint> weights_parallel_phi; |
---|
| 147 | parallel_phi.get_weights(weights_parallel_phi); |
---|
| 148 | |
---|
[975ec8e] | 149 | // Get angular averaging for psi |
---|
| 150 | vector<WeightPoint> weights_parallel_psi; |
---|
| 151 | parallel_psi.get_weights(weights_parallel_psi); |
---|
[8a48713] | 152 | |
---|
| 153 | // Perform the computation, with all weight points |
---|
| 154 | double sum = 0.0; |
---|
| 155 | double norm = 0.0; |
---|
| 156 | |
---|
| 157 | // Loop over radius weight points |
---|
[3c102d4] | 158 | for(int i=0; i< (int)weights_short_a.size(); i++) { |
---|
| 159 | dp.short_a = weights_short_a[i].value; |
---|
[8a48713] | 160 | |
---|
| 161 | // Loop over longer_edgeB weight points |
---|
[3c102d4] | 162 | for(int j=0; j< (int)weights_long_b.size(); j++) { |
---|
| 163 | dp.long_b = weights_long_b[j].value; |
---|
[8a48713] | 164 | |
---|
| 165 | // Average over longuest_edgeC distribution |
---|
[3c102d4] | 166 | for(int k=0; k< (int)weights_longer_c.size(); k++) { |
---|
| 167 | dp.longer_c = weights_longer_c[k].value; |
---|
[8a48713] | 168 | |
---|
| 169 | // Average over theta distribution |
---|
| 170 | for(int l=0; l< (int)weights_parallel_theta.size(); l++) { |
---|
| 171 | dp.parallel_theta = weights_parallel_theta[l].value; |
---|
| 172 | |
---|
| 173 | // Average over phi distribution |
---|
| 174 | for(int m=0; m< (int)weights_parallel_phi.size(); m++) { |
---|
| 175 | dp.parallel_phi = weights_parallel_phi[m].value; |
---|
| 176 | |
---|
[975ec8e] | 177 | // Average over phi distribution |
---|
| 178 | for(int n=0; n< (int)weights_parallel_psi.size(); n++) { |
---|
| 179 | dp.parallel_psi = weights_parallel_psi[n].value; |
---|
| 180 | |
---|
[3c102d4] | 181 | double _ptvalue = weights_short_a[i].weight |
---|
| 182 | * weights_long_b[j].weight |
---|
| 183 | * weights_longer_c[k].weight |
---|
[975ec8e] | 184 | * weights_parallel_theta[l].weight |
---|
| 185 | * weights_parallel_phi[m].weight |
---|
| 186 | * weights_parallel_psi[n].weight |
---|
| 187 | * parallelepiped_analytical_2DXY(&dp, qx, qy); |
---|
| 188 | if (weights_parallel_theta.size()>1) { |
---|
| 189 | _ptvalue *= sin(weights_parallel_theta[l].value); |
---|
| 190 | } |
---|
| 191 | sum += _ptvalue; |
---|
| 192 | |
---|
[3c102d4] | 193 | norm += weights_short_a[i].weight |
---|
| 194 | * weights_long_b[j].weight |
---|
| 195 | * weights_longer_c[k].weight |
---|
[975ec8e] | 196 | * weights_parallel_theta[l].weight |
---|
| 197 | * weights_parallel_phi[m].weight |
---|
| 198 | * weights_parallel_psi[n].weight; |
---|
[8a48713] | 199 | } |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | // Averaging in theta needs an extra normalization |
---|
| 207 | // factor to account for the sin(theta) term in the |
---|
| 208 | // integration (see documentation). |
---|
| 209 | if (weights_parallel_theta.size()>1) norm = norm / asin(1.0); |
---|
| 210 | return sum/norm + background(); |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | |
---|
| 214 | /** |
---|
| 215 | * Function to evaluate 2D scattering function |
---|
| 216 | * @param pars: parameters of the cylinder |
---|
| 217 | * @param q: q-value |
---|
| 218 | * @param phi: angle phi |
---|
| 219 | * @return: function value |
---|
| 220 | */ |
---|
| 221 | double ParallelepipedModel :: evaluate_rphi(double q, double phi) { |
---|
| 222 | double qx = q*cos(phi); |
---|
| 223 | double qy = q*sin(phi); |
---|
| 224 | return (*this).operator()(qx, qy); |
---|
| 225 | } |
---|