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

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

clean up effective radius functions; improve mono_gauss_coil accuracy; start moving VR into C

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