[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" |
---|
| 31 | #include "ellipsoid.h" |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | EllipsoidModel :: EllipsoidModel() { |
---|
| 35 | scale = Parameter(1.0); |
---|
| 36 | radius_a = Parameter(20.0, true); |
---|
| 37 | radius_a.set_min(0.0); |
---|
| 38 | radius_b = Parameter(400.0, true); |
---|
| 39 | radius_b.set_min(0.0); |
---|
| 40 | contrast = Parameter(3.e-6); |
---|
| 41 | background = Parameter(0.0); |
---|
| 42 | axis_theta = Parameter(1.57, true); |
---|
| 43 | axis_phi = Parameter(0.0, true); |
---|
| 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 EllipsoidModel :: operator()(double q) { |
---|
| 53 | double dp[5]; |
---|
| 54 | |
---|
| 55 | // Fill parameter array for IGOR library |
---|
| 56 | // Add the background after averaging |
---|
| 57 | dp[0] = scale(); |
---|
| 58 | dp[1] = radius_a(); |
---|
| 59 | dp[2] = radius_b(); |
---|
| 60 | dp[3] = contrast(); |
---|
| 61 | dp[4] = 0.0; |
---|
| 62 | |
---|
| 63 | // Get the dispersion points for the radius_a |
---|
| 64 | vector<WeightPoint> weights_rad_a; |
---|
| 65 | radius_a.get_weights(weights_rad_a); |
---|
| 66 | |
---|
| 67 | // Get the dispersion points for the radius_b |
---|
| 68 | vector<WeightPoint> weights_rad_b; |
---|
| 69 | radius_b.get_weights(weights_rad_b); |
---|
| 70 | |
---|
| 71 | // Perform the computation, with all weight points |
---|
| 72 | double sum = 0.0; |
---|
| 73 | double norm = 0.0; |
---|
| 74 | |
---|
| 75 | // Loop over radius_a weight points |
---|
| 76 | for(int i=0; i<weights_rad_a.size(); i++) { |
---|
| 77 | dp[1] = weights_rad_a[i].value; |
---|
| 78 | |
---|
| 79 | // Loop over radius_b weight points |
---|
| 80 | for(int j=0; j<weights_rad_b.size(); j++) { |
---|
| 81 | dp[2] = weights_rad_b[j].value; |
---|
| 82 | |
---|
| 83 | sum += weights_rad_a[i].weight |
---|
| 84 | * weights_rad_b[j].weight * EllipsoidForm(dp, q); |
---|
| 85 | norm += weights_rad_a[i].weight |
---|
| 86 | * weights_rad_b[j].weight; |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | return sum/norm + background(); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | /** |
---|
| 93 | * Function to evaluate 2D scattering function |
---|
| 94 | * @param q_x: value of Q along x |
---|
| 95 | * @param q_y: value of Q along y |
---|
| 96 | * @return: function value |
---|
| 97 | */ |
---|
| 98 | double EllipsoidModel :: operator()(double qx, double qy) { |
---|
| 99 | EllipsoidParameters dp; |
---|
| 100 | // Fill parameter array |
---|
| 101 | dp.scale = scale(); |
---|
| 102 | dp.radius_a = radius_a(); |
---|
| 103 | dp.radius_b = radius_b(); |
---|
| 104 | dp.contrast = contrast(); |
---|
| 105 | dp.background = 0.0; |
---|
| 106 | dp.axis_theta = axis_theta(); |
---|
| 107 | dp.axis_phi = axis_phi(); |
---|
| 108 | |
---|
| 109 | // Get the dispersion points for the radius_a |
---|
| 110 | vector<WeightPoint> weights_rad_a; |
---|
| 111 | radius_a.get_weights(weights_rad_a); |
---|
| 112 | |
---|
| 113 | // Get the dispersion points for the radius_b |
---|
| 114 | vector<WeightPoint> weights_rad_b; |
---|
| 115 | radius_b.get_weights(weights_rad_b); |
---|
| 116 | |
---|
| 117 | // Get angular averaging for theta |
---|
| 118 | vector<WeightPoint> weights_theta; |
---|
| 119 | axis_theta.get_weights(weights_theta); |
---|
| 120 | |
---|
| 121 | // Get angular averaging for phi |
---|
| 122 | vector<WeightPoint> weights_phi; |
---|
| 123 | axis_phi.get_weights(weights_phi); |
---|
| 124 | |
---|
| 125 | // Perform the computation, with all weight points |
---|
| 126 | double sum = 0.0; |
---|
| 127 | double norm = 0.0; |
---|
| 128 | |
---|
| 129 | // Loop over radius weight points |
---|
| 130 | for(int i=0; i<weights_rad_a.size(); i++) { |
---|
| 131 | dp.radius_a = weights_rad_a[i].value; |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | // Loop over length weight points |
---|
| 135 | for(int j=0; j<weights_rad_b.size(); j++) { |
---|
| 136 | dp.radius_b = weights_rad_b[j].value; |
---|
| 137 | |
---|
| 138 | // Average over theta distribution |
---|
| 139 | for(int k=0; k<weights_theta.size(); k++) { |
---|
| 140 | dp.axis_theta = weights_theta[k].value; |
---|
| 141 | |
---|
| 142 | // Average over phi distribution |
---|
| 143 | for(int l=0; l<weights_phi.size(); l++) { |
---|
| 144 | dp.axis_phi = weights_phi[l].value; |
---|
| 145 | |
---|
| 146 | double _ptvalue = weights_rad_a[i].weight |
---|
| 147 | * weights_rad_b[j].weight |
---|
| 148 | * weights_theta[k].weight |
---|
| 149 | * weights_phi[l].weight |
---|
| 150 | * ellipsoid_analytical_2DXY(&dp, qx, qy); |
---|
| 151 | if (weights_theta.size()>1) { |
---|
| 152 | _ptvalue *= sin(weights_theta[k].value); |
---|
| 153 | } |
---|
| 154 | sum += _ptvalue; |
---|
| 155 | |
---|
| 156 | norm += weights_rad_a[i].weight |
---|
| 157 | * weights_rad_b[j].weight |
---|
| 158 | * weights_theta[k].weight |
---|
| 159 | * weights_phi[l].weight; |
---|
| 160 | |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | // Averaging in theta needs an extra normalization |
---|
| 166 | // factor to account for the sin(theta) term in the |
---|
| 167 | // integration (see documentation). |
---|
| 168 | if (weights_theta.size()>1) norm = norm / asin(1.0); |
---|
| 169 | return sum/norm + background(); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | /** |
---|
| 173 | * Function to evaluate 2D scattering function |
---|
| 174 | * @param pars: parameters of the cylinder |
---|
| 175 | * @param q: q-value |
---|
| 176 | * @param phi: angle phi |
---|
| 177 | * @return: function value |
---|
| 178 | */ |
---|
| 179 | double EllipsoidModel :: evaluate_rphi(double q, double phi) { |
---|
| 180 | double qx = q*cos(phi); |
---|
| 181 | double qy = q*sin(phi); |
---|
| 182 | return (*this).operator()(qx, qy); |
---|
| 183 | } |
---|