source: sasmodels/sasmodels/models/cylinder.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: 2.5 KB
RevLine 
[03cac08]1#define INVALID(v) (v.radius<0 || v.length<0)
2
[2a0b2b1]3static double
4form_volume(double radius, double length)
[14de349]5{
6    return M_PI*radius*radius*length;
7}
8
[2a0b2b1]9static double
[71b751d]10_fq(double qab, double qc, double radius, double length)
[14de349]11{
[2a0b2b1]12    return sas_2J1x_x(qab*radius) * sas_sinx_x(qc*0.5*length);
[0d6e865]13}
[50e1e40]14
[d277229]15static double
[99658f6]16radius_from_excluded_volume(double radius, double length)
17{
18    return 0.5*cbrt(0.75*radius*(2.0*radius*length + (radius + length)*(M_PI*radius + length)));
19}
20
21static double
[d277229]22radius_from_volume(double radius, double length)
23{
[6d5601c]24    return cbrt(M_PI*radius*radius*length/M_4PI_3);
[d277229]25}
26
27static double
28radius_from_diagonal(double radius, double length)
29{
30    return sqrt(radius*radius + 0.25*length*length);
31}
32
33static double
34effective_radius(int mode, double radius, double length)
35{
[ee60aa7]36    switch (mode) {
[d42dd4a]37    default:
[ee60aa7]38    case 1:
[99658f6]39        return radius_from_excluded_volume(radius, length);
[ee60aa7]40    case 2:
[99658f6]41        return radius_from_volume(radius, length);
[ee60aa7]42    case 3:
[99658f6]43        return radius;
[ee60aa7]44    case 4:
[99658f6]45        return 0.5*length;
[ee60aa7]46    case 5:
[99658f6]47        return (radius < 0.5*length ? radius : 0.5*length);
[ee60aa7]48    case 6:
[99658f6]49        return (radius > 0.5*length ? radius : 0.5*length);
50    case 7:
[d277229]51        return radius_from_diagonal(radius,length);
52    }
53}
54
[71b751d]55static void
56Fq(double q,
57    double *F1,
58    double *F2,
59    double sld,
60    double solvent_sld,
61    double radius,
62    double length)
[0d6e865]63{
[50e1e40]64    // translate a point in [-1,1] to a point in [0, pi/2]
65    const double zm = M_PI_4;
[2a0b2b1]66    const double zb = M_PI_4;
[50e1e40]67
[71b751d]68    double total_F1 = 0.0;
69    double total_F2 = 0.0;
[74768cb]70    for (int i=0; i<GAUSS_N ;i++) {
71        const double theta = GAUSS_Z[i]*zm + zb;
[2a0b2b1]72        double sin_theta, cos_theta; // slots to hold sincos function output
73        // theta (theta,phi) the projection of the cylinder on the detector plane
74        SINCOS(theta , sin_theta, cos_theta);
[71b751d]75        const double form = _fq(q*sin_theta, q*cos_theta, radius, length);
76        total_F1 += GAUSS_W[i] * form * sin_theta;
77        total_F2 += GAUSS_W[i] * form * form * sin_theta;
[14de349]78    }
[ff7119b]79    // translate dx in [-1,1] to dx in [lower,upper]
[71b751d]80    total_F1 *= zm;
81    total_F2 *= zm;
[50e1e40]82    const double s = (sld - solvent_sld) * form_volume(radius, length);
[71b751d]83    *F1 = 1e-2 * s * total_F1;
84    *F2 = 1e-4 * s * s * total_F2;
[14de349]85}
86
[71b751d]87
88
[2a0b2b1]89static double
[108e70e]90Iqac(double qab, double qc,
[994d77f]91    double sld,
92    double solvent_sld,
93    double radius,
[becded3]94    double length)
[14de349]95{
[71b751d]96    const double form = _fq(qab, qc, radius, length);
[50e1e40]97    const double s = (sld-solvent_sld) * form_volume(radius, length);
[73e08ae]98    return 1.0e-4 * square(s * form);
[14de349]99}
[71b751d]100
Note: See TracBrowser for help on using the repository browser.