Changeset eec5fd6 in sasmodels for sasmodels/models


Ignore:
Timestamp:
Mar 18, 2016 4:58:02 AM (8 years ago)
Author:
richardh
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:
ead4bd5
Parents:
4f4e0d5 (diff), 4554131 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of https://github.com/SasView/sasmodels

Location:
sasmodels/models
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/bessel.py

    r07142f3 rcbd37a7  
    6767#Bessel 
    6868parameters = [ 
     69    ["ignored", "", 0.0, [-inf, inf], "", "no parameterless functions"], 
    6970             ] 
    7071 
    71 source = ["lib/polevl.c", "lib/j1d.c"] 
     72source = ["lib/polevl.c", "lib/j1_cephes.c"] 
    7273 
    7374# No volume normalization despite having a volume parameter 
     
    7778 
    7879Iq = """ 
    79     return j1(q); 
     80    return 2.0*j1(q)/q; 
    8081    """ 
    8182 
  • sasmodels/models/lib/j0_cephes.c

    rbfef528 r094e320  
    4444 */ 
    4545 
    46 /*                                                      y0.c 
    47  * 
    48  *      Bessel function of the second kind, order zero 
    49  * 
    50  * 
    51  * 
    52  * SYNOPSIS: 
    53  * 
    54  * double x, y, y0(); 
    55  * 
    56  * y = y0( x ); 
    57  * 
    58  * 
    59  * 
    60  * DESCRIPTION: 
    61  * 
    62  * Returns Bessel function of the second kind, of order 
    63  * zero, of the argument. 
    64  * 
    65  * The domain is divided into the intervals [0, 5] and 
    66  * (5, infinity). In the first interval a rational approximation 
    67  * R(x) is employed to compute 
    68  *   y0(x)  = R(x)  +   2 * log(x) * j0(x) / PI. 
    69  * Thus a call to j0() is required. 
    70  * 
    71  * In the second interval, the Hankel asymptotic expansion 
    72  * is employed with two rational functions of degree 6/6 
    73  * and 7/7. 
    74  * 
    75  * 
    76  * 
    77  * ACCURACY: 
    78  * 
    79  *  Absolute error, when y0(x) < 1; else relative error: 
    80  * 
    81  * arithmetic   domain     # trials      peak         rms 
    82  *    DEC       0, 30        9400       7.0e-17     7.9e-18 
    83  *    IEEE      0, 30       30000       1.3e-15     1.6e-16 
    84  * 
    85  */ 
    86  
    8746 
    8847/* 
     
    9554 
    9655double j0( double ); 
    97  
    9856double j0(double x) { 
    9957 
     
    291249 
    292250    q = 1.0/x; 
    293     w = sqrtf(q); 
     251    w = sqrt(q); 
    294252 
    295253    p = w * polevl( q, MO, 7); 
    296254    w = q*q; 
    297255    xn = q * polevl( w, PH, 7) - PIO4F; 
    298     p = p * cosf(xn + xx); 
     256    p = p * cos(xn + xx); 
    299257    return(p); 
    300258#endif 
  • sasmodels/models/lib/j1_cephes.c

    rbfef528 re2af2a9  
    3232 *    IEEE      0, 30       30000       2.6e-16     1.1e-16 
    3333 * 
    34  * 
    35  */ 
    36 /*                                                      y1.c 
    37  * 
    38  *      Bessel function of second kind of order one 
    39  * 
    40  * 
    41  * 
    42  * SYNOPSIS: 
    43  * 
    44  * double x, y, y1(); 
    45  * 
    46  * y = y1( x ); 
    47  * 
    48  * 
    49  * 
    50  * DESCRIPTION: 
    51  * 
    52  * Returns Bessel function of the second kind of order one 
    53  * of the argument. 
    54  * 
    55  * The domain is divided into the intervals [0, 8] and 
    56  * (8, infinity). In the first interval a 25 term Chebyshev 
    57  * expansion is used, and a call to j1() is required. 
    58  * In the second, the asymptotic trigonometric representation 
    59  * is employed using two rational functions of degree 5/5. 
    60  * 
    61  * 
    62  * 
    63  * ACCURACY: 
    64  * 
    65  *                      Absolute error: 
    66  * arithmetic   domain      # trials      peak         rms 
    67  *    DEC       0, 30       10000       8.6e-17     1.3e-17 
    68  *    IEEE      0, 30       30000       1.0e-15     1.3e-16 
    69  * 
    70  * (error criterion relative when |y1| > 1). 
    7134 * 
    7235 */ 
  • sasmodels/models/lib/polevl.c

    r3936ad3 re2af2a9  
    5050Direct inquiries to 30 Frost Street, Cambridge, MA 02140 
    5151*/ 
     52 
    5253double polevl( double x, double coef[8], int N ); 
    5354double p1evl( double x, double coef[8], int N ); 
  • sasmodels/models/poly_gauss_coil.py

    r246517d r09b84ed  
    5050""" 
    5151 
    52 from numpy import inf, sqrt, power 
     52from numpy import inf, sqrt, exp, power 
    5353 
    5454name =  "poly_gauss_coil" 
     
    6969def Iq(q, i_zero, radius_gyration, polydispersity): 
    7070    # pylint: disable = missing-docstring 
    71     # need to trap the case of the polydispersity being 1 (ie, monodispersity) 
    7271    u = polydispersity - 1.0 
    73     if polydispersity == 1: 
    74        minusoneonu = -1.0 / u 
    75     else: 
    76        minusoneonu = -1.0 / u 
    7772    z = ((q * radius_gyration) * (q * radius_gyration)) / (1.0 + 2.0 * u) 
    7873    if (q == 0).any(): 
    79        inten = i_zero 
     74        inten = i_zero 
    8075    else: 
    81        inten = i_zero * 2.0 * (power((1.0 + u * z),minusoneonu) + z - 1.0 ) / ((1.0 + u) * (z * z)) 
     76    # need to trap the case of the polydispersity being 1 (ie, monodispersity!) 
     77        if polydispersity == 1: 
     78            inten = i_zero * 2.0 * (exp(-z) + z - 1.0 ) / (z * z) 
     79        else: 
     80            minusoneonu = -1.0 / u 
     81            inten = i_zero * 2.0 * (power((1.0 + u * z),minusoneonu) + z - 1.0 ) / ((1.0 + u) * (z * z)) 
    8282    return inten 
    83 Iq.vectorized =  True  # Iq accepts an array of q values 
     83#Iq.vectorized =  True  # Iq accepts an array of q values 
    8484 
    8585def Iqxy(qx, qy, *args): 
     
    100100               background = 'background') 
    101101 
     102# these unit test values taken from SasView 3.1.2 
    102103tests =  [ 
    103     [{'scale': 70.0, 'radius_gyration': 75.0, 'polydispersity': 2.0, 'background': 0.0}, 
     104    [{'scale': 1.0, 'i_zero': 70.0, 'radius_gyration': 75.0, 'polydispersity': 2.0, 'background': 0.0}, 
    104105     [0.0106939, 0.469418], [57.6405, 0.169016]], 
    105106    ] 
  • sasmodels/models/adsorbed_layer.py

    rf10bc52 r4f4e0d5  
    66 
    77r""" 
    8 This model describes the scattering from a layer of surfactant or polymer adsorbed on spherical particles under the conditions that (i) the particles (cores) are contrast-matched to the dispersion medium, (ii) *S(Q)* ~ 1 (ie, the particle volume fraction is dilute), (iii) the particle radius is >> layer thickness (ie, the interface is locally flat), and (iv) scattering from excess unadsorbed adsorbate in the bulk medium is absent or has been corrected for. 
     8This model describes the scattering from a layer of surfactant or polymer adsorbed on large, smooth, notionally spherical particles under the conditions that (i) the particles (cores) are contrast-matched to the dispersion medium, (ii) *S(Q)* ~ 1 (ie, the particle volume fraction is dilute), (iii) the particle radius is >> layer thickness (ie, the interface is locally flat), and (iv) scattering from excess unadsorbed adsorbate in the bulk medium is absent or has been corrected for. 
    99 
    1010Unlike many other core-shell models, this model does not assume any form for the density distribution of the adsorbed species normal to the interface (cf, a core-shell model normally assumes the density distribution to be a homogeneous step-function). For comparison, if the thickness of a (traditional core-shell like) step function distribution is *t*, the second moment about the mean of the density distribution (ie, the distance of the centre-of-mass of the distribution from the interface), |sigma| =  sqrt((*t* :sup:`2` )/12). 
     
    3434 
    3535description =  """ 
    36     Evaluates the scattering from particles 
     36    Evaluates the scattering from large particles 
    3737    with an adsorbed layer of surfactant or 
    3838    polymer, independent of the form of the 
     
    4242 
    4343#             ["name", "units", default, [lower, upper], "type", "description"], 
    44 parameters =  [["second_moment", "Ang", 23.0, [0.0, inf], "", "Second moment"], 
    45               ["adsorbed_amount", "mg/m2", 1.9, [0.0, inf], "", "Adsorbed amount"], 
    46               ["density_poly", "g/cm3", 0.7, [0.0, inf], "", "Polymer density"], 
    47               ["radius", "Ang", 500.0, [0.0, inf], "", "Particle radius"], 
    48               ["volfraction", "None", 0.14, [0.0, inf], "", "Particle vol fraction"], 
    49               ["polymer_sld", "1/Ang^2", 1.5e-06, [-inf, inf], "", "Polymer SLD"], 
    50               ["solvent_sld", "1/Ang^2", 6.3e-06, [-inf, inf], "", "Solvent SLD"]] 
     44parameters =  [["second_moment", "Ang", 23.0, [0.0, inf], "", "Second moment of polymer distribution"], 
     45              ["adsorbed_amount", "mg/m2", 1.9, [0.0, inf], "", "Adsorbed amount of polymer"], 
     46              ["density_shell", "g/cm3", 0.7, [0.0, inf], "", "Bulk density of polymer in the shell"], 
     47              ["radius", "Ang", 500.0, [0.0, inf], "", "Core particle radius"], 
     48              ["volfraction", "None", 0.14, [0.0, inf], "", "Core particle volume fraction"], 
     49              ["sld_shell", "1e-6/Ang^2", 1.5, [-inf, inf], "sld", "Polymer shell SLD"], 
     50              ["sld_solvent", "1e-6/Ang^2", 6.3, [-inf, inf], "sld", "Solvent SLD"]] 
    5151 
    5252# NB: Scale and Background are implicit parameters on every model 
    53 def Iq(q, second_moment, adsorbed_amount, density_poly, radius,  
    54         volfraction, polymer_sld, solvent_sld): 
     53def Iq(q, second_moment, adsorbed_amount, density_shell, radius,  
     54        volfraction, sld_shell, sld_solvent): 
    5555    # pylint: disable = missing-docstring 
    56     deltarhosqrd =  (polymer_sld - solvent_sld) * (polymer_sld - solvent_sld) 
    57     numerator =  6.0 * pi * volfraction * (adsorbed_amount * adsorbed_amount) 
    58     denominator =  (q * q) * (density_poly * density_poly) * radius 
    59     eterm =  exp(-1.0 * (q * q) * (second_moment * second_moment)) 
    60     #scale by 10^10 for units conversion to cm^-1 
    61     inten =  1.0e+10 * deltarhosqrd * ((numerator / denominator) * eterm) 
     56#    deltarhosqrd =  (sld_shell - sld_solvent) * (sld_shell - sld_solvent) 
     57#    numerator =  6.0 * pi * volfraction * (adsorbed_amount * adsorbed_amount) 
     58#    denominator =  (q * q) * (density_shell * density_shell) * radius 
     59#    eterm =  exp(-1.0 * (q * q) * (second_moment * second_moment)) 
     60#    #scale by 10^-2 for units conversion to cm^-1 
     61#    inten =  1.0e-02 * deltarhosqrd * ((numerator / denominator) * eterm) 
     62    aa =  (sld_shell - sld_solvent) * adsorbed_amount / q / density_shell  
     63    bb = q * second_moment 
     64    #scale by 10^-2 for units conversion to cm^-1 
     65    inten =  6.0e-02 * pi * volfraction * aa * aa * exp(-bb * bb) / radius 
    6266    return inten 
    6367Iq.vectorized =  True  # Iq accepts an array of q values 
     
    7175            second_moment = 23.0, 
    7276            adsorbed_amount = 1.9, 
    73             density_poly = 0.7, 
     77            density_shell = 0.7, 
    7478            radius = 500.0, 
    7579            volfraction = 0.14, 
    76             polymer_sld = 1.5e-06, 
    77             solvent_sld = 6.3e-06, 
     80            sld_shell = 1.5, 
     81            sld_solvent = 6.3, 
    7882            background = 0.0) 
    7983 
     
    8286               second_moment = 'second_moment', 
    8387               adsorbed_amount = 'ads_amount', 
    84                density_poly = 'density_poly', 
     88               density_shell = 'density_poly', 
    8589               radius = 'radius_core', 
    8690               volfraction = 'volf_cores', 
    87                polymer_sld = 'sld_poly', 
    88                solvent_sld = 'sld_solv', 
     91               sld_shell = 'sld_poly', 
     92               sld_solvent = 'sld_solv', 
    8993               background = 'background') 
    9094 
     
    9296tests =  [ 
    9397    [{'scale': 1.0, 'second_moment': 23.0, 'adsorbed_amount': 1.9,  
    94      'density_poly': 0.7, 'radius': 500.0, 'volfraction': 0.14,  
    95      'polymer_sld': 1.5e-06, 'solvent_sld': 6.3e-06, 'background': 0.0}, 
     98     'density_shell': 0.7, 'radius': 500.0, 'volfraction': 0.14,  
     99     'sld_shell': 1.5, 'sld_solvent': 6.3, 'background': 0.0}, 
    96100     [0.0106939, 0.469418], [73.741, 9.65391e-53]], 
    97101    ] 
     102# ADDED by: SMK  ON: 16Mar2016  convert from sasview, check vs SANDRA, 18Mar2016 RKH some edits & renaming 
Note: See TracChangeset for help on using the changeset viewer.