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

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

Models updated to include choices for effective interaction radii

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