[27a0771] | 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 | * TODO: add 2D function |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | #include <math.h> |
---|
| 25 | #include "models.hh" |
---|
| 26 | #include "parameters.hh" |
---|
| 27 | #include <stdio.h> |
---|
| 28 | using namespace std; |
---|
| 29 | |
---|
| 30 | extern "C" { |
---|
| 31 | #include "libCylinder.h" |
---|
| 32 | #include "lamellarPS_HG.h" |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | LamellarPSHGModel :: LamellarPSHGModel() { |
---|
| 36 | scale = Parameter(1.0); |
---|
[96b59384] | 37 | spacing = Parameter(40.0, true); |
---|
| 38 | spacing.set_min(0.0); |
---|
[27a0771] | 39 | deltaT = Parameter(10.0, true); |
---|
| 40 | deltaT.set_min(0.0); |
---|
| 41 | deltaH = Parameter(2.0, true); |
---|
| 42 | deltaH.set_min(0.0); |
---|
| 43 | sld_tail = Parameter(4e-7); |
---|
| 44 | sld_head = Parameter(2e-6); |
---|
| 45 | sld_solvent = Parameter(6e-6); |
---|
| 46 | n_plates = Parameter(30); |
---|
| 47 | caille = Parameter(0.001); |
---|
| 48 | background = Parameter(0.001); |
---|
| 49 | |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | * Function to evaluate 1D scattering function |
---|
| 54 | * The NIST IGOR library is used for the actual calculation. |
---|
| 55 | * @param q: q-value |
---|
| 56 | * @return: function value |
---|
| 57 | */ |
---|
| 58 | double LamellarPSHGModel :: operator()(double q) { |
---|
| 59 | double dp[10]; |
---|
| 60 | |
---|
| 61 | // Fill parameter array for IGOR library |
---|
| 62 | // Add the background after averaging |
---|
| 63 | dp[0] = scale(); |
---|
| 64 | dp[1] = spacing(); |
---|
| 65 | dp[2] = deltaT(); |
---|
| 66 | dp[3] = deltaH(); |
---|
| 67 | dp[4] = sld_tail(); |
---|
| 68 | dp[5] = sld_head(); |
---|
| 69 | dp[6] = sld_solvent(); |
---|
| 70 | dp[7] = n_plates(); |
---|
| 71 | dp[8] = caille(); |
---|
[96b59384] | 72 | dp[9] = 0.0; |
---|
| 73 | |
---|
[27a0771] | 74 | |
---|
| 75 | // Get the dispersion points for (deltaT) thickness of the tail |
---|
| 76 | vector<WeightPoint> weights_deltaT; |
---|
| 77 | deltaT.get_weights(weights_deltaT); |
---|
[96b59384] | 78 | |
---|
[27a0771] | 79 | // Get the dispersion points for (deltaH) thickness of the head |
---|
| 80 | vector<WeightPoint> weights_deltaH; |
---|
| 81 | deltaH.get_weights(weights_deltaH); |
---|
| 82 | |
---|
[96b59384] | 83 | // Get the dispersion points for spacing |
---|
| 84 | vector<WeightPoint> weights_spacing; |
---|
| 85 | spacing.get_weights(weights_spacing); |
---|
| 86 | |
---|
[27a0771] | 87 | // Perform the computation, with all weight points |
---|
| 88 | double sum = 0.0; |
---|
| 89 | double norm = 0.0; |
---|
[96b59384] | 90 | |
---|
[27a0771] | 91 | // Loop over deltaT weight points |
---|
| 92 | for(int i=0; i< (int)weights_deltaT.size(); i++) { |
---|
| 93 | dp[2] = weights_deltaT[i].value; |
---|
| 94 | |
---|
| 95 | // Loop over deltaH weight points |
---|
| 96 | for(int j=0; j< (int)weights_deltaH.size(); j++) { |
---|
| 97 | dp[3] = weights_deltaH[j].value; |
---|
[96b59384] | 98 | // Loop over spacing weight points |
---|
| 99 | for(int k=0; k< (int)weights_spacing.size(); k++) { |
---|
| 100 | dp[1] = weights_spacing[k].value; |
---|
| 101 | |
---|
| 102 | sum += weights_deltaT[i].weight * weights_deltaH[j].weight *weights_spacing[k].weight |
---|
| 103 | *LamellarPS_HG(dp, q); |
---|
| 104 | norm += weights_deltaT[i].weight * weights_deltaH[j].weight * weights_spacing[k].weight; |
---|
| 105 | } |
---|
[27a0771] | 106 | } |
---|
| 107 | } |
---|
| 108 | return sum/norm + background(); |
---|
| 109 | } |
---|
| 110 | /** |
---|
| 111 | * Function to evaluate 2D scattering function |
---|
| 112 | * @param q_x: value of Q along x |
---|
| 113 | * @param q_y: value of Q along y |
---|
| 114 | * @return: function value |
---|
| 115 | */ |
---|
| 116 | double LamellarPSHGModel :: operator()(double qx, double qy) { |
---|
[96b59384] | 117 | double q = sqrt(qx*qx + qy*qy); |
---|
| 118 | return (*this).operator()(q); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | * Function to evaluate 2D scattering function |
---|
| 123 | * @param pars: parameters of the lamellarPS_HG |
---|
| 124 | * @param q: q-value |
---|
| 125 | * @param phi: angle phi |
---|
| 126 | * @return: function value |
---|
| 127 | */ |
---|
| 128 | double LamellarPSHGModel :: evaluate_rphi(double q, double phi) { |
---|
| 129 | return (*this).operator()(q); |
---|
| 130 | } |
---|
[5eb9154] | 131 | /** |
---|
| 132 | * Function to calculate effective radius |
---|
| 133 | * @return: effective radius value |
---|
| 134 | */ |
---|
| 135 | double LamellarPSHGModel :: calculate_ER() { |
---|
| 136 | //NOT implemented yet!!! |
---|
| 137 | } |
---|
[96b59384] | 138 | |
---|
| 139 | /* |
---|
| 140 | double LamellarPSHGModel :: operator()(double qx, double qy) { |
---|
[27a0771] | 141 | LamellarPSHGParameters dp; |
---|
| 142 | // Fill parameter array |
---|
| 143 | dp.scale = scale(); |
---|
| 144 | dp.spacing = spacing(); |
---|
| 145 | dp.deltaT = deltaT(); |
---|
| 146 | dp.deltaH = deltaH(); |
---|
| 147 | dp.sld_tail = sld_tail(); |
---|
| 148 | dp.sld_head = sld_head(); |
---|
| 149 | dp.sld_solvent = sld_solvent(); |
---|
| 150 | dp.n_plates = n_plates(); |
---|
| 151 | dp.caille = caille(); |
---|
| 152 | dp.background = background(); |
---|
[96b59384] | 153 | |
---|
[27a0771] | 154 | // Get the dispersion points for the deltaT |
---|
| 155 | vector<WeightPoint> weights_deltaT; |
---|
| 156 | deltaT.get_weights(weights_deltaT); |
---|
| 157 | |
---|
| 158 | // Get the dispersion points for the deltaH |
---|
| 159 | vector<WeightPoint> weights_deltaH; |
---|
| 160 | deltaH.get_weights(weights_deltaH); |
---|
| 161 | |
---|
| 162 | // Perform the computation, with all weight points |
---|
| 163 | double sum = 0.0; |
---|
| 164 | double norm = 0.0; |
---|
| 165 | |
---|
| 166 | // Loop over deltaT weight points |
---|
| 167 | for(int i=0; i< (int)weights_deltaT.size(); i++) { |
---|
| 168 | dp.deltaT = weights_deltaT[i].value; |
---|
[96b59384] | 169 | |
---|
[27a0771] | 170 | // Loop over deltaH weight points |
---|
| 171 | for(int j=0; j< (int)weights_deltaH.size(); j++) { |
---|
| 172 | dp.deltaH = weights_deltaH[j].value; |
---|
| 173 | |
---|
[96b59384] | 174 | sum += weights_deltaT[i].weight *weights_deltaH[j].weight *lamellarPS_HG_analytical_2DXY(&dp, qx, qy); |
---|
| 175 | norm += weights_deltaT[i].weight * weights_deltaH[j].weight; |
---|
[27a0771] | 176 | } |
---|
| 177 | } |
---|
| 178 | return sum/norm + background(); |
---|
| 179 | } |
---|
[96b59384] | 180 | */ |
---|
[27a0771] | 181 | |
---|
| 182 | |
---|