source: sasmodels/sasmodels/models/fcc_paracrystal.c @ 2a0b2b1

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

restructure all 2D models to work with (qa,qb,qc) = rotate(qx,qy) rather than working with angles directly in preparation for revised jitter algorithm

  • Property mode set to 100644
File size: 3.1 KB
Line 
1static double
2_sq_fcc(double qa, double qb, double qc, double dnn, double d_factor)
3{
4    // Rewriting equations for efficiency, accuracy and readability, and so
5    // code is reusable between 1D and 2D models.
6    const double a1 = qb + qa;
7    const double a2 = qa + qc;
8    const double a3 = qb + qc;
9
10    const double half_dnn = 0.5*dnn;
11    const double arg = 0.5*square(half_dnn*d_factor)*(a1*a1 + a2*a2 + a3*a3);
12
13    // Numerator: (1 - exp(a)^2)^3
14    //         => (-(exp(2a) - 1))^3
15    //         => -expm1(2a)^3
16    // Denominator: prod(1 - 2 cos(xk) exp(a) + exp(a)^2)
17    //         => exp(a)^2 - 2 cos(xk) exp(a) + 1
18    //         => (exp(a) - 2 cos(xk)) * exp(a) + 1
19    const double exp_arg = exp(-arg);
20    const double Sq = -cube(expm1(-2.0*arg))
21        / ( ((exp_arg - 2.0*cos(half_dnn*a1))*exp_arg + 1.0)
22          * ((exp_arg - 2.0*cos(half_dnn*a2))*exp_arg + 1.0)
23          * ((exp_arg - 2.0*cos(half_dnn*a3))*exp_arg + 1.0));
24
25    return Sq;
26}
27
28
29// occupied volume fraction calculated from lattice symmetry and sphere radius
30static double
31_fcc_volume_fraction(double radius, double dnn)
32{
33    return 4.0*sphere_volume(M_SQRT1_2*radius/dnn);
34}
35
36static double
37form_volume(double radius)
38{
39    return sphere_volume(radius);
40}
41
42
43static double Iq(double q, double dnn,
44  double d_factor, double radius,
45  double sld, double solvent_sld)
46{
47    // translate a point in [-1,1] to a point in [0, 2 pi]
48    const double phi_m = M_PI;
49    const double phi_b = M_PI;
50    // translate a point in [-1,1] to a point in [0, pi]
51    const double theta_m = M_PI_2;
52    const double theta_b = M_PI_2;
53
54    double outer_sum = 0.0;
55    for(int i=0; i<150; i++) {
56        double inner_sum = 0.0;
57        const double theta = Gauss150Z[i]*theta_m + theta_b;
58        double sin_theta, cos_theta;
59        SINCOS(theta, sin_theta, cos_theta);
60        const double qc = q*cos_theta;
61        const double qab = q*sin_theta;
62        for(int j=0;j<150;j++) {
63            const double phi = Gauss150Z[j]*phi_m + phi_b;
64            double sin_phi, cos_phi;
65            SINCOS(phi, sin_phi, cos_phi);
66            const double qa = qab*cos_phi;
67            const double qb = qab*sin_phi;
68            const double fq = _sq_fcc(qa, qb, qc, dnn, d_factor);
69            inner_sum += Gauss150Wt[j] * fq;
70        }
71        inner_sum *= phi_m;  // sum(f(x)dx) = sum(f(x)) dx
72        outer_sum += Gauss150Wt[i] * inner_sum * sin_theta;
73    }
74    outer_sum *= theta_m;
75    const double Sq = outer_sum/(4.0*M_PI);
76    const double Pq = sphere_form(q, radius, sld, solvent_sld);
77
78    return _fcc_volume_fraction(radius, dnn) * Pq * Sq;
79}
80
81
82static double Iqxy(double qx, double qy,
83    double dnn, double d_factor, double radius,
84    double sld, double solvent_sld,
85    double theta, double phi, double psi)
86{
87    double q, zhat, yhat, xhat;
88    ORIENT_ASYMMETRIC(qx, qy, theta, phi, psi, q, xhat, yhat, zhat);
89    const double qa = q*xhat;
90    const double qb = q*yhat;
91    const double qc = q*zhat;
92
93    q = sqrt(qa*qa + qb*qb + qc*qc);
94    const double Pq = sphere_form(q, radius, sld, solvent_sld);
95    const double Sq = _sq_fcc(qa, qb, qc, dnn, d_factor);
96    return _fcc_volume_fraction(radius, dnn) * Pq * Sq;
97}
Note: See TracBrowser for help on using the repository browser.