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
RevLine 
[d86f0fc]1static double
[e44432d]2shell_volume(double length_a, double b2a_ratio, double c2a_ratio, double thickness)
[deb7ee0]3{
[e44432d]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;
[ee60aa7]12}
13
14static double
15form_volume(double length_a, double b2a_ratio, double c2a_ratio, double thickness)
16{
[e44432d]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;
[deb7ee0]21}
22
[d277229]23static double
24effective_radius(int mode, double length_a, double b2a_ratio, double c2a_ratio, double thickness)
[a94046f]25// NOTE length_a is external dimension!
[d277229]26{
[ee60aa7]27    switch (mode) {
28    case 1: // equivalent sphere
[d277229]29        return cbrt(0.75*cube(length_a)*b2a_ratio*c2a_ratio/M_PI);
[ee60aa7]30    case 2: // half length_a
[d277229]31        return 0.5 * length_a;
[ee60aa7]32    case 3: // half length_b
[d277229]33        return 0.5 * length_a*b2a_ratio;
[ee60aa7]34    case 4: // half length_c
[d277229]35        return 0.5 * length_a*c2a_ratio;
[ee60aa7]36    case 5: // equivalent outer circular cross-section
[d277229]37        return length_a*sqrt(b2a_ratio/M_PI);
[ee60aa7]38    case 6: // half ab diagonal
[d277229]39        return 0.5*sqrt(square(length_a) * (1.0 + square(b2a_ratio)));
[ee60aa7]40    case 7: // half diagonal
[d277229]41        return 0.5*sqrt(square(length_a) * (1.0 + square(b2a_ratio) + square(c2a_ratio)));
42    }
43}
44
[71b751d]45static void
46Fq(double q,
47    double *F1,
48    double *F2,
[deb7ee0]49    double sld,
50    double solvent_sld,
[a807206]51    double length_a,
[deb7ee0]52    double b2a_ratio,
53    double c2a_ratio,
54    double thickness)
55{
[6f676fb]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);
[deb7ee0]63
[ab2aea8]64    //Integration limits to use in Gaussian quadrature
[6f676fb]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
[8de1477]69
[71b751d]70    double outer_sum_F1 = 0.0;
71    double outer_sum_F2 = 0.0;
[74768cb]72    for(int i=0; i<GAUSS_N; i++) {
[deb7ee0]73
[74768cb]74        const double theta = 0.5 * ( GAUSS_Z[i]*(v1b-v1a) + v1a + v1b );
[6f676fb]75        double sin_theta, cos_theta;
76        SINCOS(theta, sin_theta, cos_theta);
[deb7ee0]77
[1e7b0db0]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));
[deb7ee0]80
[71b751d]81        double inner_sum_F1 = 0.0;
82        double inner_sum_F2 = 0.0;
[74768cb]83        for(int j=0; j<GAUSS_N; j++) {
[deb7ee0]84
[74768cb]85            const double phi = 0.5 * ( GAUSS_Z[j]*(v2b-v2a) + v2a + v2b );
[6f676fb]86            double sin_phi, cos_phi;
87            SINCOS(phi, sin_phi, cos_phi);
[deb7ee0]88
89            // Amplitude AP from eqn. (13), rewritten to avoid round-off effects when arg=0
90
[1e7b0db0]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);
[deb7ee0]93
[1e7b0db0]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);
[deb7ee0]96
[6f676fb]97            const double AP1 = vol_total * termA1 * termB1 * termC1;
98            const double AP2 = vol_core * termA2 * termB2 * termC2;
[deb7ee0]99
[71b751d]100            inner_sum_F1 += GAUSS_W[j] * (AP1-AP2);
101            inner_sum_F2 += GAUSS_W[j] * square(AP1-AP2);
[ab2aea8]102        }
[71b751d]103        inner_sum_F1 *= 0.5 * (v2b-v2a);
104        inner_sum_F2 *= 0.5 * (v2b-v2a);
[deb7ee0]105
[71b751d]106        outer_sum_F1 += GAUSS_W[i] * inner_sum_F1 * sin(theta);
107        outer_sum_F2 += GAUSS_W[i] * inner_sum_F2 * sin(theta);
[deb7ee0]108    }
[71b751d]109    outer_sum_F1 *= 0.5*(v1b-v1a);
110    outer_sum_F2 *= 0.5*(v1b-v1a);
[deb7ee0]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)
[71b751d]114    const double form_avg = outer_sum_F1/M_PI_2;
115    const double form_squared_avg = outer_sum_F2/M_PI_2;
[deb7ee0]116
117    // Multiply by contrast^2. Factor corresponding to volume^2 cancels with previous normalization.
[71b751d]118    const double contrast = sld - solvent_sld;
[deb7ee0]119
120    // Convert from [1e-12 A-1] to [cm-1]
[71b751d]121    *F1 = 1.0e-2 * contrast * form_avg;
122    *F2 = 1.0e-4 * contrast * contrast * form_squared_avg;
[deb7ee0]123}
[8de1477]124
[d86f0fc]125static double
126Iqabc(double qa, double qb, double qc,
[8de1477]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));
[71b751d]161}
Note: See TracBrowser for help on using the repository browser.