source: sasmodels/sasmodels/models/hollow_rectangular_prism.c @ a34b811

ticket-1257-vesicle-productticket_1156ticket_822_more_unit_tests
Last change on this file since a34b811 was a34b811, checked in by Paul Kienzle <pkienzle@…>, 5 years ago

use radius_effective/radius_effective_mode/radius_effective_modes consistently throughout the code

  • Property mode set to 100644
File size: 6.3 KB
Line 
1static double
2shell_volume(double length_a, double b2a_ratio, double c2a_ratio, double thickness)
3{
4    const double length_b = length_a * b2a_ratio;
5    const double length_c = length_a * c2a_ratio;
6    const double form_volume = length_a * length_b * length_c;
7    const double a_core = length_a - 2.0*thickness;
8    const double b_core = length_b - 2.0*thickness;
9    const double c_core = length_c - 2.0*thickness;
10    const double core_volume = a_core * b_core * c_core;
11    return form_volume - core_volume;
12}
13
14static double
15form_volume(double length_a, double b2a_ratio, double c2a_ratio, double thickness)
16{
17    const double length_b = length_a * b2a_ratio;
18    const double length_c = length_a * c2a_ratio;
19    const double form_volume = length_a * length_b * length_c;
20    return form_volume;
21}
22
23static double
24radius_from_excluded_volume(double length_a, double b2a_ratio, double c2a_ratio)
25{
26    const double r_equiv = sqrt(length_a*length_a*b2a_ratio/M_PI);
27    const double length_c = length_a*c2a_ratio;
28    return 0.5*cbrt(0.75*r_equiv*(2.0*r_equiv*length_c + (r_equiv + length_c)*(M_PI*r_equiv + length_c)));
29}
30
31static double
32radius_effective(int mode, double length_a, double b2a_ratio, double c2a_ratio, double thickness)
33// NOTE length_a is external dimension!
34{
35    switch (mode) {
36    default:
37    case 1: // equivalent cylinder excluded volume
38        return radius_from_excluded_volume(length_a, b2a_ratio, c2a_ratio);
39    case 2: // equivalent outer volume sphere
40        return cbrt(cube(length_a)*b2a_ratio*c2a_ratio/M_4PI_3);
41    case 3: // half length_a
42        return 0.5 * length_a;
43    case 4: // half length_b
44        return 0.5 * length_a*b2a_ratio;
45    case 5: // half length_c
46        return 0.5 * length_a*c2a_ratio;
47    case 6: // equivalent outer circular cross-section
48        return length_a*sqrt(b2a_ratio/M_PI);
49    case 7: // half ab diagonal
50        return 0.5*sqrt(square(length_a) * (1.0 + square(b2a_ratio)));
51    case 8: // half diagonal
52        return 0.5*sqrt(square(length_a) * (1.0 + square(b2a_ratio) + square(c2a_ratio)));
53    }
54}
55
56static void
57Fq(double q,
58    double *F1,
59    double *F2,
60    double sld,
61    double solvent_sld,
62    double length_a,
63    double b2a_ratio,
64    double c2a_ratio,
65    double thickness)
66{
67    const double length_b = length_a * b2a_ratio;
68    const double length_c = length_a * c2a_ratio;
69    const double a_half = 0.5 * length_a;
70    const double b_half = 0.5 * length_b;
71    const double c_half = 0.5 * length_c;
72    const double vol_total = length_a * length_b * length_c;
73    const double vol_core = 8.0 * (a_half-thickness) * (b_half-thickness) * (c_half-thickness);
74
75    //Integration limits to use in Gaussian quadrature
76    const double v1a = 0.0;
77    const double v1b = M_PI_2;  //theta integration limits
78    const double v2a = 0.0;
79    const double v2b = M_PI_2;  //phi integration limits
80
81    double outer_sum_F1 = 0.0;
82    double outer_sum_F2 = 0.0;
83    for(int i=0; i<GAUSS_N; i++) {
84
85        const double theta = 0.5 * ( GAUSS_Z[i]*(v1b-v1a) + v1a + v1b );
86        double sin_theta, cos_theta;
87        SINCOS(theta, sin_theta, cos_theta);
88
89        const double termC1 = sas_sinx_x(q * c_half * cos(theta));
90        const double termC2 = sas_sinx_x(q * (c_half-thickness)*cos(theta));
91
92        double inner_sum_F1 = 0.0;
93        double inner_sum_F2 = 0.0;
94        for(int j=0; j<GAUSS_N; j++) {
95
96            const double phi = 0.5 * ( GAUSS_Z[j]*(v2b-v2a) + v2a + v2b );
97            double sin_phi, cos_phi;
98            SINCOS(phi, sin_phi, cos_phi);
99
100            // Amplitude AP from eqn. (13), rewritten to avoid round-off effects when arg=0
101
102            const double termA1 = sas_sinx_x(q * a_half * sin_theta * sin_phi);
103            const double termA2 = sas_sinx_x(q * (a_half-thickness) * sin_theta * sin_phi);
104
105            const double termB1 = sas_sinx_x(q * b_half * sin_theta * cos_phi);
106            const double termB2 = sas_sinx_x(q * (b_half-thickness) * sin_theta * cos_phi);
107
108            const double AP1 = vol_total * termA1 * termB1 * termC1;
109            const double AP2 = vol_core * termA2 * termB2 * termC2;
110
111            inner_sum_F1 += GAUSS_W[j] * (AP1-AP2);
112            inner_sum_F2 += GAUSS_W[j] * square(AP1-AP2);
113        }
114        inner_sum_F1 *= 0.5 * (v2b-v2a);
115        inner_sum_F2 *= 0.5 * (v2b-v2a);
116
117        outer_sum_F1 += GAUSS_W[i] * inner_sum_F1 * sin(theta);
118        outer_sum_F2 += GAUSS_W[i] * inner_sum_F2 * sin(theta);
119    }
120    outer_sum_F1 *= 0.5*(v1b-v1a);
121    outer_sum_F2 *= 0.5*(v1b-v1a);
122
123    // Normalize as in Eqn. (15) without the volume factor (as cancels with (V*DelRho)^2 normalization)
124    // The factor 2 is due to the different theta integration limit (pi/2 instead of pi)
125    const double form_avg = outer_sum_F1/M_PI_2;
126    const double form_squared_avg = outer_sum_F2/M_PI_2;
127
128    // Multiply by contrast^2. Factor corresponding to volume^2 cancels with previous normalization.
129    const double contrast = sld - solvent_sld;
130
131    // Convert from [1e-12 A-1] to [cm-1]
132    *F1 = 1.0e-2 * contrast * form_avg;
133    *F2 = 1.0e-4 * contrast * contrast * form_squared_avg;
134}
135
136static double
137Iqabc(double qa, double qb, double qc,
138    double sld,
139    double solvent_sld,
140    double length_a,
141    double b2a_ratio,
142    double c2a_ratio,
143    double thickness)
144{
145    const double length_b = length_a * b2a_ratio;
146    const double length_c = length_a * c2a_ratio;
147    const double a_half = 0.5 * length_a;
148    const double b_half = 0.5 * length_b;
149    const double c_half = 0.5 * length_c;
150    const double vol_total = length_a * length_b * length_c;
151    const double vol_core = 8.0 * (a_half-thickness) * (b_half-thickness) * (c_half-thickness);
152
153    // Amplitude AP from eqn. (13)
154
155    const double termA1 = sas_sinx_x(qa * a_half);
156    const double termA2 = sas_sinx_x(qa * (a_half-thickness));
157
158    const double termB1 = sas_sinx_x(qb * b_half);
159    const double termB2 = sas_sinx_x(qb * (b_half-thickness));
160
161    const double termC1 = sas_sinx_x(qc * c_half);
162    const double termC2 = sas_sinx_x(qc * (c_half-thickness));
163
164    const double AP1 = vol_total * termA1 * termB1 * termC1;
165    const double AP2 = vol_core * termA2 * termB2 * termC2;
166
167    // Multiply by contrast^2. Factor corresponding to volume^2 cancels with previous normalization.
168    const double delrho = sld - solvent_sld;
169
170    // Convert from [1e-12 A-1] to [cm-1]
171    return 1.0e-4 * square(delrho * (AP1-AP2));
172}
Note: See TracBrowser for help on using the repository browser.