source: sasmodels/sasmodels/models/barbell.c @ 2222134

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 2222134 was 2222134, checked in by butler, 8 years ago

Updating parameter names regarding #649

  • Property mode set to 100644
File size: 4.3 KB
Line 
1double form_volume(double radius_bell, double radius, double length);
2double Iq(double q, double sld, double solvent_sld,
3        double radius_bell, double radius, double length);
4double Iqxy(double qx, double qy, double sld, double solvent_sld,
5        double radius_bell, double radius, double length,
6        double theta, double phi);
7
8#define INVALID(v) (v.radius_bell < v.radius)
9
10//barbell kernel - same as dumbell
11static double
12_bell_kernel(double q, double h, double radius_bell,
13             double half_length, double sin_alpha, double cos_alpha)
14{
15    // translate a point in [-1,1] to a point in [lower,upper]
16    const double upper = 1.0;
17    const double lower = h/radius_bell;
18    const double zm = 0.5*(upper-lower);
19    const double zb = 0.5*(upper+lower);
20
21    // cos term in integral is:
22    //    cos (q (R t - h + L/2) cos(alpha))
23    // so turn it into:
24    //    cos (m t + b)
25    // where:
26    //    m = q R cos(alpha)
27    //    b = q(L/2-h) cos(alpha)
28    const double m = q*radius_bell*cos_alpha; // cos argument slope
29    const double b = q*(half_length-h)*cos_alpha; // cos argument intercept
30    const double qrst = q*radius_bell*sin_alpha; // Q*R*sin(theta)
31    double total = 0.0;
32    for (int i = 0; i < 76; i++){
33        const double t = Gauss76Z[i]*zm + zb;
34        const double radical = 1.0 - t*t;
35        const double bj = sas_J1c(qrst*sqrt(radical));
36        const double Fq = cos(m*t + b) * radical * bj;
37        total += Gauss76Wt[i] * Fq;
38    }
39    // translate dx in [-1,1] to dx in [lower,upper]
40    const double integral = total*zm;
41    const double bell_Fq = 2*M_PI*cube(radius_bell)*integral;
42    return bell_Fq;
43}
44
45double form_volume(double radius_bell,
46        double radius,
47        double length)
48{
49
50    // bell radius should never be less than radius when this is called
51    const double hdist = sqrt(square(radius_bell) - square(radius));
52    const double p1 = 2.0/3.0*cube(radius_bell);
53    const double p2 = square(radius_bell)*hdist;
54    const double p3 = cube(hdist)/3.0;
55
56    return M_PI*square(radius)*length + 2.0*M_PI*(p1+p2-p3);
57}
58
59double Iq(double q, double sld, double solvent_sld,
60          double radius_bell, double radius, double length)
61{
62    const double h = -sqrt(radius_bell*radius_bell - radius*radius);
63    const double half_length = 0.5*length;
64
65    // translate a point in [-1,1] to a point in [0, pi/2]
66    const double zm = M_PI_4;
67    const double zb = M_PI_4;
68    double total = 0.0;
69    for (int i = 0; i < 76; i++){
70        const double alpha= Gauss76Z[i]*zm + zb;
71        double sin_alpha, cos_alpha; // slots to hold sincos function output
72        SINCOS(alpha, sin_alpha, cos_alpha);
73
74        const double bell_Fq = _bell_kernel(q, h, radius_bell, half_length, sin_alpha, cos_alpha);
75        const double bj = sas_J1c(q*radius*sin_alpha);
76        const double si = sinc(q*half_length*cos_alpha);
77        const double cyl_Fq = M_PI*radius*radius*length*bj*si;
78        const double Aq = bell_Fq + cyl_Fq;
79        total += Gauss76Wt[i] * Aq * Aq * sin_alpha;
80    }
81    // translate dx in [-1,1] to dx in [lower,upper]
82    const double form = total*zm;
83
84    //Contrast
85    const double s = (sld - solvent_sld);
86    return 1.0e-4 * s * s * form;
87}
88
89
90double Iqxy(double qx, double qy,
91        double sld, double solvent_sld,
92        double radius_bell, double radius, double length,
93        double theta, double phi)
94{
95    // Compute angle alpha between q and the cylinder axis
96    double sn, cn; // slots to hold sincos function output
97    SINCOS(theta*M_PI_180, sn, cn);
98    const double q = sqrt(qx*qx+qy*qy);
99    const double cos_val = cn*cos(phi*M_PI_180)*(qx/q) + sn*(qy/q);
100    const double alpha = acos(cos_val); // rod angle relative to q
101
102    const double h = -sqrt(square(radius_bell) - square(radius));
103    const double half_length = 0.5*length;
104
105    double sin_alpha, cos_alpha; // slots to hold sincos function output
106    SINCOS(alpha, sin_alpha, cos_alpha);
107    const double bell_Fq = _bell_kernel(q, h, radius_bell, half_length, sin_alpha, cos_alpha);
108    const double bj = sas_J1c(q*radius*sin_alpha);
109    const double si = sinc(q*half_length*cos_alpha);
110    const double cyl_Fq = M_PI*radius*radius*length*bj*si;
111    const double Aq = cyl_Fq + bell_Fq;
112
113    // Multiply by contrast^2 and convert to cm-1
114    const double s = (sld - solvent_sld);
115    return 1.0e-4 * square(s * Aq);
116}
Note: See TracBrowser for help on using the repository browser.