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