[5068697] | 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 |
---|
[ea07075] | 21 | * TODO: add 2d |
---|
[5068697] | 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" |
---|
[5eb9154] | 32 | #include "libStructureFactor.h" |
---|
[5068697] | 33 | #include "flexible_cylinder.h" |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | FlexibleCylinderModel :: FlexibleCylinderModel() { |
---|
| 37 | scale = Parameter(1.0); |
---|
| 38 | length = Parameter(1000.0, true); |
---|
| 39 | length.set_min(0.0); |
---|
| 40 | kuhn_length = Parameter(100.0, true); |
---|
| 41 | kuhn_length.set_min(0.0); |
---|
| 42 | radius = Parameter(20.0, true); |
---|
| 43 | radius.set_min(0.0); |
---|
| 44 | contrast = Parameter(5.3e-6); |
---|
| 45 | background = Parameter(0.0001); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | /** |
---|
| 49 | * Function to evaluate 1D scattering function |
---|
| 50 | * The NIST IGOR library is used for the actual calculation. |
---|
| 51 | * @param q: q-value |
---|
| 52 | * @return: function value |
---|
| 53 | */ |
---|
| 54 | double FlexibleCylinderModel :: operator()(double q) { |
---|
[2cc633b] | 55 | double dp[6]; |
---|
[5068697] | 56 | |
---|
| 57 | // Fill parameter array for IGOR library |
---|
| 58 | // Add the background after averaging |
---|
| 59 | dp[0] = scale(); |
---|
| 60 | dp[1] = length(); |
---|
| 61 | dp[2] = kuhn_length(); |
---|
| 62 | dp[3] = radius(); |
---|
| 63 | dp[4] = contrast(); |
---|
[b4679de] | 64 | dp[5] = 0.0; |
---|
[5068697] | 65 | |
---|
| 66 | // Get the dispersion points for the length |
---|
[2cc633b] | 67 | vector<WeightPoint> weights_len; |
---|
| 68 | length.get_weights(weights_len); |
---|
[5068697] | 69 | |
---|
[e6fa43e] | 70 | // Get the dispersion points for the kuhn_length |
---|
[2cc633b] | 71 | vector<WeightPoint> weights_kuhn; |
---|
| 72 | kuhn_length.get_weights(weights_kuhn); |
---|
[e6fa43e] | 73 | |
---|
[5068697] | 74 | // Get the dispersion points for the radius |
---|
[2cc633b] | 75 | vector<WeightPoint> weights_rad; |
---|
| 76 | radius.get_weights(weights_rad); |
---|
[5068697] | 77 | |
---|
| 78 | // Perform the computation, with all weight points |
---|
| 79 | double sum = 0.0; |
---|
| 80 | double norm = 0.0; |
---|
| 81 | |
---|
| 82 | // Loop over semi axis A weight points |
---|
[2cc633b] | 83 | for(int i=0; i< (int)weights_len.size(); i++) { |
---|
| 84 | dp[1] = weights_len[i].value; |
---|
[5068697] | 85 | |
---|
| 86 | // Loop over semi axis B weight points |
---|
[2cc633b] | 87 | for(int j=0; j< (int)weights_kuhn.size(); j++) { |
---|
| 88 | dp[2] = weights_kuhn[j].value; |
---|
[e6fa43e] | 89 | |
---|
| 90 | // Loop over semi axis C weight points |
---|
[2cc633b] | 91 | for(int k=0; k< (int)weights_rad.size(); k++) { |
---|
| 92 | dp[3] = weights_rad[k].value; |
---|
| 93 | |
---|
| 94 | sum += weights_len[i].weight |
---|
| 95 | * weights_kuhn[j].weight*weights_rad[k].weight * FlexExclVolCyl(dp, q); |
---|
| 96 | norm += weights_len[i].weight |
---|
| 97 | * weights_kuhn[j].weight*weights_rad[k].weight; |
---|
| 98 | } |
---|
[5068697] | 99 | } |
---|
| 100 | } |
---|
| 101 | return sum/norm + background(); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | /** |
---|
| 105 | * Function to evaluate 2D scattering function |
---|
| 106 | * @param q_x: value of Q along x |
---|
| 107 | * @param q_y: value of Q along y |
---|
| 108 | * @return: function value |
---|
| 109 | */ |
---|
| 110 | double FlexibleCylinderModel :: operator()(double qx, double qy) { |
---|
[ea07075] | 111 | double q = sqrt(qx*qx + qy*qy); |
---|
| 112 | return (*this).operator()(q); |
---|
[5068697] | 113 | } |
---|
| 114 | |
---|
| 115 | /** |
---|
| 116 | * Function to evaluate 2D scattering function |
---|
| 117 | * @param pars: parameters of the triaxial ellipsoid |
---|
| 118 | * @param q: q-value |
---|
| 119 | * @param phi: angle phi |
---|
| 120 | * @return: function value |
---|
| 121 | */ |
---|
| 122 | double FlexibleCylinderModel :: evaluate_rphi(double q, double phi) { |
---|
[ea07075] | 123 | //double qx = q*cos(phi); |
---|
| 124 | //double qy = q*sin(phi); |
---|
| 125 | return (*this).operator()(q); |
---|
[5068697] | 126 | } |
---|
[5eb9154] | 127 | /** |
---|
| 128 | * Function to calculate effective radius |
---|
| 129 | * @return: effective radius value |
---|
| 130 | */ |
---|
| 131 | double FlexibleCylinderModel :: calculate_ER() { |
---|
| 132 | FlexibleCylinderParameters dp; |
---|
| 133 | |
---|
| 134 | dp.radius = radius(); |
---|
| 135 | dp.length = length(); |
---|
| 136 | |
---|
| 137 | double rad_out = 0.0; |
---|
| 138 | |
---|
| 139 | // Perform the computation, with all weight points |
---|
| 140 | double sum = 0.0; |
---|
| 141 | double norm = 0.0; |
---|
| 142 | |
---|
| 143 | // Get the dispersion points for the major shell |
---|
| 144 | vector<WeightPoint> weights_length; |
---|
| 145 | length.get_weights(weights_length); |
---|
| 146 | |
---|
| 147 | // Get the dispersion points for the minor shell |
---|
| 148 | vector<WeightPoint> weights_radius ; |
---|
| 149 | radius.get_weights(weights_radius); |
---|
| 150 | |
---|
| 151 | // Loop over major shell weight points |
---|
| 152 | for(int i=0; i< (int)weights_length.size(); i++) { |
---|
| 153 | dp.length = weights_length[i].value; |
---|
| 154 | for(int k=0; k< (int)weights_radius.size(); k++) { |
---|
| 155 | dp.radius = weights_radius[k].value; |
---|
| 156 | //Note: output of "DiamCyl(dp.length,dp.radius)" is DIAMETER. |
---|
| 157 | sum +=weights_length[i].weight |
---|
| 158 | * weights_radius[k].weight*DiamCyl(dp.length,dp.radius)/2.0; |
---|
| 159 | norm += weights_length[i].weight* weights_radius[k].weight; |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | if (norm != 0){ |
---|
| 163 | //return the averaged value |
---|
| 164 | rad_out = sum/norm;} |
---|
| 165 | else{ |
---|
| 166 | //return normal value |
---|
| 167 | //Note: output of "DiamCyl(dp.length,dp.radius)" is DIAMETER. |
---|
| 168 | rad_out = DiamCyl(dp.length,dp.radius)/2.0;} |
---|
| 169 | |
---|
| 170 | return rad_out; |
---|
| 171 | } |
---|