source: sasmodels/sasmodels/models/core_shell_cylinder.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: 3.5 KB
Line 
1// vd = volume * delta_rho
2// besarg = q * R * sin(theta)
3// siarg = q * L/2 * cos(theta)
4static double _cyl(double vd, double besarg, double siarg)
5{
6    return vd * sas_sinx_x(siarg) * sas_2J1x_x(besarg);
7}
8
9static double
10form_volume(double radius, double thickness, double length)
11{
12    return M_PI*square(radius+thickness)*(length+2.0*thickness);
13}
14
15static double
16radius_from_volume(double radius, double thickness, double length)
17{
18    const double volume_outer_cyl = form_volume(radius,thickness,length);
19    return cbrt(0.75*volume_outer_cyl/M_PI);
20}
21
22static double
23radius_from_diagonal(double radius, double thickness, double length)
24{
25    const double radius_outer = radius + thickness;
26    const double length_outer = length + 2.0*thickness;
27    return sqrt(radius_outer*radius_outer + 0.25*length_outer*length_outer);
28}
29
30static double
31effective_radius(int mode, double radius, double thickness, double length)
32{
33    switch (mode) {
34    case 1: // equivalent sphere
35        return radius_from_volume(radius, thickness, length);
36    case 2: // outer radius
37        return radius + thickness;
38    case 3: // half outer length
39        return 0.5*length + thickness;
40    case 4: // half min outer length
41        return (radius < 0.5*length ? radius + thickness : 0.5*length + thickness);
42    case 5: // half max outer length
43        return (radius > 0.5*length ? radius + thickness : 0.5*length + thickness);
44    case 6: // half outer diagonal
45        return radius_from_diagonal(radius,thickness,length);
46    }
47}
48
49static void
50Fq(double q,
51    double *F1,
52    double *F2,
53    double core_sld,
54    double shell_sld,
55    double solvent_sld,
56    double radius,
57    double thickness,
58    double length)
59{
60    // precalculate constants
61    const double core_r = radius;
62    const double core_h = 0.5*length;
63    const double core_vd = form_volume(radius,0,length) * (core_sld-shell_sld);
64    const double shell_r = (radius + thickness);
65    const double shell_h = (0.5*length + thickness);
66    const double shell_vd = form_volume(radius,thickness,length) * (shell_sld-solvent_sld);
67    double total_F1 = 0.0;
68    double total_F2 = 0.0;
69    for (int i=0; i<GAUSS_N ;i++) {
70        // translate a point in [-1,1] to a point in [0, pi/2]
71        //const double theta = ( GAUSS_Z[i]*(upper-lower) + upper + lower )/2.0;
72        double sin_theta, cos_theta;
73        const double theta = GAUSS_Z[i]*M_PI_4 + M_PI_4;
74        SINCOS(theta, sin_theta,  cos_theta);
75        const double qab = q*sin_theta;
76        const double qc = q*cos_theta;
77        const double fq = _cyl(core_vd, core_r*qab, core_h*qc)
78            + _cyl(shell_vd, shell_r*qab, shell_h*qc);
79        total_F1 += GAUSS_W[i] * fq * sin_theta;
80        total_F2 += GAUSS_W[i] * fq * fq * sin_theta;
81    }
82    // translate dx in [-1,1] to dx in [lower,upper]
83    //const double form = (upper-lower)/2.0*total;
84    *F1 = 1.0e-2 * total_F1 * M_PI_4;
85    *F2 = 1.0e-4 * total_F2 * M_PI_4;
86}
87
88static double
89Iqac(double qab, double qc,
90    double core_sld,
91    double shell_sld,
92    double solvent_sld,
93    double radius,
94    double thickness,
95    double length)
96{
97    const double core_r = radius;
98    const double core_h = 0.5*length;
99    const double core_vd = form_volume(radius,0,length) * (core_sld-shell_sld);
100    const double shell_r = (radius + thickness);
101    const double shell_h = (0.5*length + thickness);
102    const double shell_vd = form_volume(radius,thickness,length) * (shell_sld-solvent_sld);
103
104    const double fq = _cyl(core_vd, core_r*qab, core_h*qc)
105        + _cyl(shell_vd, shell_r*qab, shell_h*qc);
106    return 1.0e-4 * fq * fq;
107}
Note: See TracBrowser for help on using the repository browser.