source: sasmodels/sasmodels/models/core_shell_bicelle_elliptical.c @ 99658f6

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 99658f6 was 99658f6, checked in by grethevj, 5 years ago

updated ER functions including cylinder excluded volume, to match 4.x

  • Property mode set to 100644
File size: 6.1 KB
RevLine 
[fcb33e4]1// NOTE that "length" here is the full height of the core!
[44e8a93]2static double
3form_volume(double r_minor,
[becded3]4    double x_core,
5    double thick_rim,
6    double thick_face,
7    double length)
[fcb33e4]8{
[44e8a93]9    return M_PI*(r_minor+thick_rim)*(r_minor*x_core+thick_rim)*(length+2.0*thick_face);
[fcb33e4]10}
11
[d277229]12static double
[99658f6]13radius_from_excluded_volume(double r_minor, double x_core, double thick_rim, double thick_face, double length)
14{
15    const double r_equiv     = sqrt((r_minor + thick_rim)*(r_minor*x_core + thick_rim));
16    const double length_tot  = length + 2.0*thick_face;
17    return 0.5*cbrt(0.75*r_equiv*(2.0*r_equiv*length_tot + (r_equiv + length_tot)*(M_PI*r_equiv + length_tot)));
18}
19
20static double
[d277229]21radius_from_volume(double r_minor, double x_core, double thick_rim, double thick_face, double length)
22{
23    const double volume_bicelle = form_volume(r_minor, x_core, thick_rim,thick_face,length);
[6d5601c]24    return cbrt(volume_bicelle/M_4PI_3);
[d277229]25}
26
27static double
28radius_from_diagonal(double r_minor, double x_core, double thick_rim, double thick_face, double length)
29{
30    const double radius_max = (x_core < 1.0 ? r_minor : x_core*r_minor);
31    const double radius_max_tot = radius_max + thick_rim;
32    const double length_tot = length + 2.0*thick_face;
33    return sqrt(radius_max_tot*radius_max_tot + 0.25*length_tot*length_tot);
34}
35
36static double
37effective_radius(int mode, double r_minor, double x_core, double thick_rim, double thick_face, double length)
38{
[ee60aa7]39    switch (mode) {
[d42dd4a]40    default:
[99658f6]41    case 1: // equivalent cylinder excluded volume
42        return radius_from_excluded_volume(r_minor, x_core, thick_rim, thick_face, length);
43    case 2: // equivalent volume sphere
[d277229]44        return radius_from_volume(r_minor, x_core, thick_rim, thick_face, length);
[99658f6]45    case 3: // outer rim average radius
[d277229]46        return 0.5*r_minor*(1.0 + x_core) + thick_rim;
[99658f6]47    case 4: // outer rim min radius
[d277229]48        return (x_core < 1.0 ? x_core*r_minor+thick_rim : r_minor+thick_rim);
[99658f6]49    case 5: // outer max radius
[d277229]50        return (x_core > 1.0 ? x_core*r_minor+thick_rim : r_minor+thick_rim);
[99658f6]51    case 6: // half outer thickness
[d277229]52        return 0.5*length + thick_face;
[99658f6]53    case 7: // half diagonal
[d277229]54        return radius_from_diagonal(r_minor,x_core,thick_rim,thick_face,length);
55    }
56}
57
[71b751d]58static void
59Fq(double q,
60    double *F1,
61    double *F2,
[becded3]62    double r_minor,
63    double x_core,
64    double thick_rim,
65    double thick_face,
66    double length,
67    double sld_core,
68    double sld_face,
69    double sld_rim,
70    double sld_solvent)
[fcb33e4]71{
72     // core_shell_bicelle_elliptical, RKH Dec 2016, based on elliptical_cylinder and core_shell_bicelle
[dedcf34]73     // tested against limiting cases of cylinder, elliptical_cylinder, stacked_discs, and core_shell_bicelle
[fcb33e4]74    const double halfheight = 0.5*length;
[44e8a93]75    const double r_major = r_minor * x_core;
[dedcf34]76    const double r2A = 0.5*(square(r_major) + square(r_minor));
77    const double r2B = 0.5*(square(r_major) - square(r_minor));
[2a0b2b1]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+thick_face);
80    const double vol3 = M_PI*r_minor*r_major*2.0*(halfheight+thick_face);
81    const double dr1 = vol1*(sld_core-sld_face);
82    const double dr2 = vol2*(sld_rim-sld_solvent);
83    const double dr3 = vol3*(sld_face-sld_rim);
[fcb33e4]84
85    //initialize integral
[71b751d]86    double outer_total_F1 = 0.0;
87    double outer_total_F2 = 0.0;
[74768cb]88    for(int i=0;i<GAUSS_N;i++) {
[fcb33e4]89        //setup inner integral over the ellipsoidal cross-section
[74768cb]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;
[2a0b2b1]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);
[71b751d]97        double inner_total_F1 = 0;
98        double inner_total_F2 = 0;
[74768cb]99        for(int j=0;j<GAUSS_N;j++) {
[fcb33e4]100            //76 gauss points for the inner integral (WAS 20 points,so this may make unecessarily slow, but playing safe)
[71b751d]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));
[2a0b2b1]104            const double be1 = sas_2J1x_x(rr*qab);
105            const double be2 = sas_2J1x_x((rr+thick_rim)*qab);
[71b751d]106            const double f = dr1*si1*be1 + dr2*si2*be2 + dr3*si2*be1;
[2a0b2b1]107
[71b751d]108            inner_total_F1 += GAUSS_W[j] * f;
109            inner_total_F2 += GAUSS_W[j] * f * f;
[fcb33e4]110        }
111        //now calculate outer integral
[71b751d]112        outer_total_F1 += GAUSS_W[i] * inner_total_F1;
113        outer_total_F2 += GAUSS_W[i] * inner_total_F2;
[fcb33e4]114    }
[71b751d]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;
[fcb33e4]118
[71b751d]119    //convert from [1e-12 A-1] to [cm-1]
120    *F1 = 1e-2*outer_total_F1;
121    *F2 = 1e-4*outer_total_F2;
[fcb33e4]122}
123
[44e8a93]124static double
[108e70e]125Iqabc(double qa, double qb, double qc,
[becded3]126    double r_minor,
127    double x_core,
128    double thick_rim,
129    double thick_face,
130    double length,
131    double sld_core,
132    double sld_face,
133    double sld_rim,
134    double sld_solvent)
[fcb33e4]135{
[2a0b2b1]136    const double dr1 = sld_core-sld_face;
137    const double dr2 = sld_rim-sld_solvent;
138    const double dr3 = sld_face-sld_rim;
[44e8a93]139    const double r_major = r_minor*x_core;
[fcb33e4]140    const double halfheight = 0.5*length;
[44e8a93]141    const double vol1 = M_PI*r_minor*r_major*length;
142    const double vol2 = M_PI*(r_minor+thick_rim)*(r_major+thick_rim)*2.0*(halfheight+thick_face);
143    const double vol3 = M_PI*r_minor*r_major*2.0*(halfheight+thick_face);
[fcb33e4]144
[44e8a93]145    // Compute effective radius in rotated coordinates
[82592da]146    const double qr_hat = sqrt(square(r_major*qb) + square(r_minor*qa));
147    const double qrshell_hat = sqrt(square((r_major+thick_rim)*qb)
148                                   + square((r_minor+thick_rim)*qa));
[2a0b2b1]149    const double be1 = sas_2J1x_x( qr_hat );
150    const double be2 = sas_2J1x_x( qrshell_hat );
151    const double si1 = sas_sinx_x( halfheight*qc );
152    const double si2 = sas_sinx_x( (halfheight + thick_face)*qc );
153    const double fq = vol1*dr1*si1*be1 + vol2*dr2*si2*be2 +  vol3*dr3*si2*be1;
154    return 1.0e-4 * fq*fq;
[fcb33e4]155}
Note: See TracBrowser for help on using the repository browser.