diff --git a/openmc/deplete/__init__.py b/openmc/deplete/__init__.py index 994a51e12..4bdde3935 100644 --- a/openmc/deplete/__init__.py +++ b/openmc/deplete/__init__.py @@ -1,8 +1,8 @@ """ -OpenDeplete -=========== +openmc.deplete +============== -A simple depletion front-end tool. +A depletion front-end tool. """ from .dummy_comm import DummyCommunicator diff --git a/openmc/deplete/atom_number.py b/openmc/deplete/atom_number.py index 03bedbf53..63c9af836 100644 --- a/openmc/deplete/atom_number.py +++ b/openmc/deplete/atom_number.py @@ -7,7 +7,7 @@ import numpy as np class AtomNumber(object): - """ AtomNumber module. + """AtomNumber module. An ndarray to store atom densities with string, integer, or slice indexing. @@ -71,7 +71,7 @@ class AtomNumber(object): self._burn_mat_list = None def __getitem__(self, pos): - """ Retrieves total atom number from AtomNumber. + """Retrieves total atom number from AtomNumber. Parameters ---------- @@ -95,7 +95,7 @@ class AtomNumber(object): return self.number[mat, nuc] def __setitem__(self, pos, val): - """ Sets total atom number into AtomNumber. + """Sets total atom number into AtomNumber. Parameters ---------- @@ -116,7 +116,7 @@ class AtomNumber(object): self.number[mat, nuc] = val def get_atom_density(self, mat, nuc): - """ Accesses atom density instead of total number. + """Accesses atom density instead of total number. Parameters ---------- @@ -139,7 +139,7 @@ class AtomNumber(object): return self[mat, nuc] / self.volume[mat] def set_atom_density(self, mat, nuc, val): - """ Sets atom density instead of total number. + """Sets atom density instead of total number. Parameters ---------- @@ -159,7 +159,7 @@ class AtomNumber(object): self[mat, nuc] = val * self.volume[mat] def get_mat_slice(self, mat): - """ Gets atom quantity indexed by mats for all burned nuclides + """Gets atom quantity indexed by mats for all burned nuclides Parameters ---------- @@ -178,7 +178,7 @@ class AtomNumber(object): return self[mat, 0:self.n_nuc_burn] def set_mat_slice(self, mat, val): - """ Sets atom quantity indexed by mats for all burned nuclides + """Sets atom quantity indexed by mats for all burned nuclides Parameters ---------- @@ -205,7 +205,7 @@ class AtomNumber(object): @property def burn_nuc_list(self): - """ burn_nuc_list : list of str + """burn_nuc_list : list of str A list of all nuclide material names. Used for sorting the simulation. """ @@ -221,7 +221,7 @@ class AtomNumber(object): @property def burn_mat_list(self): - """ burn_mat_list : list of str + """burn_mat_list : list of str A list of all burning material names. Used for sorting the simulation. """ diff --git a/openmc/deplete/depletion_chain.py b/openmc/deplete/depletion_chain.py index 05cc9db43..af126035f 100644 --- a/openmc/deplete/depletion_chain.py +++ b/openmc/deplete/depletion_chain.py @@ -11,9 +11,6 @@ import math import re import os -from tqdm import tqdm -import scipy.sparse as sp -import openmc.data # Try to use lxml if it is available. It preserves the order of attributes and # provides a pretty-printer by default. If not available, use OpenMC function to # pretty print. @@ -22,9 +19,12 @@ try: _have_lxml = True except ImportError: import xml.etree.ElementTree as ET - from openmc.clean_xml import clean_xml_indentation _have_lxml = False +from tqdm import tqdm +import scipy.sparse as sp +import openmc.data +from openmc.clean_xml import clean_xml_indentation from .nuclide import Nuclide, DecayTuple, ReactionTuple @@ -109,7 +109,7 @@ def replace_missing(product, decay_data): class DepletionChain(object): - """ The DepletionChain class. + """The DepletionChain class. This class contains a full representation of a depletion chain. @@ -334,7 +334,7 @@ class DepletionChain(object): # Load XML tree try: root = ET.parse(filename) - except: + except Exception: if filename is None: print("No chain specified, either manually or in environment variable OPENDEPLETE_CHAIN.") else: @@ -374,11 +374,11 @@ class DepletionChain(object): if _have_lxml: tree.write(filename, encoding='utf-8', pretty_print=True) else: - clean_xml_indentation(root_elem, spaces_per_level=2) + clean_xml_indentation(root_elem) tree.write(filename, encoding='utf-8') def form_matrix(self, rates): - """ Forms depletion matrix. + """Forms depletion matrix. Parameters ---------- @@ -457,7 +457,7 @@ class DepletionChain(object): return matrix_dok.tocsr() def nuc_by_ind(self, ind): - """ Extracts nuclides from the list by dictionary key. + """Extracts nuclides from the list by dictionary key. Parameters ---------- diff --git a/openmc/deplete/function.py b/openmc/deplete/function.py index 74eb92422..bcc055e67 100644 --- a/openmc/deplete/function.py +++ b/openmc/deplete/function.py @@ -6,8 +6,9 @@ to run a full depletion simulation. from abc import ABCMeta, abstractmethod + class Settings(object): - """ The Settings class. + """The Settings class. Contains all parameters necessary for the integrator. @@ -24,8 +25,9 @@ class Settings(object): self.dt_vec = None self.output_dir = None + class Operator(metaclass=ABCMeta): - """ The Operator metaclass. + """The Operator metaclass. This defines all functions that the integrator needs to operate. @@ -40,7 +42,7 @@ class Operator(metaclass=ABCMeta): @abstractmethod def initial_condition(self): - """ Performs final setup and returns initial condition. + """Performs final setup and returns initial condition. Returns ------- @@ -52,7 +54,7 @@ class Operator(metaclass=ABCMeta): @abstractmethod def eval(self, vec, print_out=True): - """ Runs a simulation. + """Runs a simulation. Parameters ---------- @@ -75,7 +77,7 @@ class Operator(metaclass=ABCMeta): @abstractmethod def get_results_info(self): - """ Returns volume list, cell lists, and nuc lists. + """Returns volume list, cell lists, and nuc lists. Returns ------- @@ -93,7 +95,7 @@ class Operator(metaclass=ABCMeta): @abstractmethod def form_matrix(self, y, mat): - """ Forms the f(y) matrix in y' = f(y)y. + """Forms the f(y) matrix in y' = f(y)y. Nominally a depletion matrix, this is abstracted on the off chance that the function f has nothing to do with depletion at all. diff --git a/openmc/deplete/integrator/save_results.py b/openmc/deplete/integrator/save_results.py index 35cbc7f3f..4f20b52fd 100644 --- a/openmc/deplete/integrator/save_results.py +++ b/openmc/deplete/integrator/save_results.py @@ -1,7 +1,8 @@ """ Generic result saving code for integrators. """ -from opendeplete.results import Results, write_results +from ..results import Results, write_results + def save_results(op, x, rates, eigvls, seeds, t, step_ind): """ Creates and writes results to disk diff --git a/openmc/deplete/openmc_wrapper.py b/openmc/deplete/openmc_wrapper.py index 347dc7185..05b5057d2 100644 --- a/openmc/deplete/openmc_wrapper.py +++ b/openmc/deplete/openmc_wrapper.py @@ -1,6 +1,6 @@ -""" The OpenMC wrapper module. +"""The OpenMC wrapper module. -This module implements the OpenDeplete -> OpenMC linkage. +This module implements the depletion -> OpenMC linkage. """ import copy @@ -14,14 +14,13 @@ try: _have_lxml = True except ImportError: import xml.etree.ElementTree as ET - from openmc.clean_xml import clean_xml_indentation _have_lxml = False import h5py import numpy as np + import openmc import openmc.capi - from . import comm from .atom_number import AtomNumber from .depletion_chain import DepletionChain @@ -194,7 +193,7 @@ class OpenMCOperator(Operator): # Clear out OpenMC, create task lists, distribute if comm.rank == 0: - clean_up_openmc() + openmc.reset_auto_ids() mat_burn_list, mat_not_burn_list, volume, self.mat_tally_ind, \ nuc_dict = self.extract_mat_ids() else: @@ -224,7 +223,7 @@ class OpenMCOperator(Operator): openmc.capi.finalize() def extract_mat_ids(self): - """ Extracts materials and assigns them to processes. + """Extracts materials and assigns them to processes. Returns ------- @@ -308,7 +307,7 @@ class OpenMCOperator(Operator): return mat_burn_lists, mat_not_burn_lists, volume, mat_tally_ind, nuc_dict def extract_number(self, mat_burn, mat_not_burn, volume, nuc_dict): - """ Construct self.number read from geometry + """Construct self.number read from geometry Parameters ---------- @@ -356,7 +355,7 @@ class OpenMCOperator(Operator): self.set_number_from_mat(mat) def set_number_from_mat(self, mat): - """ Extracts material and number densities from openmc.Material + """Extracts material and number densities from openmc.Material Parameters ---------- @@ -369,12 +368,11 @@ class OpenMCOperator(Operator): nuc_dens = mat.get_nuclide_atom_densities() for nuclide in nuc_dens: - name = nuclide.name number = nuc_dens[nuclide][1] * 1.0e24 - self.number.set_atom_density(mat_id, name, number) + self.number.set_atom_density(mat_id, nuclide, number) def initialize_reaction_rates(self): - """ Create reaction rates object. """ + """Create reaction rates object. """ self.reaction_rates = ReactionRates( self.burn_mat_to_ind, self.burn_nuc_to_ind, @@ -383,7 +381,7 @@ class OpenMCOperator(Operator): self.chain.nuc_to_react_ind = self.burn_nuc_to_ind def eval(self, vec, print_out=True): - """ Runs a simulation. + """Runs a simulation. Parameters ---------- @@ -405,7 +403,7 @@ class OpenMCOperator(Operator): """ # Prevent OpenMC from complaining about re-creating tallies - clean_up_openmc() + openmc.reset_auto_ids() # Update status self.set_density(vec) @@ -435,7 +433,7 @@ class OpenMCOperator(Operator): return k, copy.deepcopy(self.reaction_rates), self.seed def form_matrix(self, y, mat): - """ Forms the depletion matrix. + """Forms the depletion matrix. Parameters ---------- @@ -453,7 +451,7 @@ class OpenMCOperator(Operator): return copy.deepcopy(self.chain.form_matrix(y[mat, :, :])) def initial_condition(self): - """ Performs final setup and returns initial condition. + """Performs final setup and returns initial condition. Returns ------- @@ -513,7 +511,7 @@ class OpenMCOperator(Operator): mat_internal.set_densities(nuclides, densities) def generate_materials_xml(self): - """ Creates materials.xml from self.number. + """Creates materials.xml from self.number. Due to uncertainty with how MPI interacts with OpenMC API, this constructs the XML manually. The long term goal is to do this @@ -531,7 +529,7 @@ class OpenMCOperator(Operator): materials.export_to_xml() def generate_settings_xml(self): - """ Generates settings.xml. + """Generates settings.xml. This function creates settings.xml using the value of the settings variable. @@ -625,7 +623,7 @@ class OpenMCOperator(Operator): tally_dep.filters = [mat_filter] def total_density_list(self): - """ Returns a list of total density lists. + """Returns a list of total density lists. This list is in the exact same order as depletion_matrix_list, so that matrix exponentiation can be done easily. @@ -641,7 +639,7 @@ class OpenMCOperator(Operator): return total_density def set_density(self, total_density): - """ Sets density. + """Sets density. Sets the density in the exact same order as total_density_list outputs, allowing for internal consistency @@ -657,7 +655,7 @@ class OpenMCOperator(Operator): self.number.set_mat_slice(i, total_density[i]) def unpack_tallies_and_normalize(self): - """ Unpack tallies from OpenMC + """Unpack tallies from OpenMC This function reads the tallies generated by OpenMC (from the tally.xml file generated in generate_tally_xml) normalizes them so that the total @@ -754,7 +752,7 @@ class OpenMCOperator(Operator): return k_combined def load_participating(self): - """ Loads a cross_sections.xml file to find participating nuclides. + """Loads a cross_sections.xml file to find participating nuclides. This allows for nuclides that are important in the decay chain but not important neutronically, or have no cross section data. @@ -772,7 +770,7 @@ class OpenMCOperator(Operator): try: tree = ET.parse(filename) - except: + except Exception: if filename is None: msg = "No cross_sections.xml specified in materials." else: @@ -802,7 +800,7 @@ class OpenMCOperator(Operator): return len(self.chain.nuclides) def get_results_info(self): - """ Returns volume list, cell lists, and nuc lists. + """Returns volume list, cell lists, and nuc lists. Returns ------- @@ -829,8 +827,10 @@ class OpenMCOperator(Operator): return volume, nuc_list, burn_list, self.mat_tally_ind + def density_to_mat(dens_dict): - """ Generates an OpenMC material from a cell ID and self.number_density. + """Generates an OpenMC material from a cell ID and self.number_density. + Parameters ---------- m_id : int @@ -847,7 +847,3 @@ def density_to_mat(dens_dict): mat.set_density('sum') return mat - -def clean_up_openmc(): - """ Resets all automatic indexing in OpenMC, as these get in the way. """ - openmc.reset_auto_ids() diff --git a/openmc/deplete/reaction_rates.py b/openmc/deplete/reaction_rates.py index 7b934027a..de3a6a728 100644 --- a/openmc/deplete/reaction_rates.py +++ b/openmc/deplete/reaction_rates.py @@ -7,7 +7,7 @@ import numpy as np class ReactionRates(object): - """ ReactionRates class. + """ReactionRates class. An ndarray to store reaction rates with string, integer, or slice indexing. @@ -47,7 +47,7 @@ class ReactionRates(object): self.rates = np.zeros((self.n_mat, self.n_nuc, self.n_react)) def __getitem__(self, pos): - """ Retrieves an item from reaction_rates. + """Retrieves an item from reaction_rates. Parameters ---------- @@ -74,7 +74,7 @@ class ReactionRates(object): return self.rates[mat, nuc, react] def __setitem__(self, pos, val): - """ Sets an item from reaction_rates. + """Sets an item from reaction_rates. Parameters ---------- diff --git a/openmc/deplete/results.py b/openmc/deplete/results.py index c0ec1627e..ae096b8ce 100644 --- a/openmc/deplete/results.py +++ b/openmc/deplete/results.py @@ -1,4 +1,4 @@ -""" The results module. +"""The results module. Contains results generation and saving capabilities. """ @@ -14,8 +14,9 @@ from .reaction_rates import ReactionRates RESULTS_VERSION = 2 + class Results(object): - """ Contains output of opendeplete. + """Contains output of opendeplete. Attributes ---------- @@ -62,7 +63,7 @@ class Results(object): self.data = None def allocate(self, volume, nuc_list, burn_list, full_burn_dict, stages): - """ Allocates memory of Results. + """Allocates memory of Results. Parameters ---------- @@ -113,7 +114,7 @@ class Results(object): return self.data.shape[0] def __getitem__(self, pos): - """ Retrieves an item from results. + """Retrieves an item from results. Parameters ---------- @@ -137,7 +138,7 @@ class Results(object): return self.data[stage, mat, nuc] def __setitem__(self, pos, val): - """ Sets an item from results. + """Sets an item from results. Parameters ---------- @@ -159,7 +160,7 @@ class Results(object): self.data[stage, mat, nuc] = val def create_hdf5(self, handle): - """ Creates file structure for a blank HDF5 file. + """Creates file structure for a blank HDF5 file. Parameters ---------- @@ -232,7 +233,7 @@ class Results(object): handle.create_dataset("time", (1, 2), maxshape=(None, 2), dtype='float64') def to_hdf5(self, handle, index): - """ Converts results object into an hdf5 object. + """Converts results object into an hdf5 object. Parameters ---------- @@ -302,7 +303,7 @@ class Results(object): time_dset[index, :] = self.time def from_hdf5(self, handle, index): - """ Loads results object from HDF5. + """Loads results object from HDF5. Parameters ---------- @@ -360,7 +361,7 @@ class Results(object): def get_dict(number): - """ Given an operator nested dictionary, output indexing dictionaries. + """Given an operator nested dictionary, output indexing dictionaries. These indexing dictionaries map mat IDs and nuclide names to indices inside of Results.data. @@ -394,7 +395,7 @@ def get_dict(number): def write_results(result, filename, index): - """ Outputs result to an .hdf5 file. + """Outputs result to an .hdf5 file. Parameters ---------- @@ -418,7 +419,7 @@ def write_results(result, filename, index): def read_results(filename): - """ Reads out a list of results objects from an hdf5 file. + """Reads out a list of results objects from an hdf5 file. Parameters ---------- diff --git a/openmc/deplete/utilities.py b/openmc/deplete/utilities.py index 54632ed9c..5433edce4 100644 --- a/openmc/deplete/utilities.py +++ b/openmc/deplete/utilities.py @@ -1,4 +1,4 @@ -""" The utilities module. +"""The utilities module. Contains functions that can be used to post-process objects that come out of the results module. @@ -6,8 +6,9 @@ the results module. import numpy as np + def evaluate_single_nuclide(results, cell, nuc): - """ Evaluates a single nuclide in a single cell from a results list. + """Evaluates a single nuclide in a single cell from a results list. Parameters ---------- @@ -38,7 +39,7 @@ def evaluate_single_nuclide(results, cell, nuc): return time, concentration def evaluate_reaction_rate(results, cell, nuc, rxn): - """ Evaluates a single nuclide reaction rate in a single cell from a results list. + """Evaluates a single nuclide reaction rate in a single cell from a results list. Parameters ---------- @@ -69,8 +70,9 @@ def evaluate_reaction_rate(results, cell, nuc, rxn): return time, rate + def evaluate_eigenvalue(results): - """ Evaluates the eigenvalue from a results list. + """Evaluates the eigenvalue from a results list. Parameters ---------- diff --git a/scripts/example_geometry.py b/scripts/example_geometry.py index 9afcc0d46..09ce0576f 100644 --- a/scripts/example_geometry.py +++ b/scripts/example_geometry.py @@ -9,8 +9,7 @@ import math import numpy as np import openmc - -from opendeplete import density_to_mat +from openmc.deplete import density_to_mat def generate_initial_number_density(): diff --git a/scripts/example_plot.py b/scripts/example_plot.py index d2c6ee9d6..c92fef6bf 100644 --- a/scripts/example_plot.py +++ b/scripts/example_plot.py @@ -1,11 +1,8 @@ """An example file showing how to plot data from a simulation.""" import matplotlib.pyplot as plt - -from opendeplete import read_results, \ - evaluate_single_nuclide, \ - evaluate_reaction_rate, \ - evaluate_eigenvalue +from openmc.deplete import (read_results, evaluate_single_nuclide, + evaluate_reaction_rate, evaluate_eigenvalue) # Set variables for where the data is, and what we want to read out. result_folder = "test" diff --git a/scripts/example_run.py b/scripts/example_run.py index bb80f6582..82d0883c3 100644 --- a/scripts/example_run.py +++ b/scripts/example_run.py @@ -1,7 +1,7 @@ """An example file showing how to run a simulation.""" import numpy as np -import opendeplete +import openmc.deplete import example_geometry @@ -16,7 +16,7 @@ N = np.floor(dt2/dt1) dt = np.repeat([dt1], N) # Create settings variable -settings = opendeplete.OpenMCSettings() +settings = openmc.deplete.OpenMCSettings() settings.openmc_call = "openmc" # An example for mpiexec: @@ -33,7 +33,7 @@ settings.power = 2.337e15*4*joule_per_mev # MeV/second cm from CASMO settings.dt_vec = dt settings.output_dir = 'test' -op = opendeplete.OpenMCOperator(geometry, settings) +op = openmc.deplete.OpenMCOperator(geometry, settings) # Perform simulation using the MCNPX/MCNP6 algorithm -opendeplete.integrator.cecm(op) +openmc.deplete.integrator.cecm(op) diff --git a/scripts/make_chain.py b/scripts/make_chain.py index 2e0d9d3bc..ccf4ef9b7 100644 --- a/scripts/make_chain.py +++ b/scripts/make_chain.py @@ -6,7 +6,7 @@ from zipfile import ZipFile import requests from tqdm import tqdm -import opendeplete +import openmc.deplete urls = [ @@ -52,7 +52,7 @@ def main(): nfy_files = glob.glob(os.path.join('nfy', '*.endf')) neutron_files = glob.glob(os.path.join('neutrons', '*.endf')) - chain = opendeplete.DepletionChain.from_endf(decay_files, nfy_files, neutron_files) + chain = openmc.deplete.DepletionChain.from_endf(decay_files, nfy_files, neutron_files) chain.xml_write('chain_endfb71.xml') diff --git a/tests/deplete_tests/dummy_geometry.py b/tests/deplete_tests/dummy_geometry.py index 610151941..614cc726e 100644 --- a/tests/deplete_tests/dummy_geometry.py +++ b/tests/deplete_tests/dummy_geometry.py @@ -1,16 +1,11 @@ -""" The OpenMC wrapper module. - -This module implements the OpenDeplete -> OpenMC linkage. -""" - import numpy as np import scipy.sparse as sp +from openmc.deplete.reaction_rates import ReactionRates +from openmc.deplete.function import Operator -from opendeplete.reaction_rates import ReactionRates -from opendeplete.function import Operator class DummyGeometry(Operator): - """ This is a dummy geometry class with no statistical uncertainty. + """This is a dummy geometry class with no statistical uncertainty. y_1' = sin(y_2) y_1 + cos(y_1) y_2 y_2' = -cos(y_2) y_1 + sin(y_1) y_2 @@ -24,14 +19,14 @@ class DummyGeometry(Operator): """ def __init__(self, settings): - Operator.__init__(self, settings) + super().__init__(settings) @property def chain(self): return self def eval(self, vec, print_out=False): - """ Evaluates F(y) + """Evaluates F(y) Parameters ---------- @@ -60,11 +55,10 @@ class DummyGeometry(Operator): reaction_rates[0, 1, 0] = vec[0][1] # Create a fake rates object - return 0.0, reaction_rates, 0 def form_matrix(self, rates): - """ Forms the f(y) matrix in y' = f(y)y. + """Forms the f(y) matrix in y' = f(y)y. Nominally a depletion matrix, this is abstracted on the off chance that the function f has nothing to do with depletion at all. @@ -137,7 +131,7 @@ class DummyGeometry(Operator): return ReactionRates(cell_to_ind, nuc_to_ind, react_to_ind) def initial_condition(self): - """ Returns initial vector. + """Returns initial vector. Returns ------- @@ -148,7 +142,7 @@ class DummyGeometry(Operator): return [np.array((1.0, 1.0))] def get_results_info(self): - """ Returns volume list, cell lists, and nuc lists. + """Returns volume list, cell lists, and nuc lists. Returns ------- diff --git a/tests/deplete_tests/test_atom_number.py b/tests/deplete_tests/test_atom_number.py index 9a17230f8..d36b96d38 100644 --- a/tests/deplete_tests/test_atom_number.py +++ b/tests/deplete_tests/test_atom_number.py @@ -3,11 +3,11 @@ import unittest import numpy as np +from openmc.deplete import atom_number -from opendeplete import atom_number class TestAtomNumber(unittest.TestCase): - """ Tests for the AtomNumber class. """ + """Tests for the AtomNumber class.""" def test_indexing(self): """Tests the __getitem__ and __setitem__ routines simultaneously.""" @@ -41,7 +41,7 @@ class TestAtomNumber(unittest.TestCase): self.assertEqual(number["10000", "U238"], 5.0) def test_n_mat(self): - """ Test number of materials property. """ + """Test number of materials property. """ mat_to_ind = {"10000" : 0, "10001" : 1} nuc_to_ind = {"U238" : 0, "U235" : 1, "Gd157" : 2} volume = {"10000" : 0.38, "10001" : 0.21} @@ -51,7 +51,7 @@ class TestAtomNumber(unittest.TestCase): self.assertEqual(number.n_mat, 2) def test_n_nuc(self): - """ Test number of nuclides property. """ + """Test number of nuclides property.""" mat_to_ind = {"10000" : 0, "10001" : 1} nuc_to_ind = {"U238" : 0, "U235" : 1, "Gd157" : 2} volume = {"10000" : 0.38, "10001" : 0.21} @@ -61,7 +61,7 @@ class TestAtomNumber(unittest.TestCase): self.assertEqual(number.n_nuc, 3) def test_burn_nuc_list(self): - """ Test the list of burned nuclides property """ + """Test the list of burned nuclides property""" mat_to_ind = {"10000" : 0, "10001" : 1} nuc_to_ind = {"U238" : 0, "U235" : 1, "Gd157" : 2} volume = {"10000" : 0.38, "10001" : 0.21} @@ -71,7 +71,7 @@ class TestAtomNumber(unittest.TestCase): self.assertEqual(number.burn_nuc_list, ["U238", "U235"]) def test_burn_mat_list(self): - """ Test the list of burned nuclides property """ + """Test the list of burned nuclides property""" mat_to_ind = {"10000" : 0, "10001" : 1, "10002" : 2} nuc_to_ind = {"U238" : 0, "U235" : 1, "Gd157" : 2} volume = {"10000" : 0.38, "10001" : 0.21} diff --git a/tests/deplete_tests/test_cecm_regression.py b/tests/deplete_tests/test_cecm_regression.py index 23a634200..0d6966c82 100644 --- a/tests/deplete_tests/test_cecm_regression.py +++ b/tests/deplete_tests/test_cecm_regression.py @@ -4,11 +4,11 @@ import os import unittest import numpy as np +import openmc.deplete +from openmc.deplete import results +from openmc.deplete import utilities -import opendeplete -from opendeplete import results -from opendeplete import utilities -import test.dummy_geometry as dummy_geometry +from . import dummy_geometry class TestCECMRegression(unittest.TestCase): @@ -26,14 +26,14 @@ class TestCECMRegression(unittest.TestCase): def test_cecm(self): """ Integral regression test of integrator algorithm using CE/CM. """ - settings = opendeplete.Settings() + settings = openmc.deplete.Settings() settings.dt_vec = [0.75, 0.75] settings.output_dir = self.results op = dummy_geometry.DummyGeometry(settings) # Perform simulation using the MCNPX/MCNP6 algorithm - opendeplete.cecm(op, print_out=False) + openmc.deplete.cecm(op, print_out=False) # Load the files res = results.read_results(settings.output_dir + "/results.h5") @@ -59,8 +59,8 @@ class TestCECMRegression(unittest.TestCase): os.chdir(cls.cwd) - opendeplete.comm.barrier() - if opendeplete.comm.rank == 0: + openmc.deplete.comm.barrier() + if openmc.deplete.comm.rank == 0: os.remove(os.path.join(cls.results, "results.h5")) os.rmdir(cls.results) diff --git a/tests/deplete_tests/test_cram.py b/tests/deplete_tests/test_cram.py index 2744adbf4..10f41fe2b 100644 --- a/tests/deplete_tests/test_cram.py +++ b/tests/deplete_tests/test_cram.py @@ -4,8 +4,8 @@ import unittest import numpy as np import scipy.sparse as sp +from openmc.deplete.integrator import CRAM16, CRAM48 -from opendeplete.integrator import CRAM16, CRAM48 class TestCram(unittest.TestCase): """ Tests for cram.py diff --git a/tests/deplete_tests/test_depletion_chain.py b/tests/deplete_tests/test_depletion_chain.py index 216d1e68f..06abbba0f 100644 --- a/tests/deplete_tests/test_depletion_chain.py +++ b/tests/deplete_tests/test_depletion_chain.py @@ -5,8 +5,7 @@ import os import unittest import numpy as np - -from opendeplete import comm, depletion_chain, reaction_rates, nuclide +from openmc.deplete import comm, depletion_chain, reaction_rates, nuclide class TestDepletionChain(unittest.TestCase): diff --git a/tests/deplete_tests/test_full.py b/tests/deplete_tests/test_full.py index f9a6c7493..88c409554 100644 --- a/tests/deplete_tests/test_full.py +++ b/tests/deplete_tests/test_full.py @@ -2,13 +2,14 @@ import shutil import unittest +from os.path import join, dirname import numpy as np +import openmc.deplete +from openmc.deplete import results +from openmc.deplete import utilities -import opendeplete -from opendeplete import results -from opendeplete import utilities -import test.example_geometry as example_geometry +from . import example_geometry class TestFull(unittest.TestCase): @@ -40,7 +41,7 @@ class TestFull(unittest.TestCase): dt = np.repeat([dt1], N) # Create settings variable - settings = opendeplete.OpenMCSettings() + settings = openmc.deplete.OpenMCSettings() settings.chain_file = "chains/chain_simple.xml" settings.openmc_call = "openmc" @@ -60,16 +61,17 @@ class TestFull(unittest.TestCase): settings.dt_vec = dt settings.output_dir = "test_full" - op = opendeplete.OpenMCOperator(geometry, settings) + op = openmc.deplete.OpenMCOperator(geometry, settings) # Perform simulation using the predictor algorithm - opendeplete.integrator.predictor(op) + openmc.deplete.integrator.predictor(op) # Load the files res_test = results.read_results(settings.output_dir + "/results.h5") # Load the reference - res_old = results.read_results("test/test_reference.h5") + filename = join(dirname(__file__), 'test_reference.h5') + res_old = results.read_results(filename) # Assert same mats for mat in res_old[0].mat_to_ind: @@ -110,8 +112,8 @@ class TestFull(unittest.TestCase): def tearDown(self): """ Clean up files""" - opendeplete.comm.barrier() - if opendeplete.comm.rank == 0: + openmc.deplete.comm.barrier() + if openmc.deplete.comm.rank == 0: shutil.rmtree("test_full", ignore_errors=True) diff --git a/tests/deplete_tests/test_integrator.py b/tests/deplete_tests/test_integrator.py index 7e121ce16..9b4cbe780 100644 --- a/tests/deplete_tests/test_integrator.py +++ b/tests/deplete_tests/test_integrator.py @@ -6,8 +6,7 @@ import unittest from unittest.mock import MagicMock import numpy as np - -from opendeplete import integrator, ReactionRates, results, comm +from openmc.deplete import integrator, ReactionRates, results, comm class TestIntegrator(unittest.TestCase): diff --git a/tests/deplete_tests/test_nuclide.py b/tests/deplete_tests/test_nuclide.py index c5439b2aa..2d379030d 100644 --- a/tests/deplete_tests/test_nuclide.py +++ b/tests/deplete_tests/test_nuclide.py @@ -3,7 +3,7 @@ import unittest import xml.etree.ElementTree as ET -from opendeplete import nuclide +from openmc.deplete import nuclide class TestNuclide(unittest.TestCase): diff --git a/tests/deplete_tests/test_predictor_regression.py b/tests/deplete_tests/test_predictor_regression.py index c72ae8a47..a41ca9ce7 100644 --- a/tests/deplete_tests/test_predictor_regression.py +++ b/tests/deplete_tests/test_predictor_regression.py @@ -4,11 +4,11 @@ import os import unittest import numpy as np +import openmc.deplete +from openmc.deplete import results +from openmc.deplete import utilities -import opendeplete -from opendeplete import results -from opendeplete import utilities -import test.dummy_geometry as dummy_geometry +from . import dummy_geometry class TestPredictorRegression(unittest.TestCase): """ Regression tests for opendeplete.integrator.predictor algorithm. @@ -25,14 +25,14 @@ class TestPredictorRegression(unittest.TestCase): def test_predictor(self): """ Integral regression test of integrator algorithm using CE/CM. """ - settings = opendeplete.Settings() + settings = openmc.deplete.Settings() settings.dt_vec = [0.75, 0.75] settings.output_dir = self.results op = dummy_geometry.DummyGeometry(settings) # Perform simulation using the predictor algorithm - opendeplete.predictor(op, print_out=False) + openmc.deplete.predictor(op, print_out=False) # Load the files res = results.read_results(settings.output_dir + "/results.h5") @@ -58,8 +58,8 @@ class TestPredictorRegression(unittest.TestCase): os.chdir(cls.cwd) - opendeplete.comm.barrier() - if opendeplete.comm.rank == 0: + openmc.deplete.comm.barrier() + if openmc.deplete.comm.rank == 0: os.remove(os.path.join(cls.results, "results.h5")) os.rmdir(cls.results) diff --git a/tests/deplete_tests/test_reaction_rates.py b/tests/deplete_tests/test_reaction_rates.py index 4821ec18c..2139be16c 100644 --- a/tests/deplete_tests/test_reaction_rates.py +++ b/tests/deplete_tests/test_reaction_rates.py @@ -2,7 +2,7 @@ import unittest -from opendeplete import reaction_rates +from openmc.deplete import reaction_rates class TestReactionRates(unittest.TestCase): diff --git a/tests/deplete_tests/test_utilities.py b/tests/deplete_tests/test_utilities.py index faa1a500b..fb60df5b7 100644 --- a/tests/deplete_tests/test_utilities.py +++ b/tests/deplete_tests/test_utilities.py @@ -1,11 +1,11 @@ """ Full system test suite. """ import unittest +from os.path import join, dirname import numpy as np - -from opendeplete import results -from opendeplete import utilities +from openmc.deplete import results +from openmc.deplete import utilities class TestUtilities(unittest.TestCase): @@ -19,7 +19,8 @@ class TestUtilities(unittest.TestCase): """ # Load the reference - res = results.read_results("test/test_reference.h5") + filename = join(dirname(__file__), 'test_reference.h5') + res = results.read_results(filename) x, y = utilities.evaluate_single_nuclide(res, "1", "Xe135") @@ -35,7 +36,8 @@ class TestUtilities(unittest.TestCase): """ # Load the reference - res = results.read_results("test/test_reference.h5") + filename = join(dirname(__file__), 'test_reference.h5') + res = results.read_results(filename) x, y = utilities.evaluate_reaction_rate(res, "1", "Xe135", "(n,gamma)") @@ -53,7 +55,8 @@ class TestUtilities(unittest.TestCase): """ # Load the reference - res = results.read_results("test/test_reference.h5") + filename = join(dirname(__file__), 'test_reference.h5') + res = results.read_results(filename) x, y = utilities.evaluate_eigenvalue(res)