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

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since a94046f was a94046f, checked in by richardh, 6 years ago

some corrections to R_eff options

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