source: sasmodels/sasmodels/models/core_shell_bicelle_elliptical_belt_rough.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: 6.4 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 +
10                 square(r_minor)*x_core*2.0*thick_face  );
11}
12
13static double
14radius_from_volume(double r_minor, double x_core, double thick_rim, double thick_face, double length)
15{
16    const double volume_bicelle = form_volume(r_minor, x_core, thick_rim,thick_face,length);
17    return cbrt(0.75*volume_bicelle/M_PI);
18}
19
20static double
21radius_from_diagonal(double r_minor, double x_core, double thick_rim, double thick_face, double length)
22{
23    const double radius_max = (x_core < 1.0 ? r_minor : x_core*r_minor);
24    const double radius_max_tot = radius_max + thick_rim;
25    const double length_tot = length + 2.0*thick_face;
26    return sqrt(radius_max_tot*radius_max_tot + 0.25*length_tot*length_tot);
27}
28
29static double
30effective_radius(int mode, double r_minor, double x_core, double thick_rim, double thick_face, double length)
31{
32    switch (mode) {
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 rhoc,
58        double rhoh,
59        double rhor,
60        double rhosolv,
61        double sigma)
62{
63     // core_shell_bicelle_elliptical_belt, RKH 5th Oct 2017, core_shell_bicelle_elliptical
64     // tested briefly against limiting cases of cylinder, hollow cylinder & elliptical cylinder models
65     //    const double uplim = M_PI_4;
66    const double halfheight = 0.5*length;
67    //const double va = 0.0;
68    //const double vb = 1.0;
69    // inner integral limits
70    //const double vaj=0.0;
71    //const double vbj=M_PI;
72
73    const double r_major = r_minor * x_core;
74    const double r2A = 0.5*(square(r_major) + square(r_minor));
75    const double r2B = 0.5*(square(r_major) - square(r_minor));
76    const double vol1 = M_PI*r_minor*r_major*(2.0*halfheight);
77    const double vol2 = M_PI*(r_minor+thick_rim)*(r_major+thick_rim)*2.0*halfheight;
78    const double vol3 = M_PI*r_minor*r_major*2.0*(halfheight+thick_face);
79    // dr1,2,3 are now for Vcore, Vcore+rim, Vcore+face,
80    const double dr1 = vol1*(-rhor - rhoh + rhoc + rhosolv);
81    const double dr2 = vol2*(rhor-rhosolv);
82    const double dr3 = vol3*(rhoh-rhosolv);
83
84    //initialize integral
85    double outer_total_F1 = 0.0;
86    double outer_total_F2 = 0.0;
87    for(int i=0;i<GAUSS_N;i++) {
88        //setup inner integral over the ellipsoidal cross-section
89        // since we generate these lots of times, why not store them somewhere?
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*si1*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*exp(-0.25*square(q*sigma));
121    *F2 = 1e-4*outer_total_F2*exp(-0.5*square(q*sigma));
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 rhoc,
132          double rhoh,
133          double rhor,
134          double rhosolv,
135          double sigma)
136{
137    // integrated 2d seems to match 1d reasonably well, except perhaps at very high Q
138    // Vol1,2,3 and dr1,2,3 are now for Vcore, Vcore+rim, Vcore+face,
139    const double dr1 = -rhor - rhoh + rhoc + rhosolv;
140    const double dr2 = rhor-rhosolv;
141    const double dr3 = rhoh-rhosolv;
142    const double r_major = r_minor*x_core;
143    const double halfheight = 0.5*length;
144    const double vol1 = M_PI*r_minor*r_major*length;
145    const double vol2 = M_PI*(r_minor+thick_rim)*(r_major+thick_rim)*2.0*halfheight;
146    const double vol3 = M_PI*r_minor*r_major*2.0*(halfheight+thick_face);
147
148    // Compute effective radius in rotated coordinates
149    const double qr_hat = sqrt(square(r_major*qb) + square(r_minor*qa));
150    // does this need to be changed for the "missing corners" where there there is no "belt" ?
151    const double qrshell_hat = sqrt(square((r_major+thick_rim)*qb)
152                                   + square((r_minor+thick_rim)*qa));
153    const double be1 = sas_2J1x_x( qr_hat );
154    const double be2 = sas_2J1x_x( qrshell_hat );
155    const double si1 = sas_sinx_x( halfheight*qc );
156    const double si2 = sas_sinx_x( (halfheight + thick_face)*qc );
157    const double fq = vol1*dr1*si1*be1 + vol2*dr2*si1*be2 +  vol3*dr3*si2*be1;
158    const double atten = exp(-0.5*(qa*qa + qb*qb + qc*qc)*(sigma*sigma));
159    return 1.0e-4 * fq*fq * atten;
160}
Note: See TracBrowser for help on using the repository browser.