Changeset 217590b in sasmodels


Ignore:
Timestamp:
Oct 20, 2016 4:48:48 PM (8 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:
5c94f41
Parents:
2b9e63f
git-author:
Paul Kienzle <pkienzle@…> (10/20/16 16:47:25)
git-committer:
Paul Kienzle <pkienzle@…> (10/20/16 16:48:48)
Message:

fractal, fractal_core_shell: support fractal_dim as low as 0.

Location:
sasmodels/models
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/fractal.c

    r6d96b66 r217590b  
    1 #define INVALID(p) (p.fractal_dim <= 0.0) 
     1#define INVALID(p) (p.fractal_dim < 0.0) 
    22 
    33static double 
     
    1010   double sld_solvent) 
    1111{ 
     12    const double sq = fractal_sq(q, radius, fractal_dim, cor_length); 
     13 
    1214    //calculate P(q) for the spherical subunits 
    13     const double pq = M_4PI_3*cube(radius) * square((sld_block-sld_solvent)*sph_j1c(q*radius)); 
    14      
    15     //calculate S(q),  using Teixeira, Eq(15) 
    16     double sq; 
    17     if (q > 0. && fractal_dim > 1.) { 
    18         // q>0, D>0 
    19         const double D = fractal_dim; 
    20         const double Dm1 = fractal_dim - 1.0; 
    21         // Note: for large Dm1, sin(Dm1*atan(q*cor_length) can go negative 
    22         const double t1 = D*sas_gamma(Dm1)*sin(Dm1*atan(q*cor_length)); 
    23         const double t2 = pow(q*radius, -D); 
    24         const double t3 = pow(1.0 + 1.0/square(q*cor_length), -0.5*Dm1); 
    25         sq = 1.0 + t1 * t2 * t3; 
    26     } else if (q > 0.) { 
    27         // q>0, D=1 
    28         sq = 1.0 + atan(q*cor_length) / (q*radius); 
    29     } else if (fractal_dim > 1.) { 
    30         // q=0, D>1 
    31         const double D = fractal_dim; 
    32         sq = 1.0 + pow(cor_length/radius, D)*sas_gamma(D+1.0); 
    33     } else { 
    34         // q=0, D=1 
    35         sq = 1.0 + cor_length/radius; 
    36     } 
     15    const double V = M_4PI_3*cube(radius); 
     16    const double pq = V * square((sld_block-sld_solvent)*sph_j1c(q*radius)); 
    3717 
    3818    // scale to units cm-1 sr-1 (assuming data on absolute scale) 
     
    4121    //    combined: 1e-4 * I(q) 
    4222 
    43     return 1.e-4 * volfraction * pq * sq; 
     23    return 1.e-4 * volfraction * sq * pq; 
    4424} 
    4525 
  • sasmodels/models/fractal.py

    r6d96b66 r217590b  
    8484              ["radius",    "Ang",  5.0, [0.0, inf], "", 
    8585               "radius of particles"], 
    86               ["fractal_dim",      "",  2.0, [1.0, 6.0], "", 
     86              ["fractal_dim",      "",  2.0, [0.0, 6.0], "", 
    8787               "fractal dimension"], 
    8888              ["cor_length", "Ang", 100.0, [0.0, inf], "", 
     
    9595# pylint: enable=bad-whitespace, line-too-long 
    9696 
    97 source = ["lib/sph_j1c.c", "lib/sas_gamma.c", "fractal.c"] 
     97source = ["lib/sph_j1c.c", "lib/sas_gamma.c", "lib/fractal_sq.c", "fractal.c"] 
    9898 
    9999demo = dict(volfraction=0.05, 
  • sasmodels/models/fractal_core_shell.c

    r6d96b66 r217590b  
    1 double form_volume(double radius, double thickness); 
    2  
    3 double Iq(double q, 
    4           double radius, 
    5           double thickness, 
    6           double core_sld, 
    7           double shell_sld, 
    8           double solvent_sld, 
    9           double volfraction, 
    10           double fractal_dim, 
    11           double cor_length); 
    12  
    13 double form_volume(double radius, double thickness) 
     1static double 
     2form_volume(double radius, double thickness) 
    143{ 
    154    return M_4PI_3 * cube(radius + thickness); 
    165} 
    176 
    18 double Iq(double q, 
    19           double radius, 
    20           double thickness, 
    21           double core_sld, 
    22           double shell_sld, 
    23           double solvent_sld, 
    24           double volfraction, 
    25           double fractal_dim, 
    26           double cor_length) { 
    27  
    28  
     7static double 
     8Iq(double q, 
     9   double radius, 
     10   double thickness, 
     11   double core_sld, 
     12   double shell_sld, 
     13   double solvent_sld, 
     14   double volfraction, 
     15   double fractal_dim, 
     16   double cor_length) 
     17{ 
     18    const double sq = fractal_sq(q, radius, fractal_dim, cor_length); 
    2919    const double pq = core_shell_kernel(q, radius, thickness, 
    3020                                        core_sld, shell_sld, solvent_sld); 
    31  
    32  
    33     //calculate S(q) 
    34     double sq; 
    35     if (q > 0. && fractal_dim > 1.) { 
    36         // q>0, D>0 
    37         const double D = fractal_dim; 
    38         const double Dm1 = fractal_dim - 1.0; 
    39         const double t1 = D*sas_gamma(Dm1)*sin((Dm1)*atan(q*cor_length)); 
    40         const double t2 = pow(q*radius, -D); 
    41         const double t3 = pow(1.0 + 1.0/square(q*cor_length), -0.5*Dm1); 
    42         sq = 1.0 + t1 * t2 * t3; 
    43     } else if (q > 0.) { 
    44         // q>0, D=1 
    45         sq = 1.0 + atan(q*cor_length) / (q*radius); 
    46     } else if (fractal_dim > 1.) { 
    47         // q=0, D>1 
    48         const double D = fractal_dim; 
    49         sq = 1.0 + pow(cor_length/radius, D)*sas_gamma(D+1.0); 
    50     } else { 
    51         // q=0, D=1 
    52         sq = 1.0 + cor_length/radius; 
    53     } 
    5421 
    5522    // Note: core_shell_kernel already performs the 1e-4 unit conversion 
  • sasmodels/models/fractal_core_shell.py

    r6d96b66 r217590b  
    6969    ["sld_solvent", "1e-6/Ang^2", 3.0,  [-inf, inf], "sld",    "Solvent scattering length density"], 
    7070    ["volfraction", "",           1.0,  [0.0, inf],  "",       "Volume fraction of building block spheres"], 
    71     ["fractal_dim",    "",        2.0,  [1.0, 6.0],  "",       "Fractal dimension"], 
     71    ["fractal_dim",    "",        2.0,  [0.0, 6.0],  "",       "Fractal dimension"], 
    7272    ["cor_length",  "Ang",      100.0,  [0.0, inf],  "",       "Correlation length of fractal-like aggregates"], 
    7373] 
    7474# pylint: enable=bad-whitespace, line-too-long 
    7575 
    76 source = ["lib/sph_j1c.c", "lib/sas_gamma.c", "lib/core_shell.c", "fractal_core_shell.c"] 
     76source = ["lib/sph_j1c.c", "lib/sas_gamma.c", "lib/core_shell.c", 
     77          "lib/fractal_sq.c", "fractal_core_shell.c"] 
    7778 
    7879demo = dict(scale=0.05, 
  • sasmodels/models/lib/sas_gamma.c

    r1596de3 r217590b  
    137137 
    138138 
    139 inline double sas_gamma( double x) { return tgamma(x+1)/x; } 
     139inline double sas_gamma(double x) { 
     140#if 1 
     141    // Fast reliable gamma in [-n,171], where n is a small integer 
     142    double norm = 1.; 
     143    while (x < 1.) { 
     144        norm *= x; 
     145        x += 1.0; 
     146    } 
     147    return tgamma(x)/norm; 
     148#else 
     149    // Fast reliable gamma in [0,170] 
     150    return tgamma(x+1)/x; 
     151#endif 
     152} 
Note: See TracChangeset for help on using the changeset viewer.