source: sasmodels/sasmodels/models/parallelepiped.c @ ee60aa7

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since ee60aa7 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: 3.4 KB
RevLine 
[becded3]1static double
2form_volume(double length_a, double length_b, double length_c)
[c5b7d07]3{
[a807206]4    return length_a * length_b * length_c;
[c5b7d07]5}
6
[d277229]7static double
8effective_radius(int mode, double length_a, double length_b, double length_c)
9{
[ee60aa7]10    switch (mode) {
11    case 1: // equivalent sphere
[d277229]12        return cbrt(0.75*length_a*length_b*length_c/M_PI);
[ee60aa7]13    case 2: // half length_a
[d277229]14        return 0.5 * length_a;
[ee60aa7]15    case 3: // half length_b
[d277229]16        return 0.5 * length_b;
[ee60aa7]17    case 4: // half length_c
[d277229]18        return 0.5 * length_c;
[ee60aa7]19    case 5: // equivalent circular cross-section
[d277229]20        return sqrt(length_a*length_b/M_PI);
[ee60aa7]21    case 6: // half ab diagonal
[d277229]22        return 0.5*sqrt(length_a*length_a + length_b*length_b);
[ee60aa7]23    case 7: // half diagonal
[d277229]24        return 0.5*sqrt(length_a*length_a + length_b*length_b + length_c*length_c);
25    }
26}
27
[71b751d]28static void
29Fq(double q,
30    double *F1,
31    double *F2,
[c5b7d07]32    double sld,
33    double solvent_sld,
[a807206]34    double length_a,
35    double length_b,
36    double length_c)
[c5b7d07]37{
[14838a3]38    const double mu = 0.5 * q * length_b;
[2a0b2b1]39
[c5b7d07]40    // Scale sides by B
[14838a3]41    const double a_scaled = length_a / length_b;
42    const double c_scaled = length_c / length_b;
[2a0b2b1]43
[14838a3]44    // outer integral (with gauss points), integration limits = 0, 1
[71b751d]45    double outer_total_F1 = 0.0; //initialize integral
46    double outer_total_F2 = 0.0; //initialize integral
[74768cb]47    for( int i=0; i<GAUSS_N; i++) {
48        const double sigma = 0.5 * ( GAUSS_Z[i] + 1.0 );
[14838a3]49        const double mu_proj = mu * sqrt(1.0-sigma*sigma);
50
51        // inner integral (with gauss points), integration limits = 0, 1
52        // corresponding to angles from 0 to pi/2.
[71b751d]53        double inner_total_F1 = 0.0;
54        double inner_total_F2 = 0.0;
[74768cb]55        for(int j=0; j<GAUSS_N; j++) {
56            const double uu = 0.5 * ( GAUSS_Z[j] + 1.0 );
[14838a3]57            double sin_uu, cos_uu;
58            SINCOS(M_PI_2*uu, sin_uu, cos_uu);
[1e7b0db0]59            const double si1 = sas_sinx_x(mu_proj * sin_uu * a_scaled);
60            const double si2 = sas_sinx_x(mu_proj * cos_uu);
[71b751d]61            const double fq = si1 * si2;
62            inner_total_F1 += GAUSS_W[j] * fq;
63            inner_total_F2 += GAUSS_W[j] * fq * fq;
[c5b7d07]64        }
[dbf1a60]65        // now complete change of inner integration variable (1-0)/(1-(-1))= 0.5
[71b751d]66        inner_total_F1 *= 0.5;
67        inner_total_F2 *= 0.5;
[c5b7d07]68
[1e7b0db0]69        const double si = sas_sinx_x(mu * c_scaled * sigma);
[71b751d]70        outer_total_F1 += GAUSS_W[i] * inner_total_F1 * si;
71        outer_total_F2 += GAUSS_W[i] * inner_total_F2 * si * si;
[14838a3]72    }
[dbf1a60]73    // now complete change of outer integration variable (1-0)/(1-(-1))= 0.5
[71b751d]74    outer_total_F1 *= 0.5;
75    outer_total_F2 *= 0.5;
[14838a3]76
77    // Multiply by contrast^2 and convert from [1e-12 A-1] to [cm-1]
78    const double V = form_volume(length_a, length_b, length_c);
[71b751d]79    const double contrast = (sld-solvent_sld);
80    const double s = contrast * V;
81    *F1 = 1.0e-2 * s * outer_total_F1;
82    *F2 = 1.0e-4 * s * s * outer_total_F2;
[c5b7d07]83}
84
[becded3]85static double
[108e70e]86Iqabc(double qa, double qb, double qc,
[c5b7d07]87    double sld,
88    double solvent_sld,
[a807206]89    double length_a,
90    double length_b,
[becded3]91    double length_c)
[c5b7d07]92{
[2a0b2b1]93    const double siA = sas_sinx_x(0.5*length_a*qa);
94    const double siB = sas_sinx_x(0.5*length_b*qb);
95    const double siC = sas_sinx_x(0.5*length_c*qc);
[14838a3]96    const double V = form_volume(length_a, length_b, length_c);
97    const double drho = (sld - solvent_sld);
98    const double form = V * drho * siA * siB * siC;
99    // Square and convert from [1e-12 A-1] to [cm-1]
100    return 1.0e-4 * form * form;
[c5b7d07]101}
Note: See TracBrowser for help on using the repository browser.