source: sasmodels/sasmodels/models/sc_paracrystal.c @ 6530963

ticket_1156
Last change on this file since 6530963 was 6530963, checked in by ajj, 6 years ago

Updating paracrystal models as per ticket #1156 to rename parameters
from nearest neighbour to lattice spacing

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[2a0b2b1]1static double
[6530963]2sc_Zq(double qa, double qb, double qc, double lattice_spacing, double lattice_distortion)
[9aac25d]3{
[f728001]4    // Equations from Matsuoka 9-10-11, multiplied by |q|
[2a0b2b1]5    const double a1 = qa;
6    const double a2 = qb;
7    const double a3 = qc;
8
[f728001]9    // Matsuoka 13-14-15
10    //     Z_k numerator: 1 - exp(a)^2
11    //     Z_k denominator: 1 - 2 cos(d a_k) exp(a) + exp(2a)
12    // Rewriting numerator
13    //         => -(exp(2a) - 1)
14    //         => -expm1(2a)
15    // Rewriting denominator
16    //         => exp(a)^2 - 2 cos(d ak) exp(a) + 1)
17    //         => (exp(a) - 2 cos(d ak)) * exp(a) + 1
[6530963]18    const double arg = -0.5*square(lattice_spacing*lattice_distortion)*(a1*a1 + a2*a2 + a3*a3);
[7e0b281]19    const double exp_arg = exp(arg);
20    const double Zq = -cube(expm1(2.0*arg))
[6530963]21        / ( ((exp_arg - 2.0*cos(lattice_spacing*a1))*exp_arg + 1.0)
22          * ((exp_arg - 2.0*cos(lattice_spacing*a2))*exp_arg + 1.0)
23          * ((exp_arg - 2.0*cos(lattice_spacing*a3))*exp_arg + 1.0));
[2a0b2b1]24
[7e0b281]25    return Zq;
[9aac25d]26}
27
[2a0b2b1]28// occupied volume fraction calculated from lattice symmetry and sphere radius
[9aac25d]29static double
[6530963]30sc_volume_fraction(double radius, double lattice_spacing)
[9aac25d]31{
[6530963]32    return sphere_volume(radius/lattice_spacing);
[9aac25d]33}
34
35static double
[2a0b2b1]36form_volume(double radius)
[9aac25d]37{
[2a0b2b1]38    return sphere_volume(radius);
[9aac25d]39}
40
41
[becded3]42static double
[6530963]43Iq(double q, double lattice_spacing,
44    double lattice_distortion, double radius,
[becded3]45    double sld, double solvent_sld)
[2a0b2b1]46{
47    // translate a point in [-1,1] to a point in [0, 2 pi]
48    const double phi_m = M_PI_4;
49    const double phi_b = M_PI_4;
50    // translate a point in [-1,1] to a point in [0, pi]
51    const double theta_m = M_PI_4;
52    const double theta_b = M_PI_4;
53
54
55    double outer_sum = 0.0;
[74768cb]56    for(int i=0; i<GAUSS_N; i++) {
[2a0b2b1]57        double inner_sum = 0.0;
[74768cb]58        const double theta = GAUSS_Z[i]*theta_m + theta_b;
[2a0b2b1]59        double sin_theta, cos_theta;
60        SINCOS(theta, sin_theta, cos_theta);
61        const double qc = q*cos_theta;
62        const double qab = q*sin_theta;
[74768cb]63        for(int j=0;j<GAUSS_N;j++) {
64            const double phi = GAUSS_Z[j]*phi_m + phi_b;
[2a0b2b1]65            double sin_phi, cos_phi;
66            SINCOS(phi, sin_phi, cos_phi);
67            const double qa = qab*cos_phi;
68            const double qb = qab*sin_phi;
[6530963]69            const double form = sc_Zq(qa, qb, qc, lattice_spacing, lattice_distortion);
[74768cb]70            inner_sum += GAUSS_W[j] * form;
[2a0b2b1]71        }
72        inner_sum *= phi_m;  // sum(f(x)dx) = sum(f(x)) dx
[74768cb]73        outer_sum += GAUSS_W[i] * inner_sum * sin_theta;
[2a0b2b1]74    }
75    outer_sum *= theta_m;
[7e0b281]76    const double Zq = outer_sum/M_PI_2;
[2a0b2b1]77    const double Pq = sphere_form(q, radius, sld, solvent_sld);
78
[6530963]79    return sc_volume_fraction(radius, lattice_spacing) * Pq * Zq;
[9aac25d]80}
81
[2a0b2b1]82
[becded3]83static double
[108e70e]84Iqabc(double qa, double qb, double qc,
[6530963]85    double lattice_spacing, double lattice_distortion, double radius,
[becded3]86    double sld, double solvent_sld)
[9aac25d]87{
[becded3]88    const double q = sqrt(qa*qa + qb*qb + qc*qc);
[2a0b2b1]89    const double Pq = sphere_form(q, radius, sld, solvent_sld);
[6530963]90    const double Zq = sc_Zq(qa, qb, qc, lattice_spacing, lattice_distortion);
91    return sc_volume_fraction(radius, lattice_spacing) * Pq * Zq;
92}
Note: See TracBrowser for help on using the repository browser.