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