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