source: sasmodels/sasmodels/models/hollow_rectangular_prism_thin_walls.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: 4.1 KB
Line 
1// TODO: interface to form_volume/shell_volume not yet settled
2static double
3shell_volume(double *total, double length_a, double b2a_ratio, double c2a_ratio)
4{
5    double length_b = length_a * b2a_ratio;
6    double length_c = length_a * c2a_ratio;
7    double vol_shell = 2.0 * (length_a*length_b + length_a*length_c + length_b*length_c);
8    *total = length_a * length_b * length_c;
9    return vol_shell;
10}
11
12static double
13form_volume(double length_a, double b2a_ratio, double c2a_ratio)
14{
15    double total;
16    return shell_volume(&total, length_a, b2a_ratio, c2a_ratio);
17}
18
19
20static double
21effective_radius(int mode, double length_a, double b2a_ratio, double c2a_ratio)
22{
23    switch (mode) {
24    case 1: // equivalent sphere
25        return cbrt(0.75*cube(length_a)*b2a_ratio*c2a_ratio/M_PI);
26    case 2: // half length_a
27        return 0.5 * length_a;
28    case 3: // half length_b
29        return 0.5 * length_a*b2a_ratio;
30    case 4: // half length_c
31        return 0.5 * length_a*c2a_ratio;
32    case 5: // equivalent outer circular cross-section
33        return length_a*sqrt(b2a_ratio/M_PI);
34    case 6: // half ab diagonal
35        return 0.5*sqrt(square(length_a) * (1.0 + square(b2a_ratio)));
36    case 7: // half diagonal
37        return 0.5*sqrt(square(length_a) * (1.0 + square(b2a_ratio) + square(c2a_ratio)));
38    }
39}
40
41static void
42Fq(double q,
43    double *F1,
44    double *F2,
45    double sld,
46    double solvent_sld,
47    double length_a,
48    double b2a_ratio,
49    double c2a_ratio)
50{
51    const double length_b = length_a * b2a_ratio;
52    const double length_c = length_a * c2a_ratio;
53    const double a_half = 0.5 * length_a;
54    const double b_half = 0.5 * length_b;
55    const double c_half = 0.5 * length_c;
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        const double theta = 0.5 * ( GAUSS_Z[i]*(v1b-v1a) + v1a + v1b );
67
68        double sin_theta, cos_theta;
69        double sin_c, cos_c;
70        SINCOS(theta, sin_theta, cos_theta);
71        SINCOS(q*c_half*cos_theta, sin_c, cos_c);
72
73        // To check potential problems if denominator goes to zero here !!!
74        const double termAL_theta = 8.0 * cos_c / (q*q*sin_theta*sin_theta);
75        const double termAT_theta = 8.0 * sin_c / (q*q*sin_theta*cos_theta);
76
77        double inner_sum_F1 = 0.0;
78        double inner_sum_F2 = 0.0;
79        for(int j=0; j<GAUSS_N; j++) {
80            const double phi = 0.5 * ( GAUSS_Z[j]*(v2b-v2a) + v2a + v2b );
81
82            double sin_phi, cos_phi;
83            double sin_a, cos_a;
84            double sin_b, cos_b;
85            SINCOS(phi, sin_phi, cos_phi);
86            SINCOS(q*a_half*sin_theta*sin_phi, sin_a, cos_a);
87            SINCOS(q*b_half*sin_theta*cos_phi, sin_b, cos_b);
88
89            // Amplitude AL from eqn. (7c)
90            const double AL = termAL_theta
91                * sin_a*sin_b / (sin_phi*cos_phi);
92
93            // Amplitude AT from eqn. (9)
94            const double AT = termAT_theta
95                * ( cos_a*sin_b/cos_phi + cos_b*sin_a/sin_phi );
96
97            inner_sum_F1 += GAUSS_W[j] * (AL+AT);
98            inner_sum_F2 += GAUSS_W[j] * square(AL+AT);
99        }
100
101        inner_sum_F1 *= 0.5 * (v2b-v2a);
102        inner_sum_F2 *= 0.5 * (v2b-v2a);
103        outer_sum_F1 += GAUSS_W[i] * inner_sum_F1 * sin_theta;
104        outer_sum_F2 += GAUSS_W[i] * inner_sum_F2 * sin_theta;
105    }
106
107    outer_sum_F1 *= 0.5*(v1b-v1a);
108    outer_sum_F2 *= 0.5*(v1b-v1a);
109
110    // Normalize as in Eqn. (15) without the volume factor (as cancels with (V*DelRho)^2 normalization)
111    // The factor 2 is due to the different theta integration limit (pi/2 instead of pi)
112    const double form_avg = outer_sum_F1/M_PI_2;
113    const double form_squared_avg = outer_sum_F2/M_PI_2;
114
115    // Multiply by contrast^2. Factor corresponding to volume^2 cancels with previous normalization.
116    const double contrast = sld - solvent_sld;
117
118    // Convert from [1e-12 A-1] to [cm-1]
119    *F1 = 1e-2 * contrast * form_avg;
120    *F2 = 1e-4 * contrast * contrast * form_squared_avg;
121}
Note: See TracBrowser for help on using the repository browser.