Changeset ef2861b in sasmodels for sasmodels/models/cylinder.c


Ignore:
Timestamp:
Oct 31, 2014 2:43:39 PM (9 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:
ba69383
Parents:
994d77f
Message:

cylinder performance tweak

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/cylinder.c

    r994d77f ref2861b  
    77// besarg = q * R * sin(alpha) 
    88// siarg = q * L/2 * cos(alpha) 
    9 double _cyl(double twovd, double besarg, double siarg); 
    10 double _cyl(double twovd, double besarg, double siarg) 
     9double _cyl(double besarg, double siarg); 
     10double _cyl(double besarg, double siarg) 
    1111{ 
    1212    const double bj = (besarg == 0.0 ? 0.5 : J1(besarg)/besarg); 
    1313    const double si = (siarg == 0.0 ? 1.0 : sin(siarg)/siarg); 
    14     return twovd*si*bj; 
     14    return si*bj; 
    1515} 
    1616 
     
    2828    const double qr = q*radius; 
    2929    const double qh = q*0.5*length; 
    30     const double twovd = 2.0*(sld-solvent_sld)*form_volume(radius, length); 
    3130    double total = 0.0; 
    3231    // double lower=0, upper=M_PI_2; 
     
    3736        double sn, cn; 
    3837        SINCOS(alpha, sn, cn); 
    39         const double fq = _cyl(twovd, qr*sn, qh*cn); 
     38        // For a bit of efficiency, we are moving the 2 V delta rho constant 
     39        // factor, 2Vd, out of the loop, so this is fq/2Vd rather than fq. 
     40        const double fq = _cyl(qr*sn, qh*cn); 
    4041        total += Gauss76Wt[i] * fq * fq * sn; 
    4142    } 
    4243    // translate dx in [-1,1] to dx in [lower,upper] 
    4344    //const double form = (upper-lower)/2.0*total; 
    44     return 1.0e-4 * total * M_PI_4; 
     45    const double twovd = 2.0*(sld-solvent_sld)*form_volume(radius, length); 
     46    return 1.0e-4 * twovd * twovd * total * M_PI_4; 
    4547} 
    4648 
     
    6264    SINCOS(theta*M_PI_180, sn, cn); 
    6365    const double q = sqrt(qx*qx+qy*qy); 
    64     const double cos_val = cn*cos(phi*M_PI_180)*(qx/q) + sn*(qy/q); 
     66    const double cos_val = (q==0. ? 1.0 : (cn*cos(phi*M_PI_180)*qx + sn*qy)/q); 
    6567    const double alpha = acos(cos_val); 
     68    SINCOS(alpha, sn, cn); 
     69    //sn = sqrt(1.0 - cos_val*cos_val); 
     70    //sn = 1.0 - 0.5*cos_val*cos_val;  // if cos_val is very small 
     71    //cn = cos_val; 
    6672 
    6773    const double twovd = 2.0*(sld-solvent_sld)*form_volume(radius, length); 
    68     SINCOS(alpha, sn, cn); 
    69     const double fq = _cyl(twovd, q*radius*sn, q*0.5*length*cn); 
     74    const double fq = twovd * _cyl(q*radius*sn, q*0.5*length*cn); 
    7075    return 1.0e-4 * fq * fq; 
    7176} 
Note: See TracChangeset for help on using the changeset viewer.