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

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

update oriented models to new interface (which will be in the next commit)

  • Property mode set to 100644
File size: 7.0 KB
Line 
1static double
2form_volume(double length_a, double length_b, double length_c,
3    double thick_rim_a, double thick_rim_b, double thick_rim_c)
4{
5    //return length_a * length_b * length_c;
6    return length_a * length_b * length_c +
7           2.0 * thick_rim_a * length_b * length_c +
8           2.0 * thick_rim_b * length_a * length_c +
9           2.0 * thick_rim_c * length_a * length_b;
10}
11
12static double
13Iq(double q,
14    double core_sld,
15    double arim_sld,
16    double brim_sld,
17    double crim_sld,
18    double solvent_sld,
19    double length_a,
20    double length_b,
21    double length_c,
22    double thick_rim_a,
23    double thick_rim_b,
24    double thick_rim_c)
25{
26    // Code converted from functions CSPPKernel and CSParallelepiped in libCylinder.c_scaled
27    // Did not understand the code completely, it should be rechecked (Miguel Gonzalez)
28
29    const double mu = 0.5 * q * length_b;
30
31    //calculate volume before rescaling (in original code, but not used)
32    //double vol = form_volume(length_a, length_b, length_c, thick_rim_a, thick_rim_b, thick_rim_c);
33    //double vol = length_a * length_b * length_c +
34    //       2.0 * thick_rim_a * length_b * length_c +
35    //       2.0 * thick_rim_b * length_a * length_c +
36    //       2.0 * thick_rim_c * length_a * length_b;
37
38    // Scale sides by B
39    const double a_scaled = length_a / length_b;
40    const double c_scaled = length_c / length_b;
41
42    // ta and tb correspond to the definitions in CSPPKernel, but they don't make sense to me (MG)
43    // the a_scaled in the definition of tb was present in CSPPKernel in libCylinder.c,
44    // while in cspkernel in csparallelepiped.cpp (used for the 2D), all the definitions
45    // for ta, tb, tc use also A + 2*rim_thickness (but not scaled by B!!!)
46    double ta = (a_scaled + 2.0*thick_rim_a)/length_b;
47    double tb = (a_scaled + 2.0*thick_rim_b)/length_b;
48
49    double Vin = length_a * length_b * length_c;
50    //double Vot = (length_a * length_b * length_c +
51    //            2.0 * thick_rim_a * length_b * length_c +
52    //            2.0 * length_a * thick_rim_b * length_c +
53    //            2.0 * length_a * length_b * thick_rim_c);
54    double V1 = (2.0 * thick_rim_a * length_b * length_c);    // incorrect V1 (aa*bb*cc+2*ta*bb*cc)
55    double V2 = (2.0 * length_a * thick_rim_b * length_c);    // incorrect V2(aa*bb*cc+2*aa*tb*cc)
56
57    // Scale factors (note that drC is not used later)
58    const double drho0 = (core_sld-solvent_sld);
59    const double drhoA = (arim_sld-solvent_sld);
60    const double drhoB = (brim_sld-solvent_sld);
61    //const double drC_Vot = (crim_sld-solvent_sld)*Vot;
62
63    // Precompute scale factors for combining cross terms from the shape
64    const double scale23 = drhoA*V1;
65    const double scale14 = drhoB*V2;
66    const double scale12 = drho0*Vin - scale23 - scale14;
67
68    // outer integral (with gauss points), integration limits = 0, 1
69    double outer_total = 0; //initialize integral
70
71    for( int i=0; i<76; i++) {
72        double sigma = 0.5 * ( Gauss76Z[i] + 1.0 );
73        double mu_proj = mu * sqrt(1.0-sigma*sigma);
74
75        // inner integral (with gauss points), integration limits = 0, 1
76        double inner_total = 0.0;
77        for(int j=0; j<76; j++) {
78            const double uu = 0.5 * ( Gauss76Z[j] + 1.0 );
79            double sin_uu, cos_uu;
80            SINCOS(M_PI_2*uu, sin_uu, cos_uu);
81            const double si1 = sas_sinx_x(mu_proj * sin_uu * a_scaled);
82            const double si2 = sas_sinx_x(mu_proj * cos_uu);
83            const double si3 = sas_sinx_x(mu_proj * sin_uu * ta);
84            const double si4 = sas_sinx_x(mu_proj * cos_uu * tb);
85
86            // Expression in libCylinder.c (neither drC nor Vot are used)
87            const double form = scale12*si1*si2 + scale23*si2*si3 + scale14*si1*si4;
88
89            // To note also that in csparallelepiped.cpp, there is a function called
90            // cspkernel, which seems to make more sense and has the following comment:
91            //   This expression is different from NIST/IGOR package (I strongly believe the IGOR is wrong!!!). 10/15/2010.
92            //   tmp =( dr0*tmp1*tmp2*tmp3*Vin + drA*(tmpt1-tmp1)*tmp2*tmp3*V1+ drB*tmp1*(tmpt2-tmp2)*tmp3*V2 + drC*tmp1*tmp2*(tmpt3-tmp3)*V3)*
93            //   ( dr0*tmp1*tmp2*tmp3*Vin + drA*(tmpt1-tmp1)*tmp2*tmp3*V1+ drB*tmp1*(tmpt2-tmp2)*tmp3*V2 + drC*tmp1*tmp2*(tmpt3-tmp3)*V3);   //  correct FF : square of sum of phase factors
94            // This is the function called by csparallelepiped_analytical_2D_scaled,
95            // while CSParallelepipedModel calls CSParallelepiped in libCylinder.c
96
97            //  correct FF : sum of square of phase factors
98            inner_total += Gauss76Wt[j] * form * form;
99        }
100        inner_total *= 0.5;
101
102        // now sum up the outer integral
103        const double si = sas_sinx_x(mu * c_scaled * sigma);
104        outer_total += Gauss76Wt[i] * inner_total * si * si;
105    }
106    outer_total *= 0.5;
107
108    //convert from [1e-12 A-1] to [cm-1]
109    return 1.0e-4 * outer_total;
110}
111
112static double
113Iqxy(double qa, double qb, double qc,
114    double core_sld,
115    double arim_sld,
116    double brim_sld,
117    double crim_sld,
118    double solvent_sld,
119    double length_a,
120    double length_b,
121    double length_c,
122    double thick_rim_a,
123    double thick_rim_b,
124    double thick_rim_c)
125{
126    // cspkernel in csparallelepiped recoded here
127    const double dr0 = core_sld-solvent_sld;
128    const double drA = arim_sld-solvent_sld;
129    const double drB = brim_sld-solvent_sld;
130    const double drC = crim_sld-solvent_sld;
131
132    double Vin = length_a * length_b * length_c;
133    double V1 = 2.0 * thick_rim_a * length_b * length_c;    // incorrect V1(aa*bb*cc+2*ta*bb*cc)
134    double V2 = 2.0 * length_a * thick_rim_b * length_c;    // incorrect V2(aa*bb*cc+2*aa*tb*cc)
135    double V3 = 2.0 * length_a * length_b * thick_rim_c;
136    // As for the 1D case, Vot is not used
137    //double Vot = (length_a * length_b * length_c +
138    //              2.0 * thick_rim_a * length_b * length_c +
139    //              2.0 * length_a * thick_rim_b * length_c +
140    //              2.0 * length_a * length_b * thick_rim_c);
141
142    // The definitions of ta, tb, tc are not the same as in the 1D case because there is no
143    // the scaling by B. The use of length_a for the 3 of them seems clearly a mistake to me,
144    // but for the moment I let it like this until understanding better the code.
145    double ta = length_a + 2.0*thick_rim_a;
146    double tb = length_a + 2.0*thick_rim_b;
147    double tc = length_a + 2.0*thick_rim_c;
148    //handle arg=0 separately, as sin(t)/t -> 1 as t->0
149    double siA = sas_sinx_x(0.5*length_a*qa);
150    double siB = sas_sinx_x(0.5*length_b*qb);
151    double siC = sas_sinx_x(0.5*length_c*qc);
152    double siAt = sas_sinx_x(0.5*ta*qa);
153    double siBt = sas_sinx_x(0.5*tb*qb);
154    double siCt = sas_sinx_x(0.5*tc*qc);
155
156
157    // f uses Vin, V1, V2, and V3 and it seems to have more sense than the value computed
158    // in the 1D code, but should be checked!
159    double f = ( dr0*siA*siB*siC*Vin
160               + drA*(siAt-siA)*siB*siC*V1
161               + drB*siA*(siBt-siB)*siC*V2
162               + drC*siA*siB*(siCt*siCt-siC)*V3);
163
164    return 1.0e-4 * f * f;
165}
Note: See TracBrowser for help on using the repository browser.