From 61fb8194a530ae3ebc1345607899d18371cf257c Mon Sep 17 00:00:00 2001 From: Adam Nelson Date: Sun, 29 May 2016 10:42:20 -0400 Subject: [PATCH] Added a test which tests creating MGXS in CE mode and piping in to MG mode. --- openmc/mgxs/library.py | 2 +- .../inputs_true.dat | 1 + .../results_true.dat | 2 + .../test_mgxs_library_ce_to_mg.py | 93 +++++++++++++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 tests/test_mgxs_library_ce_to_mg/inputs_true.dat create mode 100644 tests/test_mgxs_library_ce_to_mg/results_true.dat create mode 100644 tests/test_mgxs_library_ce_to_mg/test_mgxs_library_ce_to_mg.py diff --git a/openmc/mgxs/library.py b/openmc/mgxs/library.py index 4c2497173e..62dde28ab2 100644 --- a/openmc/mgxs/library.py +++ b/openmc/mgxs/library.py @@ -34,7 +34,7 @@ class Library(object): Parameters ---------- openmc_geometry : openmc.Geometry - An geometry which has been initialized with a root universe + A geometry which has been initialized with a root universe by_nuclide : bool If true, computes cross sections for each nuclide in each domain mgxs_types : Iterable of str diff --git a/tests/test_mgxs_library_ce_to_mg/inputs_true.dat b/tests/test_mgxs_library_ce_to_mg/inputs_true.dat new file mode 100644 index 0000000000..ad4b639655 --- /dev/null +++ b/tests/test_mgxs_library_ce_to_mg/inputs_true.dat @@ -0,0 +1 @@ +15355a90181bc3a8ba70bcc9a89beff2c240dc75abbf26c3e3b6a940c4ec2028b238422ac26af08863c24ce6fc16d48d249f17cd0bce53df0141138deccfc81a \ No newline at end of file diff --git a/tests/test_mgxs_library_ce_to_mg/results_true.dat b/tests/test_mgxs_library_ce_to_mg/results_true.dat new file mode 100644 index 0000000000..1152dd2cca --- /dev/null +++ b/tests/test_mgxs_library_ce_to_mg/results_true.dat @@ -0,0 +1,2 @@ +k-combined: +1.017325E+00 3.827758E-02 diff --git a/tests/test_mgxs_library_ce_to_mg/test_mgxs_library_ce_to_mg.py b/tests/test_mgxs_library_ce_to_mg/test_mgxs_library_ce_to_mg.py new file mode 100644 index 0000000000..9bf70bbbbe --- /dev/null +++ b/tests/test_mgxs_library_ce_to_mg/test_mgxs_library_ce_to_mg.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python + +import os +import sys +import glob +import hashlib +sys.path.insert(0, os.pardir) +from testing_harness import PyAPITestHarness +import openmc +import openmc.mgxs + + +class MGXSTestHarness(PyAPITestHarness): + def _build_inputs(self): + + # The openmc.mgxs module needs a summary.h5 file + self._input_set.settings.output = {'summary': True} + + # Generate inputs using parent class routine + super(MGXSTestHarness, self)._build_inputs() + + # Initialize a two-group structure + energy_groups = openmc.mgxs.EnergyGroups(group_edges=[0, 0.625e-6, 20.]) + + # Initialize MGXS Library for a few cross section types + self.mgxs_lib = openmc.mgxs.Library(self._input_set.geometry) + self.mgxs_lib.by_nuclide = False + self.mgxs_lib.mgxs_types = ['total', 'absorption', 'nu-fission matrix', + 'nu-scatter matrix', 'multiplicity matrix'] + self.mgxs_lib.energy_groups = energy_groups + self.mgxs_lib.correction = None + self.mgxs_lib.legendre_order = 3 + self.mgxs_lib.domain_type = 'material' + self.mgxs_lib.build_library() + + # Initialize a tallies file + self._input_set.tallies = openmc.Tallies() + self.mgxs_lib.add_to_tallies_file(self._input_set.tallies, merge=False) + self._input_set.tallies.export_to_xml() + + def _run_openmc(self): + # Initial run + if self._opts.mpi_exec is not None: + returncode = openmc.run(mpi_procs=self._opts.mpi_np, + openmc_exec=self._opts.exe, + mpi_exec=self._opts.mpi_exec) + + else: + returncode = openmc.run(openmc_exec=self._opts.exe) + + assert returncode == 0, 'CE OpenMC calculation did not exit' \ + 'successfully.' + + # Build MG Inputs + # Get data needed to execute Library calculations. + statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0] + sp = openmc.StatePoint(statepoint) + self.mgxs_lib.load_from_statepoint(sp) + self._input_set.mgxs_file, self._input_set.materials, \ + self._input_set.geometry = self.mgxs_lib.create_mg_mode() + + # Modify settings so we can run in MG mode + self._input_set.settings.cross_sections = './mgxs.xml' + self._input_set.settings.energy_mode = 'multi-group' + + # Write modified input files + self._input_set.settings.export_to_xml() + self._input_set.geometry.export_to_xml() + self._input_set.materials.export_to_xml() + self._input_set.mgxs_file.export_to_xml() + # Dont need tallies.xml, so remove the file + if os.path.exists('./tallies.xml'): + os.remove('./tallies.xml') + + # Re-run MG mode. + if self._opts.mpi_exec is not None: + returncode = openmc.run(mpi_procs=self._opts.mpi_np, + openmc_exec=self._opts.exe, + mpi_exec=self._opts.mpi_exec) + + else: + returncode = openmc.run(openmc_exec=self._opts.exe) + + def _cleanup(self): + super(MGXSTestHarness, self)._cleanup() + f = os.path.join(os.getcwd(), 'tallies.xml') + f = os.path.join(os.getcwd(), 'mgxs.xml') + if os.path.exists(f): os.remove(f) + + +if __name__ == '__main__': + harness = MGXSTestHarness('statepoint.10.*', True) + harness.main()