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

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

support hollow models in structure factor calculations

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