[58f41fe] | 1 | double form_volume(double bell_radius, double radius, double length); |
---|
[3c97ff0] | 2 | double Iq(double q, double sld, double solvent_sld, |
---|
| 3 | double bell_radius, double radius, double length); |
---|
[58f41fe] | 4 | double Iqxy(double qx, double qy, double sld, double solvent_sld, |
---|
[3c97ff0] | 5 | double bell_radius, double radius, double length, |
---|
| 6 | double theta, double phi); |
---|
[58f41fe] | 7 | |
---|
| 8 | //barbell kernel - same as dumbell |
---|
[50e1e40] | 9 | static double |
---|
| 10 | _bell_kernel(double q, double h, double bell_radius, |
---|
| 11 | double half_length, double sin_alpha, double cos_alpha) |
---|
[58f41fe] | 12 | { |
---|
[50e1e40] | 13 | // translate a point in [-1,1] to a point in [lower,upper] |
---|
[58f41fe] | 14 | const double upper = 1.0; |
---|
[50e1e40] | 15 | const double lower = h/bell_radius; |
---|
| 16 | const double zm = 0.5*(upper-lower); |
---|
| 17 | const double zb = 0.5*(upper+lower); |
---|
| 18 | |
---|
| 19 | // cos term in integral is: |
---|
| 20 | // cos (q (R t - h + L/2) cos(alpha)) |
---|
| 21 | // so turn it into: |
---|
| 22 | // cos (m t + b) |
---|
| 23 | // where: |
---|
| 24 | // m = q R cos(alpha) |
---|
| 25 | // b = q(L/2-h) cos(alpha) |
---|
| 26 | const double m = q*bell_radius*cos_alpha; // cos argument slope |
---|
| 27 | const double b = q*(half_length-h)*cos_alpha; // cos argument intercept |
---|
| 28 | const double qrst = q*bell_radius*sin_alpha; // Q*R*sin(theta) |
---|
[58f41fe] | 29 | double total = 0.0; |
---|
| 30 | for (int i = 0; i < 76; i++){ |
---|
[50e1e40] | 31 | const double t = Gauss76Z[i]*zm + zb; |
---|
| 32 | const double radical = 1.0 - t*t; |
---|
[26141cb] | 33 | const double bj = sas_J1c(qrst*sqrt(radical)); |
---|
[50e1e40] | 34 | const double Fq = cos(m*t + b) * radical * bj; |
---|
[3c97ff0] | 35 | total += Gauss76Wt[i] * Fq; |
---|
[58f41fe] | 36 | } |
---|
[50e1e40] | 37 | // translate dx in [-1,1] to dx in [lower,upper] |
---|
| 38 | const double integral = total*zm; |
---|
| 39 | const double bell_Fq = 2*M_PI*cube(bell_radius)*integral; |
---|
| 40 | return bell_Fq; |
---|
[58f41fe] | 41 | } |
---|
| 42 | |
---|
| 43 | double form_volume(double bell_radius, |
---|
| 44 | double radius, |
---|
| 45 | double length) |
---|
| 46 | { |
---|
| 47 | |
---|
| 48 | // bell radius should never be less than radius when this is called |
---|
[50e1e40] | 49 | const double hdist = sqrt(square(bell_radius) - square(radius)); |
---|
| 50 | const double p1 = 2.0/3.0*cube(bell_radius); |
---|
| 51 | const double p2 = square(bell_radius)*hdist; |
---|
| 52 | const double p3 = cube(hdist)/3.0; |
---|
[58f41fe] | 53 | |
---|
[50e1e40] | 54 | return M_PI*square(radius)*length + 2.0*M_PI*(p1+p2-p3); |
---|
[58f41fe] | 55 | } |
---|
| 56 | |
---|
[50e1e40] | 57 | double Iq(double q, double sld, double solvent_sld, |
---|
| 58 | double bell_radius, double radius, double length) |
---|
[58f41fe] | 59 | { |
---|
[50e1e40] | 60 | // Exclude invalid inputs. |
---|
[c138211] | 61 | if (bell_radius < radius) return NAN; |
---|
[50e1e40] | 62 | const double h = -sqrt(bell_radius*bell_radius - radius*radius); |
---|
| 63 | const double half_length = 0.5*length; |
---|
[58f41fe] | 64 | |
---|
[50e1e40] | 65 | // translate a point in [-1,1] to a point in [0, pi/2] |
---|
| 66 | const double zm = M_PI_4; |
---|
| 67 | const double zb = M_PI_4; |
---|
[58f41fe] | 68 | double total = 0.0; |
---|
| 69 | for (int i = 0; i < 76; i++){ |
---|
[50e1e40] | 70 | const double alpha= Gauss76Z[i]*zm + zb; |
---|
| 71 | double sin_alpha, cos_alpha; // slots to hold sincos function output |
---|
| 72 | SINCOS(alpha, sin_alpha, cos_alpha); |
---|
| 73 | |
---|
| 74 | const double bell_Fq = _bell_kernel(q, h, bell_radius, half_length, sin_alpha, cos_alpha); |
---|
[26141cb] | 75 | const double bj = sas_J1c(q*radius*sin_alpha); |
---|
[50e1e40] | 76 | const double si = sinc(q*half_length*cos_alpha); |
---|
| 77 | const double cyl_Fq = M_PI*radius*radius*length*bj*si; |
---|
| 78 | const double Aq = bell_Fq + cyl_Fq; |
---|
| 79 | total += Gauss76Wt[i] * Aq * Aq * sin_alpha; |
---|
[58f41fe] | 80 | } |
---|
[50e1e40] | 81 | // translate dx in [-1,1] to dx in [lower,upper] |
---|
| 82 | const double form = total*zm; |
---|
[58f41fe] | 83 | |
---|
[50e1e40] | 84 | //Contrast |
---|
[58f41fe] | 85 | const double s = (sld - solvent_sld); |
---|
[50e1e40] | 86 | return 1.0e-4 * s * s * form; |
---|
[58f41fe] | 87 | } |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | double Iqxy(double qx, double qy, |
---|
[50e1e40] | 91 | double sld, double solvent_sld, |
---|
| 92 | double bell_radius, double radius, double length, |
---|
| 93 | double theta, double phi) |
---|
[58f41fe] | 94 | { |
---|
| 95 | // Compute angle alpha between q and the cylinder axis |
---|
[50e1e40] | 96 | double sn, cn; // slots to hold sincos function output |
---|
[58f41fe] | 97 | SINCOS(theta*M_PI_180, sn, cn); |
---|
| 98 | const double q = sqrt(qx*qx+qy*qy); |
---|
[50e1e40] | 99 | const double cos_val = cn*cos(phi*M_PI_180)*(qx/q) + sn*(qy/q); |
---|
[58f41fe] | 100 | const double alpha = acos(cos_val); // rod angle relative to q |
---|
| 101 | |
---|
[50e1e40] | 102 | // Exclude invalid inputs. |
---|
| 103 | if (bell_radius < radius) return NAN; |
---|
| 104 | const double h = -sqrt(square(bell_radius) - square(radius)); |
---|
| 105 | const double half_length = 0.5*length; |
---|
| 106 | |
---|
| 107 | double sin_alpha, cos_alpha; // slots to hold sincos function output |
---|
| 108 | SINCOS(alpha, sin_alpha, cos_alpha); |
---|
| 109 | const double bell_Fq = _bell_kernel(q, h, bell_radius, half_length, sin_alpha, cos_alpha); |
---|
[26141cb] | 110 | const double bj = sas_J1c(q*radius*sin_alpha); |
---|
[50e1e40] | 111 | const double si = sinc(q*half_length*cos_alpha); |
---|
| 112 | const double cyl_Fq = M_PI*radius*radius*length*bj*si; |
---|
[58f41fe] | 113 | const double Aq = cyl_Fq + bell_Fq; |
---|
| 114 | |
---|
[50e1e40] | 115 | // Multiply by contrast^2 and convert to cm-1 |
---|
[58f41fe] | 116 | const double s = (sld - solvent_sld); |
---|
[50e1e40] | 117 | return 1.0e-4 * square(s * Aq); |
---|
[58f41fe] | 118 | } |
---|