[27a0771] | 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 "prolate.h" |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | ProlateModel :: ProlateModel() { |
---|
| 35 | scale = Parameter(1.0); |
---|
| 36 | major_core = Parameter(100.0, true); |
---|
| 37 | major_core.set_min(0.0); |
---|
| 38 | minor_core = Parameter(50.0, true); |
---|
| 39 | minor_core.set_min(0.0); |
---|
| 40 | major_shell = Parameter(110.0, true); |
---|
| 41 | major_shell.set_min(0.0); |
---|
| 42 | minor_shell = Parameter(60.0, true); |
---|
| 43 | minor_shell.set_min(0.0); |
---|
| 44 | contrast = Parameter(1e-6); |
---|
| 45 | sld_solvent = Parameter(6.3e-6); |
---|
| 46 | background = Parameter(0.0); |
---|
| 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 ProlateModel :: operator()(double q) { |
---|
| 56 | double dp[8]; |
---|
| 57 | |
---|
| 58 | // Fill parameter array for IGOR library |
---|
| 59 | // Add the background after averaging |
---|
| 60 | dp[0] = scale(); |
---|
| 61 | dp[1] = major_core(); |
---|
| 62 | dp[2] = minor_core(); |
---|
| 63 | dp[3] = major_shell(); |
---|
| 64 | dp[4] = minor_shell(); |
---|
| 65 | dp[5] = contrast(); |
---|
| 66 | dp[6] = sld_solvent(); |
---|
[8dc0b746] | 67 | dp[7] = 0.0; |
---|
| 68 | |
---|
[27a0771] | 69 | // Get the dispersion points for the major core |
---|
| 70 | vector<WeightPoint> weights_major_core; |
---|
| 71 | major_core.get_weights(weights_major_core); |
---|
| 72 | |
---|
| 73 | // Get the dispersion points for the minor core |
---|
| 74 | vector<WeightPoint> weights_minor_core; |
---|
| 75 | minor_core.get_weights(weights_minor_core); |
---|
| 76 | |
---|
| 77 | // Get the dispersion points for the major shell |
---|
| 78 | vector<WeightPoint> weights_major_shell; |
---|
| 79 | major_shell.get_weights(weights_major_shell); |
---|
| 80 | |
---|
| 81 | // Get the dispersion points for the minor_shell |
---|
| 82 | vector<WeightPoint> weights_minor_shell; |
---|
| 83 | minor_shell.get_weights(weights_minor_shell); |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | // Perform the computation, with all weight points |
---|
| 87 | double sum = 0.0; |
---|
| 88 | double norm = 0.0; |
---|
| 89 | |
---|
| 90 | // Loop over major core weight points |
---|
| 91 | for(int i=0; i<(int)weights_major_core.size(); i++) { |
---|
| 92 | dp[1] = weights_major_core[i].value; |
---|
| 93 | |
---|
| 94 | // Loop over minor core weight points |
---|
| 95 | for(int j=0; j<(int)weights_minor_core.size(); j++) { |
---|
| 96 | dp[2] = weights_minor_core[j].value; |
---|
| 97 | |
---|
| 98 | // Loop over major shell weight points |
---|
| 99 | for(int k=0; k<(int)weights_major_shell.size(); k++) { |
---|
| 100 | dp[3] = weights_major_shell[k].value; |
---|
| 101 | |
---|
| 102 | // Loop over minor shell weight points |
---|
| 103 | for(int l=0; l<(int)weights_minor_shell.size(); l++) { |
---|
| 104 | dp[4] = weights_minor_shell[l].value; |
---|
| 105 | |
---|
[8dc0b746] | 106 | sum += weights_major_core[i].weight* weights_minor_core[j].weight * weights_major_shell[k].weight |
---|
[27a0771] | 107 | * weights_minor_shell[l].weight * ProlateForm(dp, q); |
---|
[8dc0b746] | 108 | norm += weights_major_core[i].weight* weights_minor_core[j].weight * weights_major_shell[k].weight |
---|
[27a0771] | 109 | * weights_minor_shell[l].weight; |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | return sum/norm + background(); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | /** |
---|
| 118 | * Function to evaluate 2D scattering function |
---|
| 119 | * @param q_x: value of Q along x |
---|
| 120 | * @param q_y: value of Q along y |
---|
| 121 | * @return: function value |
---|
| 122 | */ |
---|
| 123 | double ProlateModel :: operator()(double qx, double qy) { |
---|
[8dc0b746] | 124 | double q = sqrt(qx*qx + qy*qy); |
---|
| 125 | |
---|
| 126 | return (*this).operator()(q); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | /** |
---|
| 130 | * Function to evaluate 2D scattering function |
---|
| 131 | * @param pars: parameters of the prolate |
---|
| 132 | * @param q: q-value |
---|
| 133 | * @param phi: angle phi |
---|
| 134 | * @return: function value |
---|
| 135 | */ |
---|
| 136 | double ProlateModel :: evaluate_rphi(double q, double phi) { |
---|
| 137 | return (*this).operator()(q); |
---|
| 138 | } |
---|
| 139 | /* |
---|
| 140 | double ProlateModel :: operator()(double qx, double qy) { |
---|
[27a0771] | 141 | ProlateParameters dp; |
---|
| 142 | // Fill parameter array |
---|
| 143 | dp.scale = scale(); |
---|
| 144 | dp.major_core = major_core(); |
---|
| 145 | dp.minor_core = minor_core(); |
---|
| 146 | dp.major_shell = major_shell(); |
---|
| 147 | dp.minor_shell = minor_shell(); |
---|
| 148 | dp.contrast = contrast(); |
---|
| 149 | dp.sld_solvent = sld_solvent(); |
---|
| 150 | dp.background = background(); |
---|
| 151 | dp.axis_theta = axis_theta(); |
---|
| 152 | dp.axis_phi = axis_phi(); |
---|
| 153 | |
---|
| 154 | // Get the dispersion points for the major core |
---|
| 155 | vector<WeightPoint> weights_major_core; |
---|
| 156 | major_core.get_weights(weights_major_core); |
---|
| 157 | |
---|
| 158 | // Get the dispersion points for the minor core |
---|
| 159 | vector<WeightPoint> weights_minor_core; |
---|
| 160 | minor_core.get_weights(weights_minor_core); |
---|
| 161 | |
---|
| 162 | // Get the dispersion points for the major shell |
---|
| 163 | vector<WeightPoint> weights_major_shell; |
---|
| 164 | major_shell.get_weights(weights_major_shell); |
---|
| 165 | |
---|
| 166 | // Get the dispersion points for the minor shell |
---|
| 167 | vector<WeightPoint> weights_minor_shell; |
---|
| 168 | minor_shell.get_weights(weights_minor_shell); |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | // Get angular averaging for theta |
---|
| 172 | vector<WeightPoint> weights_theta; |
---|
| 173 | axis_theta.get_weights(weights_theta); |
---|
| 174 | |
---|
| 175 | // Get angular averaging for phi |
---|
| 176 | vector<WeightPoint> weights_phi; |
---|
| 177 | axis_phi.get_weights(weights_phi); |
---|
| 178 | |
---|
| 179 | // Perform the computation, with all weight points |
---|
| 180 | double sum = 0.0; |
---|
| 181 | double norm = 0.0; |
---|
| 182 | |
---|
| 183 | // Loop over major core weight points |
---|
| 184 | for(int i=0; i< (int)weights_major_core.size(); i++) { |
---|
| 185 | dp.major_core = weights_major_core[i].value; |
---|
| 186 | |
---|
| 187 | // Loop over minor core weight points |
---|
| 188 | for(int j=0; j< (int)weights_minor_core.size(); j++) { |
---|
| 189 | dp.minor_core = weights_minor_core[j].value; |
---|
| 190 | |
---|
| 191 | // Loop over major shell weight points |
---|
| 192 | for(int k=0; k< (int)weights_major_shell.size(); k++) { |
---|
| 193 | dp.major_shell = weights_major_shell[i].value; |
---|
| 194 | |
---|
| 195 | // Loop over minor shell weight points |
---|
| 196 | for(int l=0; l< (int)weights_minor_shell.size(); l++) { |
---|
| 197 | dp.minor_shell = weights_minor_shell[l].value; |
---|
| 198 | |
---|
| 199 | // Average over theta distribution |
---|
| 200 | for(int m=0; m< (int)weights_theta.size(); m++) { |
---|
| 201 | dp.axis_theta = weights_theta[m].value; |
---|
| 202 | |
---|
| 203 | // Average over phi distribution |
---|
| 204 | for(int n=0; n< (int)weights_phi.size(); n++) { |
---|
| 205 | dp.axis_phi = weights_phi[n].value; |
---|
| 206 | |
---|
| 207 | double _ptvalue = weights_major_core[i].weight *weights_minor_core[j].weight |
---|
| 208 | * weights_major_shell[k].weight * weights_minor_shell[l].weight |
---|
| 209 | * weights_theta[m].weight |
---|
| 210 | * weights_phi[n].weight |
---|
| 211 | * prolate_analytical_2DXY(&dp, qx, qy); |
---|
| 212 | if (weights_theta.size()>1) { |
---|
| 213 | _ptvalue *= sin(weights_theta[k].value); |
---|
| 214 | } |
---|
| 215 | sum += _ptvalue; |
---|
| 216 | |
---|
| 217 | norm += weights_major_core[i].weight *weights_minor_core[j].weight |
---|
| 218 | * weights_major_shell[k].weight * weights_minor_shell[l].weight |
---|
| 219 | * weights_theta[m].weight * weights_phi[n].weight; |
---|
| 220 | } |
---|
| 221 | } |
---|
| 222 | } |
---|
| 223 | } |
---|
| 224 | } |
---|
| 225 | } |
---|
| 226 | // Averaging in theta needs an extra normalization |
---|
| 227 | // factor to account for the sin(theta) term in the |
---|
| 228 | // integration (see documentation). |
---|
| 229 | if (weights_theta.size()>1) norm = norm / asin(1.0); |
---|
| 230 | return sum/norm + background(); |
---|
| 231 | } |
---|
| 232 | |
---|
[8dc0b746] | 233 | */ |
---|