[94a3f8f] | 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 | */ |
---|
| 21 | |
---|
| 22 | #include <math.h> |
---|
| 23 | #include "models.hh" |
---|
| 24 | #include "parameters.hh" |
---|
| 25 | #include <stdio.h> |
---|
| 26 | using namespace std; |
---|
| 27 | |
---|
| 28 | extern "C" { |
---|
| 29 | #include "libSphere.h" |
---|
| 30 | #include "sc.h" |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | SCCrystalModel :: SCCrystalModel() { |
---|
| 34 | scale = Parameter(1.0); |
---|
| 35 | dnn = Parameter(220.0); |
---|
| 36 | d_factor = Parameter(0.06); |
---|
| 37 | radius = Parameter(40.0, true); |
---|
| 38 | radius.set_min(0.0); |
---|
| 39 | sldSph = Parameter(3.0e-6); |
---|
| 40 | sldSolv = Parameter(6.3e-6); |
---|
| 41 | background = Parameter(0.0); |
---|
| 42 | theta = Parameter(0.0, true); |
---|
| 43 | phi = Parameter(0.0, true); |
---|
| 44 | psi = 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 SCCrystalModel :: operator()(double q) { |
---|
| 54 | double dp[7]; |
---|
| 55 | |
---|
| 56 | // Fill parameter array for IGOR library |
---|
| 57 | // Add the background after averaging |
---|
| 58 | dp[0] = scale(); |
---|
| 59 | dp[1] = dnn(); |
---|
| 60 | dp[2] = d_factor(); |
---|
| 61 | dp[3] = radius(); |
---|
| 62 | dp[4] = sldSph(); |
---|
| 63 | dp[5] = sldSolv(); |
---|
| 64 | dp[6] = 0.0; |
---|
| 65 | |
---|
| 66 | // Get the dispersion points for the radius |
---|
| 67 | vector<WeightPoint> weights_rad; |
---|
| 68 | radius.get_weights(weights_rad); |
---|
| 69 | |
---|
| 70 | // Perform the computation, with all weight points |
---|
| 71 | double sum = 0.0; |
---|
| 72 | double norm = 0.0; |
---|
| 73 | double vol = 0.0; |
---|
| 74 | double result; |
---|
| 75 | |
---|
| 76 | // Loop over radius weight points |
---|
| 77 | for(int i=0; i<weights_rad.size(); i++) { |
---|
| 78 | dp[3] = weights_rad[i].value; |
---|
| 79 | |
---|
| 80 | //Un-normalize SphereForm by volume |
---|
| 81 | result = SC_ParaCrystal(dp, q) * pow(weights_rad[i].value,3); |
---|
| 82 | // This FIXES a singualrity the kernel in libigor. |
---|
| 83 | if ( result == INFINITY || result == NAN){ |
---|
| 84 | result = 0.0; |
---|
| 85 | } |
---|
| 86 | sum += weights_rad[i].weight |
---|
| 87 | * result; |
---|
| 88 | //Find average volume |
---|
| 89 | vol += weights_rad[i].weight |
---|
| 90 | * pow(weights_rad[i].value,3); |
---|
| 91 | |
---|
| 92 | norm += weights_rad[i].weight; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | if (vol != 0.0 && norm != 0.0) { |
---|
| 96 | //Re-normalize by avg volume |
---|
| 97 | sum = sum/(vol/norm);} |
---|
| 98 | return sum/norm + background(); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | /** |
---|
| 102 | * Function to evaluate 2D scattering function |
---|
| 103 | * @param q_x: value of Q along x |
---|
| 104 | * @param q_y: value of Q along y |
---|
| 105 | * @return: function value |
---|
| 106 | */ |
---|
| 107 | double SCCrystalModel :: operator()(double qx, double qy) { |
---|
| 108 | SCParameters dp; |
---|
| 109 | double q = sqrt(qx*qx + qy*qy); |
---|
| 110 | dp.scale = scale(); |
---|
| 111 | dp.dnn = dnn(); |
---|
| 112 | dp.d_factor = d_factor(); |
---|
| 113 | dp.radius = radius(); |
---|
| 114 | dp.sldSph = sldSph(); |
---|
| 115 | dp.sldSolv = sldSolv(); |
---|
| 116 | dp.background = 0.0; |
---|
| 117 | dp.theta = theta(); |
---|
| 118 | dp.phi = phi(); |
---|
| 119 | dp.psi = psi(); |
---|
| 120 | |
---|
| 121 | // Get the dispersion points for the radius |
---|
| 122 | vector<WeightPoint> weights_rad; |
---|
| 123 | radius.get_weights(weights_rad); |
---|
| 124 | |
---|
| 125 | // Get angular averaging for theta |
---|
| 126 | vector<WeightPoint> weights_theta; |
---|
| 127 | theta.get_weights(weights_theta); |
---|
| 128 | |
---|
| 129 | // Get angular averaging for phi |
---|
| 130 | vector<WeightPoint> weights_phi; |
---|
| 131 | phi.get_weights(weights_phi); |
---|
| 132 | |
---|
| 133 | // Get angular averaging for psi |
---|
| 134 | vector<WeightPoint> weights_psi; |
---|
| 135 | psi.get_weights(weights_psi); |
---|
| 136 | |
---|
| 137 | // Perform the computation, with all weight points |
---|
| 138 | double sum = 0.0; |
---|
| 139 | double norm = 0.0; |
---|
| 140 | double norm_vol = 0.0; |
---|
| 141 | double vol = 0.0; |
---|
[4628e31] | 142 | double pi = 4.0*atan(1.0); |
---|
[94a3f8f] | 143 | // Loop over radius weight points |
---|
| 144 | for(int i=0; i<weights_rad.size(); i++) { |
---|
| 145 | dp.radius = weights_rad[i].value; |
---|
| 146 | // Average over theta distribution |
---|
| 147 | for(int j=0; j< weights_theta.size(); j++) { |
---|
| 148 | dp.theta = weights_theta[j].value; |
---|
| 149 | // Average over phi distribution |
---|
| 150 | for(int k=0; k< weights_phi.size(); k++) { |
---|
| 151 | dp.phi = weights_phi[k].value; |
---|
| 152 | // Average over phi distribution |
---|
| 153 | for(int l=0; l< weights_psi.size(); l++) { |
---|
| 154 | dp.psi = weights_psi[l].value; |
---|
| 155 | //Un-normalize SphereForm by volume |
---|
| 156 | double _ptvalue = weights_rad[i].weight |
---|
| 157 | * weights_theta[j].weight |
---|
| 158 | * weights_phi[k].weight |
---|
| 159 | * weights_psi[l].weight |
---|
| 160 | * sc_analytical_2DXY(&dp, qx, qy); |
---|
| 161 | //* pow(weights_rad[i].value,3.0); |
---|
| 162 | // Consider when there is infinte or nan. |
---|
| 163 | if ( _ptvalue == INFINITY || _ptvalue == NAN){ |
---|
| 164 | _ptvalue = 0.0; |
---|
| 165 | } |
---|
| 166 | if (weights_theta.size()>1) { |
---|
[4628e31] | 167 | _ptvalue *= fabs(sin(weights_theta[j].value*pi/180.0)); |
---|
[94a3f8f] | 168 | } |
---|
| 169 | sum += _ptvalue; |
---|
| 170 | // This model dose not need the volume of spheres correction!!! |
---|
| 171 | //Find average volume |
---|
| 172 | //vol += weights_rad[i].weight |
---|
| 173 | // * pow(weights_rad[i].value,3); |
---|
| 174 | //Find norm for volume |
---|
| 175 | //norm_vol += weights_rad[i].weight; |
---|
| 176 | |
---|
| 177 | norm += weights_rad[i].weight |
---|
| 178 | * weights_theta[j].weight |
---|
| 179 | * weights_phi[k].weight |
---|
| 180 | * weights_psi[l].weight; |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | } |
---|
| 184 | } |
---|
| 185 | // Averaging in theta needs an extra normalization |
---|
| 186 | // factor to account for the sin(theta) term in the |
---|
| 187 | // integration (see documentation). |
---|
| 188 | if (weights_theta.size()>1) norm = norm / asin(1.0); |
---|
| 189 | |
---|
| 190 | if (vol != 0.0 && norm_vol != 0.0) { |
---|
| 191 | //Re-normalize by avg volume |
---|
| 192 | sum = sum/(vol/norm_vol);} |
---|
| 193 | |
---|
| 194 | return sum/norm + background(); |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | /** |
---|
| 198 | * Function to evaluate 2D scattering function |
---|
| 199 | * @param pars: parameters of the SCCrystal |
---|
| 200 | * @param q: q-value |
---|
| 201 | * @param phi: angle phi |
---|
| 202 | * @return: function value |
---|
| 203 | */ |
---|
| 204 | double SCCrystalModel :: evaluate_rphi(double q, double phi) { |
---|
| 205 | return (*this).operator()(q); |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | /** |
---|
| 209 | * Function to calculate effective radius |
---|
| 210 | * @return: effective radius value |
---|
| 211 | */ |
---|
| 212 | double SCCrystalModel :: calculate_ER() { |
---|
| 213 | //NOT implemented yet!!! |
---|
| 214 | } |
---|