source: sasmodels/sasmodels/models/core_shell_bicelle_elliptical_belt_rough.c @ 6d5601c

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

use 4/3 pi constant when computing R_eff

  • Property mode set to 100644
File size: 6.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 +
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(volume_bicelle/M_4PI_3);
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 (this ignores the missing "corners", so may give unexpected answer if thick_face
44            //  or thick_rim is extremely large)
45        return radius_from_diagonal(r_minor,x_core,thick_rim,thick_face,length);
46    }
47}
48
49static void
50Fq(double q,
51        double *F1,
52        double *F2,
53        double r_minor,
54        double x_core,
55        double thick_rim,
56        double thick_face,
57        double length,
58        double rhoc,
59        double rhoh,
60        double rhor,
61        double rhosolv,
62        double sigma)
63{
64     // core_shell_bicelle_elliptical_belt, RKH 5th Oct 2017, core_shell_bicelle_elliptical
65     // tested briefly against limiting cases of cylinder, hollow cylinder & elliptical cylinder models
66     //    const double uplim = M_PI_4;
67    const double halfheight = 0.5*length;
68    //const double va = 0.0;
69    //const double vb = 1.0;
70    // inner integral limits
71    //const double vaj=0.0;
72    //const double vbj=M_PI;
73
74    const double r_major = r_minor * x_core;
75    const double r2A = 0.5*(square(r_major) + square(r_minor));
76    const double r2B = 0.5*(square(r_major) - square(r_minor));
77    const double vol1 = M_PI*r_minor*r_major*(2.0*halfheight);
78    const double vol2 = M_PI*(r_minor+thick_rim)*(r_major+thick_rim)*2.0*halfheight;
79    const double vol3 = M_PI*r_minor*r_major*2.0*(halfheight+thick_face);
80    // dr1,2,3 are now for Vcore, Vcore+rim, Vcore+face,
81    const double dr1 = vol1*(-rhor - rhoh + rhoc + rhosolv);
82    const double dr2 = vol2*(rhor-rhosolv);
83    const double dr3 = vol3*(rhoh-rhosolv);
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        // since we generate these lots of times, why not store them somewhere?
91        //const double cos_theta = ( GAUSS_Z[i]*(vb-va) + va + vb )/2.0;
92        const double cos_theta = ( GAUSS_Z[i] + 1.0 )/2.0;
93        const double sin_theta = sqrt(1.0 - cos_theta*cos_theta);
94        const double qab = q*sin_theta;
95        const double qc = q*cos_theta;
96        const double si1 = sas_sinx_x(halfheight*qc);
97        const double si2 = sas_sinx_x((halfheight+thick_face)*qc);
98        double inner_total_F1 = 0;
99        double inner_total_F2 = 0;
100        for(int j=0;j<GAUSS_N;j++) {
101            //76 gauss points for the inner integral (WAS 20 points,so this may make unecessarily slow, but playing safe)
102            //const double beta = ( GAUSS_Z[j]*(vbj-vaj) + vaj + vbj )/2.0;
103            const double beta = ( GAUSS_Z[j] +1.0)*M_PI_2;
104            const double rr = sqrt(r2A - r2B*cos(beta));
105            const double be1 = sas_2J1x_x(rr*qab);
106            const double be2 = sas_2J1x_x((rr+thick_rim)*qab);
107            const double f = dr1*si1*be1 + dr2*si1*be2 + dr3*si2*be1;
108
109            inner_total_F1 += GAUSS_W[j] * f;
110            inner_total_F2 += GAUSS_W[j] * f * f;
111        }
112        //now calculate outer integral
113        outer_total_F1 += GAUSS_W[i] * inner_total_F1;
114        outer_total_F2 += GAUSS_W[i] * inner_total_F2;
115    }
116    // now complete change of integration variables (1-0)/(1-(-1))= 0.5
117    outer_total_F1 *= 0.25;
118    outer_total_F2 *= 0.25;
119
120    //convert from [1e-12 A-1] to [cm-1]
121    *F1 = 1e-2*outer_total_F1*exp(-0.25*square(q*sigma));
122    *F2 = 1e-4*outer_total_F2*exp(-0.5*square(q*sigma));
123}
124
125static double
126Iqabc(double qa, double qb, double qc,
127          double r_minor,
128          double x_core,
129          double thick_rim,
130          double thick_face,
131          double length,
132          double rhoc,
133          double rhoh,
134          double rhor,
135          double rhosolv,
136          double sigma)
137{
138    // integrated 2d seems to match 1d reasonably well, except perhaps at very high Q
139    // Vol1,2,3 and dr1,2,3 are now for Vcore, Vcore+rim, Vcore+face,
140    const double dr1 = -rhor - rhoh + rhoc + rhosolv;
141    const double dr2 = rhor-rhosolv;
142    const double dr3 = rhoh-rhosolv;
143    const double r_major = r_minor*x_core;
144    const double halfheight = 0.5*length;
145    const double vol1 = M_PI*r_minor*r_major*length;
146    const double vol2 = M_PI*(r_minor+thick_rim)*(r_major+thick_rim)*2.0*halfheight;
147    const double vol3 = M_PI*r_minor*r_major*2.0*(halfheight+thick_face);
148
149    // Compute effective radius in rotated coordinates
150    const double qr_hat = sqrt(square(r_major*qb) + square(r_minor*qa));
151    // does this need to be changed for the "missing corners" where there there is no "belt" ?
152    const double qrshell_hat = sqrt(square((r_major+thick_rim)*qb)
153                                   + square((r_minor+thick_rim)*qa));
154    const double be1 = sas_2J1x_x( qr_hat );
155    const double be2 = sas_2J1x_x( qrshell_hat );
156    const double si1 = sas_sinx_x( halfheight*qc );
157    const double si2 = sas_sinx_x( (halfheight + thick_face)*qc );
158    const double fq = vol1*dr1*si1*be1 + vol2*dr2*si1*be2 +  vol3*dr3*si2*be1;
159    const double atten = exp(-0.5*(qa*qa + qb*qb + qc*qc)*(sigma*sigma));
160    return 1.0e-4 * fq*fq * atten;
161}
Note: See TracBrowser for help on using the repository browser.