Changeset ff31782 in sasmodels


Ignore:
Timestamp:
Nov 6, 2017 4:10:09 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
d4db147
Parents:
74768cb
Message:

add -ngauss option to compare in order to set the number of integration points

Location:
sasmodels
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    r376b0ee rff31782  
    4444from .direct_model import DirectModel, get_mesh 
    4545from .convert import revert_name, revert_pars, constrain_new_to_old 
    46 from .generate import FLOAT_RE 
     46from .generate import FLOAT_RE, set_integration_size 
    4747from .weights import plot_weights 
    4848 
     
    801801    return data, index 
    802802 
    803 def make_engine(model_info, data, dtype, cutoff): 
     803def make_engine(model_info, data, dtype, cutoff, ngauss=0): 
    804804    # type: (ModelInfo, Data, str, float) -> Calculator 
    805805    """ 
     
    809809    than OpenCL. 
    810810    """ 
     811    if ngauss: 
     812        set_integration_size(model_info, ngauss) 
     813 
    811814    if dtype == 'sasview': 
    812815        return eval_sasview(model_info, data) 
     
    10451048    'poly', 'mono', 'cutoff=', 
    10461049    'magnetic', 'nonmagnetic', 
    1047     'accuracy=', 
     1050    'accuracy=', 'ngauss=', 
    10481051    'neval=',  # for timing... 
    10491052 
     
    11791182        'show_weights' : False, 
    11801183        'sphere'    : 0, 
     1184        'ngauss'    : '0', 
    11811185    } 
    11821186    for arg in flags: 
     
    12051209        elif arg.startswith('-engine='):   opts['engine'] = arg[8:] 
    12061210        elif arg.startswith('-neval='):    opts['count'] = arg[7:] 
     1211        elif arg.startswith('-ngauss='):   opts['ngauss'] = arg[8:] 
    12071212        elif arg.startswith('-random='): 
    12081213            opts['seed'] = int(arg[8:]) 
     
    12601265 
    12611266    comparison = any(PAR_SPLIT in v for v in values) 
     1267 
    12621268    if PAR_SPLIT in name: 
    12631269        names = name.split(PAR_SPLIT, 2) 
     
    12721278        return None 
    12731279 
     1280    if PAR_SPLIT in opts['ngauss']: 
     1281        opts['ngauss'] = [int(k) for k in opts['ngauss'].split(PAR_SPLIT, 2)] 
     1282        comparison = True 
     1283    else: 
     1284        opts['ngauss'] = [int(opts['ngauss'])]*2 
     1285 
    12741286    if PAR_SPLIT in opts['engine']: 
    12751287        opts['engine'] = opts['engine'].split(PAR_SPLIT, 2) 
     
    12901302        opts['cutoff'] = [float(opts['cutoff'])]*2 
    12911303 
    1292     base = make_engine(model_info[0], data, opts['engine'][0], opts['cutoff'][0]) 
     1304    base = make_engine(model_info[0], data, opts['engine'][0], 
     1305                       opts['cutoff'][0], opts['ngauss'][0]) 
    12931306    if comparison: 
    1294         comp = make_engine(model_info[1], data, opts['engine'][1], opts['cutoff'][1]) 
     1307        comp = make_engine(model_info[1], data, opts['engine'][1], 
     1308                           opts['cutoff'][1], opts['ngauss'][1]) 
    12951309    else: 
    12961310        comp = None 
  • sasmodels/generate.py

    r4991048 rff31782  
    268268""" 
    269269 
     270 
     271def set_integration_size(info, n): 
     272    # type: (ModelInfo, int) -> None 
     273    """ 
     274    Update the model definition, replacing the gaussian integration with 
     275    a gaussian integration of a different size. 
     276 
     277    Note: this really ought to be a method in modelinfo, but that leads to 
     278    import loops. 
     279    """ 
     280    if (info.source and any(lib.startswith('lib/gauss') for lib in info.source)): 
     281        import os.path 
     282        from .gengauss import gengauss 
     283        path = os.path.join(MODEL_PATH, "lib", "gauss%d.c"%n) 
     284        if not os.path.exists(path): 
     285            gengauss(n, path) 
     286        info.source = ["lib/gauss%d.c"%n if lib.startswith('lib/gauss') 
     287                        else lib for lib in info.source] 
    270288 
    271289def format_units(units): 
Note: See TracChangeset for help on using the changeset viewer.