source: sasmodels/sasmodels/models/capped_cylinder.c @ 2a0b2b1

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 2a0b2b1 was 2a0b2b1, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

restructure all 2D models to work with (qa,qb,qc) = rotate(qx,qy) rather than working with angles directly in preparation for revised jitter algorithm

  • Property mode set to 100644
File size: 5.0 KB
Line 
1double form_volume(double radius, double radius_cap, double length);
2double Iq(double q, double sld, double solvent_sld,
3    double radius, double radius_cap, double length);
4double Iqxy(double qx, double qy, double sld, double solvent_sld,
5    double radius, double radius_cap, double length, double theta, double phi);
6
7#define INVALID(v) (v.radius_cap < v.radius)
8
9// Integral over a convex lens kernel for t in [h/R,1].  See the docs for
10// the definition of the function being integrated.
11//   q is the magnitude of the q vector.
12//   h is the length of the lens "inside" the cylinder.  This negative wrt the
13//       definition of h in the docs.
14//   radius_cap is the radius of the lens
15//   length is the cylinder length, or the separation between the lens halves
16//   theta is the angle of the cylinder wrt q.
17static double
18_cap_kernel(double qab, double qc, double h, double radius_cap,
19            double half_length)
20{
21    // translate a point in [-1,1] to a point in [lower,upper]
22    const double upper = 1.0;
23    const double lower = h/radius_cap; // integral lower bound
24    const double zm = 0.5*(upper-lower);
25    const double zb = 0.5*(upper+lower);
26
27    // cos term in integral is:
28    //    cos (q (R t - h + L/2) cos(theta))
29    // so turn it into:
30    //    cos (m t + b)
31    // where:
32    //    m = q R cos(theta)
33    //    b = q(L/2-h) cos(theta)
34    const double m = radius_cap*qc; // cos argument slope
35    const double b = (half_length-h)*qc; // cos argument intercept
36    const double qab_r = radius_cap*qab; // Q*R*sin(theta)
37    double total = 0.0;
38    for (int i=0; i<76 ;i++) {
39        const double t = Gauss76Z[i]*zm + zb;
40        const double radical = 1.0 - t*t;
41        const double bj = sas_2J1x_x(qab_r*sqrt(radical));
42        const double Fq = cos(m*t + b) * radical * bj;
43        total += Gauss76Wt[i] * Fq;
44    }
45    // translate dx in [-1,1] to dx in [lower,upper]
46    const double integral = total*zm;
47    const double cap_Fq = 2.0*M_PI*cube(radius_cap)*integral;
48    return cap_Fq;
49}
50
51static double
52_fq(double qab, double qc, double h, double radius_cap, double radius, double half_length)
53{
54    const double cap_Fq = _cap_kernel(qab, qc, h, radius_cap, half_length);
55    const double bj = sas_2J1x_x(radius*qab);
56    const double si = sas_sinx_x(half_length*qc);
57    const double cyl_Fq = 2.0*M_PI*radius*radius*half_length*bj*si;
58    const double Aq = cap_Fq + cyl_Fq;
59    return Aq;
60}
61
62double form_volume(double radius, double radius_cap, double length)
63{
64    // cap radius should never be less than radius when this is called
65
66    // Note: volume V = 2*V_cap + V_cyl
67    //
68    // V_cyl = pi r_cyl^2 L
69    // V_cap = 1/6 pi h_c (3 r_cyl^2 + h_c^2) = 1/3 pi h_c^2 (3 r_cap - h_c)
70    //
71    // The docs for capped cylinder give the volume as:
72    //    V = pi r^2 L + 2/3 pi (R-h)^2 (2R + h)
73    // where r_cap=R and h = R - h_c.
74    //
75    // The first part is clearly V_cyl.  The second part requires some work:
76    //    (R-h)^2 => h_c^2
77    //    (2R+h) => 2R+ h_c-h_c + h => 2R + (R-h)-h_c + h => 3R-h_c
78    // And so:
79    //    2/3 pi (R-h)^2 (2R + h) => 2/3 pi h_c^2 (3 r_cap - h_c)
80    // which is 2 V_cap, using the second form above.
81    //
82    // In this function we are going to use the first form of V_cap
83    //
84    //      V = V_cyl + 2 V_cap
85    //        = pi r^2 L + pi hc (r^2 + hc^2/3)
86    //        = pi (r^2 (L+hc) + hc^3/3)
87    const double hc = radius_cap - sqrt(radius_cap*radius_cap - radius*radius);
88    return M_PI*(radius*radius*(length+hc) + hc*hc*hc/3.0);
89}
90
91double Iq(double q, double sld, double solvent_sld,
92          double radius, double radius_cap, double length)
93{
94    const double h = sqrt(radius_cap*radius_cap - radius*radius);
95    const double half_length = 0.5*length;
96
97    // translate a point in [-1,1] to a point in [0, pi/2]
98    const double zm = M_PI_4;
99    const double zb = M_PI_4;
100    double total = 0.0;
101    for (int i=0; i<76 ;i++) {
102        const double theta = Gauss76Z[i]*zm + zb;
103        double sin_theta, cos_theta; // slots to hold sincos function output
104        SINCOS(theta, sin_theta, cos_theta);
105        const double qab = q*sin_theta;
106        const double qc = q*cos_theta;
107        const double Aq = _fq(qab, qc, h, radius_cap, radius, half_length);
108        // scale by sin_theta for spherical coord integration
109        total += Gauss76Wt[i] * Aq * Aq * sin_theta;
110    }
111    // translate dx in [-1,1] to dx in [lower,upper]
112    const double form = total * zm;
113
114    // Contrast
115    const double s = (sld - solvent_sld);
116    return 1.0e-4 * s * s * form;
117}
118
119
120double Iqxy(double qx, double qy,
121    double sld, double solvent_sld, double radius,
122    double radius_cap, double length,
123    double theta, double phi)
124{
125    double q, sin_alpha, cos_alpha;
126    ORIENT_SYMMETRIC(qx, qy, theta, phi, q, sin_alpha, cos_alpha);
127    const double qab = q*sin_alpha;
128    const double qc = q*cos_alpha;
129
130    const double h = sqrt(radius_cap*radius_cap - radius*radius);
131    const double Aq = _fq(qab, qc, h, radius_cap, radius, 0.5*length);
132
133    // Multiply by contrast^2 and convert to cm-1
134    const double s = (sld - solvent_sld);
135    return 1.0e-4 * square(s * Aq);
136}
Note: See TracBrowser for help on using the repository browser.