openmc.model.Model

class openmc.model.Model(geometry=None, materials=None, settings=None, tallies=None, plots=None)[source]

Model container.

This class can be used to store instances of openmc.Geometry, openmc.Materials, openmc.Settings, openmc.Tallies, and openmc.Plots, thus making a complete model. The Model.export_to_xml() method will export XML files for all attributes that have been set. If the Model.materials attribute is not set, it will attempt to create a materials.xml file based on all materials appearing in the geometry.

Changed in version 0.13.0: The model information can now be loaded in to OpenMC directly via openmc.lib

Parameters
Variables
calculate_volumes(threads=None, output=True, cwd='.', openmc_exec='openmc', mpi_args=None, apply_volumes=True)[source]

Runs an OpenMC stochastic volume calculation and, if requested, applies volumes to the model

New in version 0.13.0.

Parameters
  • threads (int, optional) – Number of OpenMP threads. If OpenMC is compiled with OpenMP threading enabled, the default is implementation-dependent but is usually equal to the number of hardware threads available (or a value set by the OMP_NUM_THREADS environment variable). This currenty only applies to the case when not using the C API.

  • output (bool, optional) – Capture OpenMC output from standard out

  • openmc_exec (str, optional) – Path to OpenMC executable. Defaults to ‘openmc’. This only applies to the case when not using the C API.

  • mpi_args (list of str, optional) – MPI execute command and any additional MPI arguments to pass, e.g. [‘mpiexec’, ‘-n’, ‘8’]. This only applies to the case when not using the C API.

  • cwd (str, optional) – Path to working directory to run in. Defaults to the current working directory.

  • apply_volumes (bool, optional) – Whether apply the volume calculation results from this calculation to the model. Defaults to applying the volumes.

deplete(timesteps, method='cecm', final_step=True, operator_kwargs=None, directory='.', output=True, **integrator_kwargs)[source]

Deplete model using specified timesteps/power

Changed in version 0.13.0: The final_step, operator_kwargs, directory, and output arguments were added.

Parameters
  • timesteps (iterable of float) – Array of timesteps in units of [s]. Note that values are not cumulative.

  • method (str, optional) – Integration method used for depletion (e.g., ‘cecm’, ‘predictor’). Defaults to ‘cecm’.

  • final_step (bool, optional) – Indicate whether or not a transport solve should be run at the end of the last timestep. Defaults to running this transport solve.

  • operator_kwargs (dict) – Keyword arguments passed to the depletion operator initializer (e.g., openmc.deplete.Operator())

  • directory (str, optional) – Directory to write XML files to. If it doesn’t exist already, it will be created. Defaults to the current working directory

  • output (bool) – Capture OpenMC output from standard out

  • integrator_kwargs (dict) – Remaining keyword arguments passed to the depletion Integrator initializer (e.g., openmc.deplete.integrator.cecm()).

export_to_model_xml(path='model.xml', remove_surfs=False)[source]

Export model to a single XML file.

New in version 0.13.3.

Parameters
  • path (str or PathLike) – Location of the XML file to write (default is ‘model.xml’). Can be a directory or file path.

  • remove_surfs (bool) – Whether or not to remove redundant surfaces from the geometry when exporting.

export_to_xml(directory='.', remove_surfs=False)[source]

Export model to separate XML files.

Parameters
  • directory (str) – Directory to write XML files to. If it doesn’t exist already, it will be created.

  • remove_surfs (bool) –

    Whether or not to remove redundant surfaces from the geometry when exporting.

    New in version 0.13.1.

finalize_lib()[source]

Finalize simulation and free memory allocated for the C API

New in version 0.13.0.

classmethod from_model_xml(path='model.xml')[source]

Create model from single XML file

New in version 0.13.3.

Parameters

path (str or PathLike) – Path to model.xml file

classmethod from_xml(geometry='geometry.xml', materials='materials.xml', settings='settings.xml', tallies='tallies.xml', plots='plots.xml') Model[source]

Create model from existing XML files

Parameters
  • geometry (str) – Path to geometry.xml file

  • materials (str) – Path to materials.xml file

  • settings (str) – Path to settings.xml file

  • tallies (str) –

    Path to tallies.xml file

    New in version 0.13.0.

  • plots (str) –

    Path to plots.xml file

    New in version 0.13.0.

Returns

Model created from XML files

Return type

openmc.model.Model

import_properties(filename)[source]

Import physical properties

Changed in version 0.13.0: This method now updates values as loaded in memory with the C API

Parameters

filename (str) – Path to properties HDF5 file

init_lib(threads=None, geometry_debug=False, restart_file=None, tracks=False, output=True, event_based=None, intracomm=None)[source]

Initializes the model in memory via the C API

New in version 0.13.0.

Parameters
  • threads (int, optional) – Number of OpenMP threads. If OpenMC is compiled with OpenMP threading enabled, the default is implementation-dependent but is usually equal to the number of hardware threads available (or a value set by the OMP_NUM_THREADS environment variable).

  • geometry_debug (bool, optional) – Turn on geometry debugging during simulation. Defaults to False.

  • restart_file (str, optional) – Path to restart file to use

  • tracks (bool, optional) – Enables the writing of particles tracks. The number of particle tracks written to tracks.h5 is limited to 1000 unless Settings.max_tracks is set. Defaults to False.

  • output (bool) – Capture OpenMC output from standard out

  • event_based (None or bool, optional) – Turns on event-based parallelism if True. If None, the value in the Settings will be used.

  • intracomm (mpi4py.MPI.Intracomm or None, optional) – MPI intracommunicator

plot_geometry(output=True, cwd='.', openmc_exec='openmc')[source]

Creates plot images as specified by the Model.plots attribute

New in version 0.13.0.

Parameters
  • output (bool, optional) – Capture OpenMC output from standard out

  • cwd (str, optional) – Path to working directory to run in. Defaults to the current working directory.

  • openmc_exec (str, optional) – Path to OpenMC executable. Defaults to ‘openmc’. This only applies to the case when not using the C API.

rotate_cells(names_or_ids, vector)[source]

Rotate the identified cell(s) by the specified rotation vector. The rotation is only applied to cells filled with a universe.

Note

If applying this change to a name that is not unique, then the change will be applied to all objects of that name.

New in version 0.13.0.

Parameters
  • names_or_ids (Iterable of str or int) – The cell names (if str) or id (if int) that are to be translated or rotated. This parameter can include a mix of names and ids.

  • vector (Iterable of float) – The rotation vector of length 3 to apply. This array specifies the angles in degrees about the x, y, and z axes, respectively.

run(particles=None, threads=None, geometry_debug=False, restart_file=None, tracks=False, output=True, cwd='.', openmc_exec='openmc', mpi_args=None, event_based=None, export_model_xml=True, **export_kwargs)[source]

Run OpenMC

If the C API has been initialized, then the C API is used, otherwise, this method creates the XML files and runs OpenMC via a system call. In both cases this method returns the path to the last statepoint file generated. .. versionchanged:: 0.12

Instead of returning the final k-effective value, this function now returns the path to the final statepoint written.

Changed in version 0.13.0: This method can utilize the C API for execution

Parameters
  • particles (int, optional) – Number of particles to simulate per generation.

  • threads (int, optional) – Number of OpenMP threads. If OpenMC is compiled with OpenMP threading enabled, the default is implementation-dependent but is usually equal to the number of hardware threads available (or a value set by the OMP_NUM_THREADS environment variable).

  • geometry_debug (bool, optional) – Turn on geometry debugging during simulation. Defaults to False.

  • restart_file (str or PathLike) – Path to restart file to use

  • tracks (bool, optional) – Enables the writing of particles tracks. The number of particle tracks written to tracks.h5 is limited to 1000 unless Settings.max_tracks is set. Defaults to False.

  • output (bool, optional) – Capture OpenMC output from standard out

  • cwd (PathLike, optional) – Path to working directory to run in. Defaults to the current working directory.

  • openmc_exec (str, optional) – Path to OpenMC executable. Defaults to ‘openmc’.

  • mpi_args (list of str, optional) – MPI execute command and any additional MPI arguments to pass, e.g. [‘mpiexec’, ‘-n’, ‘8’].

  • event_based (None or bool, optional) – Turns on event-based parallelism if True. If None, the value in the Settings will be used.

  • export_model_xml (bool, optional) –

    Exports a single model.xml file rather than separate files. Defaults to True.

    New in version 0.13.3.

  • **export_kwargs – Keyword arguments passed to either Model.export_to_model_xml() or Model.export_to_xml().

Returns

Path to the last statepoint written by this run (None if no statepoint was written)

Return type

Path

translate_cells(names_or_ids, vector)[source]

Translate the identified cell(s) by the specified translation vector. The translation is only applied to cells filled with a universe.

Note

If applying this change to a name that is not unique, then the change will be applied to all objects of that name.

New in version 0.13.0.

Parameters
  • names_or_ids (Iterable of str or int) – The cell names (if str) or id (if int) that are to be translated or rotated. This parameter can include a mix of names and ids.

  • vector (Iterable of float) – The translation vector of length 3 to apply. This array specifies the x, y, and z dimensions of the translation.

update_cell_temperatures(names_or_ids, temperature)[source]

Update the temperature of a set of cells to the given value

Note

If applying this change to a name that is not unique, then the change will be applied to all objects of that name.

New in version 0.13.0.

Parameters
  • names_or_ids (Iterable of str or int) – The cell names (if str) or id (if int) that are to be updated. This parameter can include a mix of names and ids.

  • temperature (float) – The temperature to apply in units of Kelvin

update_densities(names_or_ids, density, density_units='atom/b-cm')[source]

Update the density of a given set of materials to a new value

Note

If applying this change to a name that is not unique, then the change will be applied to all objects of that name.

New in version 0.13.0.

Parameters
  • names_or_ids (Iterable of str or int) – The material names (if str) or id (if int) that are to be updated. This parameter can include a mix of names and ids.

  • density (float) – The density to apply in the units specified by density_units

  • density_units ({'atom/b-cm', 'g/cm3'}, optional) – Units for density. Defaults to ‘atom/b-cm’

update_material_volumes(names_or_ids, volume)[source]

Update the volume of a set of materials to the given value

Note

If applying this change to a name that is not unique, then the change will be applied to all objects of that name.

New in version 0.13.0.

Parameters
  • names_or_ids (Iterable of str or int) – The material names (if str) or id (if int) that are to be updated. This parameter can include a mix of names and ids.

  • volume (float) – The volume to apply in units of cm^3