source: sasmodels/sasmodels/models/barbell.c @ 592343f

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 592343f was 592343f, checked in by wojciech, 7 years ago

sas_J1c translated to sas_2J1x_x

  • 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
[2222134]12_bell_kernel(double q, double h, double radius_bell,
[50e1e40]13             double half_length, double sin_alpha, double cos_alpha)
[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)
[2222134]28    const double m = q*radius_bell*cos_alpha; // cos argument slope
[50e1e40]29    const double b = q*(half_length-h)*cos_alpha; // cos argument intercept
[2222134]30    const double qrst = q*radius_bell*sin_alpha; // 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;
[592343f]35        const double bj = sas_2J1x_x(qrst*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
46_fq(double q, double h,
47    double radius_bell, double radius, double half_length,
48    double sin_alpha, double cos_alpha)
49{
50    const double bell_fq = _bell_kernel(q, h, radius_bell, half_length, sin_alpha, cos_alpha);
[592343f]51    const double bj = sas_2J1x_x(q*radius*sin_alpha);
[1e7b0db0]52    const double si = sas_sinx_x(q*half_length*cos_alpha);
[11ca2ab]53    const double cyl_fq = 2.0*M_PI*radius*radius*half_length*bj*si;
54    const double Aq = bell_fq + cyl_fq;
55    return Aq;
56}
57
58
[2222134]59double form_volume(double radius_bell,
[58f41fe]60        double radius,
61        double length)
62{
63    // bell radius should never be less than radius when this is called
[2222134]64    const double hdist = sqrt(square(radius_bell) - square(radius));
65    const double p1 = 2.0/3.0*cube(radius_bell);
66    const double p2 = square(radius_bell)*hdist;
[50e1e40]67    const double p3 = cube(hdist)/3.0;
[58f41fe]68
[50e1e40]69    return M_PI*square(radius)*length + 2.0*M_PI*(p1+p2-p3);
[58f41fe]70}
71
[50e1e40]72double Iq(double q, double sld, double solvent_sld,
[2222134]73          double radius_bell, double radius, double length)
[58f41fe]74{
[2222134]75    const double h = -sqrt(radius_bell*radius_bell - radius*radius);
[50e1e40]76    const double half_length = 0.5*length;
[58f41fe]77
[50e1e40]78    // translate a point in [-1,1] to a point in [0, pi/2]
79    const double zm = M_PI_4;
80    const double zb = M_PI_4;
[58f41fe]81    double total = 0.0;
82    for (int i = 0; i < 76; i++){
[50e1e40]83        const double alpha= Gauss76Z[i]*zm + zb;
84        double sin_alpha, cos_alpha; // slots to hold sincos function output
85        SINCOS(alpha, sin_alpha, cos_alpha);
[11ca2ab]86        const double Aq = _fq(q, h, radius_bell, radius, half_length, sin_alpha, cos_alpha);
[50e1e40]87        total += Gauss76Wt[i] * Aq * Aq * sin_alpha;
[58f41fe]88    }
[50e1e40]89    // translate dx in [-1,1] to dx in [lower,upper]
90    const double form = total*zm;
[58f41fe]91
[50e1e40]92    //Contrast
[58f41fe]93    const double s = (sld - solvent_sld);
[50e1e40]94    return 1.0e-4 * s * s * form;
[58f41fe]95}
96
97
98double Iqxy(double qx, double qy,
[50e1e40]99        double sld, double solvent_sld,
[2222134]100        double radius_bell, double radius, double length,
[50e1e40]101        double theta, double phi)
[58f41fe]102{
[11ca2ab]103    double q, sin_alpha, cos_alpha;
104    ORIENT_SYMMETRIC(qx, qy, theta, phi, q, sin_alpha, cos_alpha);
[58f41fe]105
[2222134]106    const double h = -sqrt(square(radius_bell) - square(radius));
[11ca2ab]107    const double Aq = _fq(q, h, radius_bell, radius, 0.5*length, sin_alpha, cos_alpha);
[58f41fe]108
[50e1e40]109    // Multiply by contrast^2 and convert to cm-1
[58f41fe]110    const double s = (sld - solvent_sld);
[50e1e40]111    return 1.0e-4 * square(s * Aq);
[58f41fe]112}
Note: See TracBrowser for help on using the repository browser.