[8c8cb05] | 1 | /** |
---|
| 2 | * spheresld model |
---|
| 3 | */ |
---|
| 4 | #include <math.h> |
---|
| 5 | #include "pearlnecklace.h" |
---|
| 6 | #include "libmultifunc/libfunc.h" |
---|
| 7 | #include <stdio.h> |
---|
| 8 | #include <stdlib.h> |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | double pearl_necklace_kernel(double dp[], double q) { |
---|
| 12 | // fit parameters |
---|
| 13 | double scale = dp[0]; |
---|
| 14 | double radius = dp[1]; |
---|
| 15 | double edge_separation = dp[2]; |
---|
| 16 | double thick_string = dp[3]; |
---|
| 17 | double num_pearls = dp[4]; |
---|
| 18 | double sld_pearl = dp[5]; |
---|
| 19 | double sld_string = dp[6]; |
---|
| 20 | double sld_solv = dp[7]; |
---|
| 21 | double background = dp[8]; |
---|
| 22 | |
---|
| 23 | //relative slds |
---|
| 24 | double contrast_pearl = sld_pearl - sld_solv; |
---|
| 25 | double contrast_string = sld_string - sld_solv; |
---|
| 26 | |
---|
| 27 | // number of string segments |
---|
| 28 | double num_strings = num_pearls - 1.0; |
---|
| 29 | |
---|
| 30 | //Pi |
---|
| 31 | double pi = 4.0*atan(1.0); |
---|
| 32 | |
---|
| 33 | // each volumes |
---|
| 34 | double string_vol = edge_separation * pi * pow((thick_string / 2.0), 2); |
---|
| 35 | double pearl_vol = 4.0 /3.0 * pi * pow(radius, 3); |
---|
| 36 | |
---|
| 37 | //total volume |
---|
| 38 | double tot_vol; |
---|
| 39 | tot_vol = num_strings * string_vol; |
---|
| 40 | tot_vol += num_pearls * pearl_vol; |
---|
| 41 | |
---|
| 42 | //each masses |
---|
| 43 | double m_r= contrast_string * string_vol; |
---|
| 44 | double m_s= contrast_pearl * pearl_vol; |
---|
| 45 | |
---|
| 46 | //sine functions of a pearl |
---|
| 47 | double psi; |
---|
| 48 | psi = sin(q*radius); |
---|
| 49 | psi -= q * radius * cos(q * radius); |
---|
| 50 | psi /= pow((q * radius), 3); |
---|
| 51 | psi *= 3.0; |
---|
| 52 | |
---|
| 53 | // Note take only 20 terms in Si series: 10 terms may be enough though. |
---|
| 54 | double gamma; |
---|
| 55 | gamma = Si(q* edge_separation, 6); |
---|
| 56 | gamma /= (q* edge_separation); |
---|
| 57 | double beta; |
---|
| 58 | beta = Si(q * (edge_separation + radius), 6); |
---|
| 59 | beta -= Si(q * radius, 6); |
---|
| 60 | beta /= (q* edge_separation); |
---|
| 61 | |
---|
| 62 | //form factors |
---|
| 63 | double sss; //pearls |
---|
| 64 | double srr; //strings |
---|
| 65 | double srs; //cross |
---|
| 66 | // center to center distance between the neighboring pearls |
---|
| 67 | double A_s = edge_separation + 2.0 * radius; |
---|
| 68 | |
---|
| 69 | // form factor for num_pearls |
---|
| 70 | sss = 1.0 - pow(sin_x(q*A_s), (int)num_pearls ); |
---|
| 71 | sss /= pow((1.0-sin_x(q*A_s)), 2); |
---|
| 72 | sss *= sin_x(q*A_s); |
---|
| 73 | sss -= num_pearls/2.0; |
---|
| 74 | sss += num_pearls/(1.0-sin_x(q*A_s)); |
---|
| 75 | sss *= 2.0 * pow((m_s*psi), 2); |
---|
| 76 | |
---|
| 77 | // form factor for num_strings (like thin rods) |
---|
| 78 | double srr_1; |
---|
| 79 | srr_1 = -pow(sin_x(q*edge_separation/2.0), 2); |
---|
| 80 | //printf ("sss %g, %g, %g\n",sss, srr_1, gamma); |
---|
| 81 | srr_1 += 2.0 * gamma; |
---|
| 82 | srr_1 *= num_strings; |
---|
| 83 | double srr_2; |
---|
| 84 | srr_2 = 2.0/(1.0-sin_x(q*A_s)); |
---|
| 85 | srr_2 *= num_strings; |
---|
| 86 | srr_2 *= pow(beta, 2); |
---|
| 87 | double srr_3; |
---|
| 88 | srr_3 = 1.0 - pow(sin_x(q*A_s), (int)num_strings); |
---|
| 89 | srr_3 /= pow((1.0-sin_x(q*A_s)), 2); |
---|
| 90 | srr_3 *= pow(beta, 2); |
---|
| 91 | srr_3 *= -2.0; |
---|
| 92 | |
---|
| 93 | // total srr |
---|
| 94 | srr = srr_1 + srr_2 + srr_3; |
---|
| 95 | srr *= pow(m_r, 2); |
---|
| 96 | |
---|
| 97 | // form factor for correlations |
---|
| 98 | srs = -1.0; |
---|
| 99 | srs -= pow(sin_x(q*A_s), (int)num_strings); |
---|
| 100 | srs /= pow((1.0-sin_x(q*A_s)), 2); |
---|
| 101 | srs *= sin_x(q*A_s); |
---|
| 102 | srs += (num_strings/(1.0-sin_x(q*A_s))); |
---|
| 103 | srs *= 4.0; |
---|
| 104 | srs *= (m_r * m_s * beta * psi); |
---|
| 105 | |
---|
| 106 | double form_factor; |
---|
| 107 | form_factor = sss + srr + srs; |
---|
| 108 | form_factor /= (tot_vol * 1.0e-8); // norm by volume and A^-1 to cm^-1 |
---|
| 109 | |
---|
| 110 | // scale and background |
---|
| 111 | form_factor *= scale; |
---|
| 112 | form_factor += background; |
---|
| 113 | |
---|
| 114 | return (form_factor); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | /** |
---|
| 118 | * Function to evaluate pearlnecklace function |
---|
| 119 | * @param pars: parameters of pearlnecklace |
---|
| 120 | * @param q: q-value |
---|
| 121 | * @return: function value |
---|
| 122 | */ |
---|
| 123 | |
---|
| 124 | double pearl_necklace_analytical_1D(PeralNecklaceParameters *pars, double q) { |
---|
| 125 | double dp[9]; |
---|
| 126 | |
---|
| 127 | dp[0] = pars->scale; |
---|
| 128 | dp[1] = pars->radius; |
---|
| 129 | dp[2] = pars->edge_separation; |
---|
| 130 | dp[3] = pars->thick_string; |
---|
| 131 | dp[4] = pars->num_pearls; |
---|
| 132 | dp[5] = pars->sld_pearl; |
---|
| 133 | dp[6] = pars->sld_string; |
---|
| 134 | dp[7] = pars->sld_solv; |
---|
| 135 | dp[8] = pars->background; |
---|
| 136 | |
---|
| 137 | return pearl_necklace_kernel(dp, q); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | /** |
---|
| 141 | * Function to evaluate pearl_necklace function |
---|
| 142 | * @param pars: parameters of PeralNecklace |
---|
| 143 | * @param q: q-value |
---|
| 144 | * @return: function value |
---|
| 145 | */ |
---|
| 146 | double pearl_necklace_analytical_2D(PeralNecklaceParameters *pars, double q, double phi) { |
---|
| 147 | return pearl_necklace_analytical_1D(pars,q); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | double pearl_necklace_analytical_2DXY(PeralNecklaceParameters *pars, double qx, double qy){ |
---|
| 151 | return pearl_necklace_analytical_1D(pars,sqrt(qx*qx+qy*qy)); |
---|
| 152 | } |
---|
| 153 | |
---|