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

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

use predefined constants for fractions of pi

  • Property mode set to 100644
File size: 2.5 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    double termA, termB, termC;
18   
19    double b_side = length_a * b2a_ratio;
20    double c_side = length_a * c2a_ratio;
21    double volume = length_a * b_side * c_side;
22    double a_half = 0.5 * length_a;
23    double b_half = 0.5 * b_side;
24    double c_half = 0.5 * c_side;
25
26   //Integration limits to use in Gaussian quadrature
27    double v1a = 0.0;
28    double v1b = M_PI_2;  //theta integration limits
29    double v2a = 0.0;
30    double v2b = M_PI_2;  //phi integration limits
31   
32    //Order of integration
33    int nordi=76;                               
34    int nordj=76;
35
36    double sumi = 0.0;
37   
38    for(int i=0; i<nordi; i++) {
39
40            double theta = 0.5 * ( Gauss76Z[i]*(v1b-v1a) + v1a + v1b ); 
41
42            double arg = q * c_half * cos(theta);
43            if (fabs(arg) > 1.e-16) {termC = sin(arg)/arg;} else {termC = 1.0;} 
44
45            double sumj = 0.0;
46       
47            for(int j=0; j<nordj; j++) {
48
49            double phi = 0.5 * ( Gauss76Z[j]*(v2b-v2a) + v2a + v2b ); 
50
51                // Amplitude AP from eqn. (12), rewritten to avoid round-off effects when arg=0
52
53                arg = q * a_half * sin(theta) * sin(phi); 
54                if (fabs(arg) > 1.e-16) {termA = sin(arg)/arg;} else {termA = 1.0;}
55               
56                arg = q * b_half * sin(theta) * cos(phi); 
57                if (fabs(arg) > 1.e-16) {termB = sin(arg)/arg;} else {termB = 1.0;}       
58               
59                double AP = termA * termB * termC; 
60
61                sumj += Gauss76Wt[j] * (AP*AP);
62
63            }
64
65            sumj = 0.5 * (v2b-v2a) * sumj;
66            sumi += Gauss76Wt[i] * sumj * sin(theta);
67
68    }
69
70    double answer = 0.5*(v1b-v1a)*sumi;
71
72    // Normalize by Pi (Eqn. 16).
73    // The term (ABC)^2 does not appear because it was introduced before on
74    // the definitions of termA, termB, termC.
75    // The factor 2 appears because the theta integral has been defined between
76    // 0 and pi/2, instead of 0 to pi.
77    answer /= M_PI_2; //Form factor P(q)
78
79    // Multiply by contrast^2 and volume^2
80    answer *= (sld-solvent_sld)*(sld-solvent_sld)*volume*volume;
81
82    // Convert from [1e-12 A-1] to [cm-1]
83    answer *= 1.0e-4;
84
85    return answer;
86   
87}
Note: See TracBrowser for help on using the repository browser.