source: sasmodels/sasmodels/models/hollow_rectangular_prism_thin_walls.c @ d277229

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since d277229 was d277229, checked in by grethevj, 18 months ago

Models updated to include choices for effective interaction radii

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