Changeset ad90df9 in sasmodels


Ignore:
Timestamp:
Mar 1, 2016 8:23:21 PM (4 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:
e6f1410, 7d4b2ae
Parents:
50e1e40
Message:

refactor sphere/fcc/bcc/sc_crystal to use common code

Location:
sasmodels/models
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/bcc.c

    r9aac25d rad90df9  
    4040} 
    4141 
    42  
    4342double form_volume(double radius){ 
    44     return 1.333333333333333*M_PI*radius*radius*radius; 
     43    return sphere_volume(radius); 
    4544} 
    4645 
     
    5251        //Volume fraction calculated from lattice symmetry and sphere radius 
    5352        const double s1 = dnn/sqrt(0.75); 
    54         const double latticescale = 2.0*(4.0/3.0)*M_PI*(radius*radius*radius)/(s1*s1*s1); 
     53        const double latticescale = 2.0*sphere_volume(radius/s1); 
    5554 
    5655    const double va = 0.0; 
     
    113112 
    114113  //the occupied volume of the lattice 
    115   const double latticescale = 2.0*(4.0/3.0)*M_PI*(radius*radius*radius)/(s1*s1*s1); 
     114  const double latticescale = 2.0*sphere_volume(radius/s1); 
    116115  // q vector 
    117116  //q_z = 0.0; // for SANS; assuming qz is negligible 
  • sasmodels/models/bcc.py

    r9aac25d rad90df9  
    132132# pylint: enable=bad-whitespace, line-too-long 
    133133 
    134 source = ["lib/J1.c", "lib/gauss150.c", "lib/sphere_form.c", "bcc.c"] 
     134source = ["lib/sph_j1c.c", "lib/J1.c", "lib/gauss150.c", "lib/sphere_form.c", "bcc.c"] 
    135135 
    136136# parameters for demo 
  • sasmodels/models/fcc.c

    r9aac25d rad90df9  
    4141 
    4242double form_volume(double radius){ 
    43     return 1.333333333333333*M_PI*radius*radius*radius; 
     43    return sphere_volume(radius); 
    4444} 
    4545 
     
    5151        //Volume fraction calculated from lattice symmetry and sphere radius 
    5252        const double s1 = dnn*sqrt(2.0); 
    53         const double latticescale = 4.0*(4.0/3.0)*M_PI*(radius*radius*radius)/(s1*s1*s1); 
     53        const double latticescale = 4.0*sphere_volume(radius/s1); 
    5454 
    5555    const double va = 0.0; 
     
    112112 
    113113  //the occupied volume of the lattice 
    114   const double latticescale = 2.0*(4.0/3.0)*M_PI*(radius*radius*radius)/(s1*s1*s1); 
     114  const double latticescale = 2.0*sphere_volume(radius/s1); 
    115115  // q vector 
    116116  // q_z = 0.0; // for SANS; assuming qz is negligible 
  • sasmodels/models/fcc.py

    rc0ccea8 rad90df9  
    127127# pylint: enable=bad-whitespace, line-too-long 
    128128 
    129 source = ["lib/J1.c", "lib/gauss150.c", "lib/sphere_form.c", "fcc.c"] 
     129source = ["lib/sph_j1c.c", "lib/J1.c", "lib/gauss150.c", "lib/sphere_form.c", "fcc.c"] 
    130130 
    131131# parameters for demo 
  • sasmodels/models/lib/sphere_form.c

    r9aac25d rad90df9  
    1 double 
     1inline double 
     2sphere_volume(double radius) 
     3{ 
     4    return M_4PI_3*cube(radius); 
     5} 
     6 
     7inline double 
    28sphere_form(double q, double radius, double sld, double solvent_sld) 
    39{ 
    4     const double qr = q*radius; 
    5     double sn, cn; 
    6     SINCOS(qr, sn, cn); 
    7     const double vol = 1.333333333333333*M_PI*radius*radius*radius; 
    8     const double bes = (qr == 0.0 ? 1.0 : 3.0*(sn-qr*cn)/(qr*qr*qr)); 
    9     const double fq = bes * (sld - solvent_sld)*vol; 
    10     return 1.0e-4*fq*fq; 
     10    const double fq = sphere_volume(radius) * sph_j1c(q*radius); 
     11    const double contrast = (sld - solvent_sld); 
     12    return 1.0e-4*square(contrast * fq); 
    1113} 
    12  
    13 // Do we even need the paracrystal form? 
    14 // The only difference is the return value at r=0 
    15 double 
    16 sphere_form_paracrystal(double q, double radius, double delrho) 
    17 { 
    18     const double qr = q*radius; 
    19     const double vol = 1.333333333333333*M_PI*radius*radius*radius; 
    20         const double f = vol*delrho*delrho*1.0e-4; 
    21     double sn, cn; 
    22     SINCOS(qr, sn, cn); 
    23         const double bes = (qr == 0.0 ? f : 3.0*(sn-qr*cn)/(qr*qr*qr)); 
    24         const double fq = bes*delrho*vol; 
    25         return fq*fq * 1.0e-4; 
    26 } 
  • sasmodels/models/sc_crystal.c

    r9aac25d rad90df9  
    2020double form_volume(double radius) 
    2121{ 
    22     return 1.333333333333333*M_PI*radius*radius*radius; 
     22    return sphere_volume(radius); 
    2323} 
    2424 
     
    9595 
    9696        //Volume fraction calculated from lattice symmetry and sphere radius 
    97         const double latticeScale = (4.0/3.0)*M_PI*(radius*radius*radius)/pow(dnn,3); 
    98  
    99         //answer *= sphere_form_paracrystal(q, radius,contrast)*latticeScale; 
     97        // NB: 4/3 pi r^3 / dnn^3 = 4/3 pi(r/dnn)^3 
     98        const double latticeScale = sphere_volume(radius/dnn); 
     99 
    100100        answer *= sphere_form(q, radius, sphere_sld, solvent_sld)*latticeScale; 
    101101 
     
    180180 
    181181    //consider scales 
    182     const double latticeScale = (4.0/3.0)*M_PI*(radius*radius*radius)/pow(dnn,3.0); 
     182    const double latticeScale = sphere_volume(radius/dnn); 
    183183    answer *= latticeScale; 
    184184 
  • sasmodels/models/sc_crystal.py

    r9aac25d rad90df9  
    142142# pylint: enable=bad-whitespace, line-too-long 
    143143 
    144 source = ["lib/sphere_form.c", "lib/gauss150.c", "sc_crystal.c"] 
     144source = ["lib/sph_j1c.c", "lib/sphere_form.c", "lib/gauss150.c", "sc_crystal.c"] 
    145145 
    146146demo = dict(scale=1, background=0, 
  • sasmodels/models/sphere.py

    r50e1e40 rad90df9  
    7878             ] 
    7979 
    80 source = ["lib/sph_j1c.c"] 
     80source = ["lib/sph_j1c.c", "lib/sphere_form.c"] 
    8181 
    8282# No volume normalization despite having a volume parameter 
    8383# This should perhaps be volume normalized? 
    8484form_volume = """ 
    85     return M_4PI_3*cube(radius); 
     85    return sphere_volume(radius); 
    8686    """ 
    8787 
    8888Iq = """ 
    89     const double qr = q*radius; 
    90     const double bes = sph_j1c(qr); 
    91     const double fq = bes * (sld - solvent_sld) * form_volume(radius); 
    92     return 1.0e-4*fq*fq; 
     89    return sphere_form(q, radius, sld, solvent_sld); 
    9390    """ 
    9491 
Note: See TracChangeset for help on using the changeset viewer.