[6b38781] | 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 | * TODO: refactor so that we pull in the old sansmodels.c_extensions |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | #include <math.h> |
---|
| 24 | #include "models.hh" |
---|
| 25 | #include "parameters.hh" |
---|
| 26 | #include <stdio.h> |
---|
| 27 | using namespace std; |
---|
| 28 | |
---|
| 29 | extern "C" { |
---|
| 30 | #include "libStructureFactor.h" |
---|
| 31 | #include "DiamEllip.h" |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | DiamEllipFunc :: DiamEllipFunc() { |
---|
| 35 | radius_a = Parameter(20.0, true); |
---|
| 36 | radius_a.set_min(0.0); |
---|
| 37 | radius_b = Parameter(400, true); |
---|
| 38 | radius_b.set_min(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 DiamEllipFunc :: operator()(double q) { |
---|
| 48 | double dp[2]; |
---|
| 49 | |
---|
| 50 | // Fill parameter array for IGOR library |
---|
| 51 | // Add the background after averaging |
---|
| 52 | dp[0] = radius_a(); |
---|
| 53 | dp[1] = radius_b(); |
---|
| 54 | |
---|
| 55 | // Get the dispersion points for the radius a |
---|
| 56 | vector<WeightPoint> weights_rad_a; |
---|
| 57 | radius_a.get_weights(weights_rad_a); |
---|
| 58 | |
---|
| 59 | // Get the dispersion points for the radius b |
---|
| 60 | vector<WeightPoint> weights_rad_b; |
---|
| 61 | radius_b.get_weights(weights_rad_b); |
---|
| 62 | |
---|
| 63 | // Perform the computation, with all weight points |
---|
| 64 | double sum = 0.0; |
---|
| 65 | double norm = 0.0; |
---|
| 66 | |
---|
| 67 | // Loop over radius weight points |
---|
| 68 | for(int i=0; i<weights_rad_a.size(); i++) { |
---|
| 69 | dp[0] = weights_rad_a[i].value; |
---|
| 70 | // Loop over length weight points |
---|
| 71 | for(int j=0; j<weights_rad_b.size(); j++) { |
---|
| 72 | dp[1] = weights_rad_b[j].value; |
---|
| 73 | |
---|
| 74 | sum += weights_rad_a[i].weight*weights_rad_b[j].weight |
---|
| 75 | * DiamEllip(dp, q); |
---|
| 76 | norm += weights_rad_a[i].weight*weights_rad_b[j].weight; |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | return sum/norm ; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | /** |
---|
| 83 | * Function to evaluate 2D scattering function |
---|
| 84 | * @param q_x: value of Q along x |
---|
| 85 | * @param q_y: value of Q along y |
---|
| 86 | * @return: function value |
---|
| 87 | */ |
---|
| 88 | double DiamEllipFunc :: operator()(double qx, double qy) { |
---|
| 89 | DiamEllipsParameters dp; |
---|
| 90 | // Fill parameter array |
---|
| 91 | dp.radius_a = radius_a(); |
---|
| 92 | dp.radius_b = radius_b(); |
---|
| 93 | |
---|
| 94 | // Get the dispersion points for the radius a |
---|
| 95 | vector<WeightPoint> weights_rad_a; |
---|
| 96 | radius_a.get_weights(weights_rad_a); |
---|
| 97 | |
---|
| 98 | // Get the dispersion points for the radius b |
---|
| 99 | vector<WeightPoint> weights_rad_b; |
---|
| 100 | radius_b.get_weights(weights_rad_b); |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | // Perform the computation, with all weight points |
---|
| 104 | double sum = 0.0; |
---|
| 105 | double norm = 0.0; |
---|
| 106 | |
---|
| 107 | // Loop over radius weight points |
---|
| 108 | for(int i=0; i<weights_rad_a.size(); i++) { |
---|
| 109 | dp.radius_a = weights_rad_a[i].value; |
---|
| 110 | // Loop over length weight points |
---|
| 111 | for(int j=0; j<weights_rad_b.size(); j++) { |
---|
| 112 | dp.radius_b = weights_rad_b[j].value; |
---|
| 113 | |
---|
| 114 | double _ptvalue = weights_rad_a[i].weight |
---|
| 115 | *weights_rad_b[j].weight* DiamEllips_analytical_2DXY(&dp, qx, qy); |
---|
| 116 | sum += _ptvalue; |
---|
| 117 | |
---|
| 118 | norm += weights_rad_a[i].weight*weights_rad_b[j].weight; |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | // Averaging in theta needs an extra normalization |
---|
| 122 | // factor to account for the sin(theta) term in the |
---|
| 123 | // integration (see documentation). |
---|
| 124 | return sum/norm; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | /** |
---|
| 128 | * Function to evaluate 2D scattering function |
---|
| 129 | * @param pars: parameters of the cylinder |
---|
| 130 | * @param q: q-value |
---|
| 131 | * @param phi: angle phi |
---|
| 132 | * @return: function value |
---|
| 133 | */ |
---|
| 134 | double DiamEllipFunc :: evaluate_rphi(double q, double phi) { |
---|
| 135 | double qx = q*cos(phi); |
---|
| 136 | double qy = q*sin(phi); |
---|
| 137 | return (*this).operator()(qx, qy); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | // Testing code |
---|
| 141 | /* |
---|
| 142 | int main(void) |
---|
| 143 | { |
---|
| 144 | SquareWellModel c = SquareWellModel(); |
---|
| 145 | |
---|
| 146 | printf("I(Qx=%g,Qy=%g) = %g\n", 0.001, 0.001, c(0.001, 0.001)); |
---|
| 147 | printf("I(Q=%g) = %g\n", 0.001, c(0.001)); |
---|
| 148 | c.radius.dispersion = new GaussianDispersion(); |
---|
| 149 | c.radius.dispersion->npts = 100; |
---|
| 150 | c.radius.dispersion->width = 5; |
---|
| 151 | |
---|
| 152 | //c.length.dispersion = GaussianDispersion(); |
---|
| 153 | //c.length.dispersion.npts = 20; |
---|
| 154 | //c.length.dispersion.width = 65; |
---|
| 155 | |
---|
| 156 | printf("I(Q=%g) = %g\n", 0.001, c(0.001)); |
---|
| 157 | printf("I(Q=%g) = %g\n", 0.001, c(0.001)); |
---|
| 158 | printf("I(Qx=%g, Qy=%g) = %g\n", 0.001, 0.001, c(0.001, 0.001)); |
---|
| 159 | printf("I(Q=%g, Phi=%g) = %g\n", 0.00447, .7854, c.evaluate_rphi(sqrt(0.00002), .7854)); |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | double i_avg = c(0.01, 0.01); |
---|
| 164 | double i_1d = c(sqrt(0.0002)); |
---|
| 165 | |
---|
| 166 | printf("\nI(Qx=%g, Qy=%g) = %g\n", 0.01, 0.01, i_avg); |
---|
| 167 | printf("I(Q=%g) = %g\n", sqrt(0.0002), i_1d); |
---|
| 168 | printf("ratio %g %g\n", i_avg/i_1d, i_1d/i_avg); |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | return 0; |
---|
| 172 | } |
---|
| 173 | */ |
---|