1 | #define INVALID(v) (v.radius_bell < v.radius) |
---|
2 | |
---|
3 | //barbell kernel - same as dumbell |
---|
4 | static double |
---|
5 | _bell_kernel(double qab, double qc, double h, double radius_bell, |
---|
6 | double half_length) |
---|
7 | { |
---|
8 | // translate a point in [-1,1] to a point in [lower,upper] |
---|
9 | const double upper = 1.0; |
---|
10 | const double lower = h/radius_bell; |
---|
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) |
---|
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) |
---|
24 | double total = 0.0; |
---|
25 | for (int i = 0; i < GAUSS_N; i++){ |
---|
26 | const double t = GAUSS_Z[i]*zm + zb; |
---|
27 | const double radical = 1.0 - t*t; |
---|
28 | const double bj = sas_2J1x_x(qab_r*sqrt(radical)); |
---|
29 | const double Fq = cos(m*t + b) * radical * bj; |
---|
30 | total += GAUSS_W[i] * Fq; |
---|
31 | } |
---|
32 | // translate dx in [-1,1] to dx in [lower,upper] |
---|
33 | const double integral = total*zm; |
---|
34 | const double bell_fq = 2.0*M_PI*cube(radius_bell)*integral; |
---|
35 | return bell_fq; |
---|
36 | } |
---|
37 | |
---|
38 | static double |
---|
39 | _fq(double qab, double qc, double h, |
---|
40 | double radius_bell, double radius, double half_length) |
---|
41 | { |
---|
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); |
---|
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 | |
---|
50 | static double |
---|
51 | form_volume(double radius_bell, |
---|
52 | double radius, |
---|
53 | double length) |
---|
54 | { |
---|
55 | // bell radius should never be less than radius when this is called |
---|
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; |
---|
59 | const double p3 = cube(hdist)/3.0; |
---|
60 | |
---|
61 | return M_PI*square(radius)*length + 2.0*M_PI*(p1+p2-p3); |
---|
62 | } |
---|
63 | |
---|
64 | static double |
---|
65 | radius_from_excluded_volume(double radius_bell, double radius, double length) |
---|
66 | { |
---|
67 | const double hdist = sqrt(square(radius_bell) - square(radius)); |
---|
68 | const double length_tot = length + 2.0*(hdist+ radius); |
---|
69 | return 0.5*cbrt(0.75*radius_bell*(2.0*radius_bell*length_tot + (radius_bell + length_tot)*(M_PI*radius_bell + length_tot))); |
---|
70 | } |
---|
71 | |
---|
72 | static double |
---|
73 | radius_from_volume(double radius_bell, double radius, double length) |
---|
74 | { |
---|
75 | const double vol_barbell = form_volume(radius_bell,radius,length); |
---|
76 | return cbrt(vol_barbell/M_4PI_3); |
---|
77 | } |
---|
78 | |
---|
79 | static double |
---|
80 | radius_from_totallength(double radius_bell, double radius, double length) |
---|
81 | { |
---|
82 | const double hdist = sqrt(square(radius_bell) - square(radius)); |
---|
83 | return 0.5*length + hdist + radius_bell; |
---|
84 | } |
---|
85 | |
---|
86 | static double |
---|
87 | effective_radius(int mode, double radius_bell, double radius, double length) |
---|
88 | { |
---|
89 | switch (mode) { |
---|
90 | default: |
---|
91 | case 1: // equivalent cylinder excluded volume |
---|
92 | return radius_from_excluded_volume(radius_bell, radius , length); |
---|
93 | case 2: // equivalent volume sphere |
---|
94 | return radius_from_volume(radius_bell, radius , length); |
---|
95 | case 3: // radius |
---|
96 | return radius; |
---|
97 | case 4: // half length |
---|
98 | return 0.5*length; |
---|
99 | case 5: // half total length |
---|
100 | return radius_from_totallength(radius_bell,radius,length); |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | static void |
---|
105 | Fq(double q,double *F1, double *F2, double sld, double solvent_sld, |
---|
106 | double radius_bell, double radius, double length) |
---|
107 | { |
---|
108 | const double h = -sqrt(radius_bell*radius_bell - radius*radius); |
---|
109 | const double half_length = 0.5*length; |
---|
110 | |
---|
111 | // translate a point in [-1,1] to a point in [0, pi/2] |
---|
112 | const double zm = M_PI_4; |
---|
113 | const double zb = M_PI_4; |
---|
114 | double total_F1 = 0.0; |
---|
115 | double total_F2 = 0.0; |
---|
116 | for (int i = 0; i < GAUSS_N; i++){ |
---|
117 | const double alpha= GAUSS_Z[i]*zm + zb; |
---|
118 | double sin_alpha, cos_alpha; // slots to hold sincos function output |
---|
119 | SINCOS(alpha, sin_alpha, cos_alpha); |
---|
120 | const double Aq = _fq(q*sin_alpha, q*cos_alpha, h, radius_bell, radius, half_length); |
---|
121 | total_F1 += GAUSS_W[i] * Aq * sin_alpha; |
---|
122 | total_F2 += GAUSS_W[i] * Aq * Aq * sin_alpha; |
---|
123 | } |
---|
124 | // translate dx in [-1,1] to dx in [lower,upper] |
---|
125 | const double form_avg = total_F1*zm; |
---|
126 | const double form_squared_avg = total_F2*zm; |
---|
127 | |
---|
128 | //Contrast |
---|
129 | const double s = (sld - solvent_sld); |
---|
130 | *F1 = 1.0e-2 * s * form_avg; |
---|
131 | *F2 = 1.0e-4 * s * s * form_squared_avg; |
---|
132 | } |
---|
133 | |
---|
134 | static double |
---|
135 | Iqac(double qab, double qc, |
---|
136 | double sld, double solvent_sld, |
---|
137 | double radius_bell, double radius, double length) |
---|
138 | { |
---|
139 | const double h = -sqrt(square(radius_bell) - square(radius)); |
---|
140 | const double Aq = _fq(qab, qc, h, radius_bell, radius, 0.5*length); |
---|
141 | |
---|
142 | // Multiply by contrast^2 and convert to cm-1 |
---|
143 | const double s = (sld - solvent_sld); |
---|
144 | return 1.0e-4 * square(s * Aq); |
---|
145 | } |
---|