source: sasmodels/sasmodels/models/barbell.c @ 6d5601c

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

use 4/3 pi constant when computing R_eff

  • Property mode set to 100644
File size: 4.4 KB
RevLine 
[2222134]1#define INVALID(v) (v.radius_bell < v.radius)
[2f5c6d4]2
[58f41fe]3//barbell kernel - same as dumbell
[50e1e40]4static double
[2a0b2b1]5_bell_kernel(double qab, double qc, double h, double radius_bell,
6             double half_length)
[58f41fe]7{
[50e1e40]8    // translate a point in [-1,1] to a point in [lower,upper]
[58f41fe]9    const double upper = 1.0;
[2222134]10    const double lower = h/radius_bell;
[50e1e40]11    const double zm = 0.5*(upper-lower);
12    const double zb = 0.5*(upper+lower);
13
14    // cos term in integral is:
15    //    cos (q (R t - h + L/2) cos(alpha))
16    // so turn it into:
17    //    cos (m t + b)
18    // where:
19    //    m = q R cos(alpha)
20    //    b = q(L/2-h) cos(alpha)
[2a0b2b1]21    const double m = radius_bell*qc; // cos argument slope
22    const double b = (half_length-h)*qc; // cos argument intercept
23    const double qab_r = radius_bell*qab; // Q*R*sin(theta)
[58f41fe]24    double total = 0.0;
[74768cb]25    for (int i = 0; i < GAUSS_N; i++){
26        const double t = GAUSS_Z[i]*zm + zb;
[50e1e40]27        const double radical = 1.0 - t*t;
[2a0b2b1]28        const double bj = sas_2J1x_x(qab_r*sqrt(radical));
[50e1e40]29        const double Fq = cos(m*t + b) * radical * bj;
[74768cb]30        total += GAUSS_W[i] * Fq;
[58f41fe]31    }
[50e1e40]32    // translate dx in [-1,1] to dx in [lower,upper]
33    const double integral = total*zm;
[3a48772]34    const double bell_fq = 2.0*M_PI*cube(radius_bell)*integral;
[11ca2ab]35    return bell_fq;
[58f41fe]36}
37
[11ca2ab]38static double
[2a0b2b1]39_fq(double qab, double qc, double h,
40    double radius_bell, double radius, double half_length)
[11ca2ab]41{
[2a0b2b1]42    const double bell_fq = _bell_kernel(qab, qc, h, radius_bell, half_length);
43    const double bj = sas_2J1x_x(radius*qab);
44    const double si = sas_sinx_x(half_length*qc);
[11ca2ab]45    const double cyl_fq = 2.0*M_PI*radius*radius*half_length*bj*si;
46    const double Aq = bell_fq + cyl_fq;
47    return Aq;
48}
49
[becded3]50static double
51form_volume(double radius_bell,
52    double radius,
53    double length)
[58f41fe]54{
55    // bell radius should never be less than radius when this is called
[2222134]56    const double hdist = sqrt(square(radius_bell) - square(radius));
57    const double p1 = 2.0/3.0*cube(radius_bell);
58    const double p2 = square(radius_bell)*hdist;
[50e1e40]59    const double p3 = cube(hdist)/3.0;
[58f41fe]60
[50e1e40]61    return M_PI*square(radius)*length + 2.0*M_PI*(p1+p2-p3);
[58f41fe]62}
63
[d277229]64static double
65radius_from_volume(double radius_bell, double radius, double length)
66{
67    const double vol_barbell = form_volume(radius_bell,radius,length);
[6d5601c]68    return cbrt(vol_barbell/M_4PI_3);
[d277229]69}
70
71static double
72radius_from_totallength(double radius_bell, double radius, double length)
73{
74    const double hdist = sqrt(square(radius_bell) - square(radius));
75    return 0.5*length + hdist + radius_bell;
76}
77
78static double
79effective_radius(int mode, double radius_bell, double radius, double length)
80{
[ee60aa7]81    switch (mode) {
82    case 1: // equivalent sphere
[d277229]83        return radius_from_volume(radius_bell, radius , length);
[ee60aa7]84    case 2: // radius
[d277229]85        return radius;
[ee60aa7]86    case 3: // half length
[d277229]87        return 0.5*length;
[ee60aa7]88    case 4: // half total length
[d277229]89        return radius_from_totallength(radius_bell,radius,length);
90    }
91}
92
[71b751d]93static void
94Fq(double q,double *F1, double *F2, double sld, double solvent_sld,
[becded3]95    double radius_bell, double radius, double length)
[58f41fe]96{
[2222134]97    const double h = -sqrt(radius_bell*radius_bell - radius*radius);
[50e1e40]98    const double half_length = 0.5*length;
[58f41fe]99
[50e1e40]100    // translate a point in [-1,1] to a point in [0, pi/2]
101    const double zm = M_PI_4;
102    const double zb = M_PI_4;
[71b751d]103    double total_F1 = 0.0;
104    double total_F2 = 0.0;
[74768cb]105    for (int i = 0; i < GAUSS_N; i++){
106        const double alpha= GAUSS_Z[i]*zm + zb;
[50e1e40]107        double sin_alpha, cos_alpha; // slots to hold sincos function output
108        SINCOS(alpha, sin_alpha, cos_alpha);
[2a0b2b1]109        const double Aq = _fq(q*sin_alpha, q*cos_alpha, h, radius_bell, radius, half_length);
[71b751d]110        total_F1 += GAUSS_W[i] * Aq * sin_alpha;
111        total_F2 += GAUSS_W[i] * Aq * Aq * sin_alpha;
[58f41fe]112    }
[50e1e40]113    // translate dx in [-1,1] to dx in [lower,upper]
[71b751d]114    const double form_avg = total_F1*zm;
115    const double form_squared_avg = total_F2*zm;
[58f41fe]116
[50e1e40]117    //Contrast
[58f41fe]118    const double s = (sld - solvent_sld);
[71b751d]119    *F1 = 1.0e-2 * s * form_avg;
120    *F2 = 1.0e-4 * s * s * form_squared_avg;
[58f41fe]121}
122
[becded3]123static double
[108e70e]124Iqac(double qab, double qc,
[becded3]125    double sld, double solvent_sld,
126    double radius_bell, double radius, double length)
[58f41fe]127{
[2222134]128    const double h = -sqrt(square(radius_bell) - square(radius));
[2a0b2b1]129    const double Aq = _fq(qab, qc, h, radius_bell, radius, 0.5*length);
[58f41fe]130
[50e1e40]131    // Multiply by contrast^2 and convert to cm-1
[58f41fe]132    const double s = (sld - solvent_sld);
[50e1e40]133    return 1.0e-4 * square(s * Aq);
[58f41fe]134}
Note: See TracBrowser for help on using the repository browser.