Changeset 3a48772 in sasmodels


Ignore:
Timestamp:
Oct 14, 2016 3:23:40 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:
a5b6997
Parents:
b716cc6
Message:

use predefined constants for fractions of pi

Location:
sasmodels/models
Files:
25 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/barbell.c

    r11ca2ab r3a48772  
    3939    // translate dx in [-1,1] to dx in [lower,upper] 
    4040    const double integral = total*zm; 
    41     const double bell_fq = 2*M_PI*cube(radius_bell)*integral; 
     41    const double bell_fq = 2.0*M_PI*cube(radius_bell)*integral; 
    4242    return bell_fq; 
    4343} 
  • sasmodels/models/binary_hard_sphere.c

    r87bc707 r3a48772  
    4949    // /* do form factor calculations  */ 
    5050     
    51     v1 = 4.0*M_PI/3.0*r1*r1*r1; 
    52     v2 = 4.0*M_PI/3.0*r2*r2*r2; 
     51    v1 = M_4PI_3*r1*r1*r1; 
     52    v2 = M_4PI_3*r2*r2*r2; 
    5353     
    5454    n1 = phi1/v1; 
     
    7070    sc1 = sph_j1c(qr1); 
    7171    sc2 = sph_j1c(qr2); 
    72     b1 = r1*r1*r1*(rho1-rhos)*4.0/3.0*M_PI*sc1; 
    73     b2 = r2*r2*r2*(rho2-rhos)*4.0/3.0*M_PI*sc2; 
     72    b1 = r1*r1*r1*(rho1-rhos)*M_4PI_3*sc1; 
     73    b2 = r2*r2*r2*(rho2-rhos)*M_4PI_3*sc2; 
    7474    inten = n1*b1*b1*psf11; 
    7575    inten += sqrt(n1*n2)*2.0*b1*b2*psf12; 
  • sasmodels/models/capped_cylinder.c

    r5bddd89 r3a48772  
    4545    // translate dx in [-1,1] to dx in [lower,upper] 
    4646    const double integral = total*zm; 
    47     const double cap_Fq = 2*M_PI*cube(radius_cap)*integral; 
     47    const double cap_Fq = 2.0*M_PI*cube(radius_cap)*integral; 
    4848    return cap_Fq; 
    4949} 
     
    5656    const double bj = sas_J1c(q*radius*sin_alpha); 
    5757    const double si = sinc(q*half_length*cos_alpha); 
    58     const double cyl_Fq = 2.*M_PI*radius*radius*half_length*bj*si; 
     58    const double cyl_Fq = 2.0*M_PI*radius*radius*half_length*bj*si; 
    5959    const double Aq = cap_Fq + cyl_Fq; 
    6060    return Aq; 
  • sasmodels/models/core_shell_parallelepiped.c

    r2222134 r3a48772  
    8989            double tb = (a_scaled+2.0*thick_rim_b)/length_b; 
    9090     
    91                 double arg1 = (0.5*mudum*a_scaled) * sin(0.5*M_PI*uu); 
    92                 double arg2 = (0.5*mudum) * cos(0.5*M_PI*uu); 
    93                 double arg3=  (0.5*mudum*ta) * sin(0.5*M_PI*uu); 
    94                 double arg4=  (0.5*mudum*tb) * cos(0.5*M_PI*uu); 
     91                double arg1 = (0.5*mudum*a_scaled) * sin(M_PI_2*uu); 
     92                double arg2 = (0.5*mudum) * cos(M_PI_2*uu); 
     93                double arg3=  (0.5*mudum*ta) * sin(M_PI_2*uu); 
     94                double arg4=  (0.5*mudum*tb) * cos(M_PI_2*uu); 
    9595 
    9696                if(arg1==0.0){ 
  • sasmodels/models/core_shell_sphere.c

    r2c74c11 r3a48772  
    1616double form_volume(double radius, double thickness) 
    1717{ 
    18     return 4.0 * M_PI / 3.0 * pow((radius + thickness), 3); 
     18    return M_4PI_3 * cube(radius + thickness); 
    1919} 
  • sasmodels/models/flexible_cylinder_elliptical.c

    r87bc707 r3a48772  
    1818 
    1919    for(int i=0;i<N_POINTS_76;i++) { 
    20         double zi = ( Gauss76Z[i] + 1.0 )*M_PI/4.0; 
     20        double zi = ( Gauss76Z[i] + 1.0 )*M_PI_4; 
    2121        double sn, cn; 
    2222        SINCOS(zi, sn, cn); 
  • sasmodels/models/fractal_core_shell.c

    ra807206 r3a48772  
    1313double form_volume(double radius, double thickness) 
    1414{ 
    15     return 4.0 * M_PI / 3.0 * pow((radius + thickness), 3); 
     15    return M_4PI_3 * cube(radius + thickness); 
    1616} 
    1717 
  • sasmodels/models/fuzzy_sphere.py

    r9a4811a r3a48772  
    8686# This should perhaps be volume normalized? 
    8787form_volume = """ 
    88     return 1.333333333333333*M_PI*radius*radius*radius; 
     88    return M_4PI_3*cube(radius); 
    8989    """ 
    9090 
  • sasmodels/models/hayter_msa.c

    r0bef47b r3a48772  
    2323        double SIdiam, diam, Kappa, cs, IonSt; 
    2424        double  Perm, Beta; 
    25         double pi, charge; 
     25        double charge; 
    2626        int ierr; 
    2727         
    28         pi = M_PI; 
    29  
    3028        diam=2*radius_effective;                //in A 
    3129 
     
    3836        charge=zz*Elcharge;             //in Coulomb (C) 
    3937        SIdiam = diam*1.0E-10;          //in m 
    40         Vp=4.0*pi/3.0*(SIdiam/2.0)*(SIdiam/2.0)*(SIdiam/2.0);   //in m^3 
     38        Vp=M_4PI_3*cube(SIdiam/2.0);    //in m^3 
    4139        cs=csalt*6.022E23*1.0E3;        //# salt molecules/m^3 
    4240         
     
    5048        Kappa=sqrt(2*Beta*IonSt/Perm);     //Kappa calc from Ionic strength 
    5149                                                                           //   Kappa=2/SIdiam                                  // Use to compare with HP paper 
    52         gMSAWave[5]=Beta*charge*charge/(pi*Perm*SIdiam*pow((2.0+Kappa*SIdiam),2)); 
     50        gMSAWave[5]=Beta*charge*charge/(M_PI*Perm*SIdiam*pow((2.0+Kappa*SIdiam),2)); 
    5351         
    5452        //         Finally set up dimensionless parameters  
  • sasmodels/models/hollow_rectangular_prism.c

    r87bc707 r3a48772  
    3434   //Integration limits to use in Gaussian quadrature 
    3535    double v1a = 0.0; 
    36     double v1b = 0.5 * M_PI;  //theta integration limits 
     36    double v1b = M_PI_2;  //theta integration limits 
    3737    double v2a = 0.0; 
    38     double v2b = 0.5 * M_PI;  //phi integration limits 
     38    double v2b = M_PI_2;  //phi integration limits 
    3939     
    4040    //Order of integration 
     
    8888    // Normalize as in Eqn. (15) without the volume factor (as cancels with (V*DelRho)^2 normalization) 
    8989    // The factor 2 is due to the different theta integration limit (pi/2 instead of pi) 
    90     answer *= (2.0/M_PI); 
     90    answer /= M_PI_2; 
    9191 
    9292    // Multiply by contrast^2. Factor corresponding to volume^2 cancels with previous normalization. 
  • sasmodels/models/hollow_rectangular_prism_thin_walls.c

    r87bc707 r3a48772  
    2626   //Integration limits to use in Gaussian quadrature 
    2727    double v1a = 0.0; 
    28     double v1b = 0.5 * M_PI;  //theta integration limits 
     28    double v1b = M_PI_2;  //theta integration limits 
    2929    double v2a = 0.0; 
    30     double v2b = 0.5 * M_PI;  //phi integration limits 
     30    double v2b = M_PI_2;  //phi integration limits 
    3131     
    3232    //Order of integration 
     
    7171    // Normalize as in Eqn. (15) without the volume factor (as cancels with (V*DelRho)^2 normalization) 
    7272    // The factor 2 is due to the different theta integration limit (pi/2 instead of pi) 
    73     answer *= (2.0/M_PI); 
     73    answer /= M_PI_2; 
    7474 
    7575    // Multiply by contrast^2. Factor corresponding to volume^2 cancels with previous normalization. 
  • sasmodels/models/lib/core_shell.c

    r7d4b2ae r3a48772  
    1717    const double core_contrast = core_sld - shell_sld; 
    1818    const double core_bes = sph_j1c(core_qr); 
    19     const double core_volume = 4.0 * M_PI / 3.0 * radius * radius * radius; 
     19    const double core_volume = M_4PI_3 * cube(radius); 
    2020    double f = core_volume * core_bes * core_contrast; 
    2121 
     
    2424    const double shell_contrast = shell_sld - solvent_sld; 
    2525    const double shell_bes = sph_j1c(shell_qr); 
    26     const double shell_volume = 4.0 * M_PI / 3.0 * pow((radius + thickness), 3); 
     26    const double shell_volume = M_4PI_3 * cube(radius + thickness); 
    2727    f += shell_volume * shell_bes * shell_contrast; 
    2828    return f * f * 1.0e-4; 
  • sasmodels/models/lib/gfn.c

    r177c1a1 r3a48772  
    1212{ 
    1313    // local variables 
    14     const double pi43=4.0/3.0*M_PI; 
    1514    const double aa = crmaj; 
    1615    const double bb = crmin; 
     
    2019    //const double siq = (uq == 0.0 ? 1.0 : 3.0*(sin(uq)/uq/uq - cos(uq)/uq)/uq); 
    2120    const double siq = sph_j1c(uq); 
    22     const double vc = pi43*aa*aa*bb; 
     21    const double vc = M_4PI_3*aa*aa*bb; 
    2322    const double gfnc = siq*vc*delpc; 
    2423 
    2524    const double ut2 = (trmin*trmin*xx*xx + trmaj*trmaj*(1.0-xx*xx)); 
    2625    const double ut= sqrt(ut2)*qq; 
    27     const double vt = pi43*trmaj*trmaj*trmin; 
     26    const double vt = M_4PI_3*trmaj*trmaj*trmin; 
    2827    //const double sit = (ut == 0.0 ? 1.0 : 3.0*(sin(ut)/ut/ut - cos(ut)/ut)/ut); 
    2928    const double sit = sph_j1c(ut); 
     
    3332    const double result = tgfn*tgfn; 
    3433 
    35     return (result); 
     34    return result; 
    3635} 
  • sasmodels/models/linear_pearls.c

    r2c74c11 r3a48772  
    1919{ 
    2020    // Pearl volume 
    21     double pearl_vol = 4.0 /3.0 * M_PI * pow(radius, 3.0); 
     21    double pearl_vol = M_4PI_3 * cube(radius); 
    2222    // Return total volume 
    2323    return num_pearls * pearl_vol;; 
     
    3535    double contrast_pearl = pearl_sld - solvent_sld; 
    3636    //each volume 
    37     double pearl_vol = 4.0 /3.0 * M_PI * pow(radius, 3.0); 
     37    double pearl_vol = M_4PI_3 * cube(radius); 
    3838    //total volume 
    3939    double tot_vol = num_pearls * pearl_vol; 
  • sasmodels/models/mass_fractal.c

    ra807206 r3a48772  
    3434double form_volume(double radius){ 
    3535 
    36     return 1.333333333333333*M_PI*radius*radius*radius; 
     36    return M_4PI_3*radius*radius*radius; 
    3737} 
    3838 
  • sasmodels/models/mass_surface_fractal.c

    r30fbe2e r3a48772  
    3737double form_volume(double radius){ 
    3838 
    39     return 1.333333333333333*M_PI*radius*radius*radius; 
     39    return M_4PI_3*radius*radius*radius; 
    4040} 
    4141 
  • sasmodels/models/multilayer_vesicle.c

    r2c74c11 r3a48772  
    1919 
    2020        // layer 1 
    21         voli = 4.0*M_PI/3.0*ri*ri*ri; 
     21        voli = M_4PI_3*ri*ri*ri; 
    2222        fval += voli*sldi*sph_j1c(ri*q); 
    2323 
     
    2525 
    2626        // layer 2 
    27         voli = 4.0*M_PI/3.0*ri*ri*ri; 
     27        voli = M_4PI_3*ri*ri*ri; 
    2828        fval -= voli*sldi*sph_j1c(ri*q); 
    2929 
  • sasmodels/models/parallelepiped.c

    ra807206 r3a48772  
    7171            double uu = 0.5 * ( Gauss76Z[j] + 1.0 ); 
    7272            double mudum = mu * sqrt(1.0-sigma*sigma); 
    73                 double arg1 = 0.5 * mudum * cos(0.5*M_PI*uu); 
    74                 double arg2 = 0.5 * mudum * a_scaled * sin(0.5*M_PI*uu); 
     73                double arg1 = 0.5 * mudum * cos(M_PI_2*uu); 
     74                double arg2 = 0.5 * mudum * a_scaled * sin(M_PI_2*uu); 
    7575            if(arg1==0.0) { 
    7676                tmp1 = 1.0; 
  • sasmodels/models/pearl_necklace.c

    ra807206 r3a48772  
    2323        double num_strings = num_pearls - 1.0; 
    2424         
    25         //Pi 
    26         double pi = 4.0*atan(1.0); 
    27          
    2825        // center to center distance between the neighboring pearls 
    2926        double A_s = edge_sep + 2.0 * radius; 
     
    3633         
    3734        // each volume 
    38         double string_vol = edge_sep * pi * thick_string * thick_string / 4.0; 
    39         double pearl_vol = 4.0 / 3.0 * pi * radius * radius * radius; 
     35        double string_vol = edge_sep * M_PI * thick_string * thick_string / 4.0; 
     36        double pearl_vol = M_4PI_3 * radius * radius * radius; 
    4037 
    4138        //total volume 
     
    110107        double total_vol; 
    111108 
    112         double pi = 4.0*atan(1.0); 
    113109        double number_of_strings = num_pearls - 1.0; 
    114110         
    115         double string_vol = edge_sep * pi * thick_string * thick_string / 4.0; 
    116         double pearl_vol = 4.0 / 3.0 * pi * radius * radius * radius; 
     111        double string_vol = edge_sep * M_PI * thick_string * thick_string / 4.0; 
     112        double pearl_vol = M_4PI_3 * radius * radius * radius; 
    117113 
    118114        total_vol = number_of_strings * string_vol; 
  • sasmodels/models/rectangular_prism.c

    r87bc707 r3a48772  
    7575    // The factor 2 appears because the theta integral has been defined between  
    7676    // 0 and pi/2, instead of 0 to pi. 
    77     answer *= (2.0/M_PI); //Form factor P(q) 
     77    answer /= M_PI_2; //Form factor P(q) 
    7878 
    7979    // Multiply by contrast^2 and volume^2 
  • sasmodels/models/sc_paracrystal.c

    r0b717c5 r3a48772  
    5555 
    5656        double integrand = temp2*sc_eval(yy,xx,temp3,temp4,temp5); 
    57         integrand *= 2.0/M_PI; 
     57        integrand /= M_PI_2; 
    5858 
    5959        return(integrand); 
     
    6868{ 
    6969        const double va = 0.0; 
    70         const double vb = M_PI/2.0; //orientation average, outer integral 
     70        const double vb = M_PI_2; //orientation average, outer integral 
    7171 
    7272    double summ=0.0; 
  • sasmodels/models/star_polymer.c

    r2c74c11 r3a48772  
    66{ 
    77 
    8     double u_2 = radius2 * pow(q,2); 
     8    double u_2 = radius2 * q * q; 
    99    double v = u_2 * arms / (3.0 * arms - 2.0); 
    1010 
    11     double term1 = v - 1.0 + exp(-v); 
    12     double term2 = ((arms - 1.0)/2.0)* pow((1.0 - exp(-v)),2.0); 
     11    double term1 = v + expm1(-v); 
     12    double term2 = ((arms - 1.0)/2.0) * square(expm1(-v)); 
    1313 
    14     return (2.0 * (term1 + term2)) / (arms * pow(v,2.0)); 
     14    return (2.0 * (term1 + term2)) / (arms * v * v); 
    1515 
    1616} 
  • sasmodels/models/triaxial_ellipsoid.c

    r11ca2ab r3a48772  
    1010double form_volume(double radius_equat_minor, double radius_equat_major, double radius_polar) 
    1111{ 
    12     return 1.333333333333333*M_PI*radius_equat_minor*radius_equat_major*radius_polar; 
     12    return M_4PI_3*radius_equat_minor*radius_equat_major*radius_polar; 
    1313} 
    1414 
  • sasmodels/models/vesicle.c

    r2c74c11 r3a48772  
    88{ 
    99    //note that for the vesicle model, the volume is ONLY the shell volume 
    10     double volume; 
    11     volume =4.*M_PI*(radius+thickness)*(radius+thickness)*(radius+thickness)/3; 
    12     volume -=4.*M_PI*radius*radius*radius/3.; 
    13     return volume; 
     10    return M_4PI_3*(cube(radius+thickness) - cube(radius)); 
    1411} 
    1512 
     
    3229    // core first, then add in shell 
    3330    contrast = sld_solvent-sld; 
    34     vol = 4.0*M_PI/3.0*radius*radius*radius; 
    35     f = vol*sph_j1c(q*radius)*contrast; 
     31    vol = M_4PI_3*cube(radius); 
     32    f = vol * sph_j1c(q*radius) * contrast; 
    3633  
    3734    //now the shell. No volume normalization as this is done by the caller 
    3835    contrast = sld-sld_solvent; 
    39     vol = 4.0*M_PI/3.0*(radius+thickness)*(radius+thickness)*(radius+thickness); 
    40     f += vol*sph_j1c(q*(radius+thickness))*contrast; 
     36    vol = M_4PI_3*cube(radius+thickness); 
     37    f += vol * sph_j1c(q*(radius+thickness)) * contrast; 
    4138 
    4239    //rescale to [cm-1].  
    43     f2 = volfraction*f*f*1.0e-4; 
     40    f2 = volfraction * f*f*1.0e-4; 
    4441     
    45     return(f2); 
     42    return f2; 
    4643} 
  • sasmodels/models/vesicle.py

    re77872e r3a48772  
    116116    ''' 
    117117 
    118     whole = 4. * pi * (radius + thickness) ** 3. / 3. 
    119     core = 4. * pi * radius ** 3. / 3. 
     118    whole = 4./3. * pi * (radius + thickness)**3 
     119    core = 4./3. * pi * radius**3 
    120120    return whole, whole - core 
    121121 
Note: See TracChangeset for help on using the changeset viewer.