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

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since a807206 was a807206, checked in by butler, 7 years ago

updating more parameter names addressing #649

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