Changeset 994d77f in sasmodels for sasmodels/models/cylinder_clone.c


Ignore:
Timestamp:
Oct 30, 2014 12:33:53 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:
ef2861b
Parents:
d087487b
Message:

Convert double to float rather than using real

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/cylinder_clone.c

    r5d4777d r994d77f  
    1 real form_volume(real radius, real length); 
    2 real Iq(real q, real sld, real solvent_sld, real radius, real length); 
    3 real Iqxy(real qx, real qy, real sld, real solvent_sld, real radius, real length, real theta, real phi); 
     1double form_volume(double radius, double length); 
     2double Iq(double q, double sld, double solvent_sld, double radius, double length); 
     3double Iqxy(double qx, double qy, double sld, double solvent_sld, double radius, double length, double theta, double phi); 
    44 
    55 
     
    77// besarg = q * R * sin(alpha) 
    88// siarg = q * L/2 * cos(alpha) 
    9 real _cyl(real twovd, real besarg, real siarg, real alpha); 
    10 real _cyl(real twovd, real besarg, real siarg, real alpha) 
     9double _cyl(double twovd, double besarg, double siarg, double alpha); 
     10double _cyl(double twovd, double besarg, double siarg, double alpha) 
    1111{ 
    12     const real bj = (besarg == REAL(0.0) ? REAL(0.5) : J1(besarg)/besarg); 
    13     const real si = (siarg == REAL(0.0) ? REAL(1.0) : sin(siarg)/siarg); 
     12    const double bj = (besarg == 0.0 ? 0.5 : J1(besarg)/besarg); 
     13    const double si = (siarg == 0.0 ? 1.0 : sin(siarg)/siarg); 
    1414    return twovd*si*bj; 
    1515} 
    1616 
    17 real form_volume(real radius, real length) 
     17double form_volume(double radius, double length) 
    1818{ 
    1919    return M_PI*radius*radius*length; 
    2020} 
    21 real Iq(real q, 
    22     real sldCyl, 
    23     real sldSolv, 
    24     real radius, 
    25     real length) 
     21double Iq(double q, 
     22    double sldCyl, 
     23    double sldSolv, 
     24    double radius, 
     25    double length) 
    2626{ 
    27     const real qr = q*radius; 
    28     const real qh = q*REAL(0.5)*length; 
    29     const real twovd = REAL(2.0)*(sldCyl-sldSolv)*form_volume(radius, length); 
    30     real total = REAL(0.0); 
    31     // real lower=0, upper=M_PI_2; 
     27    const double qr = q*radius; 
     28    const double qh = q*0.5*length; 
     29    const double twovd = 2.0*(sldCyl-sldSolv)*form_volume(radius, length); 
     30    double total = 0.0; 
     31    // double lower=0, upper=M_PI_2; 
    3232    for (int i=0; i<76 ;i++) { 
    3333        // translate a point in [-1,1] to a point in [lower,upper] 
    34         //const real alpha = ( Gauss76Z[i]*(upper-lower) + upper + lower )/2.0; 
    35         const real alpha = REAL(0.5)*(Gauss76Z[i]*M_PI_2 + M_PI_2); 
    36         real sn, cn; 
     34        //const double alpha = ( Gauss76Z[i]*(upper-lower) + upper + lower )/2.0; 
     35        const double alpha = 0.5*(Gauss76Z[i]*M_PI_2 + M_PI_2); 
     36        double sn, cn; 
    3737        SINCOS(alpha, sn, cn); 
    38         const real fq = _cyl(twovd, qr*sn, qh*cn, alpha); 
     38        const double fq = _cyl(twovd, qr*sn, qh*cn, alpha); 
    3939        total += Gauss76Wt[i] * fq * fq * sn; 
    4040    } 
    4141    // translate dx in [-1,1] to dx in [lower,upper] 
    42     //const real form = (upper-lower)/2.0*total; 
    43     return REAL(1.0e8) * total * M_PI_4; 
     42    //const double form = (upper-lower)/2.0*total; 
     43    return 1.0e8 * total * M_PI_4; 
    4444} 
    4545 
    46 real Iqxy(real qx, real qy, 
    47     real sldCyl, 
    48     real sldSolv, 
    49     real radius, 
    50     real length, 
    51     real cyl_theta, 
    52     real cyl_phi) 
     46double Iqxy(double qx, double qy, 
     47    double sldCyl, 
     48    double sldSolv, 
     49    double radius, 
     50    double length, 
     51    double cyl_theta, 
     52    double cyl_phi) 
    5353{ 
    54     real sn, cn; // slots to hold sincos function output 
     54    double sn, cn; // slots to hold sincos function output 
    5555 
    5656    // Compute angle alpha between q and the cylinder axis 
     
    5858    // # The following correction factor exists in sasview, but it can't be 
    5959    // # right, so we are leaving it out for now. 
    60     const real spherical_integration = fabs(cn)*M_PI_2; 
    61     const real q = sqrt(qx*qx+qy*qy); 
    62     const real cos_val = cn*cos(cyl_phi*M_PI_180)*(qx/q) + sn*(qy/q); 
    63     const real alpha = acos(cos_val); 
     60    const double spherical_integration = fabs(cn)*M_PI_2; 
     61    const double q = sqrt(qx*qx+qy*qy); 
     62    const double cos_val = cn*cos(cyl_phi*M_PI_180)*(qx/q) + sn*(qy/q); 
     63    const double alpha = acos(cos_val); 
    6464 
    65     const real qr = q*radius; 
    66     const real qh = q*REAL(0.5)*length; 
    67     const real twovd = REAL(2.0)*(sldCyl-sldSolv)*form_volume(radius, length); 
     65    const double qr = q*radius; 
     66    const double qh = q*0.5*length; 
     67    const double twovd = 2.0*(sldCyl-sldSolv)*form_volume(radius, length); 
    6868    SINCOS(alpha, sn, cn); 
    69     const real fq = _cyl(twovd, qr*sn, qh*cn, alpha); 
    70     return REAL(1.0e8) * fq * fq * spherical_integration; 
     69    const double fq = _cyl(twovd, qr*sn, qh*cn, alpha); 
     70    return 1.0e8 * fq * fq * spherical_integration; 
    7171} 
Note: See TracChangeset for help on using the changeset viewer.