source: sasmodels/sasmodels/models/parallelepiped.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: 3.4 KB
Line 
1static double
2form_volume(double length_a, double length_b, double length_c)
3{
4    return length_a * length_b * length_c;
5}
6
7static double
8effective_radius(int mode, double length_a, double length_b, double length_c)
9{
10    switch (mode) {
11    case 1: // equivalent sphere
12        return cbrt(0.75*length_a*length_b*length_c/M_PI);
13    case 2: // half length_a
14        return 0.5 * length_a;
15    case 3: // half length_b
16        return 0.5 * length_b;
17    case 4: // half length_c
18        return 0.5 * length_c;
19    case 5: // equivalent circular cross-section
20        return sqrt(length_a*length_b/M_PI);
21    case 6: // half ab diagonal
22        return 0.5*sqrt(length_a*length_a + length_b*length_b);
23    case 7: // half diagonal
24        return 0.5*sqrt(length_a*length_a + length_b*length_b + length_c*length_c);
25    }
26}
27
28static void
29Fq(double q,
30    double *F1,
31    double *F2,
32    double sld,
33    double solvent_sld,
34    double length_a,
35    double length_b,
36    double length_c)
37{
38    const double mu = 0.5 * q * length_b;
39
40    // Scale sides by B
41    const double a_scaled = length_a / length_b;
42    const double c_scaled = length_c / length_b;
43
44    // outer integral (with gauss points), integration limits = 0, 1
45    double outer_total_F1 = 0.0; //initialize integral
46    double outer_total_F2 = 0.0; //initialize integral
47    for( int i=0; i<GAUSS_N; i++) {
48        const double sigma = 0.5 * ( GAUSS_Z[i] + 1.0 );
49        const double mu_proj = mu * sqrt(1.0-sigma*sigma);
50
51        // inner integral (with gauss points), integration limits = 0, 1
52        // corresponding to angles from 0 to pi/2.
53        double inner_total_F1 = 0.0;
54        double inner_total_F2 = 0.0;
55        for(int j=0; j<GAUSS_N; j++) {
56            const double uu = 0.5 * ( GAUSS_Z[j] + 1.0 );
57            double sin_uu, cos_uu;
58            SINCOS(M_PI_2*uu, sin_uu, cos_uu);
59            const double si1 = sas_sinx_x(mu_proj * sin_uu * a_scaled);
60            const double si2 = sas_sinx_x(mu_proj * cos_uu);
61            const double fq = si1 * si2;
62            inner_total_F1 += GAUSS_W[j] * fq;
63            inner_total_F2 += GAUSS_W[j] * fq * fq;
64        }
65        // now complete change of inner integration variable (1-0)/(1-(-1))= 0.5
66        inner_total_F1 *= 0.5;
67        inner_total_F2 *= 0.5;
68
69        const double si = sas_sinx_x(mu * c_scaled * sigma);
70        outer_total_F1 += GAUSS_W[i] * inner_total_F1 * si;
71        outer_total_F2 += GAUSS_W[i] * inner_total_F2 * si * si;
72    }
73    // now complete change of outer integration variable (1-0)/(1-(-1))= 0.5
74    outer_total_F1 *= 0.5;
75    outer_total_F2 *= 0.5;
76
77    // Multiply by contrast^2 and convert from [1e-12 A-1] to [cm-1]
78    const double V = form_volume(length_a, length_b, length_c);
79    const double contrast = (sld-solvent_sld);
80    const double s = contrast * V;
81    *F1 = 1.0e-2 * s * outer_total_F1;
82    *F2 = 1.0e-4 * s * s * outer_total_F2;
83}
84
85static double
86Iqabc(double qa, double qb, double qc,
87    double sld,
88    double solvent_sld,
89    double length_a,
90    double length_b,
91    double length_c)
92{
93    const double siA = sas_sinx_x(0.5*length_a*qa);
94    const double siB = sas_sinx_x(0.5*length_b*qb);
95    const double siC = sas_sinx_x(0.5*length_c*qc);
96    const double V = form_volume(length_a, length_b, length_c);
97    const double drho = (sld - solvent_sld);
98    const double form = V * drho * siA * siB * siC;
99    // Square and convert from [1e-12 A-1] to [cm-1]
100    return 1.0e-4 * form * form;
101}
Note: See TracBrowser for help on using the repository browser.