[5068697] | 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 "libCylinder.h" |
---|
| 31 | #include "triaxial_ellipsoid.h" |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | TriaxialEllipsoidModel :: TriaxialEllipsoidModel() { |
---|
| 35 | scale = Parameter(1.0); |
---|
[3c102d4] | 36 | semi_axisA = Parameter(35.0, true); |
---|
[5068697] | 37 | semi_axisA.set_min(0.0); |
---|
[3c102d4] | 38 | semi_axisB = Parameter(100.0, true); |
---|
[5068697] | 39 | semi_axisB.set_min(0.0); |
---|
| 40 | semi_axisC = Parameter(400.0, true); |
---|
| 41 | semi_axisC.set_min(0.0); |
---|
| 42 | contrast = Parameter(5.3e-6); |
---|
| 43 | background = Parameter(0.0); |
---|
[3c102d4] | 44 | axis_theta = Parameter(1.0, true); |
---|
| 45 | axis_phi = Parameter(1.0, true); |
---|
[975ec8e] | 46 | axis_psi = Parameter(0.0, true); |
---|
[5068697] | 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 TriaxialEllipsoidModel :: operator()(double q) { |
---|
[975ec8e] | 56 | double dp[6]; |
---|
[5068697] | 57 | |
---|
| 58 | // Fill parameter array for IGOR library |
---|
| 59 | // Add the background after averaging |
---|
| 60 | dp[0] = scale(); |
---|
| 61 | dp[1] = semi_axisA(); |
---|
| 62 | dp[2] = semi_axisB(); |
---|
| 63 | dp[3] = semi_axisC(); |
---|
| 64 | dp[4] = contrast(); |
---|
[9188cc1] | 65 | dp[5] = 0.0; |
---|
[5068697] | 66 | |
---|
| 67 | // Get the dispersion points for the semi axis A |
---|
| 68 | vector<WeightPoint> weights_semi_axisA; |
---|
| 69 | semi_axisA.get_weights(weights_semi_axisA); |
---|
| 70 | |
---|
| 71 | // Get the dispersion points for the semi axis B |
---|
| 72 | vector<WeightPoint> weights_semi_axisB; |
---|
| 73 | semi_axisB.get_weights(weights_semi_axisB); |
---|
| 74 | |
---|
| 75 | // Get the dispersion points for the semi axis C |
---|
| 76 | vector<WeightPoint> weights_semi_axisC; |
---|
| 77 | semi_axisC.get_weights(weights_semi_axisC); |
---|
| 78 | |
---|
| 79 | // Perform the computation, with all weight points |
---|
| 80 | double sum = 0.0; |
---|
| 81 | double norm = 0.0; |
---|
| 82 | |
---|
| 83 | // Loop over semi axis A weight points |
---|
| 84 | for(int i=0; i< (int)weights_semi_axisA.size(); i++) { |
---|
| 85 | dp[1] = weights_semi_axisA[i].value; |
---|
| 86 | |
---|
| 87 | // Loop over semi axis B weight points |
---|
| 88 | for(int j=0; j< (int)weights_semi_axisB.size(); j++) { |
---|
| 89 | dp[2] = weights_semi_axisB[j].value; |
---|
| 90 | |
---|
| 91 | // Loop over semi axis C weight points |
---|
| 92 | for(int k=0; k< (int)weights_semi_axisC.size(); k++) { |
---|
| 93 | dp[3] = weights_semi_axisC[k].value; |
---|
| 94 | |
---|
| 95 | sum += weights_semi_axisA[i].weight |
---|
| 96 | * weights_semi_axisB[j].weight * weights_semi_axisC[k].weight* TriaxialEllipsoid(dp, q); |
---|
| 97 | norm += weights_semi_axisA[i].weight |
---|
| 98 | * weights_semi_axisB[j].weight * weights_semi_axisC[k].weight; |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | return sum/norm + background(); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | /** |
---|
| 106 | * Function to evaluate 2D scattering function |
---|
| 107 | * @param q_x: value of Q along x |
---|
| 108 | * @param q_y: value of Q along y |
---|
| 109 | * @return: function value |
---|
| 110 | */ |
---|
| 111 | double TriaxialEllipsoidModel :: operator()(double qx, double qy) { |
---|
| 112 | TriaxialEllipsoidParameters dp; |
---|
| 113 | // Fill parameter array |
---|
| 114 | dp.scale = scale(); |
---|
| 115 | dp.semi_axisA = semi_axisA(); |
---|
| 116 | dp.semi_axisB = semi_axisB(); |
---|
| 117 | dp.semi_axisC = semi_axisC(); |
---|
| 118 | dp.contrast = contrast(); |
---|
| 119 | dp.background = 0.0; |
---|
| 120 | dp.axis_theta = axis_theta(); |
---|
| 121 | dp.axis_phi = axis_phi(); |
---|
[975ec8e] | 122 | dp.axis_psi = axis_psi(); |
---|
[5068697] | 123 | |
---|
| 124 | // Get the dispersion points for the semi_axis A |
---|
| 125 | vector<WeightPoint> weights_semi_axisA; |
---|
| 126 | semi_axisA.get_weights(weights_semi_axisA); |
---|
| 127 | |
---|
| 128 | // Get the dispersion points for the semi_axis B |
---|
| 129 | vector<WeightPoint> weights_semi_axisB; |
---|
| 130 | semi_axisB.get_weights(weights_semi_axisB); |
---|
| 131 | |
---|
| 132 | // Get the dispersion points for the semi_axis C |
---|
| 133 | vector<WeightPoint> weights_semi_axisC; |
---|
| 134 | semi_axisC.get_weights(weights_semi_axisC); |
---|
| 135 | |
---|
| 136 | // Get angular averaging for theta |
---|
| 137 | vector<WeightPoint> weights_theta; |
---|
| 138 | axis_theta.get_weights(weights_theta); |
---|
| 139 | |
---|
| 140 | // Get angular averaging for phi |
---|
| 141 | vector<WeightPoint> weights_phi; |
---|
| 142 | axis_phi.get_weights(weights_phi); |
---|
| 143 | |
---|
[975ec8e] | 144 | // Get angular averaging for psi |
---|
| 145 | vector<WeightPoint> weights_psi; |
---|
| 146 | axis_psi.get_weights(weights_psi); |
---|
| 147 | |
---|
[5068697] | 148 | // Perform the computation, with all weight points |
---|
| 149 | double sum = 0.0; |
---|
| 150 | double norm = 0.0; |
---|
| 151 | |
---|
| 152 | // Loop over semi axis A weight points |
---|
| 153 | for(int i=0; i< (int)weights_semi_axisA.size(); i++) { |
---|
| 154 | dp.semi_axisA = weights_semi_axisA[i].value; |
---|
| 155 | |
---|
| 156 | // Loop over semi axis B weight points |
---|
| 157 | for(int j=0; j< (int)weights_semi_axisB.size(); j++) { |
---|
| 158 | dp.semi_axisB = weights_semi_axisB[j].value; |
---|
| 159 | |
---|
| 160 | // Loop over semi axis C weight points |
---|
| 161 | for(int k=0; k < (int)weights_semi_axisC.size(); k++) { |
---|
| 162 | dp.semi_axisC = weights_semi_axisC[k].value; |
---|
| 163 | |
---|
| 164 | // Average over theta distribution |
---|
| 165 | for(int l=0; l< (int)weights_theta.size(); l++) { |
---|
| 166 | dp.axis_theta = weights_theta[l].value; |
---|
| 167 | |
---|
| 168 | // Average over phi distribution |
---|
| 169 | for(int m=0; m <(int)weights_phi.size(); m++) { |
---|
| 170 | dp.axis_phi = weights_phi[m].value; |
---|
[975ec8e] | 171 | // Average over psi distribution |
---|
| 172 | for(int n=0; n <(int)weights_psi.size(); n++) { |
---|
| 173 | dp.axis_psi = weights_psi[n].value; |
---|
| 174 | |
---|
| 175 | double _ptvalue = weights_semi_axisA[i].weight |
---|
| 176 | * weights_semi_axisB[j].weight |
---|
| 177 | * weights_semi_axisC[k].weight |
---|
| 178 | * weights_theta[l].weight |
---|
| 179 | * weights_phi[m].weight |
---|
| 180 | * weights_psi[n].weight |
---|
| 181 | * triaxial_ellipsoid_analytical_2DXY(&dp, qx, qy); |
---|
| 182 | if (weights_theta.size()>1) { |
---|
| 183 | _ptvalue *= sin(weights_theta[k].value); |
---|
| 184 | } |
---|
| 185 | sum += _ptvalue; |
---|
| 186 | |
---|
| 187 | norm += weights_semi_axisA[i].weight |
---|
| 188 | * weights_semi_axisB[j].weight |
---|
| 189 | * weights_semi_axisC[k].weight |
---|
| 190 | * weights_theta[l].weight |
---|
| 191 | * weights_phi[m].weight |
---|
[3c102d4] | 192 | * weights_psi[n].weight; |
---|
[5068697] | 193 | } |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | // Averaging in theta needs an extra normalization |
---|
| 201 | // factor to account for the sin(theta) term in the |
---|
| 202 | // integration (see documentation). |
---|
| 203 | if (weights_theta.size()>1) norm = norm / asin(1.0); |
---|
| 204 | return sum/norm + background(); |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | /** |
---|
| 208 | * Function to evaluate 2D scattering function |
---|
| 209 | * @param pars: parameters of the triaxial ellipsoid |
---|
| 210 | * @param q: q-value |
---|
| 211 | * @param phi: angle phi |
---|
| 212 | * @return: function value |
---|
| 213 | */ |
---|
| 214 | double TriaxialEllipsoidModel :: evaluate_rphi(double q, double phi) { |
---|
| 215 | double qx = q*cos(phi); |
---|
| 216 | double qy = q*sin(phi); |
---|
| 217 | return (*this).operator()(qx, qy); |
---|
| 218 | } |
---|