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

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

clean up effective radius functions; improve mono_gauss_coil accuracy; start moving VR into C

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