Model Translation
MCNPy includes modules to support translation between MCNP, Serpent, and OpenMC. The related modules are optional loaded if the appropriate packages for the related codes are available.
Dependencies
Important
At this time, SerPy must be manually downloaded and then installed from the .whl
file. Running pip install serpy
will retrieve the wrong package.
Basic Usage
MCNPy’s translation functions are equipped with a simple front-end which only requires the user to provide the path to the file(s) being translated. For instance, an MCNP deck can be translated to Serpent as follows:
import mcnpy
mcnp_file_path = '/path/to/mcnp/deck.mcnp'
# The translation direction is determined based on the supplied file extension.
# A '.mcnp' file will translate to a Serpent file and vice versa.
serpent_deck = mcnpy.translate_mcnp_serpent.translate_file(mcnp_file_path)
serpent_deck.write('from_mcnp_deck.serpent')
Translations from OpenMC to MCNP require additional arguments since an OpenMC input is composed of multiple files.
import mcnpy
geom = '/path/to/openmc/files/geometry.xml'
mats = '/path/to/openmc/files/materials.xml'
settings = '/path/to/openmc/files/settings.xml'
# Providing a single '.mcnp' file would invoke translation from MCNP to OpenMC instead.
mcnp_deck = mcnpy.translate_mcnp_openmc.translate_file(geom, mats, settings)
mcnp_deck.write('from_openmc.mcnp')
Advanced Usage
The basic usage examples demonstrate the translate_file
function which requires a file to exist on-disk and be parsed into memory. If one already has an in-memory model, it can be translated directly without being serialized. This can be both a time saver and allows more fluid multi-code translations.
import mcnpy
# Use included pin-cell example to construct a deck.
mcnp_deck = mcnpy.example.Pincell().deck
# Translate to Serpent.
# The MCNP deck DOES NOT exist on-disk.
serp_deck = mcnpy.translate_mcnp_serpent.mcnp_to_serpent(mcnp_deck)
With an in-memory Serpent deck, it is possible to perform further translations with the Serpent deck as the starting point. For illustrative purposes, we’ll use the just translated pin-cell to go from Serpent to OpenMC (with MCNP as the intermediary).
# Translate to MCNP.
new_mcnp_deck = mcnpy.translate_mcnp_serpent.serpent_to_mcnp(serp_deck)
# Translate to OpenMC.
openmc_model = mcnpy.translate_mcnp_openmc.mcnp_to_openmc(new_mcnp_deck)
# Serialize OpenMC XML files.
openmc_model[0].export_to_xml('model.geometry.xml')
openmc_model[1].export_to_xml('model.materials.xml')
Modules
- Serpent Model
- Serpent Surfaces
- OpenMC Model
- OpenMC Surfaces
make_mcnp_boundary()
make_mcnp_plane()
make_mcnp_quadric()
make_mcnp_sphere()
make_mcnp_xcone()
make_mcnp_xcone_1side()
make_mcnp_xcylinder()
make_mcnp_xplane()
make_mcnp_xtorus()
make_mcnp_ycone()
make_mcnp_ycone_1side()
make_mcnp_ycylinder()
make_mcnp_yplane()
make_mcnp_ytorus()
make_mcnp_zcone()
make_mcnp_zcone_1side()
make_mcnp_zcylinder()
make_mcnp_zplane()
make_mcnp_ztorus()
make_openmc_boundary()
make_openmc_plane()
make_openmc_points_plane()
make_openmc_quadric()
make_openmc_sphere()
make_openmc_xcone()
make_openmc_xcylinder()
make_openmc_xplane()
make_openmc_xpoints()
make_openmc_xtorus()
make_openmc_xyzquadric()
make_openmc_ycone()
make_openmc_ycylinder()
make_openmc_yplane()
make_openmc_ypoints()
make_openmc_ytorus()
make_openmc_zcone()
make_openmc_zcylinder()
make_openmc_zplane()
make_openmc_zpoints()
make_openmc_ztorus()
mcnp_surfs_to_openmc()
openmc_surfs_to_mcnp()
- Macrobody Decomposition