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