source: sasmodels/sasmodels/models/cylinder.c @ 0db7dbd

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 0db7dbd was 0db7dbd, checked in by pkienzle, 6 years ago

cuda support: allow cylinder model to run under CUDA as well as OpenCL

  • Property mode set to 100644
File size: 1.5 KB
Line 
1#define INVALID(v) (v.radius<0 || v.length<0)
2
3__device__
4static double
5form_volume(double radius, double length)
6{
7    return M_PI*radius*radius*length;
8}
9
10__device__
11static double
12fq(double qab, double qc, double radius, double length)
13{
14    return sas_2J1x_x(qab*radius) * sas_sinx_x(qc*0.5*length);
15}
16
17__device__
18static double
19orient_avg_1D(double q, double radius, double length)
20{
21    // translate a point in [-1,1] to a point in [0, pi/2]
22    const double zm = M_PI_4;
23    const double zb = M_PI_4;
24
25    double total = 0.0;
26    for (int i=0; i<GAUSS_N ;i++) {
27        const double theta = GAUSS_Z[i]*zm + zb;
28        double sin_theta, cos_theta; // slots to hold sincos function output
29        // theta (theta,phi) the projection of the cylinder on the detector plane
30        SINCOS(theta , sin_theta, cos_theta);
31        const double form = fq(q*sin_theta, q*cos_theta, radius, length);
32        total += GAUSS_W[i] * form * form * sin_theta;
33    }
34    // translate dx in [-1,1] to dx in [lower,upper]
35    return total*zm;
36}
37
38__device__
39static double
40Iq(double q,
41    double sld,
42    double solvent_sld,
43    double radius,
44    double length)
45{
46    const double s = (sld - solvent_sld) * form_volume(radius, length);
47    return 1.0e-4 * s * s * orient_avg_1D(q, radius, length);
48}
49
50__device__
51static double
52Iqac(double qab, double qc,
53    double sld,
54    double solvent_sld,
55    double radius,
56    double length)
57{
58    const double s = (sld-solvent_sld) * form_volume(radius, length);
59    const double form = fq(qab, qc, radius, length);
60    return 1.0e-4 * square(s * form);
61}
Note: See TracBrowser for help on using the repository browser.