source: sasmodels/sasmodels/models/rectangular_prism.c @ fc7bcd5

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since fc7bcd5 was d86f0fc, checked in by Paul Kienzle <pkienzle@…>, 6 years ago

lint reduction

  • Property mode set to 100644
File size: 3.2 KB
Line 
1static double
2form_volume(double length_a, double b2a_ratio, double c2a_ratio)
3{
4    return length_a * (length_a*b2a_ratio) * (length_a*c2a_ratio);
5}
6
7static double
8Iq(double q,
9    double sld,
10    double solvent_sld,
11    double length_a,
12    double b2a_ratio,
13    double c2a_ratio)
14{
15    const double length_b = length_a * b2a_ratio;
16    const double length_c = length_a * c2a_ratio;
17    const double a_half = 0.5 * length_a;
18    const double b_half = 0.5 * length_b;
19    const double c_half = 0.5 * length_c;
20
21   //Integration limits to use in Gaussian quadrature
22    const double v1a = 0.0;
23    const double v1b = M_PI_2;  //theta integration limits
24    const double v2a = 0.0;
25    const double v2b = M_PI_2;  //phi integration limits
26
27    double outer_sum = 0.0;
28    for(int i=0; i<GAUSS_N; i++) {
29        const double theta = 0.5 * ( GAUSS_Z[i]*(v1b-v1a) + v1a + v1b );
30        double sin_theta, cos_theta;
31        SINCOS(theta, sin_theta, cos_theta);
32
33        const double termC = sas_sinx_x(q * c_half * cos_theta);
34
35        double inner_sum = 0.0;
36        for(int j=0; j<GAUSS_N; j++) {
37            double phi = 0.5 * ( GAUSS_Z[j]*(v2b-v2a) + v2a + v2b );
38            double sin_phi, cos_phi;
39            SINCOS(phi, sin_phi, cos_phi);
40
41            // Amplitude AP from eqn. (12), rewritten to avoid round-off effects when arg=0
42            const double termA = sas_sinx_x(q * a_half * sin_theta * sin_phi);
43            const double termB = sas_sinx_x(q * b_half * sin_theta * cos_phi);
44            const double AP = termA * termB * termC;
45            inner_sum += GAUSS_W[j] * AP * AP;
46        }
47        inner_sum = 0.5 * (v2b-v2a) * inner_sum;
48        outer_sum += GAUSS_W[i] * inner_sum * sin_theta;
49    }
50
51    double answer = 0.5*(v1b-v1a)*outer_sum;
52
53    // Normalize by Pi (Eqn. 16).
54    // The term (ABC)^2 does not appear because it was introduced before on
55    // the definitions of termA, termB, termC.
56    // The factor 2 appears because the theta integral has been defined between
57    // 0 and pi/2, instead of 0 to pi.
58    answer /= M_PI_2; //Form factor P(q)
59
60    // Multiply by contrast^2 and volume^2
61    const double volume = length_a * length_b * length_c;
62    answer *= square((sld-solvent_sld)*volume);
63
64    // Convert from [1e-12 A-1] to [cm-1]
65    answer *= 1.0e-4;
66
67    return answer;
68}
69
70
71static double
72Iqabc(double qa, double qb, double qc,
73    double sld,
74    double solvent_sld,
75    double length_a,
76    double b2a_ratio,
77    double c2a_ratio)
78{
79    const double length_b = length_a * b2a_ratio;
80    const double length_c = length_a * c2a_ratio;
81    const double a_half = 0.5 * length_a;
82    const double b_half = 0.5 * length_b;
83    const double c_half = 0.5 * length_c;
84    const double volume = length_a * length_b * length_c;
85
86    // Amplitude AP from eqn. (13)
87
88    const double termA = sas_sinx_x(qa * a_half);
89    const double termB = sas_sinx_x(qb * b_half);
90    const double termC = sas_sinx_x(qc * c_half);
91
92    const double AP = termA * termB * termC;
93
94    // Multiply by contrast^2. Factor corresponding to volume^2 cancels with previous normalization.
95    const double delrho = sld - solvent_sld;
96
97    // Convert from [1e-12 A-1] to [cm-1]
98    return 1.0e-4 * square(volume * delrho * AP);
99}
Note: See TracBrowser for help on using the repository browser.