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