Skip to content

pshriwise/catbird

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CI

Catbird

A code for generation of Python objects and input for various MOOSE.

Caveats: This currently only parses data for the MOOSE::Problem type.

Prerequisites

  • Python version >=3.6
  • NumPy
  • pytest (for testing)

Installation

From a terminal, run

pip install .

To include packages for testsing, run

pip install .[test]

Example

Below is an example generating Python classes for the OpenMCCellAverageProblem and NekRSProblem types in the Cardinal.

In [1]: from catbird import app_from_exec

In [2]: cardinal = app_from_exec('./cardinal-opt')

In [3]: openmc_prob = cardinal['problems']['OpenMCCellAverageProblem']()

In [4]: openmc_prob.batches?
Type:        property
String form: <property object at 0x12906ec50>
Docstring:
Type: int
Number of batches to run in OpenMC; this overrides the setting in the XML files.

Features

Every attribute comes with type and dimensionality checking (for array types). This provides live feedback to users when setting problem parameters. In the example above, setting openmc_prob.batches to a non-integer value results in the following

In [5]: openmc_prob.batches = 100

In [6]: openmc_prob.batches = 'one hundred'
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[6], line 1
----> 1 openmc_prob.batches = 'one hundred'

File ~/soft/catbird/catbird/cbird.py:66, in Catbird.prop_set.<locals>.fset(self, val)
     64 def fset(self, val):
     65     if dim == 0:
---> 66         self.check_type(name, val, attr_type)
     67         if allowed_vals is not None:
     68             self.check_vals(name, val, allowed_vals)

File ~/soft/catbird/catbird/cbird.py:40, in Catbird.check_type(name, val, attr_type)
     38     val_type_str = val.__class__.__name__
     39     exp_type_str = attr_type.__name__
---> 40     raise ValueError(f'Incorrect type "{val_type_str}" for attribute "{name}". '
     41                      f'Expected type "{exp_type_str}".')
     42 return val

ValueError: Incorrect type "str" for attribute "batches". Expected type "int".

Default values are also set on attributes automatically, so full problem descriptions can be generated by setting only required parameters.

In [7]: openmc_prob.initial_properties
Out[7]: 'moose'

About

Python object generator for MOOSE codes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages