[8c8cb05] | 1 | /** |
---|
[9cc3da6] | 2 | * pearl necklace model |
---|
[8c8cb05] | 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; |
---|
[890ac7f1] | 39 | //each masses |
---|
| 40 | double m_r= contrast_string * string_vol; |
---|
| 41 | double m_s= contrast_pearl * pearl_vol; |
---|
| 42 | double psi; |
---|
| 43 | double gamma; |
---|
| 44 | double beta; |
---|
| 45 | //form factors |
---|
| 46 | double sss; //pearls |
---|
| 47 | double srr; //strings |
---|
| 48 | double srs; //cross |
---|
| 49 | double A_s; |
---|
| 50 | double srr_1; |
---|
| 51 | double srr_2; |
---|
| 52 | double srr_3; |
---|
| 53 | double form_factor; |
---|
| 54 | |
---|
| 55 | tot_vol = num_strings * string_vol; |
---|
[8c8cb05] | 56 | tot_vol += num_pearls * pearl_vol; |
---|
| 57 | |
---|
| 58 | //sine functions of a pearl |
---|
| 59 | psi = sin(q*radius); |
---|
| 60 | psi -= q * radius * cos(q * radius); |
---|
| 61 | psi /= pow((q * radius), 3); |
---|
| 62 | psi *= 3.0; |
---|
| 63 | |
---|
| 64 | // Note take only 20 terms in Si series: 10 terms may be enough though. |
---|
[463eb76e] | 65 | gamma = Si(q* edge_separation); |
---|
[8c8cb05] | 66 | gamma /= (q* edge_separation); |
---|
[463eb76e] | 67 | beta = Si(q * (edge_separation + radius)); |
---|
| 68 | beta -= Si(q * radius); |
---|
[8c8cb05] | 69 | beta /= (q* edge_separation); |
---|
| 70 | |
---|
| 71 | // center to center distance between the neighboring pearls |
---|
[890ac7f1] | 72 | A_s = edge_separation + 2.0 * radius; |
---|
[8c8cb05] | 73 | |
---|
| 74 | // form factor for num_pearls |
---|
[463eb76e] | 75 | sss = 1.0 - pow(sinc(q*A_s), num_pearls ); |
---|
| 76 | sss /= pow((1.0-sinc(q*A_s)), 2); |
---|
| 77 | sss *= -sinc(q*A_s); |
---|
[8c8cb05] | 78 | sss -= num_pearls/2.0; |
---|
[463eb76e] | 79 | sss += num_pearls/(1.0-sinc(q*A_s)); |
---|
[8c8cb05] | 80 | sss *= 2.0 * pow((m_s*psi), 2); |
---|
| 81 | |
---|
| 82 | // form factor for num_strings (like thin rods) |
---|
[463eb76e] | 83 | srr_1 = -pow(sinc(q*edge_separation/2.0), 2); |
---|
| 84 | |
---|
[8c8cb05] | 85 | srr_1 += 2.0 * gamma; |
---|
| 86 | srr_1 *= num_strings; |
---|
[463eb76e] | 87 | srr_2 = 2.0/(1.0-sinc(q*A_s)); |
---|
[8c8cb05] | 88 | srr_2 *= num_strings; |
---|
| 89 | srr_2 *= pow(beta, 2); |
---|
[463eb76e] | 90 | srr_3 = 1.0 - pow(sinc(q*A_s), num_strings); |
---|
| 91 | srr_3 /= pow((1.0-sinc(q*A_s)), 2); |
---|
[8c8cb05] | 92 | srr_3 *= pow(beta, 2); |
---|
| 93 | srr_3 *= -2.0; |
---|
| 94 | |
---|
| 95 | // total srr |
---|
| 96 | srr = srr_1 + srr_2 + srr_3; |
---|
| 97 | srr *= pow(m_r, 2); |
---|
| 98 | |
---|
| 99 | // form factor for correlations |
---|
[463eb76e] | 100 | srs = 1.0; |
---|
| 101 | srs -= pow(sinc(q*A_s), num_strings); |
---|
| 102 | srs /= pow((1.0-sinc(q*A_s)), 2); |
---|
| 103 | srs *= -sinc(q*A_s); |
---|
| 104 | srs += (num_strings/(1.0-sinc(q*A_s))); |
---|
[8c8cb05] | 105 | srs *= 4.0; |
---|
| 106 | srs *= (m_r * m_s * beta * psi); |
---|
| 107 | |
---|
| 108 | form_factor = sss + srr + srs; |
---|
| 109 | form_factor /= (tot_vol * 1.0e-8); // norm by volume and A^-1 to cm^-1 |
---|
| 110 | |
---|
| 111 | // scale and background |
---|
| 112 | form_factor *= scale; |
---|
| 113 | form_factor += background; |
---|
| 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 | |
---|