[34c3020] | 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 "libCylinder.h" |
---|
| 31 | #include "lamellar.h" |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | LamellarModel :: LamellarModel() { |
---|
| 35 | scale = Parameter(1.0); |
---|
| 36 | delta = Parameter(50.0, true); |
---|
| 37 | delta.set_min(0.0); |
---|
| 38 | sigma = Parameter(0.15, true); |
---|
| 39 | contrast = Parameter(5.3e-6); |
---|
| 40 | background = Parameter(0.0); |
---|
| 41 | |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | /** |
---|
| 45 | * Function to evaluate 1D scattering function |
---|
| 46 | * The NIST IGOR library is used for the actual calculation. |
---|
| 47 | * @param q: q-value |
---|
| 48 | * @return: function value |
---|
| 49 | */ |
---|
| 50 | double LamellarModel :: operator()(double q) { |
---|
| 51 | double dp[5]; |
---|
| 52 | |
---|
| 53 | // Fill parameter array for IGOR library |
---|
| 54 | // Add the background after averaging |
---|
| 55 | dp[0] = scale(); |
---|
| 56 | dp[1] = delta(); |
---|
| 57 | dp[2] = sigma(); |
---|
| 58 | dp[3] = contrast(); |
---|
| 59 | dp[4] = background(); |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | // Get the dispersion points for the bilayer thickness(delta) |
---|
| 63 | vector<WeightPoint> weights_delta; |
---|
| 64 | delta.get_weights(weights_delta); |
---|
| 65 | |
---|
| 66 | // Perform the computation, with all weight points |
---|
| 67 | double sum = 0.0; |
---|
| 68 | double norm = 0.0; |
---|
| 69 | |
---|
| 70 | // Loop over semi axis A weight points |
---|
| 71 | for(int i=0; i< (int)weights_delta.size(); i++) { |
---|
| 72 | dp[1] = weights_delta[i].value; |
---|
| 73 | sum += weights_delta[i].weight* LamellarFF(dp, q); |
---|
| 74 | norm += weights_delta[i].weight; |
---|
| 75 | |
---|
| 76 | } |
---|
| 77 | return sum/norm + background(); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | /** |
---|
| 81 | * Function to evaluate 2D scattering function |
---|
| 82 | * @param q_x: value of Q along x |
---|
| 83 | * @param q_y: value of Q along y |
---|
| 84 | * @return: function value |
---|
| 85 | */ |
---|
| 86 | |
---|
| 87 | double LamellarModel :: operator()(double qx, double qy) { |
---|
| 88 | LamellarParameters dp; |
---|
| 89 | |
---|
| 90 | // Fill parameter array for IGOR library |
---|
| 91 | // Add the background after averaging |
---|
| 92 | dp.scale = scale(); |
---|
| 93 | dp.delta = delta(); |
---|
| 94 | dp.sigma = sigma(); |
---|
| 95 | dp.contrast = contrast(); |
---|
| 96 | dp.background = background(); |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | // Get the dispersion points for the bilayer thickness(delta) |
---|
| 100 | vector<WeightPoint> weights_delta; |
---|
| 101 | delta.get_weights(weights_delta); |
---|
| 102 | |
---|
| 103 | // Perform the computation, with all weight points |
---|
| 104 | double sum = 0.0; |
---|
| 105 | double norm = 0.0; |
---|
| 106 | |
---|
| 107 | // Loop over detla weight points |
---|
| 108 | for(int i=0; i< (int)weights_delta.size(); i++) { |
---|
| 109 | dp.delta = weights_delta[i].value; |
---|
| 110 | sum += weights_delta[i].weight* lamellar_analytical_2DXY(&dp, qx, qy); |
---|
| 111 | norm += weights_delta[i].weight; |
---|
| 112 | |
---|
| 113 | } |
---|
| 114 | return sum/norm + background(); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | /** |
---|
| 118 | * Function to evaluate 2D scattering function |
---|
| 119 | * @param pars: parameters of the lamellar |
---|
| 120 | * @param q: q-value |
---|
| 121 | * @param phi: angle phi |
---|
| 122 | * @return: function value |
---|
| 123 | */ |
---|
| 124 | double LamellarModel :: evaluate_rphi(double q, double phi) { |
---|
| 125 | double qx = q*cos(phi); |
---|
| 126 | double qy = q*sin(phi); |
---|
| 127 | return (*this).operator()(qx, qy); |
---|
| 128 | } |
---|