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