source: sasmodels/sasmodels/models/hollow_rectangular_prism_thin_walls.c @ 3a48772

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 3a48772 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.6 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    double b_side = length_a * b2a_ratio;
8    double c_side = length_a * c2a_ratio;
9    double vol_shell = 2.0 * (length_a*b_side + length_a*c_side + b_side*c_side);
10    return vol_shell;
11}
12
13double Iq(double q,
14    double sld,
15    double solvent_sld,
16    double length_a,
17    double b2a_ratio,
18    double c2a_ratio)
19{
20    double b_side = length_a * b2a_ratio;
21    double c_side = length_a * c2a_ratio;
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        // To check potential problems if denominator goes to zero here !!!
43        double termAL_theta = 8.0*cos(q*c_half*cos(theta)) / (q*q*sin(theta)*sin(theta));
44        double termAT_theta = 8.0*sin(q*c_half*cos(theta)) / (q*q*sin(theta)*cos(theta));
45
46            double sumj = 0.0;
47       
48            for(int j=0; j<nordj; j++) {
49
50            double phi = 0.5 * ( Gauss76Z[j]*(v2b-v2a) + v2a + v2b ); 
51           
52            // Amplitude AL from eqn. (7c)
53            double AL = termAL_theta * sin(q*a_half*sin(theta)*sin(phi)) * 
54                sin(q*b_half*sin(theta)*cos(phi)) / (sin(phi)*cos(phi));
55
56            // Amplitude AT from eqn. (9)
57            double AT = termAT_theta * (  (cos(q*a_half*sin(theta)*sin(phi))*sin(q*b_half*sin(theta)*cos(phi))/cos(phi)) 
58                + (cos(q*b_half*sin(theta)*cos(phi))*sin(q*a_half*sin(theta)*sin(phi))/sin(phi)) );
59
60            sumj += Gauss76Wt[j] * (AL+AT)*(AL+AT);
61
62            }
63
64            sumj = 0.5 * (v2b-v2a) * sumj;
65            sumi += Gauss76Wt[i] * sumj * sin(theta);
66
67    }
68
69    double answer = 0.5*(v1b-v1a)*sumi;
70
71    // Normalize as in Eqn. (15) without the volume factor (as cancels with (V*DelRho)^2 normalization)
72    // The factor 2 is due to the different theta integration limit (pi/2 instead of pi)
73    answer /= M_PI_2;
74
75    // Multiply by contrast^2. Factor corresponding to volume^2 cancels with previous normalization.
76    answer *= (sld-solvent_sld)*(sld-solvent_sld);
77
78    // Convert from [1e-12 A-1] to [cm-1]
79    answer *= 1.0e-4;
80
81    return answer;
82   
83}
Note: See TracBrowser for help on using the repository browser.