Fix test update for mg_temperature and surface_source

This commit is contained in:
Paul Romano 2021-04-19 14:56:24 -05:00
parent 8547e7082a
commit dc0850541b
2 changed files with 13 additions and 53 deletions

View file

@ -6,7 +6,7 @@ import shutil
class MgTemperatureTestHarness(TestHarness):
def execute_test(self):
def execute_test(self, update=False):
"""Run OpenMC with the appropriate arguments and check the outputs."""
base_dir = os.getcwd()
overall_results = []
@ -47,10 +47,12 @@ class MgTemperatureTestHarness(TestHarness):
overall_results.append(results)
os.chdir(base_dir)
self._write_results("".join(overall_results))
self._compare_results()
if update:
self._overwrite_results()
else:
self._compare_results()
finally:
os.chdir(base_dir)
shutil.copyfile("results_test.dat", "results_true.dat")
if (os.path.isdir("./temp")):
shutil.rmtree("./temp")
self._cleanup()
@ -59,56 +61,7 @@ class MgTemperatureTestHarness(TestHarness):
os.remove(f)
def update_results(self):
"""Update the results_true using the current version of OpenMC."""
base_dir = os.getcwd()
overall_results = []
macro_xs = create_openmc_2mg_libs(names)
types = ('micro', 'micro',
'micro', 'micro',
'micro',
'macro', 'macro',
'macro', 'macro',
'macro')
temperatures = (300., 600., 900.,
520., 600.,
300., 600., 900.,
520., 600)
methods = 2 * (3 * ('nearest',) + 2 * ('interpolation',))
analyt_interp = 10 * [None]
analyt_interp[3] = (600. - 520.) / 300.
analyt_interp[8] = (600. - 520.) / 300.
try:
if (os.path.isdir("./temp")):
shutil.rmtree("./temp")
os.mkdir("temp")
os.chdir(os.path.join(base_dir, "temp"))
for cs, t, m, ai in zip(types, temperatures, methods, analyt_interp):
if (cs == 'macro'):
build_inf_model(['macro'], '../macro_2g.h5', t, m)
else:
build_inf_model(names, '../micro_2g.h5', t, m)
if not ai:
kanalyt = analytical_solution_2g_therm(macro_xs[t])
else:
kanalyt = analytical_solution_2g_therm(macro_xs[300],
macro_xs[600], ai)
self._run_openmc()
self._test_output_created()
string = "{}, method: {}, t: {}, {}kanalyt\n{:12.6E}\n"
results = string.format(cs, m, t, self._get_results(), kanalyt)
overall_results.append(results)
os.chdir(base_dir)
self._write_results("".join(overall_results))
self._compare_results()
finally:
os.chdir(base_dir)
shutil.copyfile("results_test.dat", "results_true.dat")
if (os.path.isdir("./temp")):
shutil.rmtree("./temp")
self._cleanup()
for f in ['micro_2g.h5', 'macro_2g.h5']:
if os.path.exists(f):
os.remove(f)
self.execute_test(update=True)
def test_mg_temperature():

View file

@ -1,4 +1,5 @@
import os
import shutil
import h5py
import numpy as np
@ -101,6 +102,12 @@ class SurfaceSourceTestHarness(PyAPITestHarness):
finally:
self._cleanup()
def _overwrite_results(self):
"""Overwrite the results_true with the results_test."""
shutil.copyfile('results_test.dat', 'results_true.dat')
if os.path.exists('surface_source.h5'):
shutil.copyfile('surface_source.h5', 'surface_source_true.h5')
def _cleanup(self):
"""Delete statepoints, tally, and test files."""
super()._cleanup()