source: sasmodels/sasmodels/models/core_shell_bicelle_elliptical_belt_rough.c @ d42dd4a

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

fix compiler warnings for CUDA

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