Changeset 0fa687d in sasmodels


Ignore:
Timestamp:
Nov 25, 2015 4:09:56 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
4b41184
Parents:
319ab14
Message:

Use taylor series near q=0 for accurate single precision calculations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/sphere.py

    r3e428ec r0fa687d  
    9090Iq = """ 
    9191    const double qr = q*radius; 
     92    const double qrsq = qr*qr; 
    9293    double sn, cn; 
    9394    SINCOS(qr, sn, cn); 
    94     const double bes = qr==0.0 ? 1.0 : 3.0*(sn-qr*cn)/(qr*qr*qr); 
     95    // Use taylor series for low Q to avoid cancellation error.  Tested against 
     96    // the following expression in quad precision: 
     97    //     3.0*(sn-qr*cn)/(qr*qr*qr); 
     98    // Note that the values differ from sasview ~ 5e-12 rather than 5e-14, but 
     99    // in this case it is likely cancellation errors in the original expression 
     100    // using double precision that are the source.  Single precision only 
     101    // requires the first 3 terms.  Double precision requires the 4th term. 
     102    // The fifth term is not needed, and is commented out below. 
     103    const double bes = (qr < 1e-1) 
     104        ? 1.0 + qrsq*(-3./30. + qrsq*(3./840. + qrsq*(-3./45360.)))// + qrsq*(3./3991680.)))) 
     105        : 3.0*(sn/qr - cn)/qrsq; 
    95106    const double fq = bes * (sld - solvent_sld) * form_volume(radius); 
    96107    return 1.0e-4*fq*fq; 
    97108    """ 
    98  
    99109 
    100110Iqxy = """ 
Note: See TracChangeset for help on using the changeset viewer.