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