source: sasmodels/sasmodels/models/core_shell_cylinder.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: 3.4 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 + 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    if (mode == 1) {
34        return radius_from_volume(radius, thickness, length);
35    } else if (mode == 2) {
36        return radius + thickness;
37    } else if (mode == 3) {
38        return 0.5*length + thickness;
39    } else if (mode == 4) {
40        return (radius < 0.5*length ? radius + thickness : 0.5*length + thickness);
41    } else if (mode == 5) {
42        return (radius > 0.5*length ? radius + thickness : 0.5*length + thickness);
43    } else {
44        return radius_from_diagonal(radius,thickness,length);
45    }
46}
47
48static void
49Fq(double q,
50    double *F1,
51    double *F2,
52    double core_sld,
53    double shell_sld,
54    double solvent_sld,
55    double radius,
56    double thickness,
57    double length)
58{
59    // precalculate constants
60    const double core_r = radius;
61    const double core_h = 0.5*length;
62    const double core_vd = form_volume(radius,0,length) * (core_sld-shell_sld);
63    const double shell_r = (radius + thickness);
64    const double shell_h = (0.5*length + thickness);
65    const double shell_vd = form_volume(radius,thickness,length) * (shell_sld-solvent_sld);
66    double total_F1 = 0.0;
67    double total_F2 = 0.0;
68    for (int i=0; i<GAUSS_N ;i++) {
69        // translate a point in [-1,1] to a point in [0, pi/2]
70        //const double theta = ( GAUSS_Z[i]*(upper-lower) + upper + lower )/2.0;
71        double sin_theta, cos_theta;
72        const double theta = GAUSS_Z[i]*M_PI_4 + M_PI_4;
73        SINCOS(theta, sin_theta,  cos_theta);
74        const double qab = q*sin_theta;
75        const double qc = q*cos_theta;
76        const double fq = _cyl(core_vd, core_r*qab, core_h*qc)
77            + _cyl(shell_vd, shell_r*qab, shell_h*qc);
78        total_F1 += GAUSS_W[i] * fq * sin_theta;
79        total_F2 += GAUSS_W[i] * fq * fq * sin_theta;
80    }
81    // translate dx in [-1,1] to dx in [lower,upper]
82    //const double form = (upper-lower)/2.0*total;
83    *F1 = 1.0e-2 * total_F1 * M_PI_4;
84    *F2 = 1.0e-4 * total_F2 * M_PI_4;
85}
86
87static double
88Iqac(double qab, double qc,
89    double core_sld,
90    double shell_sld,
91    double solvent_sld,
92    double radius,
93    double thickness,
94    double length)
95{
96    const double core_r = radius;
97    const double core_h = 0.5*length;
98    const double core_vd = form_volume(radius,0,length) * (core_sld-shell_sld);
99    const double shell_r = (radius + thickness);
100    const double shell_h = (0.5*length + thickness);
101    const double shell_vd = form_volume(radius,thickness,length) * (shell_sld-solvent_sld);
102
103    const double fq = _cyl(core_vd, core_r*qab, core_h*qc)
104        + _cyl(shell_vd, shell_r*qab, shell_h*qc);
105    return 1.0e-4 * fq * fq;
106}
Note: See TracBrowser for help on using the repository browser.