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