[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 "fractal.h" |
---|
[c724ccd] | 27 | |
---|
| 28 | extern "C" { |
---|
[82c11d3] | 29 | #include "libTwoPhase.h" |
---|
[c724ccd] | 30 | } |
---|
| 31 | |
---|
| 32 | FractalModel :: FractalModel() { |
---|
[82c11d3] | 33 | scale = Parameter(1.0); |
---|
| 34 | radius = Parameter(5.0, true); |
---|
| 35 | radius.set_min(0.0); |
---|
| 36 | fractal_dim = Parameter(2.0); |
---|
| 37 | cor_length = Parameter(100.0); |
---|
| 38 | sldBlock = Parameter(2.0e-6); |
---|
| 39 | sldSolv= Parameter(6.35e-6); |
---|
| 40 | background = Parameter(0.0); |
---|
[c724ccd] | 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 FractalModel :: operator()(double q) { |
---|
[82c11d3] | 50 | double dp[7]; |
---|
| 51 | |
---|
| 52 | // Fill parameter array for IGOR library |
---|
| 53 | // Add the background after averaging |
---|
| 54 | dp[0] = scale(); |
---|
| 55 | dp[1] = radius(); |
---|
| 56 | dp[2] = fractal_dim(); |
---|
| 57 | dp[3] = cor_length(); |
---|
| 58 | dp[4] = sldBlock(); |
---|
| 59 | dp[5] = sldSolv(); |
---|
| 60 | dp[6] = 0.0; |
---|
| 61 | |
---|
| 62 | // Get the dispersion points for the radius |
---|
| 63 | vector<WeightPoint> weights_rad; |
---|
| 64 | radius.get_weights(weights_rad); |
---|
| 65 | |
---|
| 66 | // Perform the computation, with all weight points |
---|
| 67 | double sum = 0.0; |
---|
| 68 | double norm = 0.0; |
---|
| 69 | double vol = 0.0; |
---|
| 70 | |
---|
| 71 | // Loop over radius weight points |
---|
| 72 | for(size_t i=0; i<weights_rad.size(); i++) { |
---|
| 73 | dp[1] = weights_rad[i].value; |
---|
| 74 | |
---|
| 75 | //Un-normalize Fractal by volume |
---|
| 76 | sum += weights_rad[i].weight |
---|
| 77 | * Fractal(dp, fabs(q)) * pow(weights_rad[i].value,3); |
---|
| 78 | //Find average volume |
---|
| 79 | vol += weights_rad[i].weight |
---|
| 80 | * pow(weights_rad[i].value,3); |
---|
| 81 | |
---|
| 82 | norm += weights_rad[i].weight; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | if (vol != 0.0 && norm != 0.0) { |
---|
| 86 | //Re-normalize by avg volume |
---|
| 87 | sum = sum/(vol/norm);} |
---|
| 88 | return sum/norm + background(); |
---|
[c724ccd] | 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 FractalModel :: operator()(double qx, double qy) { |
---|
[82c11d3] | 98 | double q = sqrt(qx*qx + qy*qy); |
---|
| 99 | return (*this).operator()(q); |
---|
[c724ccd] | 100 | } |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * Function to evaluate 2D scattering function |
---|
| 104 | * @param pars: parameters of the FractalModel |
---|
| 105 | * @param q: q-value |
---|
| 106 | * @param phi: angle phi |
---|
| 107 | * @return: function value |
---|
| 108 | */ |
---|
| 109 | double FractalModel :: evaluate_rphi(double q, double phi) { |
---|
[82c11d3] | 110 | return (*this).operator()(q); |
---|
[c724ccd] | 111 | } |
---|
| 112 | |
---|
| 113 | /** |
---|
| 114 | * Function to calculate effective radius |
---|
| 115 | * @return: effective radius value |
---|
| 116 | */ |
---|
| 117 | double FractalModel :: calculate_ER() { |
---|
[82c11d3] | 118 | //NOT implemented yet!!! 'cause None shape Model |
---|
| 119 | return 0.0; |
---|
[c724ccd] | 120 | } |
---|