source: sasmodels/sasmodels/models/hollow_rectangular_prism.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: 3.3 KB
Line 
1double form_volume(double length_a, double b2a_ratio, double c2a_ratio, double thickness);
2double Iq(double q, double sld, double solvent_sld, double length_a, 
3          double b2a_ratio, double c2a_ratio, double thickness);
4
5double form_volume(double length_a, double b2a_ratio, double c2a_ratio, double thickness)
6{
7    double b_side = length_a * b2a_ratio;
8    double c_side = length_a * c2a_ratio;
9    double a_core = length_a - 2.0*thickness;
10    double b_core = b_side - 2.0*thickness;
11    double c_core = c_side - 2.0*thickness;
12    double vol_core = a_core * b_core * c_core;
13    double vol_total = length_a * b_side * c_side;
14    double vol_shell = vol_total - vol_core;
15    return vol_shell;
16}
17
18double Iq(double q,
19    double sld,
20    double solvent_sld,
21    double length_a,
22    double b2a_ratio,
23    double c2a_ratio,
24    double thickness)
25{
26    double termA1, termA2, termB1, termB2, termC1, termC2;
27   
28    double b_side = length_a * b2a_ratio;
29    double c_side = length_a * c2a_ratio;
30    double a_half = 0.5 * length_a;
31    double b_half = 0.5 * b_side;
32    double c_half = 0.5 * c_side;
33
34   //Integration limits to use in Gaussian quadrature
35    double v1a = 0.0;
36    double v1b = M_PI_2;  //theta integration limits
37    double v2a = 0.0;
38    double v2b = M_PI_2;  //phi integration limits
39   
40    //Order of integration
41    int nordi=76;                               
42    int nordj=76;
43
44    double sumi = 0.0;
45   
46    for(int i=0; i<nordi; i++) {
47
48            double theta = 0.5 * ( Gauss76Z[i]*(v1b-v1a) + v1a + v1b ); 
49
50            double arg = q * c_half * cos(theta);
51            if (fabs(arg) > 1.e-16) {termC1 = sin(arg)/arg;} else {termC1 = 1.0;}
52            arg = q * (c_half-thickness)*cos(theta);
53            if (fabs(arg) > 1.e-16) {termC2 = sin(arg)/arg;} else {termC2 = 1.0;}
54
55            double sumj = 0.0;
56       
57            for(int j=0; j<nordj; j++) {
58
59            double phi = 0.5 * ( Gauss76Z[j]*(v2b-v2a) + v2a + v2b ); 
60
61            // Amplitude AP from eqn. (13), rewritten to avoid round-off effects when arg=0
62
63                arg = q * a_half * sin(theta) * sin(phi);
64                if (fabs(arg) > 1.e-16) {termA1 = sin(arg)/arg;} else {termA1 = 1.0;}
65                arg = q * (a_half-thickness) * sin(theta) * sin(phi);
66                if (fabs(arg) > 1.e-16) {termA2 = sin(arg)/arg;} else {termA2 = 1.0;}
67
68                arg = q * b_half * sin(theta) * cos(phi);
69                if (fabs(arg) > 1.e-16) {termB1 = sin(arg)/arg;} else {termB1 = 1.0;}
70                arg = q * (b_half-thickness) * sin(theta) * cos(phi);
71                if (fabs(arg) > 1.e-16) {termB2 = sin(arg)/arg;} else {termB2 = 1.0;}
72
73            double AP1 = (length_a*b_side*c_side) * termA1 * termB1 * termC1;
74            double AP2 = 8.0 * (a_half-thickness) * (b_half-thickness) * (c_half-thickness) * termA2 * termB2 * termC2;
75            double AP = AP1 - AP2;
76
77                sumj += Gauss76Wt[j] * (AP*AP);
78
79            }
80
81            sumj = 0.5 * (v2b-v2a) * sumj;
82            sumi += Gauss76Wt[i] * sumj * sin(theta);
83
84    }
85
86    double answer = 0.5*(v1b-v1a)*sumi;
87
88    // Normalize as in Eqn. (15) without the volume factor (as cancels with (V*DelRho)^2 normalization)
89    // The factor 2 is due to the different theta integration limit (pi/2 instead of pi)
90    answer /= M_PI_2;
91
92    // Multiply by contrast^2. Factor corresponding to volume^2 cancels with previous normalization.
93    answer *= (sld-solvent_sld)*(sld-solvent_sld);
94
95    // Convert from [1e-12 A-1] to [cm-1]
96    answer *= 1.0e-4;
97
98    return answer;
99   
100}
Note: See TracBrowser for help on using the repository browser.