source: sasmodels/sasmodels/models/core_shell_bicelle_elliptical.c @ a34b811

ticket-1257-vesicle-productticket_1156ticket_822_more_unit_tests
Last change on this file since a34b811 was a34b811, checked in by Paul Kienzle <pkienzle@…>, 8 months ago

use radius_effective/radius_effective_mode/radius_effective_modes consistently throughout the code

  • Property mode set to 100644
File size: 6.1 KB
Line 
1// NOTE that "length" here is the full height of the core!
2static double
3form_volume(double r_minor,
4    double x_core,
5    double thick_rim,
6    double thick_face,
7    double length)
8{
9    return M_PI*(r_minor+thick_rim)*(r_minor*x_core+thick_rim)*(length+2.0*thick_face);
10}
11
12static double
13radius_from_excluded_volume(double r_minor, double x_core, double thick_rim, double thick_face, double length)
14{
15    const double r_equiv     = sqrt((r_minor + thick_rim)*(r_minor*x_core + thick_rim));
16    const double length_tot  = length + 2.0*thick_face;
17    return 0.5*cbrt(0.75*r_equiv*(2.0*r_equiv*length_tot + (r_equiv + length_tot)*(M_PI*r_equiv + length_tot)));
18}
19
20static double
21radius_from_volume(double r_minor, double x_core, double thick_rim, double thick_face, double length)
22{
23    const double volume_bicelle = form_volume(r_minor, x_core, thick_rim,thick_face,length);
24    return cbrt(volume_bicelle/M_4PI_3);
25}
26
27static double
28radius_from_diagonal(double r_minor, double x_core, double thick_rim, double thick_face, double length)
29{
30    const double radius_max = (x_core < 1.0 ? r_minor : x_core*r_minor);
31    const double radius_max_tot = radius_max + thick_rim;
32    const double length_tot = length + 2.0*thick_face;
33    return sqrt(radius_max_tot*radius_max_tot + 0.25*length_tot*length_tot);
34}
35
36static double
37radius_effective(int mode, double r_minor, double x_core, double thick_rim, double thick_face, double length)
38{
39    switch (mode) {
40    default:
41    case 1: // equivalent cylinder excluded volume
42        return radius_from_excluded_volume(r_minor, x_core, thick_rim, thick_face, length);
43    case 2: // equivalent volume sphere
44        return radius_from_volume(r_minor, x_core, thick_rim, thick_face, length);
45    case 3: // outer rim average radius
46        return 0.5*r_minor*(1.0 + x_core) + thick_rim;
47    case 4: // outer rim min radius
48        return (x_core < 1.0 ? x_core*r_minor+thick_rim : r_minor+thick_rim);
49    case 5: // outer max radius
50        return (x_core > 1.0 ? x_core*r_minor+thick_rim : r_minor+thick_rim);
51    case 6: // half outer thickness
52        return 0.5*length + thick_face;
53    case 7: // half diagonal
54        return radius_from_diagonal(r_minor,x_core,thick_rim,thick_face,length);
55    }
56}
57
58static void
59Fq(double q,
60    double *F1,
61    double *F2,
62    double r_minor,
63    double x_core,
64    double thick_rim,
65    double thick_face,
66    double length,
67    double sld_core,
68    double sld_face,
69    double sld_rim,
70    double sld_solvent)
71{
72     // core_shell_bicelle_elliptical, RKH Dec 2016, based on elliptical_cylinder and core_shell_bicelle
73     // tested against limiting cases of cylinder, elliptical_cylinder, stacked_discs, and core_shell_bicelle
74    const double halfheight = 0.5*length;
75    const double r_major = r_minor * x_core;
76    const double r2A = 0.5*(square(r_major) + square(r_minor));
77    const double r2B = 0.5*(square(r_major) - square(r_minor));
78    const double vol1 = M_PI*r_minor*r_major*(2.0*halfheight);
79    const double vol2 = M_PI*(r_minor+thick_rim)*(r_major+thick_rim)*2.0*(halfheight+thick_face);
80    const double vol3 = M_PI*r_minor*r_major*2.0*(halfheight+thick_face);
81    const double dr1 = vol1*(sld_core-sld_face);
82    const double dr2 = vol2*(sld_rim-sld_solvent);
83    const double dr3 = vol3*(sld_face-sld_rim);
84
85    //initialize integral
86    double outer_total_F1 = 0.0;
87    double outer_total_F2 = 0.0;
88    for(int i=0;i<GAUSS_N;i++) {
89        //setup inner integral over the ellipsoidal cross-section
90        //const double cos_theta = ( GAUSS_Z[i]*(vb-va) + va + vb )/2.0;
91        const double cos_theta = ( GAUSS_Z[i] + 1.0 )/2.0;
92        const double sin_theta = sqrt(1.0 - cos_theta*cos_theta);
93        const double qab = q*sin_theta;
94        const double qc = q*cos_theta;
95        const double si1 = sas_sinx_x(halfheight*qc);
96        const double si2 = sas_sinx_x((halfheight+thick_face)*qc);
97        double inner_total_F1 = 0;
98        double inner_total_F2 = 0;
99        for(int j=0;j<GAUSS_N;j++) {
100            //76 gauss points for the inner integral (WAS 20 points,so this may make unecessarily slow, but playing safe)
101            //const double beta = ( GAUSS_Z[j]*(vbj-vaj) + vaj + vbj )/2.0;
102            const double beta = ( GAUSS_Z[j] +1.0)*M_PI_2;
103            const double rr = sqrt(r2A - r2B*cos(beta));
104            const double be1 = sas_2J1x_x(rr*qab);
105            const double be2 = sas_2J1x_x((rr+thick_rim)*qab);
106            const double f = dr1*si1*be1 + dr2*si2*be2 + dr3*si2*be1;
107
108            inner_total_F1 += GAUSS_W[j] * f;
109            inner_total_F2 += GAUSS_W[j] * f * f;
110        }
111        //now calculate outer integral
112        outer_total_F1 += GAUSS_W[i] * inner_total_F1;
113        outer_total_F2 += GAUSS_W[i] * inner_total_F2;
114    }
115    // now complete change of integration variables (1-0)/(1-(-1))= 0.5
116    outer_total_F1 *= 0.25;
117    outer_total_F2 *= 0.25;
118
119    //convert from [1e-12 A-1] to [cm-1]
120    *F1 = 1e-2*outer_total_F1;
121    *F2 = 1e-4*outer_total_F2;
122}
123
124static double
125Iqabc(double qa, double qb, double qc,
126    double r_minor,
127    double x_core,
128    double thick_rim,
129    double thick_face,
130    double length,
131    double sld_core,
132    double sld_face,
133    double sld_rim,
134    double sld_solvent)
135{
136    const double dr1 = sld_core-sld_face;
137    const double dr2 = sld_rim-sld_solvent;
138    const double dr3 = sld_face-sld_rim;
139    const double r_major = r_minor*x_core;
140    const double halfheight = 0.5*length;
141    const double vol1 = M_PI*r_minor*r_major*length;
142    const double vol2 = M_PI*(r_minor+thick_rim)*(r_major+thick_rim)*2.0*(halfheight+thick_face);
143    const double vol3 = M_PI*r_minor*r_major*2.0*(halfheight+thick_face);
144
145    // Compute effective radius in rotated coordinates
146    const double qr_hat = sqrt(square(r_major*qb) + square(r_minor*qa));
147    const double qrshell_hat = sqrt(square((r_major+thick_rim)*qb)
148                                   + square((r_minor+thick_rim)*qa));
149    const double be1 = sas_2J1x_x( qr_hat );
150    const double be2 = sas_2J1x_x( qrshell_hat );
151    const double si1 = sas_sinx_x( halfheight*qc );
152    const double si2 = sas_sinx_x( (halfheight + thick_face)*qc );
153    const double fq = vol1*dr1*si1*be1 + vol2*dr2*si2*be2 +  vol3*dr3*si2*be1;
154    return 1.0e-4 * fq*fq;
155}
Note: See TracBrowser for help on using the repository browser.