source: sasmodels/sasmodels/models/rectangular_prism.c @ 8de1477

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

rectangular_prism/hollow_rectangular_prism: add 2d models

  • Property mode set to 100644
File size: 3.3 KB
Line 
1double form_volume(double length_a, double b2a_ratio, double c2a_ratio);
2double Iq(double q, double sld, double solvent_sld, double length_a,
3          double b2a_ratio, double c2a_ratio);
4
5double form_volume(double length_a, double b2a_ratio, double c2a_ratio)
6{
7    return length_a * (length_a*b2a_ratio) * (length_a*c2a_ratio);
8}
9
10double Iq(double q,
11    double sld,
12    double solvent_sld,
13    double length_a,
14    double b2a_ratio,
15    double c2a_ratio)
16{
17    const double length_b = length_a * b2a_ratio;
18    const double length_c = length_a * c2a_ratio;
19    const double a_half = 0.5 * length_a;
20    const double b_half = 0.5 * length_b;
21    const double c_half = 0.5 * length_c;
22
23   //Integration limits to use in Gaussian quadrature
24    const double v1a = 0.0;
25    const double v1b = M_PI_2;  //theta integration limits
26    const double v2a = 0.0;
27    const double v2b = M_PI_2;  //phi integration limits
28
29    double outer_sum = 0.0;
30    for(int i=0; i<76; i++) {
31        const double theta = 0.5 * ( Gauss76Z[i]*(v1b-v1a) + v1a + v1b );
32        double sin_theta, cos_theta;
33        SINCOS(theta, sin_theta, cos_theta);
34
35        const double termC = sas_sinx_x(q * c_half * cos_theta);
36
37        double inner_sum = 0.0;
38        for(int j=0; j<76; j++) {
39            double phi = 0.5 * ( Gauss76Z[j]*(v2b-v2a) + v2a + v2b );
40            double sin_phi, cos_phi;
41            SINCOS(phi, sin_phi, cos_phi);
42
43            // Amplitude AP from eqn. (12), rewritten to avoid round-off effects when arg=0
44            const double termA = sas_sinx_x(q * a_half * sin_theta * sin_phi);
45            const double termB = sas_sinx_x(q * b_half * sin_theta * cos_phi);
46            const double AP = termA * termB * termC;
47            inner_sum += Gauss76Wt[j] * AP * AP;
48        }
49        inner_sum = 0.5 * (v2b-v2a) * inner_sum;
50        outer_sum += Gauss76Wt[i] * inner_sum * sin_theta;
51    }
52
53    double answer = 0.5*(v1b-v1a)*outer_sum;
54
55    // Normalize by Pi (Eqn. 16).
56    // The term (ABC)^2 does not appear because it was introduced before on
57    // the definitions of termA, termB, termC.
58    // The factor 2 appears because the theta integral has been defined between
59    // 0 and pi/2, instead of 0 to pi.
60    answer /= M_PI_2; //Form factor P(q)
61
62    // Multiply by contrast^2 and volume^2
63    const double volume = length_a * length_b * length_c;
64    answer *= square((sld-solvent_sld)*volume);
65
66    // Convert from [1e-12 A-1] to [cm-1]
67    answer *= 1.0e-4;
68
69    return answer;
70}
71
72
73double Iqxy(double qa, double qb, double qc,
74    double sld,
75    double solvent_sld,
76    double length_a,
77    double b2a_ratio,
78    double c2a_ratio)
79{
80    const double length_b = length_a * b2a_ratio;
81    const double length_c = length_a * c2a_ratio;
82    const double a_half = 0.5 * length_a;
83    const double b_half = 0.5 * length_b;
84    const double c_half = 0.5 * length_c;
85    const double volume = length_a * length_b * length_c;
86
87    // Amplitude AP from eqn. (13)
88
89    const double termA = sas_sinx_x(qa * a_half);
90    const double termB = sas_sinx_x(qb * b_half);
91    const double termC = sas_sinx_x(qc * c_half);
92
93    const double AP = termA * termB * termC;
94
95    // Multiply by contrast^2. Factor corresponding to volume^2 cancels with previous normalization.
96    const double delrho = sld - solvent_sld;
97
98    // Convert from [1e-12 A-1] to [cm-1]
99    return 1.0e-4 * square(volume * delrho * AP);
100}
Note: See TracBrowser for help on using the repository browser.