Skip to content

Commit

Permalink
Merge pull request #174 from yardasol/separate-depcode
Browse files Browse the repository at this point in the history
Separate `depcode.py` into three files
  • Loading branch information
samgdotson authored Nov 10, 2022
2 parents 71b6e08 + 5edaf3a commit 2cf2788
Show file tree
Hide file tree
Showing 18 changed files with 661 additions and 644 deletions.
4 changes: 2 additions & 2 deletions doc/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ The unit tests check that the individual functions and classes of the ``saltproc
module return the correct type of variables and correct values, where applicable.
The regression tests run a full SaltProc simulation and check the final result
with a precalculated result.
The ``DepcodeSerpent`` integration tests require the `JEFF 3.1.2 cross section library`_ as well
The ``SerpentDepcode`` integration tests require the `JEFF 3.1.2 cross section library`_ as well
as neutron induces and spontaneous fission product yield data from JEFF 3.3.
The publicly available versions of JEFF 3.1.2 cannot be used with Serpent right
out of the box due to `Serpent's notation for isomeric states`_. The scripts in
Expand All @@ -104,7 +104,7 @@ We recommend using them for your convenience.
See the `README`_ for more information.

..
The ``DepcodeOpenmc`` integration tests require...
The ``OpenMCDepcode`` integration tests require...
.. _Serpent's notation for isomeric states: https://serpent.vtt.fi/mediawiki/index.php/Installing_and_running_Serpent#Setting_up_the_data_libraries
.. _JEFF 3.1.2 cross section library: https://www.oecd-nea.org/dbforms/data/eva/evatapes/jeff_31/JEFF312/
Expand Down
4 changes: 2 additions & 2 deletions doc/releasenotes/v0.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ Python API Changes
- ``template_inputfile_path`` → ``template_input_file_path``
- Changed `iter_inputfile` and `iter_matfile` to be attributes instead of parameters

- ``DepcodeSerpent``
- ``DepcodeSerpent`` → ``SerpentDepcode``

- ``template_inputfile_path`` → ``template_input_file_path``
- Changed `iter_inputfile` and `iter_matfile` to be attributes instead of parameters


- ``DepcodeOpenmc`` is a ``Depcode`` subclass that interfaces with ``openmc``. This class implements the following functions
- ``OpenMCDepcode`` is a ``Depcode`` subclass that interfaces with ``openmc``. This class implements the following functions

- ``run_depcode()``
- ``switch_to_next_geometry()``
Expand Down
4 changes: 3 additions & 1 deletion saltproc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from __future__ import absolute_import, division, print_function
from .version import __version__ # noqa
from .materialflow import *
from .depcode import *
from .abc import *
from .serpent_depcode import *
from .openmc_depcode import *
from .simulation import *
from .process import *
from .reactor import *
Expand Down
163 changes: 163 additions & 0 deletions saltproc/abc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
from abc import ABC, abstractmethod

class Depcode(ABC):
"""Abstract class for interfacing with monte-carlo particle transport
codes. Contains information about input, output, geometry, and template
files for running depletion simulations. Also contains neutron
population, active, and inactive cycles. Contains methods to read template
and output files, and write new input files for the depletion code.
Attributes
-----------
param : dict of str to type
Holds depletion step parameter information. Parameter names are keys
and parameter values are values.
sim_info : dict of str to type
Holds simulation settings information. Setting names are keys
and setting values are values.
iter_inputfile : str
Path to depletion code input file for depletion code rerunning.
iter_matfile : str
Path to iterative, rewritable material file for depletion code
rerunning. This file is modified during the simulation.
"""

def __init__(self,
codename,
exec_path,
template_input_file_path,
geo_files=None,
npop=50,
active_cycles=20,
inactive_cycles=20):
"""Initializes the Depcode object.
Parameters
----------
codename : str
Name of depletion code.
exec_path : str
Path to depletion code executable.
template_input_file_path : str or dict of str to str
Path(s) to depletion code input file(s), or a dictionary where
the input type (e.g. material, geometry, settings, etc.) as a
string are keys, and the path to the input file are values.
Type depends on depletion code in use.
geo_files : str or list, optional
Path to file that contains the reactor geometry.
List of `str` if reactivity control by
switching geometry is `On` or just `str` otherwise.
npop : int, optional
Size of neutron population per cycle for Monte Carlo.
active_cycles : int, optional
Number of active cycles.
inactive_cycles : int, optional
Number of inactive cycles.
"""
self.codename = codename
self.exec_path = exec_path
self.template_input_file_path = template_input_file_path
self.geo_files = geo_files
self.npop = npop
self.active_cycles = active_cycles
self.inactive_cycles = inactive_cycles
self.param = {}
self.sim_info = {}
self.iter_inputfile = './iter_input'
self.iter_matfile = './iter_mat'

@abstractmethod
def read_depcode_info(self):
"""Parses initial depletion code info data from depletion code
output and stores it in the `Depcode` object's ``sim_info`` attribute.
"""

@abstractmethod
def read_depcode_step_param(self):
"""Parses data from depletion code output for each step and stores
it in `Depcode` object's ``param`` attributes.
"""

@abstractmethod
def read_dep_comp(self, read_at_end=False):
"""Reads the depleted material data from the depcode simulation
and returns a dictionary with a `Materialflow` object for each
burnable material.
Parameters
----------
read_at_end : bool, optional
Controls at which moment in the depletion step to read the data.
If `True`, the function reads data at the end of the
depletion step. Otherwise, the function reads data at the
beginning of the depletion step.
Returns
-------
mats : dict of str to Materialflow
Dictionary that contains `Materialflow` objects.
``key``
Name of burnable material.
``value``
`Materialflow` object holding composition and properties.
"""

@abstractmethod
def run_depcode(self, cores, nodes):
"""Runs depletion code as a subprocess with the given parameters.
Parameters
----------
cores : int
Number of cores to use for depletion code run.
nodes : int
Number of nodes to use for depletion code run.
"""

@abstractmethod
def switch_to_next_geometry(self):
"""Changes the geometry used in the depletion code simulation to the
next geometry file in ``geo_files``
"""

@abstractmethod
def write_depcode_input(self, reactor, dep_step, restart):
""" Writes prepared data into depletion code input file(s).
Parameters
----------
reactor : Reactor
Contains information about power load curve and cumulative
depletion time for the integration test.
dep_step : int
Current depletion time step.
restart : bool
Is the current simulation restarted?
"""

@abstractmethod
def write_mat_file(self, dep_dict, dep_end_time):
"""Writes the iteration input file containing the burnable materials
composition used in depletion runs and updated after each depletion
step.
Parameters
----------
dep_dict : dict of str to Materialflow
Dictionary that contains `Materialflow` objects.
``key``
Name of burnable material.
``value``
`Materialflow` object holding composition and properties.
dep_end_time : float
Current time at the end of the depletion step (d).
"""



6 changes: 3 additions & 3 deletions saltproc/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import networkx as nx
import pydotplus

from saltproc import DepcodeSerpent, DepcodeOpenMC, Simulation, Reactor
from saltproc import SerpentDepcode, OpenMCDepcode, Simulation, Reactor
from saltproc import Process, Sparger, Separator, Materialflow


Expand Down Expand Up @@ -240,9 +240,9 @@ def _create_depcode_object(depcode_input):
"""Helper function for `run()` """
codename = depcode_input['codename']
if codename == 'serpent':
depcode = DepcodeSerpent
depcode = SerpentDepcode
elif codename == 'openmc':
depcode = DepcodeOpenMC
depcode = OpenMCDepcode
else:
raise ValueError(
f'{depcode_input["codename"]} is not a supported depletion code')
Expand Down
Loading

0 comments on commit 2cf2788

Please sign in to comment.