Changeset 237c9cf in sasmodels for explore


Ignore:
Timestamp:
Oct 4, 2017 1:20:48 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
5772737
Parents:
3a220e6
Message:

flexible_cylinder: improve low q Sdebye calculation; adjust code so different branches use the same equation numbers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • explore/precision.py

    r3a220e6 r237c9cf  
    326326    name="debye", 
    327327    mp_function=lambda x: 2*(mp.exp(-x**2) + x**2 - 1)/x**4, 
    328     np_function=lambda x: 2*(np.exp(-x**2) + x**2 - 1)/x**4, 
     328    np_function=lambda x: 2*(np.expm1(-x**2) + x**2)/x**4, 
    329329    ocl_function=make_ocl(""" 
    330330    const double qsq = q*q; 
    331     if (qsq < -0.75*0.75) { // Pade approximation around 0 
     331    if (qsq < 1.0) { // Pade approximation 
    332332        const double x = qsq; 
    333         if (0) { 
     333        if (0) { // 0.36 single 
    334334            // PadeApproximant[2*Exp[-x^2] + x^2-1)/x^4, {x, 0, 4}] 
    335335            return (x*x/180. + 1.)/((1./30.*x + 1./3.)*x + 1); 
    336         } else if (0) { 
     336        } else if (0) { // 1.0 for single 
    337337            // padeapproximant[2*exp[-x^2] + x^2-1)/x^4, {x, 0, 6}] 
    338             // works for single precision, with qsq < 1 
    339338            const double A1=1./24., A2=1./84, A3=-1./3360; 
    340339            const double B1=3./8., B2=3./56., B3=1./336.; 
    341340            return (((A3*x + A2)*x + A1)*x + 1.)/(((B3*x + B2)*x + B1)*x + 1.); 
    342         } else if (0) { 
     341        } else if (1) { // 1.0 for single, 0.25 for double 
    343342            // PadeApproximant[2*Exp[-x^2] + x^2-1)/x^4, {x, 0, 8}] 
    344343            const double A1=1./15., A2=1./60, A3=0., A4=1./75600.; 
     
    346345            return ((((A4*x + A3)*x + A2)*x + A1)*x + 1.) 
    347346                  /((((B4*x + B3)*x + B2)*x + B1)*x + 1.); 
    348  
    349         } else { 
     347        } else { // 1.0 for single, 0.5 for double 
    350348            // PadeApproximant[2*Exp[-x^2] + x^2-1)/x^4, {x, 0, 8}] 
    351             // works for double precision, with qsq < 9/16 
    352349            const double A1=1./12., A2=2./99., A3=1./2640., A4=1./23760., A5=-1./1995840.; 
    353350            const double B1=5./12., B2=5./66., B3=1./132., B4=1./2376., B5=1./95040.; 
     
    355352                  /(((((B5*x + B4)*x + B3)*x + B2)*x + B1)*x + 1.); 
    356353        } 
    357     } else if (qsq < 0.1) { // Taylor series around 0. 
     354    } else if (qsq < 1.) { // Taylor series; 0.9 for single, 0.25 for double 
    358355        const double x = qsq; 
    359356        const double C0 = +1.; 
     
    369366        return ((((((C7*x + C6)*x + C5)*x + C4)*x + C3)*x + C2)*x + C1)*x + C0; 
    370367    } else { 
    371         return 2.*(exp(-qsq) + qsq - 1.)/(qsq*qsq); 
     368        return 2.*(expm1(-qsq) + qsq)/(qsq*qsq); 
    372369    } 
    373370    """, "sas_debye"), 
Note: See TracChangeset for help on using the changeset viewer.