[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 | * |
---|
[836fe6e] | 20 | */ |
---|
[0f5bc9f] | 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" |
---|
[5eb9154] | 30 | #include "sphere.h" |
---|
[0f5bc9f] | 31 | } |
---|
| 32 | |
---|
| 33 | SphereModel :: SphereModel() { |
---|
| 34 | scale = Parameter(1.0); |
---|
| 35 | radius = Parameter(20.0, true); |
---|
| 36 | radius.set_min(0.0); |
---|
[f10063e] | 37 | sldSph = Parameter(4.0e-6); |
---|
| 38 | sldSolv = Parameter(1.0e-6); |
---|
[0f5bc9f] | 39 | background = Parameter(0.0); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | /** |
---|
| 43 | * Function to evaluate 1D scattering function |
---|
| 44 | * The NIST IGOR library is used for the actual calculation. |
---|
| 45 | * @param q: q-value |
---|
| 46 | * @return: function value |
---|
| 47 | */ |
---|
| 48 | double SphereModel :: operator()(double q) { |
---|
[f10063e] | 49 | double dp[5]; |
---|
[0f5bc9f] | 50 | |
---|
| 51 | // Fill parameter array for IGOR library |
---|
| 52 | // Add the background after averaging |
---|
| 53 | dp[0] = scale(); |
---|
| 54 | dp[1] = radius(); |
---|
[f10063e] | 55 | dp[2] = sldSph(); |
---|
| 56 | dp[3] = sldSolv(); |
---|
| 57 | dp[4] = 0.0; |
---|
[0f5bc9f] | 58 | |
---|
| 59 | // Get the dispersion points for the radius |
---|
| 60 | vector<WeightPoint> weights_rad; |
---|
| 61 | radius.get_weights(weights_rad); |
---|
| 62 | |
---|
| 63 | // Perform the computation, with all weight points |
---|
| 64 | double sum = 0.0; |
---|
| 65 | double norm = 0.0; |
---|
[c451be9] | 66 | double vol = 0.0; |
---|
[0f5bc9f] | 67 | |
---|
| 68 | // Loop over radius weight points |
---|
| 69 | for(int i=0; i<weights_rad.size(); i++) { |
---|
| 70 | dp[1] = weights_rad[i].value; |
---|
| 71 | |
---|
[c451be9] | 72 | //Un-normalize SphereForm by volume |
---|
[0f5bc9f] | 73 | sum += weights_rad[i].weight |
---|
[c451be9] | 74 | * SphereForm(dp, q) * pow(weights_rad[i].value,3); |
---|
| 75 | //Find average volume |
---|
| 76 | vol += weights_rad[i].weight |
---|
| 77 | * pow(weights_rad[i].value,3); |
---|
| 78 | |
---|
[0f5bc9f] | 79 | norm += weights_rad[i].weight; |
---|
| 80 | } |
---|
[c451be9] | 81 | |
---|
| 82 | if (vol != 0.0 && norm != 0.0) { |
---|
| 83 | //Re-normalize by avg volume |
---|
| 84 | sum = sum/(vol/norm);} |
---|
[0f5bc9f] | 85 | return sum/norm + background(); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | /** |
---|
| 89 | * Function to evaluate 2D scattering function |
---|
| 90 | * @param q_x: value of Q along x |
---|
| 91 | * @param q_y: value of Q along y |
---|
| 92 | * @return: function value |
---|
| 93 | */ |
---|
| 94 | double SphereModel :: operator()(double qx, double qy) { |
---|
| 95 | double q = sqrt(qx*qx + qy*qy); |
---|
| 96 | return (*this).operator()(q); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | /** |
---|
| 100 | * Function to evaluate 2D scattering function |
---|
| 101 | * @param pars: parameters of the sphere |
---|
| 102 | * @param q: q-value |
---|
| 103 | * @param phi: angle phi |
---|
| 104 | * @return: function value |
---|
| 105 | */ |
---|
| 106 | double SphereModel :: evaluate_rphi(double q, double phi) { |
---|
| 107 | return (*this).operator()(q); |
---|
| 108 | } |
---|
[5eb9154] | 109 | |
---|
| 110 | /** |
---|
| 111 | * Function to calculate effective radius |
---|
| 112 | * @return: effective radius value |
---|
| 113 | */ |
---|
| 114 | double SphereModel :: calculate_ER() { |
---|
| 115 | SphereParameters dp; |
---|
| 116 | dp.scale = scale(); |
---|
| 117 | dp.radius = radius(); |
---|
[f10063e] | 118 | dp.sldSph = sldSph(); |
---|
| 119 | dp.sldSolv = sldSolv(); |
---|
[5eb9154] | 120 | dp.background = background(); |
---|
| 121 | double rad_out = 0.0; |
---|
| 122 | |
---|
| 123 | // Perform the computation, with all weight points |
---|
| 124 | double sum = 0.0; |
---|
| 125 | double norm = 0.0; |
---|
| 126 | |
---|
| 127 | // Get the dispersion points for the radius |
---|
| 128 | vector<WeightPoint> weights_rad; |
---|
| 129 | radius.get_weights(weights_rad); |
---|
| 130 | // Loop over radius weight points to average the radius value |
---|
| 131 | for(int i=0; i<weights_rad.size(); i++) { |
---|
| 132 | sum += weights_rad[i].weight |
---|
| 133 | * weights_rad[i].value; |
---|
| 134 | norm += weights_rad[i].weight; |
---|
| 135 | } |
---|
| 136 | if (norm != 0){ |
---|
| 137 | //return the averaged value |
---|
| 138 | rad_out = sum/norm;} |
---|
| 139 | else{ |
---|
| 140 | //return normal value |
---|
| 141 | rad_out = radius();} |
---|
| 142 | |
---|
| 143 | return rad_out; |
---|
| 144 | } |
---|