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