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