[3d25331f] | 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 | */ |
---|
| 21 | |
---|
| 22 | #include <math.h> |
---|
| 23 | #include "models.hh" |
---|
| 24 | #include "parameters.hh" |
---|
| 25 | #include <stdio.h> |
---|
| 26 | using namespace std; |
---|
| 27 | |
---|
| 28 | extern "C" { |
---|
| 29 | #include "libSphere.h" |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | MultiShellModel :: MultiShellModel() { |
---|
| 33 | scale = Parameter(1.0); |
---|
| 34 | core_radius = Parameter(60.0, true); |
---|
| 35 | core_radius.set_min(0.0); |
---|
| 36 | s_thickness = Parameter(10.0); |
---|
| 37 | w_thickness = Parameter(10.0); |
---|
| 38 | core_sld = Parameter(6.4e-6); |
---|
| 39 | shell_sld = Parameter(4.0e-7); |
---|
| 40 | n_pairs = Parameter(2); |
---|
| 41 | background = Parameter(0.0); |
---|
| 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 MultiShellModel :: operator()(double q) { |
---|
| 51 | double dp[8]; |
---|
| 52 | |
---|
| 53 | // Fill parameter array for IGOR library |
---|
| 54 | // Add the background after averaging |
---|
| 55 | dp[0] = scale(); |
---|
| 56 | dp[1] = core_radius(); |
---|
| 57 | dp[2] = s_thickness(); |
---|
| 58 | dp[3] = w_thickness(); |
---|
| 59 | dp[4] = core_sld(); |
---|
| 60 | dp[5] = shell_sld(); |
---|
| 61 | dp[6] = n_pairs(); |
---|
| 62 | dp[7] = background(); |
---|
| 63 | |
---|
| 64 | // Get the dispersion points for the core radius |
---|
| 65 | vector<WeightPoint> weights_core_radius; |
---|
| 66 | core_radius.get_weights(weights_core_radius); |
---|
| 67 | |
---|
[2cc633b] | 68 | // Get the dispersion points for the s_thickness |
---|
| 69 | vector<WeightPoint> weights_s_thickness; |
---|
| 70 | s_thickness.get_weights(weights_s_thickness); |
---|
| 71 | |
---|
| 72 | // Get the dispersion points for the w_thickness |
---|
| 73 | vector<WeightPoint> weights_w_thickness; |
---|
| 74 | w_thickness.get_weights(weights_w_thickness); |
---|
| 75 | |
---|
[3d25331f] | 76 | // Perform the computation, with all weight points |
---|
| 77 | double sum = 0.0; |
---|
| 78 | double norm = 0.0; |
---|
| 79 | |
---|
| 80 | // Loop over radius weight points |
---|
| 81 | for(int i=0; i< (int)weights_core_radius.size(); i++) { |
---|
| 82 | dp[1] = weights_core_radius[i].value; |
---|
[2cc633b] | 83 | for(int j=0; j< (int)weights_s_thickness.size(); j++){ |
---|
| 84 | dp[2] = weights_s_thickness[j].value; |
---|
| 85 | for(int k=0; k< (int)weights_w_thickness.size(); k++){ |
---|
| 86 | dp[3] = weights_w_thickness[k].value; |
---|
[3d25331f] | 87 | |
---|
[2cc633b] | 88 | sum += weights_core_radius[i].weight*weights_s_thickness[j].weight |
---|
| 89 | *weights_w_thickness[k].weight* MultiShell(dp, q); |
---|
| 90 | norm += weights_core_radius[i].weight*weights_s_thickness[j].weight |
---|
| 91 | *weights_w_thickness[k].weight; |
---|
| 92 | } |
---|
| 93 | } |
---|
[3d25331f] | 94 | } |
---|
| 95 | return sum/norm + background(); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | /** |
---|
| 99 | * Function to evaluate 2D scattering function |
---|
| 100 | * @param q_x: value of Q along x |
---|
| 101 | * @param q_y: value of Q along y |
---|
| 102 | * @return: function value |
---|
| 103 | */ |
---|
| 104 | double MultiShellModel :: operator()(double qx, double qy) { |
---|
| 105 | double q = sqrt(qx*qx + qy*qy); |
---|
| 106 | return (*this).operator()(q); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | /** |
---|
| 110 | * Function to evaluate 2D scattering function |
---|
| 111 | * @param pars: parameters of the multishell |
---|
| 112 | * @param q: q-value |
---|
| 113 | * @param phi: angle phi |
---|
| 114 | * @return: function value |
---|
| 115 | */ |
---|
| 116 | double MultiShellModel :: evaluate_rphi(double q, double phi) { |
---|
| 117 | return (*this).operator()(q); |
---|
| 118 | } |
---|