[27fea3f] | 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 "hollow_cylinder.h" |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | HollowCylinderModel :: HollowCylinderModel() { |
---|
| 35 | scale = Parameter(1.0); |
---|
| 36 | core_radius = Parameter(20.0, true); |
---|
| 37 | core_radius.set_min(0.0); |
---|
[e2afadf] | 38 | radius = Parameter(30.0, true); |
---|
| 39 | radius.set_min(0.0); |
---|
[27fea3f] | 40 | length = Parameter(400.0, true); |
---|
| 41 | length.set_min(0.0); |
---|
| 42 | contrast = Parameter(5.3e-6); |
---|
| 43 | background = Parameter(0.0); |
---|
| 44 | axis_theta = Parameter(0.0, true); |
---|
| 45 | axis_phi = Parameter(0.0, true); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | /** |
---|
| 49 | * Function to evaluate 1D scattering function |
---|
| 50 | * The NIST IGOR library is used for the actual calculation. |
---|
| 51 | * @param q: q-value |
---|
| 52 | * @return: function value |
---|
| 53 | */ |
---|
| 54 | double HollowCylinderModel :: operator()(double q) { |
---|
| 55 | double dp[6]; |
---|
| 56 | |
---|
| 57 | dp[0] = scale(); |
---|
| 58 | dp[1] = core_radius(); |
---|
[e2afadf] | 59 | dp[2] = radius(); |
---|
[27fea3f] | 60 | dp[3] = length(); |
---|
| 61 | dp[4] = contrast(); |
---|
[9188cc1] | 62 | dp[5] = 0.0; |
---|
[27fea3f] | 63 | |
---|
| 64 | // Get the dispersion points for the core radius |
---|
| 65 | vector<WeightPoint> weights_core_radius; |
---|
| 66 | core_radius.get_weights(weights_core_radius); |
---|
| 67 | |
---|
| 68 | // Get the dispersion points for the shell radius |
---|
[e2afadf] | 69 | vector<WeightPoint> weights_radius; |
---|
| 70 | radius.get_weights(weights_radius); |
---|
[27fea3f] | 71 | |
---|
| 72 | // Get the dispersion points for the length |
---|
| 73 | vector<WeightPoint> weights_length; |
---|
| 74 | length.get_weights(weights_length); |
---|
| 75 | |
---|
| 76 | // Perform the computation, with all weight points |
---|
| 77 | double sum = 0.0; |
---|
| 78 | double norm = 0.0; |
---|
| 79 | |
---|
| 80 | // Loop over core radius weight points |
---|
| 81 | for(int i=0; i< (int)weights_core_radius.size(); i++) { |
---|
| 82 | dp[1] = weights_core_radius[i].value; |
---|
| 83 | |
---|
| 84 | // Loop over length weight points |
---|
| 85 | for(int j=0; j< (int)weights_length.size(); j++) { |
---|
| 86 | dp[3] = weights_length[j].value; |
---|
| 87 | |
---|
| 88 | // Loop over shell radius weight points |
---|
[e2afadf] | 89 | for(int k=0; k< (int)weights_radius.size(); k++) { |
---|
| 90 | dp[2] = weights_radius[k].value; |
---|
[27fea3f] | 91 | |
---|
| 92 | sum += weights_core_radius[i].weight |
---|
| 93 | * weights_length[j].weight |
---|
[e2afadf] | 94 | * weights_radius[k].weight |
---|
[27fea3f] | 95 | * HollowCylinder(dp, q); |
---|
| 96 | norm += weights_core_radius[i].weight |
---|
| 97 | * weights_length[j].weight |
---|
[e2afadf] | 98 | * weights_radius[k].weight; |
---|
[27fea3f] | 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 HollowCylinderModel :: operator()(double qx, double qy) { |
---|
| 112 | HollowCylinderParameters dp; |
---|
| 113 | // Fill parameter array |
---|
| 114 | dp.scale = scale(); |
---|
| 115 | dp.core_radius = core_radius(); |
---|
[e2afadf] | 116 | dp.radius = radius(); |
---|
[27fea3f] | 117 | dp.length = length(); |
---|
| 118 | dp.contrast = contrast(); |
---|
[9188cc1] | 119 | dp.background = 0.0; |
---|
[27fea3f] | 120 | dp.axis_theta = axis_theta(); |
---|
| 121 | dp.axis_phi = axis_phi(); |
---|
| 122 | |
---|
| 123 | // Get the dispersion points for the core radius |
---|
| 124 | vector<WeightPoint> weights_core_radius; |
---|
| 125 | core_radius.get_weights(weights_core_radius); |
---|
| 126 | |
---|
| 127 | // Get the dispersion points for the shell radius |
---|
[e2afadf] | 128 | vector<WeightPoint> weights_radius; |
---|
| 129 | radius.get_weights(weights_radius); |
---|
[27fea3f] | 130 | |
---|
| 131 | // Get the dispersion points for the length |
---|
| 132 | vector<WeightPoint> weights_length; |
---|
| 133 | length.get_weights(weights_length); |
---|
| 134 | |
---|
| 135 | // Get angular averaging for theta |
---|
| 136 | vector<WeightPoint> weights_theta; |
---|
| 137 | axis_theta.get_weights(weights_theta); |
---|
| 138 | |
---|
| 139 | // Get angular averaging for phi |
---|
| 140 | vector<WeightPoint> weights_phi; |
---|
| 141 | axis_phi.get_weights(weights_phi); |
---|
| 142 | |
---|
| 143 | // Perform the computation, with all weight points |
---|
| 144 | double sum = 0.0; |
---|
| 145 | double norm = 0.0; |
---|
| 146 | |
---|
| 147 | // Loop over core radius weight points |
---|
| 148 | for(int i=0; i<(int)weights_core_radius.size(); i++) { |
---|
| 149 | dp.core_radius = weights_core_radius[i].value; |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | // Loop over length weight points |
---|
| 153 | for(int j=0; j<(int)weights_length.size(); j++) { |
---|
| 154 | dp.length = weights_length[j].value; |
---|
| 155 | |
---|
| 156 | // Loop over shell radius weight points |
---|
[e2afadf] | 157 | for(int m=0; m< (int)weights_radius.size(); m++) { |
---|
| 158 | dp.radius = weights_radius[m].value; |
---|
[27fea3f] | 159 | |
---|
| 160 | // Average over theta distribution |
---|
| 161 | for(int k=0; k< (int)weights_theta.size(); k++) { |
---|
| 162 | dp.axis_theta = weights_theta[k].value; |
---|
| 163 | |
---|
| 164 | // Average over phi distribution |
---|
| 165 | for(int l=0; l< (int)weights_phi.size(); l++) { |
---|
| 166 | dp.axis_phi = weights_phi[l].value; |
---|
| 167 | |
---|
| 168 | double _ptvalue = weights_core_radius[i].weight |
---|
| 169 | * weights_length[j].weight |
---|
[e2afadf] | 170 | * weights_radius[m].weight |
---|
[27fea3f] | 171 | * weights_theta[k].weight |
---|
| 172 | * weights_phi[l].weight |
---|
| 173 | * hollow_cylinder_analytical_2DXY(&dp, qx, qy); |
---|
| 174 | if (weights_theta.size()>1) { |
---|
| 175 | _ptvalue *= sin(weights_theta[k].value); |
---|
| 176 | } |
---|
| 177 | sum += _ptvalue; |
---|
| 178 | |
---|
| 179 | norm += weights_core_radius[i].weight |
---|
| 180 | * weights_length[j].weight |
---|
[e2afadf] | 181 | * weights_radius[m].weight |
---|
[27fea3f] | 182 | * weights_theta[k].weight |
---|
| 183 | * weights_phi[l].weight; |
---|
| 184 | |
---|
| 185 | } |
---|
| 186 | } |
---|
| 187 | } |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | // Averaging in theta needs an extra normalization |
---|
| 191 | // factor to account for the sin(theta) term in the |
---|
| 192 | // integration (see documentation). |
---|
| 193 | if (weights_theta.size()>1) norm = norm / asin(1.0); |
---|
| 194 | return sum/norm + background(); |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | /** |
---|
| 198 | * Function to evaluate 2D scattering function |
---|
| 199 | * @param pars: parameters of the cylinder |
---|
| 200 | * @param q: q-value |
---|
| 201 | * @param phi: angle phi |
---|
| 202 | * @return: function value |
---|
| 203 | */ |
---|
| 204 | double HollowCylinderModel :: evaluate_rphi(double q, double phi) { |
---|
| 205 | double qx = q*cos(phi); |
---|
| 206 | double qy = q*sin(phi); |
---|
| 207 | return (*this).operator()(qx, qy); |
---|
| 208 | } |
---|