source: sasmodels/sasmodels/models/barbell.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: 3.9 KB
RevLine 
[2222134]1double form_volume(double radius_bell, double radius, double length);
[3c97ff0]2double Iq(double q, double sld, double solvent_sld,
[2222134]3        double radius_bell, double radius, double length);
[58f41fe]4double Iqxy(double qx, double qy, double sld, double solvent_sld,
[2222134]5        double radius_bell, double radius, double length,
[3c97ff0]6        double theta, double phi);
[58f41fe]7
[2222134]8#define INVALID(v) (v.radius_bell < v.radius)
[2f5c6d4]9
[58f41fe]10//barbell kernel - same as dumbell
[50e1e40]11static double
[2a0b2b1]12_bell_kernel(double qab, double qc, double h, double radius_bell,
13             double half_length)
[58f41fe]14{
[50e1e40]15    // translate a point in [-1,1] to a point in [lower,upper]
[58f41fe]16    const double upper = 1.0;
[2222134]17    const double lower = h/radius_bell;
[50e1e40]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)
[2a0b2b1]28    const double m = radius_bell*qc; // cos argument slope
29    const double b = (half_length-h)*qc; // cos argument intercept
30    const double qab_r = radius_bell*qab; // Q*R*sin(theta)
[58f41fe]31    double total = 0.0;
32    for (int i = 0; i < 76; i++){
[50e1e40]33        const double t = Gauss76Z[i]*zm + zb;
34        const double radical = 1.0 - t*t;
[2a0b2b1]35        const double bj = sas_2J1x_x(qab_r*sqrt(radical));
[50e1e40]36        const double Fq = cos(m*t + b) * radical * bj;
[3c97ff0]37        total += Gauss76Wt[i] * Fq;
[58f41fe]38    }
[50e1e40]39    // translate dx in [-1,1] to dx in [lower,upper]
40    const double integral = total*zm;
[3a48772]41    const double bell_fq = 2.0*M_PI*cube(radius_bell)*integral;
[11ca2ab]42    return bell_fq;
[58f41fe]43}
44
[11ca2ab]45static double
[2a0b2b1]46_fq(double qab, double qc, double h,
47    double radius_bell, double radius, double half_length)
[11ca2ab]48{
[2a0b2b1]49    const double bell_fq = _bell_kernel(qab, qc, h, radius_bell, half_length);
50    const double bj = sas_2J1x_x(radius*qab);
51    const double si = sas_sinx_x(half_length*qc);
[11ca2ab]52    const double cyl_fq = 2.0*M_PI*radius*radius*half_length*bj*si;
53    const double Aq = bell_fq + cyl_fq;
54    return Aq;
55}
56
57
[2222134]58double form_volume(double radius_bell,
[58f41fe]59        double radius,
60        double length)
61{
62    // bell radius should never be less than radius when this is called
[2222134]63    const double hdist = sqrt(square(radius_bell) - square(radius));
64    const double p1 = 2.0/3.0*cube(radius_bell);
65    const double p2 = square(radius_bell)*hdist;
[50e1e40]66    const double p3 = cube(hdist)/3.0;
[58f41fe]67
[50e1e40]68    return M_PI*square(radius)*length + 2.0*M_PI*(p1+p2-p3);
[58f41fe]69}
70
[50e1e40]71double Iq(double q, double sld, double solvent_sld,
[2222134]72          double radius_bell, double radius, double length)
[58f41fe]73{
[2222134]74    const double h = -sqrt(radius_bell*radius_bell - radius*radius);
[50e1e40]75    const double half_length = 0.5*length;
[58f41fe]76
[50e1e40]77    // translate a point in [-1,1] to a point in [0, pi/2]
78    const double zm = M_PI_4;
79    const double zb = M_PI_4;
[58f41fe]80    double total = 0.0;
81    for (int i = 0; i < 76; i++){
[50e1e40]82        const double alpha= Gauss76Z[i]*zm + zb;
83        double sin_alpha, cos_alpha; // slots to hold sincos function output
84        SINCOS(alpha, sin_alpha, cos_alpha);
[2a0b2b1]85        const double Aq = _fq(q*sin_alpha, q*cos_alpha, h, radius_bell, radius, half_length);
[50e1e40]86        total += Gauss76Wt[i] * Aq * Aq * sin_alpha;
[58f41fe]87    }
[50e1e40]88    // translate dx in [-1,1] to dx in [lower,upper]
89    const double form = total*zm;
[58f41fe]90
[50e1e40]91    //Contrast
[58f41fe]92    const double s = (sld - solvent_sld);
[50e1e40]93    return 1.0e-4 * s * s * form;
[58f41fe]94}
95
96
97double Iqxy(double qx, double qy,
[50e1e40]98        double sld, double solvent_sld,
[2222134]99        double radius_bell, double radius, double length,
[50e1e40]100        double theta, double phi)
[58f41fe]101{
[11ca2ab]102    double q, sin_alpha, cos_alpha;
103    ORIENT_SYMMETRIC(qx, qy, theta, phi, q, sin_alpha, cos_alpha);
[2a0b2b1]104    const double qab = q*sin_alpha;
105    const double qc = q*cos_alpha;
[58f41fe]106
[2222134]107    const double h = -sqrt(square(radius_bell) - square(radius));
[2a0b2b1]108    const double Aq = _fq(qab, qc, h, radius_bell, radius, 0.5*length);
[58f41fe]109
[50e1e40]110    // Multiply by contrast^2 and convert to cm-1
[58f41fe]111    const double s = (sld - solvent_sld);
[50e1e40]112    return 1.0e-4 * square(s * Aq);
[58f41fe]113}
Note: See TracBrowser for help on using the repository browser.