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