User Control

The serpentTools package is designed to, without intervention, be able to store all the data contained in each of the various output files. However, the serpentTools.settings module grants great flexibility to the user over what data is obtained through the serpentTools.settings.rc class.

All the settings are given in Default Settings, showing their default values and possible options.

Basic Usage

>>> import serpentTools
>>> from serpentTools.settings import rc

The serpentTools.settings.rc object can be used like a dictionary, polling all possible settings with the .keys method:

>>> rc.keys()
dict_keys(['depletion.processTotal', 'verbosity', 'xs.getInfXS',
'branching.intVariables', 'serpentVersion',
'sampler.raiseErrors', 'xs.getB1XS', 'xs.variableGroups', 'xs.variableExtras',
'depletion.materialVariables', 'depletion.metadataKeys', 'sampler.freeAll',
'sampler.allExist', 'depletion.materials', 'sampler.skipPrecheck',
'xs.reshapeScatter', 'branching.floatVariables', 'detector.names'])

Settings such as depletion.materials are specific for the DepletionReader while settings that are led with xs are sent to the ResultsReader and BranchingReader as well as their specific settings. Updating a setting is similar to setting a value in a dictionary

>>> rc['verbosity'] = 'debug'
DEBUG   : serpentTools: Updated setting verbosity to debug

The serpentTools.settings.rc object automatically checks to make sure the value is of the correct type, and is an allowable option, if given.

>>> try:
...     rc['depletion.metadataKeys'] = False
>>> except TypeError as te:
...     print(te)
Setting depletion.metadataKeys should be of type <class 'list'>, not <class
>>> try:
...     rc['serpentVersion'] = '1.2.3'
>>> except KeyError as ke:
...     print(ke)
'Setting serpentVersion is 1.2.3 and not one of the allowed options: 2.1.29,

The serpentTools.settings.rc object can also be used inside a context manager to revert changes.

>>> with rc:
...     rc['depletion.metadataKeys'] = ['ZAI', 'BU']
DEBUG   : serpentTools: Updated setting depletion.metadataKeys to ['ZAI', 'BU']
DEBUG   : serpentTools: Updated setting depletion.metadataKeys to ['ZAI', 'NAMES', 'DAYS', 'BU']
>>> rc['verbosity'] = 'info'

Group Constant Variables

Two settings control what group constant data and what variables are extracted from the results and coefficient files.

  1. xs.variableExtras: Full SERPENT_STYLE variable names, i.e. INF_TOT, FISSION_PRODUCT_DECAY_HEAT

  2. xs.variableGroups: Select keywords that represent blocks of common variables

These variable groups are described in Variable Groups and rely upon the SERPENT version to properly expand the groups.

>>> rc['serpentVersion']
>>> rc['xs.variableGroups'] = ['kinetics', 'xs', 'diffusion']
>>> rc['xs.variableExtras'] = ['XS_DATA_FILE_PATH']
>>> varSet = rc.expandVariables()
>>> print(sorted(varSet))
'S0', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'SCATT0', 'SCATT1', 'SCATT2',

However, one might see that the full group constant cross sections are not present in this set

>>> assert 'INF_SCATT3' not in varSet

This is because two additional settings instruct the BranchingReader and ResultsReader to obtain infinite medium and leakage-corrected cross sections: xs.getInfXS and xs.getB1XS, respectively. By default, xs.getInfXS and xs.getB1XS default to True. This, in conjunction with leaving the xs.variableExtras and xs.variableGroups settings to empty lists, instructs these readers to obtain all the data present in their respective files.

See the Branching Reader example for more information on using these settings to control scraped data.

Configuration Files

The serpentTools.settings.rc object allows for settings to be updated from a yaml configuration file using the loadYaml() method. The file is structured with the names of settings as keys and the desired setting value as the values. The loader also attempts to expand nested settings, like reader-specific settings, that may be lumped in a second level:

verbosity: warning
xs.getInfXS: False

However, the loader can also expand a nested dictionary structure, as:

  floatVariables: [Fhi, Blo]
  materials: [fuel*]
>>> %cat myConfig.yaml
xs.getInfXS: False
xs.getB1XS: True
xs.variableGroups: [gc-meta, kinetics,
  floatVariables: [Fhi, Blo]
  materials: [fuel*]
  metadataKeys: [NAMES, BU]
serpentVersion: 2.1.29
>>> myConf = 'myConfig.yaml'
>>> rc.loadYaml(myConf)
INFO    : serpentTools: Done
>>> rc['xs.getInfXS']