source: sasmodels/sasmodels/models/hollow_rectangular_prism.c @ 802c412

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

lint reduction

  • Property mode set to 100644
File size: 4.3 KB
Line 
1static double
2form_volume(double length_a, double b2a_ratio, double c2a_ratio, double thickness)
3{
4    double length_b = length_a * b2a_ratio;
5    double length_c = length_a * c2a_ratio;
6    double a_core = length_a - 2.0*thickness;
7    double b_core = length_b - 2.0*thickness;
8    double c_core = length_c - 2.0*thickness;
9    double vol_core = a_core * b_core * c_core;
10    double vol_total = length_a * length_b * length_c;
11    double vol_shell = vol_total - vol_core;
12    return vol_shell;
13}
14
15static double
16Iq(double q,
17    double sld,
18    double solvent_sld,
19    double length_a,
20    double b2a_ratio,
21    double c2a_ratio,
22    double thickness)
23{
24    const double length_b = length_a * b2a_ratio;
25    const double length_c = length_a * c2a_ratio;
26    const double a_half = 0.5 * length_a;
27    const double b_half = 0.5 * length_b;
28    const double c_half = 0.5 * length_c;
29    const double vol_total = length_a * length_b * length_c;
30    const double vol_core = 8.0 * (a_half-thickness) * (b_half-thickness) * (c_half-thickness);
31
32    //Integration limits to use in Gaussian quadrature
33    const double v1a = 0.0;
34    const double v1b = M_PI_2;  //theta integration limits
35    const double v2a = 0.0;
36    const double v2b = M_PI_2;  //phi integration limits
37
38    double outer_sum = 0.0;
39    for(int i=0; i<GAUSS_N; i++) {
40
41        const double theta = 0.5 * ( GAUSS_Z[i]*(v1b-v1a) + v1a + v1b );
42        double sin_theta, cos_theta;
43        SINCOS(theta, sin_theta, cos_theta);
44
45        const double termC1 = sas_sinx_x(q * c_half * cos(theta));
46        const double termC2 = sas_sinx_x(q * (c_half-thickness)*cos(theta));
47
48        double inner_sum = 0.0;
49        for(int j=0; j<GAUSS_N; j++) {
50
51            const double phi = 0.5 * ( GAUSS_Z[j]*(v2b-v2a) + v2a + v2b );
52            double sin_phi, cos_phi;
53            SINCOS(phi, sin_phi, cos_phi);
54
55            // Amplitude AP from eqn. (13), rewritten to avoid round-off effects when arg=0
56
57            const double termA1 = sas_sinx_x(q * a_half * sin_theta * sin_phi);
58            const double termA2 = sas_sinx_x(q * (a_half-thickness) * sin_theta * sin_phi);
59
60            const double termB1 = sas_sinx_x(q * b_half * sin_theta * cos_phi);
61            const double termB2 = sas_sinx_x(q * (b_half-thickness) * sin_theta * cos_phi);
62
63            const double AP1 = vol_total * termA1 * termB1 * termC1;
64            const double AP2 = vol_core * termA2 * termB2 * termC2;
65
66            inner_sum += GAUSS_W[j] * square(AP1-AP2);
67        }
68        inner_sum *= 0.5 * (v2b-v2a);
69
70        outer_sum += GAUSS_W[i] * inner_sum * sin(theta);
71    }
72    outer_sum *= 0.5*(v1b-v1a);
73
74    // Normalize as in Eqn. (15) without the volume factor (as cancels with (V*DelRho)^2 normalization)
75    // The factor 2 is due to the different theta integration limit (pi/2 instead of pi)
76    const double form = outer_sum/M_PI_2;
77
78    // Multiply by contrast^2. Factor corresponding to volume^2 cancels with previous normalization.
79    const double delrho = sld - solvent_sld;
80
81    // Convert from [1e-12 A-1] to [cm-1]
82    return 1.0e-4 * delrho * delrho * form;
83}
84
85static double
86Iqabc(double qa, double qb, double qc,
87    double sld,
88    double solvent_sld,
89    double length_a,
90    double b2a_ratio,
91    double c2a_ratio,
92    double thickness)
93{
94    const double length_b = length_a * b2a_ratio;
95    const double length_c = length_a * c2a_ratio;
96    const double a_half = 0.5 * length_a;
97    const double b_half = 0.5 * length_b;
98    const double c_half = 0.5 * length_c;
99    const double vol_total = length_a * length_b * length_c;
100    const double vol_core = 8.0 * (a_half-thickness) * (b_half-thickness) * (c_half-thickness);
101
102    // Amplitude AP from eqn. (13)
103
104    const double termA1 = sas_sinx_x(qa * a_half);
105    const double termA2 = sas_sinx_x(qa * (a_half-thickness));
106
107    const double termB1 = sas_sinx_x(qb * b_half);
108    const double termB2 = sas_sinx_x(qb * (b_half-thickness));
109
110    const double termC1 = sas_sinx_x(qc * c_half);
111    const double termC2 = sas_sinx_x(qc * (c_half-thickness));
112
113    const double AP1 = vol_total * termA1 * termB1 * termC1;
114    const double AP2 = vol_core * termA2 * termB2 * termC2;
115
116    // Multiply by contrast^2. Factor corresponding to volume^2 cancels with previous normalization.
117    const double delrho = sld - solvent_sld;
118
119    // Convert from [1e-12 A-1] to [cm-1]
120    return 1.0e-4 * square(delrho * (AP1-AP2));
121}
Note: See TracBrowser for help on using the repository browser.