[994d77f] | 1 | double form_volume(double radius, double cap_radius, double length); |
---|
| 2 | double Iq(double q, double sld, double solvent_sld, |
---|
| 3 | double radius, double cap_radius, double length); |
---|
| 4 | double Iqxy(double qx, double qy, double sld, double solvent_sld, |
---|
| 5 | double radius, double cap_radius, double length, double theta, double phi); |
---|
[5d4777d] | 6 | |
---|
| 7 | // Integral over a convex lens kernel for t in [h/R,1]. See the docs for |
---|
| 8 | // the definition of the function being integrated. |
---|
| 9 | // q is the magnitude of the q vector. |
---|
| 10 | // h is the length of the lens "inside" the cylinder. This negative wrt the |
---|
| 11 | // definition of h in the docs. |
---|
| 12 | // cap_radius is the radius of the lens |
---|
| 13 | // length is the cylinder length, or the separation between the lens halves |
---|
| 14 | // alpha is the angle of the cylinder wrt q. |
---|
[50e1e40] | 15 | static double |
---|
| 16 | _cap_kernel(double q, double h, double cap_radius, |
---|
| 17 | double half_length, double sin_alpha, double cos_alpha) |
---|
[5d4777d] | 18 | { |
---|
[50e1e40] | 19 | // translate a point in [-1,1] to a point in [lower,upper] |
---|
[994d77f] | 20 | const double upper = 1.0; |
---|
| 21 | const double lower = h/cap_radius; // integral lower bound |
---|
[139c528] | 22 | const double zm = 0.5*(upper-lower); |
---|
| 23 | const double zb = 0.5*(upper+lower); |
---|
[50e1e40] | 24 | |
---|
[f4cf580] | 25 | // cos term in integral is: |
---|
| 26 | // cos (q (R t - h + L/2) cos(alpha)) |
---|
| 27 | // so turn it into: |
---|
| 28 | // cos (m t + b) |
---|
| 29 | // where: |
---|
| 30 | // m = q R cos(alpha) |
---|
| 31 | // b = q(L/2-h) cos(alpha) |
---|
[994d77f] | 32 | const double m = q*cap_radius*cos_alpha; // cos argument slope |
---|
[50e1e40] | 33 | const double b = q*(half_length-h)*cos_alpha; // cos argument intercept |
---|
[994d77f] | 34 | const double qrst = q*cap_radius*sin_alpha; // Q*R*sin(theta) |
---|
| 35 | double total = 0.0; |
---|
[5d4777d] | 36 | for (int i=0; i<76 ;i++) { |
---|
[139c528] | 37 | const double t = Gauss76Z[i]*zm + zb; |
---|
[994d77f] | 38 | const double radical = 1.0 - t*t; |
---|
[26141cb] | 39 | const double bj = sas_J1c(qrst*sqrt(radical)); |
---|
[50e1e40] | 40 | const double Fq = cos(m*t + b) * radical * bj; |
---|
[5d4777d] | 41 | total += Gauss76Wt[i] * Fq; |
---|
| 42 | } |
---|
| 43 | // translate dx in [-1,1] to dx in [lower,upper] |
---|
[50e1e40] | 44 | const double integral = total*zm; |
---|
| 45 | const double cap_Fq = 2*M_PI*cube(cap_radius)*integral; |
---|
| 46 | return cap_Fq; |
---|
[5d4777d] | 47 | } |
---|
| 48 | |
---|
[994d77f] | 49 | double form_volume(double radius, double cap_radius, double length) |
---|
[5d4777d] | 50 | { |
---|
| 51 | // cap radius should never be less than radius when this is called |
---|
[34756fd] | 52 | |
---|
| 53 | // Note: volume V = 2*V_cap + V_cyl |
---|
| 54 | // |
---|
| 55 | // V_cyl = pi r_cyl^2 L |
---|
| 56 | // V_cap = 1/6 pi h_c (3 r_cyl^2 + h_c^2) = 1/3 pi h_c^2 (3 r_cap - h_c) |
---|
| 57 | // |
---|
| 58 | // The docs for capped cylinder give the volume as: |
---|
| 59 | // V = pi r^2 L + 2/3 pi (R-h)^2 (2R + h) |
---|
| 60 | // where r_cap=R and h = R - h_c. |
---|
| 61 | // |
---|
| 62 | // The first part is clearly V_cyl. The second part requires some work: |
---|
| 63 | // (R-h)^2 => h_c^2 |
---|
[50e1e40] | 64 | // (2R+h) => 2R+ h_c-h_c + h => 2R + (R-h)-h_c + h => 3R-h_c |
---|
[34756fd] | 65 | // And so: |
---|
| 66 | // 2/3 pi (R-h)^2 (2R + h) => 2/3 pi h_c^2 (3 r_cap - h_c) |
---|
| 67 | // which is 2 V_cap, using the second form above. |
---|
| 68 | // |
---|
| 69 | // In this function we are going to use the first form of V_cap |
---|
| 70 | // |
---|
| 71 | // V = V_cyl + 2 V_cap |
---|
[5d4777d] | 72 | // = pi r^2 L + pi hc (r^2 + hc^2/3) |
---|
[34756fd] | 73 | // = pi (r^2 (L+hc) + hc^3/3) |
---|
[994d77f] | 74 | const double hc = cap_radius - sqrt(cap_radius*cap_radius - radius*radius); |
---|
[50e1e40] | 75 | return M_PI*(radius*radius*(length+hc) + hc*hc*hc/3.0); |
---|
[5d4777d] | 76 | } |
---|
| 77 | |
---|
[50e1e40] | 78 | double Iq(double q, double sld, double solvent_sld, |
---|
| 79 | double radius, double cap_radius, double length) |
---|
[5d4777d] | 80 | { |
---|
| 81 | // Exclude invalid inputs. |
---|
[c138211] | 82 | if (cap_radius < radius) return NAN; |
---|
[50e1e40] | 83 | const double h = sqrt(cap_radius*cap_radius - radius*radius); |
---|
| 84 | const double half_length = 0.5*length; |
---|
[5d4777d] | 85 | |
---|
[50e1e40] | 86 | // translate a point in [-1,1] to a point in [0, pi/2] |
---|
| 87 | const double zm = M_PI_4; |
---|
| 88 | const double zb = M_PI_4; |
---|
[994d77f] | 89 | double total = 0.0; |
---|
[5d4777d] | 90 | for (int i=0; i<76 ;i++) { |
---|
[50e1e40] | 91 | const double alpha= Gauss76Z[i]*zm + zb; |
---|
| 92 | double sin_alpha, cos_alpha; // slots to hold sincos function output |
---|
| 93 | SINCOS(alpha, sin_alpha, cos_alpha); |
---|
| 94 | |
---|
| 95 | const double cap_Fq = _cap_kernel(q, h, cap_radius, half_length, sin_alpha, cos_alpha); |
---|
[26141cb] | 96 | const double bj = sas_J1c(q*radius*sin_alpha); |
---|
[50e1e40] | 97 | const double si = sinc(q*half_length*cos_alpha); |
---|
| 98 | const double cyl_Fq = M_PI*radius*radius*length*bj*si; |
---|
| 99 | const double Aq = cap_Fq + cyl_Fq; |
---|
| 100 | total += Gauss76Wt[i] * Aq * Aq * sin_alpha; // sin_alpha for spherical coord integration |
---|
[5d4777d] | 101 | } |
---|
| 102 | // translate dx in [-1,1] to dx in [lower,upper] |
---|
[50e1e40] | 103 | const double form = total * zm; |
---|
[5d4777d] | 104 | |
---|
[50e1e40] | 105 | // Contrast |
---|
[994d77f] | 106 | const double s = (sld - solvent_sld); |
---|
[50e1e40] | 107 | return 1.0e-4 * s * s * form; |
---|
[5d4777d] | 108 | } |
---|
| 109 | |
---|
| 110 | |
---|
[994d77f] | 111 | double Iqxy(double qx, double qy, |
---|
[50e1e40] | 112 | double sld, double solvent_sld, double radius, |
---|
| 113 | double cap_radius, double length, |
---|
| 114 | double theta, double phi) |
---|
[5d4777d] | 115 | { |
---|
| 116 | // Compute angle alpha between q and the cylinder axis |
---|
[50e1e40] | 117 | double sn, cn; |
---|
[5d4777d] | 118 | SINCOS(theta*M_PI_180, sn, cn); |
---|
[994d77f] | 119 | const double q = sqrt(qx*qx+qy*qy); |
---|
| 120 | const double cos_val = cn*cos(phi*M_PI_180)*(qx/q) + sn*(qy/q); |
---|
| 121 | const double alpha = acos(cos_val); // rod angle relative to q |
---|
[5d4777d] | 122 | |
---|
[50e1e40] | 123 | // Exclude invalid inputs. |
---|
| 124 | if (cap_radius < radius) return NAN; |
---|
| 125 | const double h = sqrt(cap_radius*cap_radius - radius*radius); |
---|
| 126 | const double half_length = 0.5*length; |
---|
| 127 | |
---|
| 128 | double sin_alpha, cos_alpha; // slots to hold sincos function output |
---|
| 129 | SINCOS(alpha, sin_alpha, cos_alpha); |
---|
| 130 | const double cap_Fq = _cap_kernel(q, h, cap_radius, half_length, sin_alpha, cos_alpha); |
---|
[26141cb] | 131 | const double bj = sas_J1c(q*radius*sin_alpha); |
---|
[50e1e40] | 132 | const double si = sinc(q*half_length*cos_alpha); |
---|
| 133 | const double cyl_Fq = M_PI*radius*radius*length*bj*si; |
---|
| 134 | const double Aq = cap_Fq + cyl_Fq; |
---|
| 135 | |
---|
| 136 | // Multiply by contrast^2 and convert to cm-1 |
---|
[994d77f] | 137 | const double s = (sld - solvent_sld); |
---|
[50e1e40] | 138 | return 1.0e-4 * square(s * Aq); |
---|
[5d4777d] | 139 | } |
---|