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

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since d277229 was d277229, checked in by grethevj, 6 years ago

Models updated to include choices for effective interaction radii

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