[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 | */ |
---|
| 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 "libStructureFactor.h" |
---|
| 30 | #include "DiamEllip.h" |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | DiamEllipFunc :: DiamEllipFunc() { |
---|
| 34 | radius_a = Parameter(20.0, true); |
---|
| 35 | radius_a.set_min(0.0); |
---|
| 36 | radius_b = Parameter(400, true); |
---|
| 37 | radius_b.set_min(0.0); |
---|
| 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 DiamEllipFunc :: operator()(double q) { |
---|
| 47 | double dp[2]; |
---|
| 48 | |
---|
| 49 | // Fill parameter array for IGOR library |
---|
| 50 | // Add the background after averaging |
---|
| 51 | dp[0] = radius_a(); |
---|
| 52 | dp[1] = radius_b(); |
---|
| 53 | |
---|
| 54 | // Get the dispersion points for the radius a |
---|
| 55 | vector<WeightPoint> weights_rad_a; |
---|
| 56 | radius_a.get_weights(weights_rad_a); |
---|
| 57 | |
---|
| 58 | // Get the dispersion points for the radius b |
---|
| 59 | vector<WeightPoint> weights_rad_b; |
---|
| 60 | radius_b.get_weights(weights_rad_b); |
---|
| 61 | |
---|
| 62 | // Perform the computation, with all weight points |
---|
| 63 | double sum = 0.0; |
---|
| 64 | double norm = 0.0; |
---|
| 65 | |
---|
| 66 | // Loop over radius weight points |
---|
[a24f530] | 67 | for(size_t i=0; i<weights_rad_a.size(); i++) { |
---|
[6b38781] | 68 | dp[0] = weights_rad_a[i].value; |
---|
| 69 | // Loop over length weight points |
---|
[a24f530] | 70 | for(size_t j=0; j<weights_rad_b.size(); j++) { |
---|
[6b38781] | 71 | dp[1] = weights_rad_b[j].value; |
---|
| 72 | |
---|
| 73 | sum += weights_rad_a[i].weight*weights_rad_b[j].weight |
---|
[5eb9154] | 74 | * DiamEllip(dp[0], dp[1]); |
---|
[6b38781] | 75 | norm += weights_rad_a[i].weight*weights_rad_b[j].weight; |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | return sum/norm ; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | /** |
---|
| 82 | * Function to evaluate 2D scattering function |
---|
| 83 | * @param q_x: value of Q along x |
---|
| 84 | * @param q_y: value of Q along y |
---|
| 85 | * @return: function value |
---|
| 86 | */ |
---|
| 87 | double DiamEllipFunc :: operator()(double qx, double qy) { |
---|
[770bab1] | 88 | double q = sqrt(qx*qx + qy*qy); |
---|
| 89 | return (*this).operator()(q); |
---|
[6b38781] | 90 | } |
---|
| 91 | /** |
---|
| 92 | * Function to evaluate 2D scattering function |
---|
| 93 | * @param pars: parameters of the cylinder |
---|
| 94 | * @param q: q-value |
---|
| 95 | * @param phi: angle phi |
---|
| 96 | * @return: function value |
---|
| 97 | */ |
---|
| 98 | double DiamEllipFunc :: evaluate_rphi(double q, double phi) { |
---|
| 99 | double qx = q*cos(phi); |
---|
| 100 | double qy = q*sin(phi); |
---|
| 101 | return (*this).operator()(qx, qy); |
---|
| 102 | } |
---|
[5eb9154] | 103 | /** |
---|
| 104 | * Function to calculate effective radius |
---|
| 105 | * @return: effective radius value |
---|
| 106 | */ |
---|
| 107 | double DiamEllipFunc :: calculate_ER() { |
---|
| 108 | //NOT implemented yet!!! |
---|
[6110bb8] | 109 | return 0.0; |
---|
[5eb9154] | 110 | } |
---|
[6b38781] | 111 | // Testing code |
---|
| 112 | /* |
---|
| 113 | int main(void) |
---|
| 114 | { |
---|
| 115 | SquareWellModel c = SquareWellModel(); |
---|
| 116 | |
---|
| 117 | printf("I(Qx=%g,Qy=%g) = %g\n", 0.001, 0.001, c(0.001, 0.001)); |
---|
| 118 | printf("I(Q=%g) = %g\n", 0.001, c(0.001)); |
---|
| 119 | c.radius.dispersion = new GaussianDispersion(); |
---|
| 120 | c.radius.dispersion->npts = 100; |
---|
| 121 | c.radius.dispersion->width = 5; |
---|
| 122 | |
---|
| 123 | //c.length.dispersion = GaussianDispersion(); |
---|
| 124 | //c.length.dispersion.npts = 20; |
---|
| 125 | //c.length.dispersion.width = 65; |
---|
| 126 | |
---|
| 127 | printf("I(Q=%g) = %g\n", 0.001, c(0.001)); |
---|
| 128 | printf("I(Q=%g) = %g\n", 0.001, c(0.001)); |
---|
| 129 | printf("I(Qx=%g, Qy=%g) = %g\n", 0.001, 0.001, c(0.001, 0.001)); |
---|
| 130 | printf("I(Q=%g, Phi=%g) = %g\n", 0.00447, .7854, c.evaluate_rphi(sqrt(0.00002), .7854)); |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | double i_avg = c(0.01, 0.01); |
---|
| 135 | double i_1d = c(sqrt(0.0002)); |
---|
| 136 | |
---|
| 137 | printf("\nI(Qx=%g, Qy=%g) = %g\n", 0.01, 0.01, i_avg); |
---|
| 138 | printf("I(Q=%g) = %g\n", sqrt(0.0002), i_1d); |
---|
| 139 | printf("ratio %g %g\n", i_avg/i_1d, i_1d/i_avg); |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | return 0; |
---|
| 143 | } |
---|
| 144 | */ |
---|