source: sasmodels/sasmodels/models/hollow_rectangular_prism.c @ 71b751d

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

update remaining form factors to use Fq interface

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