Changeset 68b8734 in sasmodels


Ignore:
Timestamp:
Mar 18, 2016 9:01:46 AM (8 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:
aceac39
Parents:
de97440 (diff), 3b12dea (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 github.com:sasview/sasmodels

Files:
3 added
4 edited
7 moved

Legend:

Unmodified
Added
Removed
  • sasmodels/models/bessel.py

    rcbd37a7 ra5af4e1  
    7878 
    7979Iq = """ 
    80     return 2.0*j1(q)/q; 
     80    return J1(q); 
    8181    """ 
    8282 
  • sasmodels/models/lamellar_hg.py

    raa2edb2 r52a3db3  
    2626 
    2727where $\delta_T$ is *tail_length*, $\delta_H$ is *head_length*, 
    28 $\Delta\rho_H$ is the head contrast (*head_sld* $-$ *solvent_sld*), 
    29 and $\Delta\rho_T$ is tail contrast (*sld* $-$ *solvent_sld*). 
     28$\Delta\rho_H$ is the head contrast (*sld_head* $-$ *sld_solvent*), 
     29and $\Delta\rho_T$ is tail contrast (*sld* $-$ *sld_solvent*). 
     30 
     31The total thickness of the lamellar sheet is $\delta_H$ + $\delta_T$ + $\delta_T$ + $\delta_H$. 
     32Note that in a non aqueous solvent the chemical "head" group may be the  
     33"Tail region" and vice-versa. 
    3034 
    3135The 2D scattering intensity is calculated in the same way as 1D, where 
     
    4953from numpy import inf 
    5054 
    51 name = "lamellar_FFHG" 
    52 title = "Random lamellar phase with Head Groups" 
     55name = "lamellar_hg" 
     56title = "Random lamellar phase with Head and Tail Groups" 
    5357description = """\ 
    54     [Random lamellar phase with Head Groups] 
     58    [Random lamellar phase with Head and Tail Groups] 
    5559        I(q)= 2*pi*P(q)/(2(H+T)*q^(2)), where 
    5660        P(q)= see manual 
    5761        layer thickness =(H+T+T+H) = 2(Head+Tail) 
    5862        sld = Tail scattering length density 
    59         head_sld = Head scattering length density 
    60         solvent_sld = solvent scattering length density 
     63        sld_head = Head scattering length density 
     64        sld_solvent = solvent scattering length density 
    6165        background = incoherent background 
    6266        scale = scale factor 
     
    6670# pylint: disable=bad-whitespace, line-too-long 
    6771#             ["name", "units", default, [lower, upper], "type","description"], 
    68 parameters = [["tail_length", "Ang",       15,   [0, inf],  "volume",  "Tail thickness"], 
    69               ["head_length", "Ang",       10,   [0, inf],  "volume",  "head thickness"], 
     72parameters = [["tail_length", "Ang",       15,   [0, inf],  "volume",  "Tail thickness ( total = H+T+T+H)"], 
     73              ["head_length", "Ang",       10,   [0, inf],  "volume",  "Head thickness"], 
    7074              ["sld",         "1e-6/Ang^2", 0.4, [-inf,inf], "",       "Tail scattering length density"], 
    71               ["head_sld",    "1e-6/Ang^2", 3.0, [-inf,inf], "",       "Head scattering length density"], 
    72               ["solvent_sld", "1e-6/Ang^2", 6,   [-inf,inf], "",       "Solvent scattering length density"]] 
     75              ["sld_head",    "1e-6/Ang^2", 3.0, [-inf,inf], "",       "Head scattering length density"], 
     76              ["sld_solvent", "1e-6/Ang^2", 6,   [-inf,inf], "",       "Solvent scattering length density"]] 
    7377# pylint: enable=bad-whitespace, line-too-long 
    7478 
     
    8185Iq = """ 
    8286    const double qsq = q*q; 
    83     const double drh = head_sld - solvent_sld; 
    84     const double drt = sld - solvent_sld;    //correction 13FEB06 by L.Porcar 
     87    const double drh = sld_head - sld_solvent; 
     88    const double drt = sld - sld_solvent;    //correction 13FEB06 by L.Porcar 
    8589    const double qT = q*tail_length; 
    8690    double Pq, inten; 
     
    106110demo = dict(scale=1, background=0, 
    107111            tail_length=15, head_length=10, 
    108             sld=0.4, head_sld=3.0, solvent_sld=6.0, 
     112            sld=0.4, sld_head=3.0, sld_solvent=6.0, 
    109113            tail_length_pd=0.2, tail_length_pd_n=40, 
    110114            head_length_pd=0.01, head_length_pd_n=40) 
     
    112116oldname = 'LamellarFFHGModel' 
    113117oldpars = dict(head_length='h_thickness', tail_length='t_length', 
    114                sld='sld_tail', head_sld='sld_head', solvent_sld='sld_solvent') 
     118               sld='sld_tail', sld_head='sld_head', sld_solvent='sld_solvent') 
    115119# 
    116120tests = [[{'scale': 1.0, 'background': 0.0, 'tail_length': 15.0, 'head_length': 10.0, 
    117            'sld': 0.4, 'head_sld': 3.0, 'solvent_sld': 6.0}, [0.001], [653143.9209]]] 
     121           'sld': 0.4, 'sld_head': 3.0, 'sld_solvent': 6.0}, [0.001], [653143.9209]]] 
     122# ADDED by: RKH  ON: 18Mar2016  converted from sasview previously, now renaming everything & sorting the docs 
  • sasmodels/models/lamellar_hg_stack_caille.py

    raa2edb2 r6ab4ed8  
    99.. math:: 
    1010 
    11     I(q) = 2 \pi \frac{P(q)S(q)}{\delta q^2} 
     11    I(q) = 2 \pi \frac{P(q)S(q)}{q^2\delta } 
    1212 
    1313 
     
    5656results for the next lower and higher values. 
    5757 
     58Be aware that the computations may be very slow. 
     59 
    5860The 2D scattering intensity is calculated in the same way as 1D, where 
    5961the $q$ vector is defined as 
     
    7375from numpy import inf 
    7476 
    75 name = "lamellarCailleHG" 
    76 title = "Random lamellar sheet with Caille structure factor" 
     77name = "lamellar_hg_stack_caille" 
     78title = "Random lamellar head/tail/tail/head sheet with Caille structure factor" 
    7779description = """\ 
    7880    [Random lamellar phase with Caille  structure factor] 
     
    104106    ["sld", "1e-6/Ang^2", 0.4, [-inf, inf], "", 
    105107     "Tail scattering length density"], 
    106     ["head_sld", "1e-6/Ang^2", 2.0, [-inf, inf], "", 
     108    ["sld_head", "1e-6/Ang^2", 2.0, [-inf, inf], "", 
    107109     "Head scattering length density"], 
    108     ["solvent_sld", "1e-6/Ang^2", 6, [-inf, inf], "", 
     110    ["sld_solvent", "1e-6/Ang^2", 6, [-inf, inf], "", 
    109111     "Solvent scattering length density"], 
    110112    ] 
    111113 
    112 source = ["lamellarCailleHG_kernel.c"] 
     114source = ["lamellar_hg_stack_caille_kernel.c"] 
    113115 
    114116# No volume normalization despite having a volume parameter 
     
    129131    Nlayers=20, spacing=200., Caille_parameter=0.05, 
    130132    tail_length=15, head_length=10, 
    131     #sld=-1, head_sld=4.0, solvent_sld=6.0, 
    132     sld=-1, head_sld=4.1, solvent_sld=6.0, 
     133    #sld=-1, sld_head=4.0, sld_solvent=6.0, 
     134    sld=-1, sld_head=4.1, sld_solvent=6.0, 
    133135    tail_length_pd=0.1, tail_length_pd_n=20, 
    134136    head_length_pd=0.05, head_length_pd_n=30, 
     
    140142oldpars = dict( 
    141143    tail_length='deltaT', head_length='deltaH', Nlayers='n_plates', 
    142     Caille_parameter='caille', sld='sld_tail', head_sld='sld_head', 
    143     solvent_sld='sld_solvent') 
     144    Caille_parameter='caille', sld='sld_tail', sld_head='sld_head', 
     145    sld_solvent='sld_solvent') 
    144146# 
    145147tests = [[{'scale': 1.0, 'background': 0.0, 'tail_length': 10.0, 'head_length': 2.0, 
    146148           'Nlayers': 30.0, 'spacing': 40., 'Caille_parameter': 0.001, 'sld': 0.4, 
    147            'head_sld': 2.0, 'solvent_sld': 6.0, 'tail_length_pd': 0.0, 
     149           'sld_head': 2.0, 'sld_solvent': 6.0, 'tail_length_pd': 0.0, 
    148150           'head_length_pd': 0.0, 'spacing_pd': 0.0}, [0.001], [6838238.571488]]] 
     151# ADDED by: RKH  ON: 18Mar2016  converted from sasview previously, now renaming everything & sorting the docs 
  • sasmodels/models/lamellar_stack_caille.py

    raa2edb2 r6ab4ed8  
    1111.. math:: 
    1212 
    13     I(q) = 2\pi \frac{P(q)S(q)}{\delta q^2} 
     13    I(q) = 2\pi \frac{P(q)S(q)}{q^2\delta } 
    1414 
    1515The form factor is 
     
    7070from numpy import inf 
    7171 
    72 name = "lamellarPS" 
     72name = "lamellar_stack_caille" 
    7373title = "Random lamellar sheet with Caille structure factor" 
    7474description = """\ 
     
    9292    ["Caille_parameter", "1/Ang^2",    0.1, [0.0,0.8],  "",       "Caille parameter"], 
    9393    ["sld",              "1e-6/Ang^2", 6.3, [-inf,inf], "",       "layer scattering length density"], 
    94     ["solvent_sld",      "1e-6/Ang^2", 1.0, [-inf,inf], "",       "Solvent scattering length density"], 
     94    ["sld_solvent",      "1e-6/Ang^2", 1.0, [-inf,inf], "",       "Solvent scattering length density"], 
    9595    ] 
    9696# pylint: enable=bad-whitespace, line-too-long 
    9797 
    98 source = ["lamellarCaille_kernel.c"] 
     98source = ["lamellar_stack_caille_kernel.c"] 
    9999 
    100100# No volume normalization despite having a volume parameter 
     
    113113demo = dict(scale=1, background=0, 
    114114            thickness=67., Nlayers=3.75, spacing=200., 
    115             Caille_parameter=0.268, sld=1.0, solvent_sld=6.34, 
     115            Caille_parameter=0.268, sld=1.0, sld_solvent=6.34, 
    116116            thickness_pd=0.1, thickness_pd_n=100, 
    117117            spacing_pd=0.05, spacing_pd_n=40) 
     
    120120oldpars = dict(thickness='delta', Nlayers='N_plates', 
    121121               Caille_parameter='caille', 
    122                sld='sld_bi', solvent_sld='sld_sol') 
     122               sld='sld_bi', sld_solvent='sld_sol') 
    123123# 
    124124tests = [ 
    125125    [{'scale': 1.0, 'background': 0.0, 'thickness': 30., 'Nlayers': 20.0, 
    126126      'spacing': 400., 'Caille_parameter': 0.1, 'sld': 6.3, 
    127       'solvent_sld': 1.0, 'thickness_pd': 0.0, 'spacing_pd': 0.0}, 
     127      'sld_solvent': 1.0, 'thickness_pd': 0.0, 'spacing_pd': 0.0}, 
    128128     [0.001], [28895.13397]] 
    129129    ] 
     130# ADDED by: RKH  ON: 18Mar2016  converted from sasview previously, now renaming everything & sorting the docs 
  • sasmodels/models/lamellar_stack_paracrystal.py

    raa2edb2 r6ab4ed8  
    1616  *not* the total excluded volume of the paracrystal), 
    1717 
    18 - *sld* $-$ *solvent_sld* is the contrast $\Delta \rho$, 
     18- *sld* $-$ *sld_solvent* is the contrast $\Delta \rho$, 
    1919 
    2020- *thickness* is the layer thickness $t$, 
     
    3636 
    3737The form factor of the bilayer is approximated as the cross section of an 
    38 infinite, planar bilayer of thickness $t$ 
     38infinite, planar bilayer of thickness $t$ (compare the equations for the 
     39lamellar model). 
    3940 
    4041.. math:: 
     
    9495from numpy import inf 
    9596 
    96 name = "lamellarPC" 
     97name = "lamellar_stack_paracrystal" 
    9798title = "Random lamellar sheet with paracrystal structure factor" 
    9899description = """\ 
     
    120121              ["sld", "1e-6/Ang^2", 1.0, [-inf, inf], "", 
    121122               "layer scattering length density"], 
    122               ["solvent_sld", "1e-6/Ang^2", 6.34, [-inf, inf], "", 
     123              ["sld_solvent", "1e-6/Ang^2", 6.34, [-inf, inf], "", 
    123124               "Solvent scattering length density"], 
    124125             ] 
    125126 
    126127 
    127 source = ["lamellarPC_kernel.c"] 
     128source = ["lamellar_stack_paracrystal_kernel.c"] 
    128129 
    129130form_volume = """ 
     
    140141demo = dict(scale=1, background=0, 
    141142            thickness=33, Nlayers=20, spacing=250, spacing_polydisp=0.2, 
    142             sld=1.0, solvent_sld=6.34, 
     143            sld=1.0, sld_solvent=6.34, 
    143144            thickness_pd=0.2, thickness_pd_n=40) 
    144145 
    145146oldname = 'LamellarPCrystalModel' 
    146147oldpars = dict(spacing_polydisp='pd_spacing', sld='sld_layer', 
    147                solvent_sld='sld_solvent') 
     148               sld_solvent='sld_solvent') 
    148149# 
    149150tests = [ 
    150151        [ {'scale': 1.0, 'background' : 0.0, 'thickness' : 33.,'Nlayers' : 20.0, 'spacing' : 250., 'spacing_polydisp' : 0.2, 
    151             'sld' : 1.0, 'solvent_sld' : 6.34, 
     152            'sld' : 1.0, 'sld_solvent' : 6.34, 
    152153            'thickness_pd' : 0.0, 'thickness_pd_n' : 40 }, [0.001, 0.215268], [21829.3, 0.00487686]] 
    153154        ] 
     155# ADDED by: RKH  ON: 18Mar2016  converted from sasview previously, now renaming everything & sorting the docs 
  • sasmodels/models/lib/j1_cephes.c

    re2af2a9 ra5af4e1  
    3939Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier 
    4040*/ 
    41 double j1(double ); 
     41double J1(double ); 
    4242 
    43 double j1(double x) { 
     43double J1(double x) { 
    4444 
    4545//Cephes double pression function 
     
    4848    double w, z, p, q, xn; 
    4949 
    50     const double DR1 = 5.78318596294678452118E0; 
    51     const double DR2 = 3.04712623436620863991E1; 
    5250    const double Z1 = 1.46819706421238932572E1; 
    5351    const double Z2 = 4.92184563216946036703E1; 
    5452    const double THPIO4 =  2.35619449019234492885; 
    5553    const double SQ2OPI = 0.79788456080286535588; 
    56  
    57     double RP[8] = { 
    58     -8.99971225705559398224E8, 
    59     4.52228297998194034323E11, 
    60     -7.27494245221818276015E13, 
    61     3.68295732863852883286E15, 
    62     0.0, 
    63     0.0, 
    64     0.0, 
    65     0.0 
    66     }; 
    67  
    68     double RQ[8] = { 
    69     /* 1.00000000000000000000E0,*/ 
    70     6.20836478118054335476E2, 
    71     2.56987256757748830383E5, 
    72     8.35146791431949253037E7, 
    73     2.21511595479792499675E10, 
    74     4.74914122079991414898E12, 
    75     7.84369607876235854894E14, 
    76     8.95222336184627338078E16, 
    77     5.32278620332680085395E18, 
    78     }; 
    79  
    80     double PP[8] = { 
    81     7.62125616208173112003E-4, 
    82     7.31397056940917570436E-2, 
    83     1.12719608129684925192E0, 
    84     5.11207951146807644818E0, 
    85     8.42404590141772420927E0, 
    86     5.21451598682361504063E0, 
    87     1.00000000000000000254E0, 
    88     0.0, 
    89     }; 
    90     double PQ[8] = { 
    91     5.71323128072548699714E-4, 
    92     6.88455908754495404082E-2, 
    93     1.10514232634061696926E0, 
    94     5.07386386128601488557E0, 
    95     8.39985554327604159757E0, 
    96     5.20982848682361821619E0, 
    97     9.99999999999999997461E-1, 
    98     0.0, 
    99     }; 
    100  
    101     double QP[8] = { 
    102     5.10862594750176621635E-2, 
    103     4.98213872951233449420E0, 
    104     7.58238284132545283818E1, 
    105     3.66779609360150777800E2, 
    106     7.10856304998926107277E2, 
    107     5.97489612400613639965E2, 
    108     2.11688757100572135698E2, 
    109     2.52070205858023719784E1, 
    110     }; 
    111  
    112     double QQ[8] = { 
    113     /* 1.00000000000000000000E0,*/ 
    114     7.42373277035675149943E1, 
    115     1.05644886038262816351E3, 
    116     4.98641058337653607651E3, 
    117     9.56231892404756170795E3, 
    118     7.99704160447350683650E3, 
    119     2.82619278517639096600E3, 
    120     3.36093607810698293419E2, 
    121     0.0, 
    122     }; 
    12354 
    12455    w = x; 
     
    12960        { 
    13061            z = x * x; 
    131             w = polevl( z, RP, 3 ) / p1evl( z, RQ, 8 ); 
     62            w = polevlRP( z, 3 ) / p1evlRQ( z, 8 ); 
    13263            w = w * x * (z - Z1) * (z - Z2); 
    13364            return( w ); 
     
    13667    w = 5.0/x; 
    13768    z = w * w; 
    138     p = polevl( z, PP, 6)/polevl( z, PQ, 6 ); 
    139     q = polevl( z, QP, 7)/p1evl( z, QQ, 7 ); 
     69 
     70    p = polevlPP( z, 6)/polevlPQ( z, 6 ); 
     71    q = polevlQP( z, 7)/p1evlQQ( z, 7 ); 
     72 
    14073    xn = x - THPIO4; 
    14174 
     
    15588 
    15689 
    157     double JP[8] = { 
    158         -4.878788132172128E-009, 
    159         6.009061827883699E-007, 
    160         -4.541343896997497E-005, 
    161         1.937383947804541E-003, 
    162         -3.405537384615824E-002, 
    163         0.0, 
    164         0.0, 
    165         0.0 
    166     }; 
    167  
    168     double MO1[8] = { 
    169         6.913942741265801E-002, 
    170         -2.284801500053359E-001, 
    171         3.138238455499697E-001, 
    172         -2.102302420403875E-001, 
    173         5.435364690523026E-003, 
    174         1.493389585089498E-001, 
    175         4.976029650847191E-006, 
    176         7.978845453073848E-001 
    177     }; 
    178  
    179     double PH1[8] = { 
    180         -4.497014141919556E+001, 
    181         5.073465654089319E+001, 
    182         -2.485774108720340E+001, 
    183         7.222973196770240E+000, 
    184         -1.544842782180211E+000, 
    185         3.503787691653334E-001, 
    186         -1.637986776941202E-001, 
    187         3.749989509080821E-001 
    188     }; 
    189  
    19090    xx = x; 
    19191    if( xx < 0 ) 
     
    19595        { 
    19696            z = xx * xx; 
    197             p = (z-Z1) * xx * polevl( z, JP, 4 ); 
     97            p = (z-Z1) * xx * polevlJP( z, 4 ); 
    19898            return( p ); 
    19999        } 
     
    202102    w = sqrt(q); 
    203103 
    204     p = w * polevl( q, MO1, 7); 
     104    p = w * polevlMO1( q, 7); 
    205105    w = q*q; 
    206     xn = q * polevl( w, PH1, 7) - THPIO4F; 
     106    xn = q * polevlPH1( w, 7) - THPIO4F; 
    207107    p = p * cos(xn + xx); 
    208108 
     
    210110#endif 
    211111} 
    212  
  • sasmodels/models/lib/polevl.c

    re2af2a9 r3b12dea  
    5151*/ 
    5252 
    53 double polevl( double x, double coef[8], int N ); 
    54 double p1evl( double x, double coef[8], int N ); 
    55  
    56 double polevl( double x, double coef[8], int N ) { 
    57  
    58     int i = 0; 
    59     double ans = coef[i]; 
    60  
    61     while (i < N) { 
    62         i++; 
    63         ans = ans * x + coef[i]; 
    64     } 
    65  
    66     return ans ; 
    67  
    68 } 
     53double polevlRP(double x, int N ) { 
     54 
     55    double coef[8] = { 
     56    -8.99971225705559398224E8, 
     57    4.52228297998194034323E11, 
     58    -7.27494245221818276015E13, 
     59    3.68295732863852883286E15, 
     60    0.0, 
     61    0.0, 
     62    0.0, 
     63    0.0 }; 
     64 
     65    int i = 0; 
     66    double ans = coef[i]; 
     67 
     68    while (i < N) { 
     69        i++; 
     70        ans = ans * x + coef[i]; 
     71    } 
     72    return ans ; 
     73} 
     74 
     75double polevlRQ(double x, int N ) { 
     76 
     77    double coef[8] = { 
     78        6.20836478118054335476E2, 
     79        2.56987256757748830383E5, 
     80        8.35146791431949253037E7, 
     81        2.21511595479792499675E10, 
     82        4.74914122079991414898E12, 
     83        7.84369607876235854894E14, 
     84        8.95222336184627338078E16, 
     85        5.32278620332680085395E18 
     86    }; 
     87 
     88    int i = 0; 
     89    double ans = coef[i]; 
     90 
     91    while (i < N) { 
     92        i++; 
     93        ans = ans * x + coef[i]; 
     94    } 
     95    return ans ; 
     96} 
     97 
     98double polevlPP(double x, int N ) { 
     99 
     100    double coef[8] = { 
     101    7.62125616208173112003E-4, 
     102    7.31397056940917570436E-2, 
     103    1.12719608129684925192E0, 
     104    5.11207951146807644818E0, 
     105    8.42404590141772420927E0, 
     106    5.21451598682361504063E0, 
     107    1.00000000000000000254E0, 
     108    0.0} ; 
     109 
     110    int i = 0; 
     111    double ans = coef[i]; 
     112 
     113    while (i < N) { 
     114        i++; 
     115        ans = ans * x + coef[i]; 
     116    } 
     117    return ans ; 
     118} 
     119 
     120double polevlPQ(double x, int N ) { 
     121 
     122    double coef[8] = { 
     123    5.71323128072548699714E-4, 
     124    6.88455908754495404082E-2, 
     125    1.10514232634061696926E0, 
     126    5.07386386128601488557E0, 
     127    8.39985554327604159757E0, 
     128    5.20982848682361821619E0, 
     129    9.99999999999999997461E-1, 
     130    0.0 }; 
     131 
     132    int i = 0; 
     133    double ans = coef[i]; 
     134 
     135    while (i < N) { 
     136        i++; 
     137        ans = ans * x + coef[i]; 
     138    } 
     139    return ans ; 
     140} 
     141 
     142double polevlQP(double x, int N ) { 
     143 
     144    double coef[8] = { 
     145    5.10862594750176621635E-2, 
     146    4.98213872951233449420E0, 
     147    7.58238284132545283818E1, 
     148    3.66779609360150777800E2, 
     149    7.10856304998926107277E2, 
     150    5.97489612400613639965E2, 
     151    2.11688757100572135698E2, 
     152    2.52070205858023719784E1 }; 
     153 
     154    int i = 0; 
     155    double ans = coef[i]; 
     156 
     157    while (i < N) { 
     158        i++; 
     159        ans = ans * x + coef[i]; 
     160    } 
     161    return ans ; 
     162 
     163} 
     164 
     165double polevlQQ(double x, int N ) { 
     166 
     167    double coef[8] = { 
     168    7.42373277035675149943E1, 
     169    1.05644886038262816351E3, 
     170    4.98641058337653607651E3, 
     171    9.56231892404756170795E3, 
     172    7.99704160447350683650E3, 
     173    2.82619278517639096600E3, 
     174    3.36093607810698293419E2, 
     175    0.0 }; 
     176 
     177    int i = 0; 
     178    double ans = coef[i]; 
     179 
     180    while (i < N) { 
     181        i++; 
     182        ans = ans * x + coef[i]; 
     183    } 
     184    return ans ; 
     185 
     186} 
     187 
     188double polevlJP( double x, int N ) { 
     189    double coef[8] = { 
     190        -4.878788132172128E-009, 
     191        6.009061827883699E-007, 
     192        -4.541343896997497E-005, 
     193        1.937383947804541E-003, 
     194        -3.405537384615824E-002, 
     195        0.0, 
     196        0.0, 
     197        0.0 
     198    }; 
     199 
     200    int i = 0; 
     201    double ans = coef[i]; 
     202 
     203    while (i < N) { 
     204        i++; 
     205        ans = ans * x + coef[i]; 
     206    } 
     207    return ans ; 
     208 
     209} 
     210 
     211double polevlMO1( double x, int N ) { 
     212    double coef[8] = { 
     213        6.913942741265801E-002, 
     214        -2.284801500053359E-001, 
     215        3.138238455499697E-001, 
     216        -2.102302420403875E-001, 
     217        5.435364690523026E-003, 
     218        1.493389585089498E-001, 
     219        4.976029650847191E-006, 
     220        7.978845453073848E-001 
     221    }; 
     222 
     223    int i = 0; 
     224    double ans = coef[i]; 
     225 
     226    while (i < N) { 
     227        i++; 
     228        ans = ans * x + coef[i]; 
     229    } 
     230    return ans ; 
     231} 
     232 
     233double polevlPH1( double x, int N ) { 
     234 
     235    double coef[8] = { 
     236        -4.497014141919556E+001, 
     237        5.073465654089319E+001, 
     238        -2.485774108720340E+001, 
     239        7.222973196770240E+000, 
     240        -1.544842782180211E+000, 
     241        3.503787691653334E-001, 
     242        -1.637986776941202E-001, 
     243        3.749989509080821E-001 
     244    }; 
     245 
     246    int i = 0; 
     247    double ans = coef[i]; 
     248 
     249    while (i < N) { 
     250        i++; 
     251        ans = ans * x + coef[i]; 
     252    } 
     253    return ans ; 
     254} 
     255 
     256/*double polevl( double x, double coef[8], int N ) { 
     257 
     258    int i = 0; 
     259    double ans = coef[i]; 
     260 
     261    while (i < N) { 
     262        i++; 
     263        ans = ans * x + coef[i]; 
     264    } 
     265 
     266    return ans ; 
     267 
     268}*/ 
    69269 
    70270/*                                                      p1evl() */ 
     
    74274 */ 
    75275 
    76 double p1evl( double x, double coef[8], int N ) { 
    77     int i=0; 
    78     double ans = x+coef[i]; 
    79  
    80     while (i < N-1) { 
    81         i++; 
    82         ans = ans*x + coef[i]; 
    83     } 
    84  
    85     return( ans ); 
    86  
    87 } 
     276double p1evlRP( double x, int N ) { 
     277    double coef[8] = { 
     278    -8.99971225705559398224E8, 
     279    4.52228297998194034323E11, 
     280    -7.27494245221818276015E13, 
     281    3.68295732863852883286E15, 
     282    0.0, 
     283    0.0, 
     284    0.0, 
     285    0.0 }; 
     286 
     287    int i=0; 
     288    double ans = x+coef[i]; 
     289 
     290    while (i < N-1) { 
     291        i++; 
     292        ans = ans*x + coef[i]; 
     293    } 
     294 
     295    return( ans ); 
     296 
     297} 
     298 
     299double p1evlRQ( double x, int N ) { 
     300//1: RQ 
     301    double coef[8] = { 
     302    6.20836478118054335476E2, 
     303    2.56987256757748830383E5, 
     304    8.35146791431949253037E7, 
     305    2.21511595479792499675E10, 
     306    4.74914122079991414898E12, 
     307    7.84369607876235854894E14, 
     308    8.95222336184627338078E16, 
     309    5.32278620332680085395E18}; 
     310 
     311    int i=0; 
     312    double ans = x+coef[i]; 
     313 
     314    while (i < N-1) { 
     315        i++; 
     316        ans = ans*x + coef[i]; 
     317    } 
     318 
     319    return( ans ); 
     320} 
     321 
     322double p1evlPP( double x, int N ) { 
     323//3 : PP 
     324    double coef[8] = { 
     325    7.62125616208173112003E-4, 
     326    7.31397056940917570436E-2, 
     327    1.12719608129684925192E0, 
     328    5.11207951146807644818E0, 
     329    8.42404590141772420927E0, 
     330    5.21451598682361504063E0, 
     331    1.00000000000000000254E0, 
     332    0.0}; 
     333 
     334    int i=0; 
     335    double ans = x+coef[i]; 
     336 
     337    while (i < N-1) { 
     338        i++; 
     339        ans = ans*x + coef[i]; 
     340    } 
     341 
     342    return( ans ); 
     343} 
     344 
     345double p1evlPQ( double x, int N ) { 
     346//4: PQ 
     347    double coef[8] = { 
     348    5.71323128072548699714E-4, 
     349    6.88455908754495404082E-2, 
     350    1.10514232634061696926E0, 
     351    5.07386386128601488557E0, 
     352    8.39985554327604159757E0, 
     353    5.20982848682361821619E0, 
     354    9.99999999999999997461E-1, 
     355    0.0}; 
     356 
     357    int i=0; 
     358    double ans = x+coef[i]; 
     359 
     360    while (i < N-1) { 
     361        i++; 
     362        ans = ans*x + coef[i]; 
     363    } 
     364 
     365    return( ans ); 
     366} 
     367 
     368double p1evlQP( double x, int N ) { 
     369//5: QP 
     370    double coef[8] = { 
     371    5.10862594750176621635E-2, 
     372    4.98213872951233449420E0, 
     373    7.58238284132545283818E1, 
     374    3.66779609360150777800E2, 
     375    7.10856304998926107277E2, 
     376    5.97489612400613639965E2, 
     377    2.11688757100572135698E2, 
     378    2.52070205858023719784E1 }; 
     379 
     380    int i=0; 
     381    double ans = x+coef[i]; 
     382 
     383    while (i < N-1) { 
     384        i++; 
     385        ans = ans*x + coef[i]; 
     386    } 
     387 
     388    return( ans ); 
     389} 
     390 
     391double p1evlQQ( double x, int N ) { 
     392    double coef[8] = { 
     393    7.42373277035675149943E1, 
     394    1.05644886038262816351E3, 
     395    4.98641058337653607651E3, 
     396    9.56231892404756170795E3, 
     397    7.99704160447350683650E3, 
     398    2.82619278517639096600E3, 
     399    3.36093607810698293419E2, 
     400    0.0}; 
     401 
     402    int i=0; 
     403    double ans = x+coef[i]; 
     404 
     405    while (i < N-1) { 
     406        i++; 
     407        ans = ans*x + coef[i]; 
     408    } 
     409 
     410    return( ans ); 
     411 
     412} 
     413 
     414double p1evlJP( double x, int N ) { 
     415    double coef[8] = { 
     416        -4.878788132172128E-009, 
     417        6.009061827883699E-007, 
     418        -4.541343896997497E-005, 
     419        1.937383947804541E-003, 
     420        -3.405537384615824E-002, 
     421        0.0, 
     422        0.0, 
     423        0.0}; 
     424 
     425    int i=0; 
     426    double ans = x+coef[i]; 
     427 
     428    while (i < N-1) { 
     429        i++; 
     430        ans = ans*x + coef[i]; 
     431    } 
     432 
     433    return( ans ); 
     434} 
     435 
     436double p1evlMO1( double x, int N ) { 
     437    double coef[8] = { 
     438        6.913942741265801E-002, 
     439        -2.284801500053359E-001, 
     440        3.138238455499697E-001, 
     441        -2.102302420403875E-001, 
     442        5.435364690523026E-003, 
     443        1.493389585089498E-001, 
     444        4.976029650847191E-006, 
     445        7.978845453073848E-001}; 
     446 
     447    int i=0; 
     448    double ans = x+coef[i]; 
     449 
     450    while (i < N-1) { 
     451        i++; 
     452        ans = ans*x + coef[i]; 
     453    } 
     454 
     455    return( ans ); 
     456 
     457} 
     458 
     459double p1evlPH1( double x, int N ) { 
     460    double coef[8] = { 
     461        -4.497014141919556E+001, 
     462        5.073465654089319E+001, 
     463        -2.485774108720340E+001, 
     464        7.222973196770240E+000, 
     465        -1.544842782180211E+000, 
     466        3.503787691653334E-001, 
     467        -1.637986776941202E-001, 
     468        3.749989509080821E-001}; 
     469    int i=0; 
     470    double ans = x+coef[i]; 
     471 
     472    while (i < N-1) { 
     473        i++; 
     474        ans = ans*x + coef[i]; 
     475    } 
     476 
     477    return( ans ); 
     478} 
     479 
     480/*double p1evl( double x, double coef[8], int N ) { 
     481    int i=0; 
     482    double ans = x+coef[i]; 
     483 
     484    while (i < N-1) { 
     485        i++; 
     486        ans = ans*x + coef[i]; 
     487    } 
     488 
     489    return( ans ); 
     490 
     491}*/ 
  • sasmodels/sasview_model.py

    r2622b3f rde97440  
    2323from . import core 
    2424 
    25 def make_class(model_info, dtype='single', namestyle='name'): 
     25def standard_models(): 
     26    return [make_class(model_name) for model_name in core.list_models()] 
     27 
     28def make_class(model_name, namestyle='name'): 
    2629    """ 
    2730    Load the sasview model defined in *kernel_module*. 
    2831 
    29     Returns a class that can be used directly as a sasview model. 
     32    Returns a class that can be used directly as a sasview model.t 
    3033 
    3134    Defaults to using the new name for a model.  Setting 
     
    3336    compatible with SasView. 
    3437    """ 
    35     model = core.build_model(model_info, dtype=dtype) 
     38    model_info = core.load_model_info(model_name) 
    3639    def __init__(self, multfactor=1): 
    37         SasviewModel.__init__(self, model) 
     40        SasviewModel.__init__(self, model_info) 
    3841    attrs = dict(__init__=__init__) 
    39     ConstructedModel = type(model.info[namestyle], (SasviewModel,), attrs) 
     42    ConstructedModel = type(model_info[namestyle], (SasviewModel,), attrs) 
    4043    return ConstructedModel 
    4144 
     
    4447    Sasview wrapper for opencl/ctypes model. 
    4548    """ 
    46     def __init__(self, model): 
    47         """Initialization""" 
    48         self._model = model 
    49  
    50         self.name = model.info['name'] 
    51         self.oldname = model.info['oldname'] 
    52         self.description = model.info['description'] 
     49    def __init__(self, model_info): 
     50        self._model_info = model_info 
     51        self._kernel = None 
     52 
     53        self.name = model_info['name'] 
     54        self.oldname = model_info['oldname'] 
     55        self.description = model_info['description'] 
    5356        self.category = None 
    5457        self.multiplicity_info = None 
     
    6063        self.params = collections.OrderedDict() 
    6164        self.dispersion = dict() 
    62         partype = model.info['partype'] 
    63  
    64         for p in model.info['parameters']: 
     65        partype = model_info['partype'] 
     66 
     67        for p in model_info['parameters']: 
    6568            self.params[p.name] = p.default 
    6669            self.details[p.name] = [p.units] + p.limits 
     
    8386 
    8487        ## independent parameter name and unit [string] 
    85         self.input_name = model.info.get("input_name", "Q") 
    86         self.input_unit = model.info.get("input_unit", "A^{-1}") 
    87         self.output_name = model.info.get("output_name", "Intensity") 
    88         self.output_unit = model.info.get("output_unit", "cm^{-1}") 
     88        self.input_name = model_info.get("input_name", "Q") 
     89        self.input_unit = model_info.get("input_unit", "A^{-1}") 
     90        self.output_name = model_info.get("output_name", "Intensity") 
     91        self.output_unit = model_info.get("output_unit", "cm^{-1}") 
    8992 
    9093        ## _persistency_dict is used by sas.perspectives.fitting.basepage 
     
    9598        ## New fields introduced for opencl rewrite 
    9699        self.cutoff = 1e-5 
     100 
     101    def __get_state__(self): 
     102        state = self.__dict__.copy() 
     103        model_id = self._model_info['id'] 
     104        state.pop('_kernel') 
     105        # May need to reload model info on set state since it has pointers 
     106        # to python implementations of Iq, etc. 
     107        #state.pop('_model_info') 
     108        return state 
     109 
     110    def __set_state__(self, state): 
     111        self.__dict__ = state 
     112        self._kernel = None 
    97113 
    98114    def __str__(self): 
     
    187203        # TODO: fix test so that parameter order doesn't matter 
    188204        ret = ['%s.%s' % (d.lower(), p) 
    189                for d in self._model.info['partype']['pd-2d'] 
     205               for d in self._model_info['partype']['pd-2d'] 
    190206               for p in ('npts', 'nsigmas', 'width')] 
    191207        #print(ret) 
     
    261277            # Check whether we have a list of ndarrays [qx,qy] 
    262278            qx, qy = qdist 
    263             partype = self._model.info['partype'] 
     279            partype = self._model_info['partype'] 
    264280            if not partype['orientation'] and not partype['magnetic']: 
    265281                return self.calculate_Iq(np.sqrt(qx ** 2 + qy ** 2)) 
     
    284300        to the card for each evaluation. 
    285301        """ 
     302        if self._kernel is None: 
     303            self._kernel = core.build_model(self._model_info) 
    286304        q_vectors = [np.asarray(q) for q in args] 
    287         fn = self._model(q_vectors) 
     305        fn = self._kernel(q_vectors) 
    288306        pars = [self.params[v] for v in fn.fixed_pars] 
    289307        pd_pars = [self._get_weights(p) for p in fn.pd_pars] 
     
    299317        :return: the value of the effective radius 
    300318        """ 
    301         ER = self._model.info.get('ER', None) 
     319        ER = self._model_info.get('ER', None) 
    302320        if ER is None: 
    303321            return 1.0 
     
    314332        :return: the value of the volf ratio 
    315333        """ 
    316         VR = self._model.info.get('VR', None) 
     334        VR = self._model_info.get('VR', None) 
    317335        if VR is None: 
    318336            return 1.0 
     
    358376        parameter set in the vector. 
    359377        """ 
    360         pars = self._model.info['partype']['volume'] 
     378        pars = self._model_info['partype']['volume'] 
    361379        return core.dispersion_mesh([self._get_weights(p) for p in pars]) 
    362380 
     
    368386        from . import weights 
    369387 
    370         relative = self._model.info['partype']['pd-rel'] 
    371         limits = self._model.info['limits'] 
     388        relative = self._model_info['partype']['pd-rel'] 
     389        limits = self._model_info['limits'] 
    372390        dis = self.dispersion[par] 
    373391        value, weight = weights.get_weights( 
     
    375393            self.params[par], limits[par], par in relative) 
    376394        return value, weight / np.sum(weight) 
     395 
Note: See TracChangeset for help on using the changeset viewer.