source: sasmodels/sasmodels/models/cylinder.c @ d42dd4a

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since d42dd4a was d42dd4a, checked in by pkienzle, 5 years ago

fix compiler warnings for CUDA

  • Property mode set to 100644
File size: 2.2 KB
Line 
1#define INVALID(v) (v.radius<0 || v.length<0)
2
3static double
4form_volume(double radius, double length)
5{
6    return M_PI*radius*radius*length;
7}
8
9static double
10_fq(double qab, double qc, double radius, double length)
11{
12    return sas_2J1x_x(qab*radius) * sas_sinx_x(qc*0.5*length);
13}
14
15static double
16radius_from_volume(double radius, double length)
17{
18    return cbrt(M_PI*radius*radius*length/M_4PI_3);
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{
30    switch (mode) {
31    default:
32    case 1:
33        return radius_from_volume(radius, length);
34    case 2:
35        return radius;
36    case 3:
37        return 0.5*length;
38    case 4:
39        return (radius < 0.5*length ? radius : 0.5*length);
40    case 5:
41        return (radius > 0.5*length ? radius : 0.5*length);
42    case 6:
43        return radius_from_diagonal(radius,length);
44    }
45}
46
47static void
48Fq(double q,
49    double *F1,
50    double *F2,
51    double sld,
52    double solvent_sld,
53    double radius,
54    double length)
55{
56    // translate a point in [-1,1] to a point in [0, pi/2]
57    const double zm = M_PI_4;
58    const double zb = M_PI_4;
59
60    double total_F1 = 0.0;
61    double total_F2 = 0.0;
62    for (int i=0; i<GAUSS_N ;i++) {
63        const double theta = GAUSS_Z[i]*zm + zb;
64        double sin_theta, cos_theta; // slots to hold sincos function output
65        // theta (theta,phi) the projection of the cylinder on the detector plane
66        SINCOS(theta , sin_theta, cos_theta);
67        const double form = _fq(q*sin_theta, q*cos_theta, radius, length);
68        total_F1 += GAUSS_W[i] * form * sin_theta;
69        total_F2 += GAUSS_W[i] * form * form * sin_theta;
70    }
71    // translate dx in [-1,1] to dx in [lower,upper]
72    total_F1 *= zm;
73    total_F2 *= zm;
74    const double s = (sld - solvent_sld) * form_volume(radius, length);
75    *F1 = 1e-2 * s * total_F1;
76    *F2 = 1e-4 * s * s * total_F2;
77}
78
79
80
81static double
82Iqac(double qab, double qc,
83    double sld,
84    double solvent_sld,
85    double radius,
86    double length)
87{
88    const double form = _fq(qab, qc, radius, length);
89    const double s = (sld-solvent_sld) * form_volume(radius, length);
90    return 1.0e-4 * square(s * form);
91}
92
Note: See TracBrowser for help on using the repository browser.