source: sasmodels/sasmodels/models/rectangular_prism.c @ ab2aea8

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since ab2aea8 was ab2aea8, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

code cleanup for rectangular prism models

  • Property mode set to 100644
File size: 2.4 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 = sinc(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 = sinc(q * a_half * sin_theta * sin_phi);
45            const double termB = sinc(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}
Note: See TracBrowser for help on using the repository browser.