Changeset 50e1e40 in sasmodels for sasmodels/models/cylinder.c


Ignore:
Timestamp:
Mar 1, 2016 7:49:00 PM (8 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:
ad90df9
Parents:
a4a7308
Message:

use lib functions to simplify barbell, capped_cylinder, cylinder, ellipsoid, triaxial_ellipsoid; fix barbell calculation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/cylinder.c

    r3c97ff0 r50e1e40  
    33double Iqxy(double qx, double qy, double sld, double solvent_sld, 
    44    double radius, double length, double theta, double phi); 
    5  
    6 // twovd = 2 * volume * delta_rho 
    7 // besarg = q * R * sin(alpha) 
    8 // siarg = q * L/2 * cos(alpha) 
    9 double _cyl(double besarg, double siarg); 
    10 double _cyl(double besarg, double siarg) 
    11 { 
    12     const double bj = (besarg == 0.0 ? 0.5 : J1(besarg)/besarg); 
    13     const double si = (siarg == 0.0 ? 1.0 : sin(siarg)/siarg); 
    14     return si*bj; 
    15 } 
    165 
    176double form_volume(double radius, double length) 
     
    2615    double length) 
    2716{ 
     17    // TODO: return NaN if radius<0 or length<0? 
     18    // precompute qr and qh to save time in the loop 
    2819    const double qr = q*radius; 
    2920    const double qh = q*0.5*length; 
     21 
     22    // translate a point in [-1,1] to a point in [0, pi/2] 
     23    const double zm = M_PI_4; 
     24    const double zb = M_PI_4; 
     25 
    3026    double total = 0.0; 
    31     // double lower=0, upper=M_PI_2; 
    3227    for (int i=0; i<76 ;i++) { 
    33         // translate a point in [-1,1] to a point in [lower,upper] 
    34         //const double alpha = ( Gauss76Z[i]*(upper-lower) + upper + lower )/2.0; 
    35         const double alpha = M_PI_4*(Gauss76Z[i] + 1.0); 
     28        const double alpha = Gauss76Z[i]*zm + zb; 
    3629        double sn, cn; 
    3730        SINCOS(alpha, sn, cn); 
    38         // For a bit of efficiency, we are moving the 2 V delta rho constant 
    39         // factor, 2Vdrho, out of the loop, so this is fq/2Vdrho rather than fq. 
    40         const double fq = _cyl(qr*sn, qh*cn); 
    41         total += Gauss76Wt[i] * fq * fq * sn; 
     31        const double fq = sinc(qh*cn) * J1c(qr*sn); 
     32        total += Gauss76Wt[i] * fq*fq * sn; 
    4233    } 
    4334    // translate dx in [-1,1] to dx in [lower,upper] 
    44     //const double form = (upper-lower)/2.0*total; 
    45     const double twoVdrho = 2.0*(sld-solvent_sld)*form_volume(radius, length); 
    46     return 1.0e-4 * twoVdrho * twoVdrho * total * M_PI_4; 
     35    const double form = total*zm; 
     36    const double s = (sld - solvent_sld) * form_volume(radius, length); 
     37    return 1.0e-4 * s * s * form; 
    4738} 
    4839 
     
    5647    double phi) 
    5748{ 
    58     // TODO: check that radius<0 and length<0 give zero scattering. 
    59     // This should be the case since the polydispersity weight vector should 
    60     // be zero length, and this function never called. 
     49    // TODO: return NaN if radius<0 or length<0? 
    6150    double sn, cn; // slots to hold sincos function output 
    6251 
    6352    // Compute angle alpha between q and the cylinder axis 
    6453    SINCOS(theta*M_PI_180, sn, cn); 
    65     const double q = sqrt(qx*qx+qy*qy); 
     54    const double q = sqrt(qx*qx + qy*qy); 
    6655    const double cos_val = (q==0. ? 1.0 : (cn*cos(phi*M_PI_180)*qx + sn*qy)/q); 
    6756    const double alpha = acos(cos_val); 
     57 
    6858    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; 
    72  
    73     const double twovd = 2.0*(sld-solvent_sld)*form_volume(radius, length); 
    74     const double fq = twovd * _cyl(q*radius*sn, q*0.5*length*cn); 
    75     return 1.0e-4 * fq * fq; 
     59    const double fq = sinc(q*0.5*length*cn) * J1c(q*radius*sn); 
     60    const double s = (sld-solvent_sld) * form_volume(radius, length); 
     61    return 1.0e-4 * square(s * fq); 
    7662} 
Note: See TracChangeset for help on using the changeset viewer.