source: sasmodels/sasmodels/models/core_shell_cylinder.c @ a34b811

ticket-1257-vesicle-productticket_1156ticket_822_more_unit_tests
Last change on this file since a34b811 was a34b811, checked in by Paul Kienzle <pkienzle@…>, 5 years ago

use radius_effective/radius_effective_mode/radius_effective_modes consistently throughout the code

  • Property mode set to 100644
File size: 4.0 KB
RevLine 
[9aa4881]1// vd = volume * delta_rho
[2a0b2b1]2// besarg = q * R * sin(theta)
3// siarg = q * L/2 * cos(theta)
4static double _cyl(double vd, double besarg, double siarg)
[5d4777d]5{
[592343f]6    return vd * sas_sinx_x(siarg) * sas_2J1x_x(besarg);
[5d4777d]7}
8
[2a0b2b1]9static double
10form_volume(double radius, double thickness, double length)
[5d4777d]11{
[2a0b2b1]12    return M_PI*square(radius+thickness)*(length+2.0*thickness);
[5d4777d]13}
14
[d277229]15static double
[99658f6]16radius_from_excluded_volume(double radius, double thickness, double length)
17{
18    const double radius_tot = radius + thickness;
19    const double length_tot = length + 2.0*thickness;
20    return 0.5*cbrt(0.75*radius_tot*(2.0*radius_tot*length_tot + (radius_tot + length_tot)*(M_PI*radius_tot + length_tot)));
21}
22
23static double
[d277229]24radius_from_volume(double radius, double thickness, double length)
25{
26    const double volume_outer_cyl = form_volume(radius,thickness,length);
[6d5601c]27    return cbrt(volume_outer_cyl/M_4PI_3);
[d277229]28}
29
30static double
31radius_from_diagonal(double radius, double thickness, double length)
32{
33    const double radius_outer = radius + thickness;
[a94046f]34    const double length_outer = length + 2.0*thickness;
[d277229]35    return sqrt(radius_outer*radius_outer + 0.25*length_outer*length_outer);
36}
37
38static double
[a34b811]39radius_effective(int mode, double radius, double thickness, double length)
[d277229]40{
[ee60aa7]41    switch (mode) {
[d42dd4a]42    default:
[99658f6]43    case 1: //cylinder excluded volume
44        return radius_from_excluded_volume(radius, thickness, length);
45    case 2: // equivalent volume sphere
[d277229]46        return radius_from_volume(radius, thickness, length);
[99658f6]47    case 3: // outer radius
[d277229]48        return radius + thickness;
[99658f6]49    case 4: // half outer length
[d277229]50        return 0.5*length + thickness;
[99658f6]51    case 5: // half min outer length
[d277229]52        return (radius < 0.5*length ? radius + thickness : 0.5*length + thickness);
[99658f6]53    case 6: // half max outer length
[d277229]54        return (radius > 0.5*length ? radius + thickness : 0.5*length + thickness);
[99658f6]55    case 7: // half outer diagonal
[d277229]56        return radius_from_diagonal(radius,thickness,length);
57    }
58}
59
[71b751d]60static void
61Fq(double q,
62    double *F1,
63    double *F2,
[994d77f]64    double core_sld,
65    double shell_sld,
66    double solvent_sld,
67    double radius,
68    double thickness,
69    double length)
[5d4777d]70{
71    // precalculate constants
[2a0b2b1]72    const double core_r = radius;
73    const double core_h = 0.5*length;
[9aa4881]74    const double core_vd = form_volume(radius,0,length) * (core_sld-shell_sld);
[2a0b2b1]75    const double shell_r = (radius + thickness);
76    const double shell_h = (0.5*length + thickness);
[9aa4881]77    const double shell_vd = form_volume(radius,thickness,length) * (shell_sld-solvent_sld);
[71b751d]78    double total_F1 = 0.0;
79    double total_F2 = 0.0;
[74768cb]80    for (int i=0; i<GAUSS_N ;i++) {
[2a0b2b1]81        // translate a point in [-1,1] to a point in [0, pi/2]
[74768cb]82        //const double theta = ( GAUSS_Z[i]*(upper-lower) + upper + lower )/2.0;
[2a0b2b1]83        double sin_theta, cos_theta;
[74768cb]84        const double theta = GAUSS_Z[i]*M_PI_4 + M_PI_4;
[2a0b2b1]85        SINCOS(theta, sin_theta,  cos_theta);
86        const double qab = q*sin_theta;
87        const double qc = q*cos_theta;
88        const double fq = _cyl(core_vd, core_r*qab, core_h*qc)
89            + _cyl(shell_vd, shell_r*qab, shell_h*qc);
[71b751d]90        total_F1 += GAUSS_W[i] * fq * sin_theta;
91        total_F2 += GAUSS_W[i] * fq * fq * sin_theta;
[5d4777d]92    }
93    // translate dx in [-1,1] to dx in [lower,upper]
[994d77f]94    //const double form = (upper-lower)/2.0*total;
[71b751d]95    *F1 = 1.0e-2 * total_F1 * M_PI_4;
96    *F2 = 1.0e-4 * total_F2 * M_PI_4;
[5d4777d]97}
98
[d86f0fc]99static double
100Iqac(double qab, double qc,
[994d77f]101    double core_sld,
102    double shell_sld,
103    double solvent_sld,
104    double radius,
105    double thickness,
[becded3]106    double length)
[5d4777d]107{
[2a0b2b1]108    const double core_r = radius;
109    const double core_h = 0.5*length;
[9aa4881]110    const double core_vd = form_volume(radius,0,length) * (core_sld-shell_sld);
[2a0b2b1]111    const double shell_r = (radius + thickness);
112    const double shell_h = (0.5*length + thickness);
[9aa4881]113    const double shell_vd = form_volume(radius,thickness,length) * (shell_sld-solvent_sld);
[5d4777d]114
[2a0b2b1]115    const double fq = _cyl(core_vd, core_r*qab, core_h*qc)
116        + _cyl(shell_vd, shell_r*qab, shell_h*qc);
[994d77f]117    return 1.0e-4 * fq * fq;
[5d4777d]118}
Note: See TracBrowser for help on using the repository browser.