[0164899a] | 1 | /** |
---|
| 2 | * Scattering model classes |
---|
| 3 | * The classes use the IGOR library found in |
---|
| 4 | * sansmodels/c_extensions/libmultifunc/librefl.h |
---|
| 5 | */ |
---|
| 6 | |
---|
| 7 | #include <math.h> |
---|
| 8 | #include "parameters.hh" |
---|
| 9 | #include <stdio.h> |
---|
| 10 | using namespace std; |
---|
[0ba3b08] | 11 | #include "sld_cal.h" |
---|
[0164899a] | 12 | |
---|
| 13 | extern "C" { |
---|
[0ba3b08] | 14 | #include "libmultifunc/librefl.h" |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | // Convenience structure |
---|
| 18 | typedef struct { |
---|
| 19 | double fun_type; |
---|
| 20 | double npts_inter; |
---|
| 21 | double shell_num; |
---|
| 22 | double nu_inter; |
---|
| 23 | double sld_left; |
---|
| 24 | double sld_right; |
---|
| 25 | } SLDCalParameters; |
---|
| 26 | |
---|
| 27 | /** |
---|
| 28 | * Function to calculate sld |
---|
| 29 | * @param pars: parameters |
---|
| 30 | * @param x: independent param-value |
---|
| 31 | * @return: sld value |
---|
| 32 | */ |
---|
| 33 | static double sld_cal_analytical_1D(SLDCalParameters *pars, double x) { |
---|
| 34 | double fun, nsl, n_s, fun_coef, sld_l, sld_r, sld_out; |
---|
| 35 | int fun_type; |
---|
| 36 | |
---|
| 37 | fun = pars->fun_type; |
---|
| 38 | nsl = pars->npts_inter; |
---|
| 39 | n_s = pars->shell_num; |
---|
| 40 | fun_coef = pars->nu_inter; |
---|
| 41 | sld_l = pars-> sld_left; |
---|
| 42 | sld_r = pars-> sld_right; |
---|
| 43 | |
---|
| 44 | fun_type = floor(fun); |
---|
| 45 | |
---|
| 46 | sld_out = intersldfunc(fun_type, nsl, n_s, fun_coef, sld_l, sld_r); |
---|
| 47 | |
---|
| 48 | return sld_out; |
---|
[0164899a] | 49 | } |
---|
| 50 | |
---|
| 51 | SLDCalFunc :: SLDCalFunc() { |
---|
| 52 | fun_type = Parameter(0); |
---|
| 53 | npts_inter = Parameter(21); |
---|
| 54 | shell_num = Parameter(1); |
---|
| 55 | nu_inter = Parameter(2.5); |
---|
| 56 | sld_left = Parameter(1.0e-06); |
---|
| 57 | sld_right = Parameter(2.0e-06); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | /** |
---|
| 61 | * Function to evaluate 1D scattering function |
---|
| 62 | * @param q: q-value |
---|
| 63 | * @return: function value |
---|
| 64 | */ |
---|
| 65 | double SLDCalFunc :: operator()(double q) { |
---|
| 66 | SLDCalParameters dp; |
---|
| 67 | |
---|
| 68 | dp.fun_type = fun_type(); |
---|
| 69 | dp.npts_inter = npts_inter(); |
---|
| 70 | dp.shell_num = shell_num(); |
---|
| 71 | dp.nu_inter = nu_inter(); |
---|
| 72 | dp.sld_left = sld_left(); |
---|
| 73 | dp.sld_right = sld_right(); |
---|
| 74 | |
---|
| 75 | return sld_cal_analytical_1D(&dp, q); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | /** |
---|
| 79 | * Function to evaluate 2D scattering function |
---|
| 80 | * @param q_x: value of Q along x |
---|
| 81 | * @param q_y: value of Q along y |
---|
| 82 | * @return: function value |
---|
| 83 | */ |
---|
| 84 | double SLDCalFunc :: operator()(double qx, double qy) { |
---|
| 85 | double q = sqrt(qx*qx + qy*qy); |
---|
| 86 | return (*this).operator()(q); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | /** |
---|
| 90 | * Function to evaluate 2D scattering function |
---|
| 91 | * @param pars: parameters of the cylinder |
---|
| 92 | * @param q: q-value |
---|
| 93 | * @param phi: angle phi |
---|
| 94 | * @return: function value |
---|
| 95 | */ |
---|
| 96 | double SLDCalFunc :: evaluate_rphi(double q, double phi) { |
---|
| 97 | return (*this).operator()(q); |
---|
| 98 | } |
---|
| 99 | /** |
---|
| 100 | * Function to calculate effective radius |
---|
| 101 | * @return: effective radius value |
---|
| 102 | */ |
---|
| 103 | double SLDCalFunc :: calculate_ER() { |
---|
| 104 | //NOT implemented yet!!! |
---|
[34c2649] | 105 | return 0.0; |
---|
[0164899a] | 106 | } |
---|