source: sasmodels/sasmodels/models/core_shell_parallelepiped.c @ a94046f

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since a94046f was a94046f, checked in by richardh, 6 years ago

some corrections to R_eff options

  • Property mode set to 100644
File size: 7.5 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_paral = form_volume(length_a, length_b, length_c, thick_rim_a, thick_rim_b, thick_rim_c);
34    return cbrt(0.75*volume_paral/M_PI);
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//effective_radius_type = ["equivalent sphere","half outer length_a", "half outer length_b", "half outer length_c",
48//                         "equivalent circular cross-section","half outer ab diagonal","half outer diagonal"]
49// note the core box is A*B*C with slabs ta, tb & tc on each face but missing the corners, though that fact is ignored here
50// in the equvalent sphere option
51{
52    if (mode == 1) {
53        return radius_from_volume(length_a, length_b, length_c, thick_rim_a, thick_rim_b, thick_rim_c);
54    } else if (mode == 2) {
55        return 0.5 * length_a + thick_rim_a;
56    } else if (mode == 3) {
57        return 0.5 * length_b + thick_rim_b;
58    } else if (mode == 4) {
59        return 0.5 * length_c + thick_rim_c;
60    } else if (mode == 5) {
61        return radius_from_crosssection(length_a, length_b, thick_rim_a, thick_rim_b);
62    } else if (mode == 6) {
63        return 0.5*sqrt(square(length_a+ 2.0*thick_rim_a) + square(length_b+ 2.0*thick_rim_b));
64    } else {
65        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));
66    }
67}
68
69static void
70Fq(double q,
71    double *F1,
72    double *F2,
73    double core_sld,
74    double arim_sld,
75    double brim_sld,
76    double crim_sld,
77    double solvent_sld,
78    double length_a,
79    double length_b,
80    double length_c,
81    double thick_rim_a,
82    double thick_rim_b,
83    double thick_rim_c)
84{
85    // Code converted from functions CSPPKernel and CSParallelepiped in libCylinder.c
86    // Did not understand the code completely, it should be rechecked (Miguel Gonzalez)
87    // Code is rewritten, the code is compliant with Diva Singh's thesis now (Dirk Honecker)
88    // Code rewritten; cross checked against hollow rectangular prism and realspace (PAK)
89
90    const double half_q = 0.5*q;
91
92    const double tA = length_a + 2.0*thick_rim_a;
93    const double tB = length_b + 2.0*thick_rim_b;
94    const double tC = length_c + 2.0*thick_rim_c;
95
96    // Scale factors
97    const double dr0 = (core_sld-solvent_sld);
98    const double drA = (arim_sld-solvent_sld);
99    const double drB = (brim_sld-solvent_sld);
100    const double drC = (crim_sld-solvent_sld);
101
102    // outer integral (with gauss points), integration limits = 0, 1
103    // substitute d_cos_alpha for sin_alpha d_alpha
104    double outer_sum_F1 = 0; //initialize integral
105    double outer_sum_F2 = 0; //initialize integral
106    for( int i=0; i<GAUSS_N; i++) {
107        const double cos_alpha = 0.5 * ( GAUSS_Z[i] + 1.0 );
108        const double mu = half_q * sqrt(1.0-cos_alpha*cos_alpha);
109        const double siC = length_c * sas_sinx_x(length_c * cos_alpha * half_q);
110        const double siCt = tC * sas_sinx_x(tC * cos_alpha * half_q);
111
112        // inner integral (with gauss points), integration limits = 0, 1
113        // substitute beta = PI/2 u (so 2/PI * d_(PI/2 * beta) = d_beta)
114        double inner_sum_F1 = 0.0;
115        double inner_sum_F2 = 0.0;
116        for(int j=0; j<GAUSS_N; j++) {
117            const double u = 0.5 * ( GAUSS_Z[j] + 1.0 );
118            double sin_beta, cos_beta;
119            SINCOS(M_PI_2*u, sin_beta, cos_beta);
120            const double siA = length_a * sas_sinx_x(length_a * mu * sin_beta);
121            const double siB = length_b * sas_sinx_x(length_b * mu * cos_beta);
122            const double siAt = tA * sas_sinx_x(tA * mu * sin_beta);
123            const double siBt = tB * sas_sinx_x(tB * mu * cos_beta);
124
125#if OVERLAPPING
126            const double f = dr0*siA*siB*siC
127                + drA*(siAt-siA)*siB*siC
128                + drB*siAt*(siBt-siB)*siC
129                + drC*siAt*siBt*(siCt-siC);
130#else
131            const double f = dr0*siA*siB*siC
132                + drA*(siAt-siA)*siB*siC
133                + drB*siA*(siBt-siB)*siC
134                + drC*siA*siB*(siCt-siC);
135#endif
136
137            inner_sum_F1 += GAUSS_W[j] * f;
138            inner_sum_F2 += GAUSS_W[j] * f * f;
139        }
140        // now complete change of inner integration variable (1-0)/(1-(-1))= 0.5
141        // and sum up the outer integral
142        outer_sum_F1 += GAUSS_W[i] * inner_sum_F1 * 0.5;
143        outer_sum_F2 += GAUSS_W[i] * inner_sum_F2 * 0.5;
144    }
145    // now complete change of outer integration variable (1-0)/(1-(-1))= 0.5
146    outer_sum_F1 *= 0.5;
147    outer_sum_F2 *= 0.5;
148
149    //convert from [1e-12 A-1] to [cm-1]
150    *F1 = 1.0e-2 * outer_sum_F1;
151    *F2 = 1.0e-4 * outer_sum_F2;
152}
153
154static double
155Iqabc(double qa, double qb, double qc,
156    double core_sld,
157    double arim_sld,
158    double brim_sld,
159    double crim_sld,
160    double solvent_sld,
161    double length_a,
162    double length_b,
163    double length_c,
164    double thick_rim_a,
165    double thick_rim_b,
166    double thick_rim_c)
167{
168    // cspkernel in csparallelepiped recoded here
169    const double dr0 = core_sld-solvent_sld;
170    const double drA = arim_sld-solvent_sld;
171    const double drB = brim_sld-solvent_sld;
172    const double drC = crim_sld-solvent_sld;
173
174    const double tA = length_a + 2.0*thick_rim_a;
175    const double tB = length_b + 2.0*thick_rim_b;
176    const double tC = length_c + 2.0*thick_rim_c;
177    const double siA = length_a*sas_sinx_x(0.5*length_a*qa);
178    const double siB = length_b*sas_sinx_x(0.5*length_b*qb);
179    const double siC = length_c*sas_sinx_x(0.5*length_c*qc);
180    const double siAt = tA*sas_sinx_x(0.5*tA*qa);
181    const double siBt = tB*sas_sinx_x(0.5*tB*qb);
182    const double siCt = tC*sas_sinx_x(0.5*tC*qc);
183
184#if OVERLAPPING
185    const double f = dr0*siA*siB*siC
186        + drA*(siAt-siA)*siB*siC
187        + drB*siAt*(siBt-siB)*siC
188        + drC*siAt*siBt*(siCt-siC);
189#else
190    const double f = dr0*siA*siB*siC
191        + drA*(siAt-siA)*siB*siC
192        + drB*siA*(siBt-siB)*siC
193        + drC*siA*siB*(siCt-siC);
194#endif
195
196    return 1.0e-4 * f * f;
197}
Note: See TracBrowser for help on using the repository browser.