source: sasmodels/sasmodels/models/core_shell_ellipsoid.c @ 6d5601c

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 6d5601c was 6d5601c, checked in by Paul Kienzle <pkienzle@…>, 6 years ago

use 4/3 pi constant when computing R_eff

  • Property mode set to 100644
File size: 5.6 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    case 1: // equivalent sphere
77        return radius_from_volume(radius_equat_core, x_core, thick_shell, x_polar_shell);
78    case 2: // average outer curvature
79        return radius_from_curvature(radius_equat_core, x_core, thick_shell, x_polar_shell);
80    case 3: // min outer radius
81        return (radius_polar_tot < radius_equat_tot ? radius_polar_tot : radius_equat_tot);
82    case 4: // max outer radius
83        return (radius_polar_tot > radius_equat_tot ? radius_polar_tot : radius_equat_tot);
84    }
85}
86
87static void
88Fq(double q,
89    double *F1,
90    double *F2,
91    double radius_equat_core,
92    double x_core,
93    double thick_shell,
94    double x_polar_shell,
95    double core_sld,
96    double shell_sld,
97    double solvent_sld)
98{
99    const double sld_core_shell = core_sld - shell_sld;
100    const double sld_shell_solvent = shell_sld - solvent_sld;
101
102    const double polar_core = radius_equat_core*x_core;
103    const double equat_shell = radius_equat_core + thick_shell;
104    const double polar_shell = radius_equat_core*x_core + thick_shell*x_polar_shell;
105
106    // translate from [-1, 1] => [0, 1]
107    const double m = 0.5;
108    const double b = 0.5;
109    double total_F1 = 0.0;     //initialize intergral
110    double total_F2 = 0.0;     //initialize intergral
111    for(int i=0;i<GAUSS_N;i++) {
112        const double cos_theta = GAUSS_Z[i]*m + b;
113        const double sin_theta = sqrt(1.0 - cos_theta*cos_theta);
114        double fq = _cs_ellipsoid_kernel(q*sin_theta, q*cos_theta,
115            radius_equat_core, polar_core,
116            equat_shell, polar_shell,
117            sld_core_shell, sld_shell_solvent);
118        total_F1 += GAUSS_W[i] * fq;
119        total_F2 += GAUSS_W[i] * fq * fq;
120    }
121    total_F1 *= m;
122    total_F2 *= m;
123
124    // convert to [cm-1]
125    *F1 = 1.0e-2 * total_F1;
126    *F2 = 1.0e-4 * total_F2;
127}
128
129
130static double
131Iqac(double qab, double qc,
132    double radius_equat_core,
133    double x_core,
134    double thick_shell,
135    double x_polar_shell,
136    double core_sld,
137    double shell_sld,
138    double solvent_sld)
139{
140    const double sld_core_shell = core_sld - shell_sld;
141    const double sld_shell_solvent = shell_sld - solvent_sld;
142
143    const double polar_core = radius_equat_core*x_core;
144    const double equat_shell = radius_equat_core + thick_shell;
145    const double polar_shell = radius_equat_core*x_core + thick_shell*x_polar_shell;
146
147    double fq = _cs_ellipsoid_kernel(qab, qc,
148                  radius_equat_core, polar_core,
149                  equat_shell, polar_shell,
150                  sld_core_shell, sld_shell_solvent);
151
152    //convert to [cm-1]
153    return 1.0e-4 * fq * fq;
154}
Note: See TracBrowser for help on using the repository browser.