[25579e8] | 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 "SquareWell.h" |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | SquareWellStructure :: SquareWellStructure() { |
---|
[5eb9154] | 35 | effect_radius = Parameter(50.0, true); |
---|
| 36 | effect_radius.set_min(0.0); |
---|
[25579e8] | 37 | volfraction = Parameter(0.04, true); |
---|
| 38 | volfraction.set_min(0.0); |
---|
| 39 | welldepth = Parameter(1.50); |
---|
| 40 | wellwidth = Parameter(1.20); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | /** |
---|
| 44 | * Function to evaluate 1D scattering function |
---|
| 45 | * The NIST IGOR library is used for the actual calculation. |
---|
| 46 | * @param q: q-value |
---|
| 47 | * @return: function value |
---|
| 48 | */ |
---|
| 49 | double SquareWellStructure :: operator()(double q) { |
---|
| 50 | double dp[4]; |
---|
| 51 | |
---|
| 52 | // Fill parameter array for IGOR library |
---|
| 53 | // Add the background after averaging |
---|
[5eb9154] | 54 | dp[0] = effect_radius(); |
---|
[25579e8] | 55 | dp[1] = volfraction(); |
---|
| 56 | dp[2] = welldepth(); |
---|
| 57 | dp[3] = wellwidth(); |
---|
| 58 | |
---|
| 59 | // Get the dispersion points for the radius |
---|
| 60 | vector<WeightPoint> weights_rad; |
---|
[5eb9154] | 61 | effect_radius.get_weights(weights_rad); |
---|
[25579e8] | 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.size(); i++) { |
---|
| 69 | dp[0] = weights_rad[i].value; |
---|
| 70 | |
---|
| 71 | sum += weights_rad[i].weight |
---|
| 72 | * SquareWellStruct(dp, q); |
---|
| 73 | norm += weights_rad[i].weight; |
---|
| 74 | } |
---|
| 75 | return sum/norm ; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | /** |
---|
| 79 | * Function to evaluate 2D scattering function |
---|
| 80 | * @param q_x: value of Q along x |
---|
| 81 | * @param q_y: value of Q along y |
---|
| 82 | * @return: function value |
---|
| 83 | */ |
---|
| 84 | double SquareWellStructure :: operator()(double qx, double qy) { |
---|
[770bab1] | 85 | double q = sqrt(qx*qx + qy*qy); |
---|
| 86 | return (*this).operator()(q); |
---|
[25579e8] | 87 | } |
---|
| 88 | |
---|
| 89 | /** |
---|
| 90 | * Function to evaluate 2D scattering function |
---|
| 91 | * @param pars: parameters of the cylinder |
---|
| 92 | * @param q: q-value |
---|
| 93 | * @param phi: angle phi |
---|
| 94 | * @return: function value |
---|
| 95 | */ |
---|
| 96 | double SquareWellStructure :: evaluate_rphi(double q, double phi) { |
---|
| 97 | double qx = q*cos(phi); |
---|
| 98 | double qy = q*sin(phi); |
---|
| 99 | return (*this).operator()(qx, qy); |
---|
| 100 | } |
---|
[5eb9154] | 101 | /** |
---|
| 102 | * Function to calculate effective radius |
---|
| 103 | * @return: effective radius value |
---|
| 104 | */ |
---|
| 105 | double SquareWellStructure :: calculate_ER() { |
---|
| 106 | //NOT implemented yet!!! |
---|
[6110bb8] | 107 | return 0.0; |
---|
[5eb9154] | 108 | } |
---|
[25579e8] | 109 | // Testing code |
---|
| 110 | /* |
---|
| 111 | int main(void) |
---|
| 112 | { |
---|
| 113 | SquareWellModel c = SquareWellModel(); |
---|
| 114 | |
---|
| 115 | printf("I(Qx=%g,Qy=%g) = %g\n", 0.001, 0.001, c(0.001, 0.001)); |
---|
| 116 | printf("I(Q=%g) = %g\n", 0.001, c(0.001)); |
---|
| 117 | c.radius.dispersion = new GaussianDispersion(); |
---|
| 118 | c.radius.dispersion->npts = 100; |
---|
| 119 | c.radius.dispersion->width = 5; |
---|
| 120 | |
---|
| 121 | //c.length.dispersion = GaussianDispersion(); |
---|
| 122 | //c.length.dispersion.npts = 20; |
---|
| 123 | //c.length.dispersion.width = 65; |
---|
| 124 | |
---|
| 125 | printf("I(Q=%g) = %g\n", 0.001, c(0.001)); |
---|
| 126 | printf("I(Q=%g) = %g\n", 0.001, c(0.001)); |
---|
| 127 | printf("I(Qx=%g, Qy=%g) = %g\n", 0.001, 0.001, c(0.001, 0.001)); |
---|
| 128 | printf("I(Q=%g, Phi=%g) = %g\n", 0.00447, .7854, c.evaluate_rphi(sqrt(0.00002), .7854)); |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | double i_avg = c(0.01, 0.01); |
---|
| 133 | double i_1d = c(sqrt(0.0002)); |
---|
| 134 | |
---|
| 135 | printf("\nI(Qx=%g, Qy=%g) = %g\n", 0.01, 0.01, i_avg); |
---|
| 136 | printf("I(Q=%g) = %g\n", sqrt(0.0002), i_1d); |
---|
| 137 | printf("ratio %g %g\n", i_avg/i_1d, i_1d/i_avg); |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | return 0; |
---|
| 141 | } |
---|
[5eb9154] | 142 | */ |
---|