source: sasmodels/sasmodels/models/core_shell_parallelepiped.c @ 12f4c19

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 12f4c19 was ee60aa7, checked in by Paul Kienzle <pkienzle@…>, 6 years ago

clean up effective radius functions; improve mono_gauss_coil accuracy; start moving VR into C

  • Property mode set to 100644
File size: 7.2 KB
Line 
1// Set OVERLAPPING to 1 in order to fill in the edges of the box, with
2// c endcaps and b overlapping a.  With the proper choice of parameters,
3// (setting rim slds to sld, core sld to solvent, rim thickness to thickness
4// and subtracting 2*thickness from length, this should match the hollow
5// rectangular prism.)  Set it to 0 for the documented behaviour.
6#define OVERLAPPING 0
7static double
8form_volume(double length_a, double length_b, double length_c,
9    double thick_rim_a, double thick_rim_b, double thick_rim_c)
10{
11    return
12#if OVERLAPPING
13        // Hollow rectangular prism only includes the volume of the shell
14        // so uncomment the next line when comparing.  Solid rectangular
15        // prism, or parallelepiped want filled cores, so comment when
16        // comparing.
17        //-length_a * length_b * length_c +
18        (length_a + 2.0*thick_rim_a) *
19        (length_b + 2.0*thick_rim_b) *
20        (length_c + 2.0*thick_rim_c);
21#else
22        length_a * length_b * length_c +
23        2.0 * thick_rim_a * length_b * length_c +
24        2.0 * length_a * thick_rim_b * length_c +
25        2.0 * length_a * length_b * thick_rim_c;
26#endif
27}
28
29static double
30radius_from_volume(double length_a, double length_b, double length_c,
31                   double thick_rim_a, double thick_rim_b, double thick_rim_c)
32{
33    const double volume = form_volume(length_a, length_b, length_c, thick_rim_a, thick_rim_b, thick_rim_c);
34    return cbrt(volume/M_4PI_3);
35}
36
37static double
38radius_from_crosssection(double length_a, double length_b, double thick_rim_a, double thick_rim_b)
39{
40    const double area_xsec_paral = length_a*length_b + 2.0*thick_rim_a*length_b + 2.0*thick_rim_b*length_a;
41    return sqrt(area_xsec_paral/M_PI);
42}
43
44static double
45effective_radius(int mode, double length_a, double length_b, double length_c,
46                 double thick_rim_a, double thick_rim_b, double thick_rim_c)
47{
48    switch (mode) {
49    case 1: // equivalent sphere
50        return radius_from_volume(length_a, length_b, length_c, thick_rim_a, thick_rim_b, thick_rim_c);
51    case 2: // half outer length a
52        return 0.5 * length_a + thick_rim_a;
53    case 3: // half outer length b
54        return 0.5 * length_b + thick_rim_b;
55    case 4: // half outer length c
56        return 0.5 * length_c + thick_rim_c;
57    case 5: // equivalent circular cross-section
58        return radius_from_crosssection(length_a, length_b, thick_rim_a, thick_rim_b);
59    case 6: // half outer ab diagonal
60        return 0.5*sqrt(square(length_a+ 2.0*thick_rim_a) + square(length_b+ 2.0*thick_rim_b));
61    case 7: // half outer diagonal
62        return 0.5*sqrt(square(length_a+ 2.0*thick_rim_a) + square(length_b+ 2.0*thick_rim_b) + square(length_c+ 2.0*thick_rim_c));
63    }
64}
65
66static void
67Fq(double q,
68    double *F1,
69    double *F2,
70    double core_sld,
71    double arim_sld,
72    double brim_sld,
73    double crim_sld,
74    double solvent_sld,
75    double length_a,
76    double length_b,
77    double length_c,
78    double thick_rim_a,
79    double thick_rim_b,
80    double thick_rim_c)
81{
82    // Code converted from functions CSPPKernel and CSParallelepiped in libCylinder.c
83    // Did not understand the code completely, it should be rechecked (Miguel Gonzalez)
84    // Code is rewritten, the code is compliant with Diva Singh's thesis now (Dirk Honecker)
85    // Code rewritten; cross checked against hollow rectangular prism and realspace (PAK)
86
87    const double half_q = 0.5*q;
88
89    const double tA = length_a + 2.0*thick_rim_a;
90    const double tB = length_b + 2.0*thick_rim_b;
91    const double tC = length_c + 2.0*thick_rim_c;
92
93    // Scale factors
94    const double dr0 = (core_sld-solvent_sld);
95    const double drA = (arim_sld-solvent_sld);
96    const double drB = (brim_sld-solvent_sld);
97    const double drC = (crim_sld-solvent_sld);
98
99    // outer integral (with gauss points), integration limits = 0, 1
100    // substitute d_cos_alpha for sin_alpha d_alpha
101    double outer_sum_F1 = 0; //initialize integral
102    double outer_sum_F2 = 0; //initialize integral
103    for( int i=0; i<GAUSS_N; i++) {
104        const double cos_alpha = 0.5 * ( GAUSS_Z[i] + 1.0 );
105        const double mu = half_q * sqrt(1.0-cos_alpha*cos_alpha);
106        const double siC = length_c * sas_sinx_x(length_c * cos_alpha * half_q);
107        const double siCt = tC * sas_sinx_x(tC * cos_alpha * half_q);
108
109        // inner integral (with gauss points), integration limits = 0, 1
110        // substitute beta = PI/2 u (so 2/PI * d_(PI/2 * beta) = d_beta)
111        double inner_sum_F1 = 0.0;
112        double inner_sum_F2 = 0.0;
113        for(int j=0; j<GAUSS_N; j++) {
114            const double u = 0.5 * ( GAUSS_Z[j] + 1.0 );
115            double sin_beta, cos_beta;
116            SINCOS(M_PI_2*u, sin_beta, cos_beta);
117            const double siA = length_a * sas_sinx_x(length_a * mu * sin_beta);
118            const double siB = length_b * sas_sinx_x(length_b * mu * cos_beta);
119            const double siAt = tA * sas_sinx_x(tA * mu * sin_beta);
120            const double siBt = tB * sas_sinx_x(tB * mu * cos_beta);
121
122#if OVERLAPPING
123            const double f = dr0*siA*siB*siC
124                + drA*(siAt-siA)*siB*siC
125                + drB*siAt*(siBt-siB)*siC
126                + drC*siAt*siBt*(siCt-siC);
127#else
128            const double f = dr0*siA*siB*siC
129                + drA*(siAt-siA)*siB*siC
130                + drB*siA*(siBt-siB)*siC
131                + drC*siA*siB*(siCt-siC);
132#endif
133
134            inner_sum_F1 += GAUSS_W[j] * f;
135            inner_sum_F2 += GAUSS_W[j] * f * f;
136        }
137        // now complete change of inner integration variable (1-0)/(1-(-1))= 0.5
138        // and sum up the outer integral
139        outer_sum_F1 += GAUSS_W[i] * inner_sum_F1 * 0.5;
140        outer_sum_F2 += GAUSS_W[i] * inner_sum_F2 * 0.5;
141    }
142    // now complete change of outer integration variable (1-0)/(1-(-1))= 0.5
143    outer_sum_F1 *= 0.5;
144    outer_sum_F2 *= 0.5;
145
146    //convert from [1e-12 A-1] to [cm-1]
147    *F1 = 1.0e-2 * outer_sum_F1;
148    *F2 = 1.0e-4 * outer_sum_F2;
149}
150
151static double
152Iqabc(double qa, double qb, double qc,
153    double core_sld,
154    double arim_sld,
155    double brim_sld,
156    double crim_sld,
157    double solvent_sld,
158    double length_a,
159    double length_b,
160    double length_c,
161    double thick_rim_a,
162    double thick_rim_b,
163    double thick_rim_c)
164{
165    // cspkernel in csparallelepiped recoded here
166    const double dr0 = core_sld-solvent_sld;
167    const double drA = arim_sld-solvent_sld;
168    const double drB = brim_sld-solvent_sld;
169    const double drC = crim_sld-solvent_sld;
170
171    const double tA = length_a + 2.0*thick_rim_a;
172    const double tB = length_b + 2.0*thick_rim_b;
173    const double tC = length_c + 2.0*thick_rim_c;
174    const double siA = length_a*sas_sinx_x(0.5*length_a*qa);
175    const double siB = length_b*sas_sinx_x(0.5*length_b*qb);
176    const double siC = length_c*sas_sinx_x(0.5*length_c*qc);
177    const double siAt = tA*sas_sinx_x(0.5*tA*qa);
178    const double siBt = tB*sas_sinx_x(0.5*tB*qb);
179    const double siCt = tC*sas_sinx_x(0.5*tC*qc);
180
181#if OVERLAPPING
182    const double f = dr0*siA*siB*siC
183        + drA*(siAt-siA)*siB*siC
184        + drB*siAt*(siBt-siB)*siC
185        + drC*siAt*siBt*(siCt-siC);
186#else
187    const double f = dr0*siA*siB*siC
188        + drA*(siAt-siA)*siB*siC
189        + drB*siA*(siBt-siB)*siC
190        + drC*siA*siB*(siCt-siC);
191#endif
192
193    return 1.0e-4 * f * f;
194}
Note: See TracBrowser for help on using the repository browser.