source: sasmodels/sasmodels/models/hollow_rectangular_prism_thin_walls.c @ 99658f6

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 99658f6 was 99658f6, checked in by grethevj, 5 years ago

updated ER functions including cylinder excluded volume, to match 4.x

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[d86f0fc]1static double
[e44432d]2shell_volume(double length_a, double b2a_ratio, double c2a_ratio)
[deb7ee0]3{
[e44432d]4    const double length_b = length_a * b2a_ratio;
5    const double length_c = length_a * c2a_ratio;
6    const double shell_volume = 2.0 * (length_a*length_b + length_a*length_c + length_b*length_c);
7    return shell_volume;
[deb7ee0]8}
9
[d277229]10static double
[ee60aa7]11form_volume(double length_a, double b2a_ratio, double c2a_ratio)
12{
[e44432d]13    const double length_b = length_a * b2a_ratio;
14    const double length_c = length_a * c2a_ratio;
15    const double form_volume = length_a * length_b * length_c;
16    return form_volume;
[ee60aa7]17}
18
19static double
[99658f6]20radius_from_excluded_volume(double length_a, double b2a_ratio, double c2a_ratio)
21{
22    const double r_equiv = sqrt(length_a*length_a*b2a_ratio/M_PI);
23    const double length_c = length_a*c2a_ratio;
24    return 0.5*cbrt(0.75*r_equiv*(2.0*r_equiv*length_c + (r_equiv + length_c)*(M_PI*r_equiv + length_c)));
25}
26
27static double
[d277229]28effective_radius(int mode, double length_a, double b2a_ratio, double c2a_ratio)
29{
[ee60aa7]30    switch (mode) {
[d42dd4a]31    default:
[99658f6]32    case 1: // equivalent cylinder excluded volume
33        return radius_from_excluded_volume(length_a, b2a_ratio, c2a_ratio);
34    case 2: // equivalent outer volume sphere
[6d5601c]35        return cbrt(cube(length_a)*b2a_ratio*c2a_ratio/M_4PI_3);
[99658f6]36    case 3: // half length_a
[d277229]37        return 0.5 * length_a;
[99658f6]38    case 4: // half length_b
[d277229]39        return 0.5 * length_a*b2a_ratio;
[99658f6]40    case 5: // half length_c
[d277229]41        return 0.5 * length_a*c2a_ratio;
[99658f6]42    case 6: // equivalent outer circular cross-section
[d277229]43        return length_a*sqrt(b2a_ratio/M_PI);
[99658f6]44    case 7: // half ab diagonal
[d277229]45        return 0.5*sqrt(square(length_a) * (1.0 + square(b2a_ratio)));
[99658f6]46    case 8: // half diagonal
[d277229]47        return 0.5*sqrt(square(length_a) * (1.0 + square(b2a_ratio) + square(c2a_ratio)));
48    }
49}
50
[71b751d]51static void
52Fq(double q,
53    double *F1,
54    double *F2,
[deb7ee0]55    double sld,
56    double solvent_sld,
[a807206]57    double length_a,
[deb7ee0]58    double b2a_ratio,
59    double c2a_ratio)
60{
[ab2aea8]61    const double length_b = length_a * b2a_ratio;
62    const double length_c = length_a * c2a_ratio;
63    const double a_half = 0.5 * length_a;
64    const double b_half = 0.5 * length_b;
65    const double c_half = 0.5 * length_c;
[deb7ee0]66
67   //Integration limits to use in Gaussian quadrature
[ab2aea8]68    const double v1a = 0.0;
69    const double v1b = M_PI_2;  //theta integration limits
70    const double v2a = 0.0;
71    const double v2b = M_PI_2;  //phi integration limits
[74768cb]72
[71b751d]73    double outer_sum_F1 = 0.0;
74    double outer_sum_F2 = 0.0;
[74768cb]75    for(int i=0; i<GAUSS_N; i++) {
76        const double theta = 0.5 * ( GAUSS_Z[i]*(v1b-v1a) + v1a + v1b );
[deb7ee0]77
[ab2aea8]78        double sin_theta, cos_theta;
79        double sin_c, cos_c;
80        SINCOS(theta, sin_theta, cos_theta);
81        SINCOS(q*c_half*cos_theta, sin_c, cos_c);
[deb7ee0]82
83        // To check potential problems if denominator goes to zero here !!!
[ab2aea8]84        const double termAL_theta = 8.0 * cos_c / (q*q*sin_theta*sin_theta);
85        const double termAT_theta = 8.0 * sin_c / (q*q*sin_theta*cos_theta);
86
[71b751d]87        double inner_sum_F1 = 0.0;
88        double inner_sum_F2 = 0.0;
[74768cb]89        for(int j=0; j<GAUSS_N; j++) {
90            const double phi = 0.5 * ( GAUSS_Z[j]*(v2b-v2a) + v2a + v2b );
[deb7ee0]91
[ab2aea8]92            double sin_phi, cos_phi;
93            double sin_a, cos_a;
94            double sin_b, cos_b;
95            SINCOS(phi, sin_phi, cos_phi);
96            SINCOS(q*a_half*sin_theta*sin_phi, sin_a, cos_a);
97            SINCOS(q*b_half*sin_theta*cos_phi, sin_b, cos_b);
[deb7ee0]98
99            // Amplitude AL from eqn. (7c)
[ab2aea8]100            const double AL = termAL_theta
101                * sin_a*sin_b / (sin_phi*cos_phi);
[deb7ee0]102
103            // Amplitude AT from eqn. (9)
[ab2aea8]104            const double AT = termAT_theta
105                * ( cos_a*sin_b/cos_phi + cos_b*sin_a/sin_phi );
[deb7ee0]106
[71b751d]107            inner_sum_F1 += GAUSS_W[j] * (AL+AT);
108            inner_sum_F2 += GAUSS_W[j] * square(AL+AT);
[ab2aea8]109        }
[deb7ee0]110
[71b751d]111        inner_sum_F1 *= 0.5 * (v2b-v2a);
112        inner_sum_F2 *= 0.5 * (v2b-v2a);
113        outer_sum_F1 += GAUSS_W[i] * inner_sum_F1 * sin_theta;
114        outer_sum_F2 += GAUSS_W[i] * inner_sum_F2 * sin_theta;
[deb7ee0]115    }
116
[71b751d]117    outer_sum_F1 *= 0.5*(v1b-v1a);
118    outer_sum_F2 *= 0.5*(v1b-v1a);
[deb7ee0]119
120    // Normalize as in Eqn. (15) without the volume factor (as cancels with (V*DelRho)^2 normalization)
121    // The factor 2 is due to the different theta integration limit (pi/2 instead of pi)
[71b751d]122    const double form_avg = outer_sum_F1/M_PI_2;
123    const double form_squared_avg = outer_sum_F2/M_PI_2;
[deb7ee0]124
125    // Multiply by contrast^2. Factor corresponding to volume^2 cancels with previous normalization.
[71b751d]126    const double contrast = sld - solvent_sld;
[deb7ee0]127
128    // Convert from [1e-12 A-1] to [cm-1]
[71b751d]129    *F1 = 1e-2 * contrast * form_avg;
130    *F2 = 1e-4 * contrast * contrast * form_squared_avg;
[deb7ee0]131}
Note: See TracBrowser for help on using the repository browser.