[cd2f75d] | 1 | /** |
---|
| 2 | * Scattering model classes |
---|
| 3 | * |
---|
| 4 | */ |
---|
| 5 | |
---|
| 6 | #include <math.h> |
---|
| 7 | #include "parameters.hh" |
---|
| 8 | #include <stdio.h> |
---|
| 9 | using namespace std; |
---|
| 10 | #include "coresecondmoment.h" |
---|
| 11 | |
---|
| 12 | static double core_secondmoment_kernel(double dp[], double q) { |
---|
| 13 | //fit parameters |
---|
| 14 | double scale = dp[0]; |
---|
| 15 | double density_poly = dp[1]; |
---|
| 16 | double sld_poly = dp[2]; |
---|
| 17 | double radius_core = dp[3]; |
---|
| 18 | double volf_cores = dp[4]; |
---|
| 19 | double ads_amount = dp[5]; |
---|
| 20 | double second_moment = dp[6]; |
---|
| 21 | double sld_solv = dp[7]; |
---|
| 22 | double background = dp[8]; |
---|
| 23 | // Not valid for very small r |
---|
| 24 | if (radius_core < 0.001){ |
---|
| 25 | return 0.0; |
---|
| 26 | } |
---|
| 27 | //others |
---|
| 28 | double form_factor = 0.0; |
---|
| 29 | double x_val = 0.0; |
---|
| 30 | //Pi |
---|
| 31 | double pi = 4.0 * atan(1.0); |
---|
| 32 | //relative sld |
---|
| 33 | double contrast = sld_poly - sld_solv; |
---|
| 34 | //x for exp |
---|
| 35 | x_val = q*second_moment; |
---|
| 36 | x_val *= x_val; |
---|
| 37 | //computation |
---|
| 38 | form_factor = contrast * ads_amount; |
---|
| 39 | form_factor /= (q * density_poly); |
---|
| 40 | form_factor *= form_factor; |
---|
| 41 | form_factor *= (6.0 * pi * volf_cores * 1.0e+10); |
---|
| 42 | form_factor /= radius_core; |
---|
| 43 | form_factor *= exp(-x_val); |
---|
| 44 | |
---|
| 45 | // scale and background |
---|
| 46 | form_factor *= scale; |
---|
| 47 | form_factor += background; |
---|
| 48 | return (form_factor); |
---|
| 49 | } |
---|
| 50 | |
---|
[7289627] | 51 | Core2ndMomentModel :: Core2ndMomentModel() { |
---|
[cd2f75d] | 52 | scale = Parameter(1.0); |
---|
| 53 | density_poly = Parameter(0.7); |
---|
| 54 | sld_poly = Parameter(1.5e-6); |
---|
| 55 | radius_core = Parameter(500.0, true); |
---|
| 56 | radius_core.set_min(0.0); |
---|
| 57 | volf_cores = Parameter(0.14); |
---|
| 58 | ads_amount = Parameter(1.9); |
---|
| 59 | second_moment = Parameter(23.0); |
---|
| 60 | sld_solv = Parameter(6.3e-6); |
---|
| 61 | background = Parameter(0.0); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | /** |
---|
| 65 | * Function to evaluate 1D scattering function |
---|
| 66 | * @param q: q-value |
---|
| 67 | * @return: function value |
---|
| 68 | */ |
---|
[7289627] | 69 | double Core2ndMomentModel :: operator()(double q) { |
---|
[cd2f75d] | 70 | double dp[9]; |
---|
| 71 | |
---|
| 72 | // Add the background after averaging |
---|
| 73 | dp[0] = scale(); |
---|
| 74 | dp[1] = density_poly(); |
---|
| 75 | dp[2] = sld_poly(); |
---|
| 76 | dp[3] = radius_core(); |
---|
| 77 | dp[4] = volf_cores(); |
---|
| 78 | dp[5] = ads_amount(); |
---|
| 79 | dp[6] = second_moment(); |
---|
| 80 | dp[7] = sld_solv(); |
---|
| 81 | dp[8] = 0.0; |
---|
| 82 | |
---|
| 83 | // Get the dispersion points for the radius |
---|
| 84 | vector<WeightPoint> weights_rad; |
---|
| 85 | radius_core.get_weights(weights_rad); |
---|
| 86 | |
---|
| 87 | // Perform the computation, with all weight points |
---|
| 88 | double sum = 0.0; |
---|
| 89 | double norm = 0.0; |
---|
| 90 | |
---|
| 91 | // Loop over radius weight points |
---|
| 92 | for(size_t i=0; i<weights_rad.size(); i++) { |
---|
| 93 | dp[3] = weights_rad[i].value; |
---|
| 94 | //weighted sum |
---|
| 95 | sum += weights_rad[i].weight |
---|
| 96 | * core_secondmoment_kernel(dp, q); |
---|
| 97 | norm += weights_rad[i].weight; |
---|
| 98 | } |
---|
| 99 | return sum/norm + background(); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * Function to evaluate 2D scattering function |
---|
| 104 | * @param q_x: value of Q along x |
---|
| 105 | * @param q_y: value of Q along y |
---|
| 106 | * @return: function value |
---|
| 107 | */ |
---|
[7289627] | 108 | double Core2ndMomentModel :: operator()(double qx, double qy) { |
---|
[cd2f75d] | 109 | double q = sqrt(qx*qx + qy*qy); |
---|
| 110 | return (*this).operator()(q); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | /** |
---|
| 114 | * Function to evaluate 2D scattering function |
---|
| 115 | * @param pars: parameters of the sphere |
---|
| 116 | * @param q: q-value |
---|
| 117 | * @param phi: angle phi |
---|
| 118 | * @return: function value |
---|
| 119 | */ |
---|
[7289627] | 120 | double Core2ndMomentModel :: evaluate_rphi(double q, double phi) { |
---|
[cd2f75d] | 121 | return (*this).operator()(q); |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | /** |
---|
| 125 | * Function to calculate effective radius |
---|
| 126 | * @return: effective radius value |
---|
| 127 | */ |
---|
[7289627] | 128 | double Core2ndMomentModel :: calculate_ER() { |
---|
[cd2f75d] | 129 | return 0.0; |
---|
| 130 | } |
---|
[e08bd5b] | 131 | double Core2ndMomentModel :: calculate_VR() { |
---|
| 132 | return 1.0; |
---|
| 133 | } |
---|