[c724ccd] | 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 "libTwoPhase.h" |
---|
| 30 | #include "polygausscoil.h" |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | Poly_GaussCoil :: Poly_GaussCoil() { |
---|
| 34 | scale = Parameter(1.0); |
---|
| 35 | rg = Parameter(60.0, true); |
---|
| 36 | rg.set_min(0.0); |
---|
| 37 | poly_m = Parameter(2.0); |
---|
| 38 | background = Parameter(0.001); |
---|
| 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 Poly_GaussCoil :: operator()(double q) { |
---|
| 48 | double dp[4]; |
---|
| 49 | |
---|
| 50 | // Fill parameter array for IGOR library |
---|
| 51 | // Add the background after averaging |
---|
| 52 | dp[0] = scale(); |
---|
| 53 | dp[1] = rg(); |
---|
| 54 | dp[2] = poly_m(); |
---|
| 55 | dp[3] = 0.0; |
---|
| 56 | |
---|
| 57 | // Get the dispersion points for the radius |
---|
| 58 | //vector<WeightPoint> weights_rad; |
---|
| 59 | //rg.get_weights(weights_rad); |
---|
| 60 | |
---|
| 61 | // Perform the computation, with all weight points |
---|
| 62 | double sum = 0.0; |
---|
| 63 | |
---|
| 64 | /**** No rg polydispersion is applied |
---|
| 65 | double norm = 0.0; |
---|
| 66 | double vol = 0.0; |
---|
| 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 | |
---|
| 72 | //Un-normalize SphereForm by volume |
---|
| 73 | sum += weights_rad[i].weight |
---|
| 74 | * PolyGaussCoil(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 | |
---|
| 79 | norm += weights_rad[i].weight; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | if (vol != 0.0 && norm != 0.0) { |
---|
| 83 | //Re-normalize by avg volume |
---|
| 84 | sum = sum/(vol/norm);} |
---|
| 85 | return sum/norm + background(); |
---|
| 86 | ****/ |
---|
| 87 | |
---|
| 88 | sum = PolyGaussCoil(dp, q); |
---|
| 89 | return sum + background(); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | /** |
---|
| 93 | * Function to evaluate 2D scattering function |
---|
| 94 | * @param q_x: value of Q along x |
---|
| 95 | * @param q_y: value of Q along y |
---|
| 96 | * @return: function value |
---|
| 97 | */ |
---|
| 98 | double Poly_GaussCoil :: operator()(double qx, double qy) { |
---|
| 99 | double q = sqrt(qx*qx + qy*qy); |
---|
| 100 | return (*this).operator()(q); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | /** |
---|
| 104 | * Function to evaluate 2D scattering function |
---|
| 105 | * @param pars: parameters of the sphere |
---|
| 106 | * @param q: q-value |
---|
| 107 | * @param phi: angle phi |
---|
| 108 | * @return: function value |
---|
| 109 | */ |
---|
| 110 | double Poly_GaussCoil :: evaluate_rphi(double q, double phi) { |
---|
| 111 | return (*this).operator()(q); |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | /** |
---|
| 115 | * Function to calculate effective radius |
---|
| 116 | * @return: effective radius value |
---|
| 117 | */ |
---|
| 118 | double Poly_GaussCoil :: calculate_ER() { |
---|
| 119 | PolyGaussCoilParameters dp; |
---|
| 120 | dp.scale = scale(); |
---|
| 121 | dp.rg= rg(); |
---|
| 122 | dp.poly_m = poly_m(); |
---|
| 123 | dp.background = background(); |
---|
| 124 | double rad_out = 0.0; |
---|
| 125 | |
---|
| 126 | // Perform the computation, with all weight points |
---|
| 127 | double sum = 0.0; |
---|
| 128 | double norm = 0.0; |
---|
| 129 | |
---|
| 130 | // Get the dispersion points for the radius |
---|
| 131 | vector<WeightPoint> weights_rad; |
---|
| 132 | rg.get_weights(weights_rad); |
---|
| 133 | // Loop over radius weight points to average the radius value |
---|
| 134 | for(int i=0; i<weights_rad.size(); i++) { |
---|
| 135 | sum += weights_rad[i].weight |
---|
| 136 | * weights_rad[i].value; |
---|
| 137 | norm += weights_rad[i].weight; |
---|
| 138 | } |
---|
| 139 | if (norm != 0){ |
---|
| 140 | //return the averaged value |
---|
| 141 | rad_out = sum/norm;} |
---|
| 142 | else{ |
---|
| 143 | //return normal value |
---|
| 144 | rad_out = rg();} |
---|
| 145 | |
---|
| 146 | return rad_out; |
---|
| 147 | } |
---|