source: sasmodels/sasmodels/models/core_shell_ellipsoid.c @ e5cb3df

ticket-1257-vesicle-productticket_1156ticket_822_more_unit_tests
Last change on this file since e5cb3df was 99658f6, checked in by grethevj, 5 years ago

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

  • Property mode set to 100644
File size: 5.7 KB
Line 
1
2// Converted from Igor function gfn4, using the same pattern as ellipsoid
3// for evaluating the parts of the integral.
4//     FUNCTION gfn4:    CONTAINS F(Q,A,B,MU)**2  AS GIVEN
5//                       BY (53) & (58-59) IN CHEN AND
6//                       KOTLARCHYK REFERENCE
7//
8//       <OBLATE ELLIPSOID>
9static double
10_cs_ellipsoid_kernel(double qab, double qc,
11    double equat_core, double polar_core,
12    double equat_shell, double polar_shell,
13    double sld_core_shell, double sld_shell_solvent)
14{
15    const double qr_core = sqrt(square(equat_core*qab) + square(polar_core*qc));
16    const double si_core = sas_3j1x_x(qr_core);
17    const double volume_core = M_4PI_3*equat_core*equat_core*polar_core;
18    const double fq_core = si_core*volume_core*sld_core_shell;
19
20    const double qr_shell = sqrt(square(equat_shell*qab) + square(polar_shell*qc));
21    const double si_shell = sas_3j1x_x(qr_shell);
22    const double volume_shell = M_4PI_3*equat_shell*equat_shell*polar_shell;
23    const double fq_shell = si_shell*volume_shell*sld_shell_solvent;
24
25    return fq_core + fq_shell;
26}
27
28static double
29form_volume(double radius_equat_core,
30    double x_core,
31    double thick_shell,
32    double x_polar_shell)
33{
34    const double equat_shell = radius_equat_core + thick_shell;
35    const double polar_shell = radius_equat_core*x_core + thick_shell*x_polar_shell;
36    double vol = M_4PI_3*equat_shell*equat_shell*polar_shell;
37    return vol;
38}
39
40static double
41radius_from_volume(double radius_equat_core, double x_core, double thick_shell, double x_polar_shell)
42{
43    const double volume_ellipsoid = form_volume(radius_equat_core, x_core, thick_shell, x_polar_shell);
44    return cbrt(volume_ellipsoid/M_4PI_3);
45}
46
47static double
48radius_from_curvature(double radius_equat_core, double x_core, double thick_shell, double x_polar_shell)
49{
50    // Trivial cases
51    if (1.0 == x_core && 1.0 == x_polar_shell) return radius_equat_core + thick_shell;
52    if ((radius_equat_core + thick_shell)*(radius_equat_core*x_core + thick_shell*x_polar_shell) == 0.)  return 0.;
53
54    // see equation (26) in A.Isihara, J.Chem.Phys. 18(1950)1446-1449
55    const double radius_equat_tot = radius_equat_core + thick_shell;
56    const double radius_polar_tot = radius_equat_core*x_core + thick_shell*x_polar_shell;
57    const double ratio = (radius_polar_tot < radius_equat_tot
58                          ? radius_polar_tot / radius_equat_tot
59                          : radius_equat_tot / radius_polar_tot);
60    const double e1 = sqrt(1.0 - ratio*ratio);
61    const double b1 = 1.0 + asin(e1) / (e1 * ratio);
62    const double bL = (1.0 + e1) / (1.0 - e1);
63    const double b2 = 1.0 + 0.5 * ratio * ratio / e1 * log(bL);
64    const double delta = 0.75 * b1 * b2;
65    const double ddd = 2.0 * (delta + 1.0) * radius_polar_tot * radius_equat_tot * radius_equat_tot;
66    return 0.5 * cbrt(ddd);
67}
68
69static double
70effective_radius(int mode, double radius_equat_core, double x_core, double thick_shell, double x_polar_shell)
71{
72    const double radius_equat_tot = radius_equat_core + thick_shell;
73    const double radius_polar_tot = radius_equat_core*x_core + thick_shell*x_polar_shell;
74
75    switch (mode) {
76    default:
77    case 1: // average outer curvature
78        return radius_from_curvature(radius_equat_core, x_core, thick_shell, x_polar_shell);
79    case 2: // equivalent volume sphere
80        return radius_from_volume(radius_equat_core, x_core, thick_shell, x_polar_shell);
81    case 3: // min outer radius
82        return (radius_polar_tot < radius_equat_tot ? radius_polar_tot : radius_equat_tot);
83    case 4: // max outer radius
84        return (radius_polar_tot > radius_equat_tot ? radius_polar_tot : radius_equat_tot);
85    }
86}
87
88static void
89Fq(double q,
90    double *F1,
91    double *F2,
92    double radius_equat_core,
93    double x_core,
94    double thick_shell,
95    double x_polar_shell,
96    double core_sld,
97    double shell_sld,
98    double solvent_sld)
99{
100    const double sld_core_shell = core_sld - shell_sld;
101    const double sld_shell_solvent = shell_sld - solvent_sld;
102
103    const double polar_core = radius_equat_core*x_core;
104    const double equat_shell = radius_equat_core + thick_shell;
105    const double polar_shell = radius_equat_core*x_core + thick_shell*x_polar_shell;
106
107    // translate from [-1, 1] => [0, 1]
108    const double m = 0.5;
109    const double b = 0.5;
110    double total_F1 = 0.0;     //initialize intergral
111    double total_F2 = 0.0;     //initialize intergral
112    for(int i=0;i<GAUSS_N;i++) {
113        const double cos_theta = GAUSS_Z[i]*m + b;
114        const double sin_theta = sqrt(1.0 - cos_theta*cos_theta);
115        double fq = _cs_ellipsoid_kernel(q*sin_theta, q*cos_theta,
116            radius_equat_core, polar_core,
117            equat_shell, polar_shell,
118            sld_core_shell, sld_shell_solvent);
119        total_F1 += GAUSS_W[i] * fq;
120        total_F2 += GAUSS_W[i] * fq * fq;
121    }
122    total_F1 *= m;
123    total_F2 *= m;
124
125    // convert to [cm-1]
126    *F1 = 1.0e-2 * total_F1;
127    *F2 = 1.0e-4 * total_F2;
128}
129
130
131static double
132Iqac(double qab, double qc,
133    double radius_equat_core,
134    double x_core,
135    double thick_shell,
136    double x_polar_shell,
137    double core_sld,
138    double shell_sld,
139    double solvent_sld)
140{
141    const double sld_core_shell = core_sld - shell_sld;
142    const double sld_shell_solvent = shell_sld - solvent_sld;
143
144    const double polar_core = radius_equat_core*x_core;
145    const double equat_shell = radius_equat_core + thick_shell;
146    const double polar_shell = radius_equat_core*x_core + thick_shell*x_polar_shell;
147
148    double fq = _cs_ellipsoid_kernel(qab, qc,
149                  radius_equat_core, polar_core,
150                  equat_shell, polar_shell,
151                  sld_core_shell, sld_shell_solvent);
152
153    //convert to [cm-1]
154    return 1.0e-4 * fq * fq;
155}
Note: See TracBrowser for help on using the repository browser.