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

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 0706431 was 0706431, checked in by ajj, 9 years ago

Fixed barbell model - now giving same result as sasview model

  • Property mode set to 100644
File size: 4.3 KB
Line 
1double form_volume(double bell_radius, double radius, double length);
2double Iq(double q, double sld, double solvent_sld, double bell_radius, double radius, double length);
3double Iqxy(double qx, double qy, double sld, double solvent_sld,
4    double bell_radius, double radius, double length, double theta, double phi);
5
6//barbell kernel - same as dumbell
7double _bell_kernel(double q, double h, double bell_radius,
8    double length, double sin_alpha, double cos_alpha);
9double _bell_kernel(double q, double h, double bell_radius,
10    double length, double sin_alpha, double cos_alpha)
11{
12    const double upper = 1.0;
13    const double lower = -1.0*h/bell_radius;
14
15    double total = 0.0;
16    for (int i = 0; i < 76; i++){
17        const double t = 0.5*(Gauss76Z[i]*(upper-lower)+upper+lower);
18            const double arg1 = q*cos_alpha*(bell_radius*t+h+length*0.5);
19            const double arg2 = q*bell_radius*sin_alpha*sqrt(1.0-t*t);
20
21        const double be = (arg2 == 0.0 ? 0.5 :J1(arg2)/arg2);
22
23            const double Fq = cos(arg1)*(1.0-t*t)*be;
24
25            total += Gauss76Wt[i] * Fq;
26    }
27    const double integral = 0.5*(upper-lower)*total;
28    return 4.0*M_PI*bell_radius*bell_radius*bell_radius*integral;
29}
30
31double form_volume(double bell_radius,
32        double radius,
33        double length)
34{
35
36    // bell radius should never be less than radius when this is called
37    const double hdist = sqrt(bell_radius*bell_radius - radius*radius);
38    const double p1 = 2.0*bell_radius*bell_radius*bell_radius/3.0;
39    const double p2 = bell_radius*bell_radius*hdist;
40    const double p3 = hdist*hdist*hdist/3.0;
41
42    return M_PI*radius*radius*length + 2.0*M_PI*(p1+p2-p3);
43}
44
45double Iq(double q, double sld,
46    double solvent_sld,
47    double bell_radius,
48    double radius,
49    double length)
50{
51    double sn, cn; // slots to hold sincos function output
52
53    if (bell_radius < radius) return -1.0;
54
55    const double lower = 0.0;
56    const double upper = M_PI_2;
57    const double h = sqrt(bell_radius*bell_radius-radius*radius);
58    double total = 0.0;
59    for (int i = 0; i < 76; i++){
60        const double alpha= 0.5*(Gauss76Z[i]*(upper-lower) + upper + lower);
61        SINCOS(alpha, sn, cn);
62
63        const double bell_Fq = _bell_kernel(q, h, bell_radius, length, sn, cn);
64
65        const double arg1 = q*length*0.5*cn;
66        const double arg2 = q*radius*sn;
67        // lim_{x->0} J1(x)/x = 1/2,   lim_{x->0} sin(x)/x = 1
68        const double be = (arg2 == 0.0 ? 0.5 :J1(arg2)/arg2);
69        const double si = (arg1 == 0.0 ? 1.0 :sin(arg1)/arg1);
70        const double cyl_Fq = M_PI*radius*radius*length*si*2.0*be;
71
72        const double Aq = cyl_Fq + bell_Fq;
73        total += Gauss76Wt[i] * Aq * Aq * sn;
74    }
75
76    const double form = total*(upper-lower)*0.5;
77
78    //Contrast and volume normalization
79    const double s = (sld - solvent_sld);
80    return form*1.0e-4*s*s; //form_volume(bell_radius,radius,length);
81}
82
83
84
85double Iqxy(double qx, double qy,
86    double sld,
87    double solvent_sld,
88    double bell_radius,
89    double radius,
90    double length,
91    double theta,
92    double phi)
93{
94     double sn, cn; // slots to hold sincos function output
95
96    // Exclude invalid inputs.
97    if (bell_radius < radius) return -1.0;
98
99    // Compute angle alpha between q and the cylinder axis
100    SINCOS(theta*M_PI_180, sn, cn);
101    // # The following correction factor exists in sasview, but it can't be
102    // # right, so we are leaving it out for now.
103    const double q = sqrt(qx*qx+qy*qy);
104    const double cos_val = cn*cos(phi*M_PI_180)*qx + sn*qy;
105    const double alpha = acos(cos_val); // rod angle relative to q
106    SINCOS(alpha, sn, cn);
107
108    const double h = sqrt(bell_radius*bell_radius - radius*radius); // negative h
109    const double bell_Fq = _bell_kernel(q, h, bell_radius, length, sn, cn)/sn;
110
111    const double besarg = q*radius*sn;
112    const double siarg = q*0.5*length*cn;
113    // lim_{x->0} J1(x)/x = 1/2,   lim_{x->0} sin(x)/x = 1
114    const double bj = (besarg == 0.0 ? 0.5 : J1(besarg)/besarg);
115    const double si = (siarg == 0.0 ? 1.0 : sin(siarg)/siarg);
116    const double cyl_Fq = M_PI*radius*radius*length*2.0*bj*si;
117
118    // Volume weighted average F(q)
119    const double Aq = cyl_Fq + bell_Fq;
120
121    // Multiply by contrast^2, normalize by cylinder volume and convert to cm-1
122    const double s = (sld - solvent_sld);
123    return 1.0e-4 * Aq * Aq * s * s; // form_volume(radius, cap_radius, length);
124}
Note: See TracBrowser for help on using the repository browser.