source: sasmodels/sasmodels/models/pearl_necklace.c @ 99658f6

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 99658f6 was 99658f6, checked in by grethevj, 10 months ago

updated ER functions including cylinder excluded volume, to match 4.x

  • Property mode set to 100644
File size: 3.8 KB
Line 
1double form_volume(double radius, double edge_sep,
2    double thick_string, double fp_num_pearls);
3double Iq(double q, double radius, double edge_sep,
4    double thick_string, double fp_num_pearls, double sld,
5    double string_sld, double solvent_sld);
6
7#define INVALID(v) (v.thick_string >= v.radius || v.num_pearls <= 0)
8
9// From Igor library
10static double
11pearl_necklace_kernel(double q, double radius, double edge_sep, double thick_string,
12    int num_pearls, double sld_pearl, double sld_string, double sld_solv)
13{
14    // number of string segments
15    const int num_strings = num_pearls - 1;
16
17    //each masses: contrast * volume
18    const double contrast_pearl = sld_pearl - sld_solv;
19    const double contrast_string = sld_string - sld_solv;
20    const double string_vol = edge_sep * M_PI_4 * thick_string * thick_string;
21    const double pearl_vol = M_4PI_3 * radius * radius * radius;
22    const double m_string = contrast_string * string_vol;
23    const double m_pearl = contrast_pearl * pearl_vol;
24
25    // center to center distance between the neighboring pearls
26    const double A_s = edge_sep + 2.0 * radius;
27
28    //sine functions of a pearl
29    // Note: lim_(q->0) Si(q*a)/(q*b) = a/b
30    // So therefore:
31    //    beta = q==0. ? 1.0 : (Si(q*(A_s-radius)) - Si(q*radius))/q_edge;
32    //    gamma = q==0. ? 1.0 : Si(q_edge)/q_edge;
33    // But there is a 1/(1-sinc) term below which blows up so don't bother
34    const double q_edge = q * edge_sep;
35    const double beta = (sas_Si(q*(A_s-radius)) - sas_Si(q*radius)) / q_edge;
36    const double gamma = sas_Si(q_edge) / q_edge;
37    const double psi = sas_3j1x_x(q*radius);
38
39    // Precomputed sinc terms
40    const double si = sas_sinx_x(q*A_s);
41    const double omsi = 1.0 - si;
42    const double pow_si = pow(si, num_pearls);
43
44    // form factor for num_pearls
45    const double sss = 2.0*square(m_pearl*psi) * (
46        - si * (1.0 - pow_si) / (omsi*omsi)
47        + num_pearls / omsi
48        - 0.5 * num_pearls
49        );
50
51    // form factor for num_strings (like thin rods)
52    const double srr = m_string * m_string * (
53        - 2.0 * (1.0 - pow_si/si)*beta*beta / (omsi*omsi)
54        + 2.0 * num_strings*beta*beta / omsi
55        + num_strings * (2.0*gamma - square(sas_sinx_x(q_edge/2.0)))
56        );
57
58    // form factor for correlations
59    const double srs = 4.0 * m_string * m_pearl * beta * psi * (
60        - si * (1.0 - pow_si/si) / (omsi*omsi)
61        + num_strings / omsi
62        );
63
64    const double form = sss + srr + srs;
65
66    return 1.0e-4 * form;
67}
68
69double form_volume(double radius, double edge_sep, double thick_string, double fp_num_pearls)
70{
71    const int num_pearls = (int)(fp_num_pearls + 0.5); //Force integer number of pearls
72    const int num_strings = num_pearls - 1;
73    const double string_vol = edge_sep * M_PI_4 * thick_string * thick_string;
74    const double pearl_vol = M_4PI_3 * radius * radius * radius;
75    const double volume = num_strings*string_vol + num_pearls*pearl_vol;
76
77    return volume;
78}
79
80static double
81radius_from_volume(double radius, double edge_sep, double thick_string, double fp_num_pearls)
82{
83    const int num_pearls = (int) fp_num_pearls +0.5;
84    const double vol_tot = form_volume(radius, edge_sep, thick_string, fp_num_pearls);
85    return cbrt(vol_tot/M_4PI_3);
86}
87
88static double
89effective_radius(int mode, double radius, double edge_sep, double thick_string, double fp_num_pearls)
90{
91    switch (mode) {
92    default:
93    case 1:
94        return radius_from_volume(radius, edge_sep, thick_string, fp_num_pearls);
95    }
96}
97
98double Iq(double q, double radius, double edge_sep,
99    double thick_string, double fp_num_pearls, double sld,
100    double string_sld, double solvent_sld)
101{
102    const int num_pearls = (int)(fp_num_pearls + 0.5); //Force integer number of pearls
103    const double form = pearl_necklace_kernel(q, radius, edge_sep,
104        thick_string, num_pearls, sld, string_sld, solvent_sld);
105
106    return form;
107}
Note: See TracBrowser for help on using the repository browser.