source: sasmodels/sasmodels/models/core_shell_bicelle_elliptical.c @ 5024a56

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 5024a56 was d42dd4a, checked in by pkienzle, 6 years ago

fix compiler warnings for CUDA

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