source: sasmodels/sasmodels/models/hollow_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@…>, 8 years ago

code cleanup for rectangular prism models

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