Changeset f0afad2 in sasmodels for sasmodels/models/poly_gauss_coil.py


Ignore:
Timestamp:
Oct 18, 2016 10:54:57 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:
b829b16
Parents:
6d96b66
Message:

poly_gauss_coil: improved accuracy

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/poly_gauss_coil.py

    ra807206 rf0afad2  
    5959""" 
    6060 
    61 from numpy import inf, exp, power 
     61import numpy as np 
     62from numpy import inf, expm1, power 
    6263 
    6364name = "poly_gauss_coil" 
     
    8384    # pylint: disable = missing-docstring 
    8485    u = polydispersity - 1.0 
    85     z = (q*rg)**2 / (1.0 + 2.0*u) 
     86    z = q**2 * (rg**2 / (1.0 + 2.0*u)) 
     87 
    8688    # need to trap the case of the polydispersity being 1 (ie, monodisperse!) 
    8789    if polydispersity == 1.0: 
    88         inten = i_zero * 2.0 * (exp(-z) + z - 1.0) 
     90        result = 2.0 * (expm1(-z) + z) 
     91        index = q != 0. 
     92        result[index] /= z[index]**2 
     93        result[~index] = 1.0 
    8994    else: 
    90         inten = i_zero * 2.0 * (power(1.0 + u*z, -1.0/u) + z - 1.0) / (1.0 + u) 
    91     index = q != 0. 
    92     inten[~index] = i_zero 
    93     inten[index] /= z[index]**2 
    94     return inten 
     95        # Taylor series around z=0 of (2*(1+uz)^(-1/u) + z - 1) / (z^2(u+1)) 
     96        p = [ 
     97            #(-1 - 20*u - 155*u**2 - 580*u**3 - 1044*u**4 - 720*u**5) / 2520., 
     98            #( 1 + 14*u + 71*u**2 + 154*u**3 + 120*u**4) / 360., 
     99            #(-1 - 9*u - 26*u**2 - 24*u**3) / 60., 
     100            ( 1 + 5*u + 6*u**2) / 12., 
     101            (-1 - 2*u) / 3., 
     102            ( 1 ), 
     103            ] 
     104        result = 2.0 * (power(1.0 + u*z, -1.0/u) + z - 1.0) / (1.0 + u) 
     105        index = z > 1e-4 
     106        result[index] /= z[index]**2 
     107        result[~index] = np.polyval(p, z[~index]) 
     108    return i_zero * result 
    95109Iq.vectorized = True  # Iq accepts an array of q values 
    96110 
Note: See TracChangeset for help on using the changeset viewer.