From b4a2687af95526a0decb8518505935fa30b06dcb Mon Sep 17 00:00:00 2001 From: Shikhar Kumar Date: Sat, 24 Nov 2018 02:09:42 -0500 Subject: [PATCH] Update CMFD test suite --- tests/regression_tests/cmfd_feed/cmfd.xml | 15 ------ .../cmfd_feed/results_true.dat | 34 +++--------- tests/regression_tests/cmfd_feed/test.py | 41 +++++++++++++- tests/regression_tests/cmfd_nofeed/cmfd.xml | 16 ------ .../cmfd_nofeed/results_true.dat | 34 +++--------- tests/regression_tests/cmfd_nofeed/test.py | 41 +++++++++++++- tests/testing_harness.py | 54 ++++++++++--------- tests/unit_tests/test_settings.py | 1 - 8 files changed, 120 insertions(+), 116 deletions(-) delete mode 100644 tests/regression_tests/cmfd_feed/cmfd.xml delete mode 100644 tests/regression_tests/cmfd_nofeed/cmfd.xml diff --git a/tests/regression_tests/cmfd_feed/cmfd.xml b/tests/regression_tests/cmfd_feed/cmfd.xml deleted file mode 100644 index ae50243c03..0000000000 --- a/tests/regression_tests/cmfd_feed/cmfd.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - -10 -1 -1 - 10 1 1 - 10 1 1 - 0.0 0.0 1.0 1.0 1.0 1.0 - - - 5 - dominance - true - 1.e-15 1.e-20 - diff --git a/tests/regression_tests/cmfd_feed/results_true.dat b/tests/regression_tests/cmfd_feed/results_true.dat index aba219ba83..c175dd7db9 100644 --- a/tests/regression_tests/cmfd_feed/results_true.dat +++ b/tests/regression_tests/cmfd_feed/results_true.dat @@ -391,10 +391,6 @@ cmfd indices 1.000000E+00 1.000000E+00 k cmfd -0.000000E+00 -0.000000E+00 -0.000000E+00 -0.000000E+00 1.170416E+00 1.172966E+00 1.165537E+00 @@ -412,10 +408,6 @@ k cmfd 1.167848E+00 1.165116E+00 cmfd entropy -0.000000E+00 -0.000000E+00 -0.000000E+00 -0.000000E+00 3.203643E+00 3.207943E+00 3.213367E+00 @@ -433,10 +425,6 @@ cmfd entropy 3.233193E+00 3.232564E+00 cmfd balance -0.000000E+00 -0.000000E+00 -0.000000E+00 -0.000000E+00 4.009062E-03 4.431773E-03 3.152666E-03 @@ -446,18 +434,14 @@ cmfd balance 1.502427E-03 1.589825E-03 1.566020E-03 -1.219160E-03 -1.017888E-03 -9.771622E-04 -1.010120E-03 -1.073382E-03 -1.172758E-03 -9.827332E-04 +1.170009E-03 +9.507594E-04 +9.072590E-04 +1.009003E-03 +1.064703E-03 +1.163610E-03 +9.756308E-04 cmfd dominance ratio - 0.000E+00 - 0.000E+00 - 0.000E+00 - 0.000E+00 5.397E-01 5.425E-01 5.481E-01 @@ -475,10 +459,6 @@ cmfd dominance ratio 5.524E-01 5.523E-01 cmfd openmc source comparison -0.000000E+00 -0.000000E+00 -0.000000E+00 -0.000000E+00 6.959834E-03 5.655657E-03 3.886185E-03 diff --git a/tests/regression_tests/cmfd_feed/test.py b/tests/regression_tests/cmfd_feed/test.py index 4fc39d96ad..368e81aee2 100644 --- a/tests/regression_tests/cmfd_feed/test.py +++ b/tests/regression_tests/cmfd_feed/test.py @@ -1,6 +1,43 @@ from tests.testing_harness import CMFDTestHarness - +import openmc +import numpy as np def test_cmfd_feed(): - harness = CMFDTestHarness('statepoint.20.h5') + # Initialize and set CMFD mesh + cmfd_mesh = openmc.CMFDMesh() + cmfd_mesh.lower_left = -10.0, -1.0, -1.0 + cmfd_mesh.upper_right = 10.0, 1.0, 1.0 + cmfd_mesh.dimension = 10, 1, 1 + cmfd_mesh.albedo = 0.0, 0.0, 1.0, 1.0, 1.0, 1.0 + + # Initialize and run CMFDRun object + cmfd_run = openmc.CMFDRun() + cmfd_run.cmfd_mesh = cmfd_mesh + cmfd_run.cmfd_begin = 5 + cmfd_run.cmfd_display = 'dominance' + cmfd_run.cmfd_feedback = True + cmfd_run.gauss_seidel_tolerance = [1.e-15, 1.e-20] + cmfd_run.run() + + # Create output string of all CMFD results to pass into testing harness + outstr = 'cmfd indices\n' + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in cmfd_run._indices]) + outstr += '\nk cmfd\n' + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in cmfd_run._k_cmfd]) + outstr += '\ncmfd entropy\n' + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in cmfd_run._entropy]) + outstr += '\ncmfd balance\n' + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in cmfd_run._balance]) + outstr += '\ncmfd dominance ratio\n' + outstr += '\n'.join(['{0:10.3E}'.format(x) for x in cmfd_run._dom]) + outstr += '\ncmfd openmc source comparison\n' + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in cmfd_run._src_cmp]) + outstr += '\ncmfd source\n' + cmfdsrc = np.reshape(cmfd_run._cmfd_src, np.product(cmfd_run._indices), + order='F') + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in cmfdsrc]) + outstr += '\n' + + # Initialize and run CMFD test harness + harness = CMFDTestHarness('statepoint.20.h5', cmfd_results=outstr) harness.main() diff --git a/tests/regression_tests/cmfd_nofeed/cmfd.xml b/tests/regression_tests/cmfd_nofeed/cmfd.xml deleted file mode 100644 index 2e13cff6b8..0000000000 --- a/tests/regression_tests/cmfd_nofeed/cmfd.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - -10 -1 -1 - 10 1 1 - 10 1 1 - 0.0 0.0 1.0 1.0 1.0 1.0 - - - 5 - dominance - false - 1.e-15 1.e-20 - - diff --git a/tests/regression_tests/cmfd_nofeed/results_true.dat b/tests/regression_tests/cmfd_nofeed/results_true.dat index 23368457d0..33dff8811f 100644 --- a/tests/regression_tests/cmfd_nofeed/results_true.dat +++ b/tests/regression_tests/cmfd_nofeed/results_true.dat @@ -391,10 +391,6 @@ cmfd indices 1.000000E+00 1.000000E+00 k cmfd -0.000000E+00 -0.000000E+00 -0.000000E+00 -0.000000E+00 1.170416E+00 1.172572E+00 1.171159E+00 @@ -412,10 +408,6 @@ k cmfd 1.153714E+00 1.159485E+00 cmfd entropy -0.000000E+00 -0.000000E+00 -0.000000E+00 -0.000000E+00 3.203643E+00 3.204555E+00 3.210935E+00 @@ -433,10 +425,6 @@ cmfd entropy 3.221580E+00 3.220523E+00 cmfd balance -0.000000E+00 -0.000000E+00 -0.000000E+00 -0.000000E+00 4.009062E-03 4.869661E-03 2.997290E-03 @@ -446,18 +434,14 @@ cmfd balance 1.403979E-03 1.398429E-03 1.818398E-03 -1.761250E-03 -1.646649E-03 -1.480119E-03 -1.399559E-03 -1.400162E-03 -1.178363E-03 -1.292280E-03 +1.458254E-03 +1.437876E-03 +1.276844E-03 +1.289036E-03 +1.330300E-03 +1.139999E-03 +1.233647E-03 cmfd dominance ratio - 0.000E+00 - 0.000E+00 - 0.000E+00 - 0.000E+00 5.397E-01 5.405E-01 5.412E-01 @@ -475,10 +459,6 @@ cmfd dominance ratio 5.461E-01 5.443E-01 cmfd openmc source comparison -0.000000E+00 -0.000000E+00 -0.000000E+00 -0.000000E+00 6.959834E-03 5.494667E-03 4.076255E-03 diff --git a/tests/regression_tests/cmfd_nofeed/test.py b/tests/regression_tests/cmfd_nofeed/test.py index a3c7301738..4e34029a9e 100644 --- a/tests/regression_tests/cmfd_nofeed/test.py +++ b/tests/regression_tests/cmfd_nofeed/test.py @@ -1,6 +1,43 @@ from tests.testing_harness import CMFDTestHarness - +import openmc +import numpy as np def test_cmfd_nofeed(): - harness = CMFDTestHarness('statepoint.20.h5') + # Initialize and set CMFD mesh + cmfd_mesh = openmc.CMFDMesh() + cmfd_mesh.lower_left = -10.0, -1.0, -1.0 + cmfd_mesh.upper_right = 10.0, 1.0, 1.0 + cmfd_mesh.dimension = 10, 1, 1 + cmfd_mesh.albedo = 0.0, 0.0, 1.0, 1.0, 1.0, 1.0 + + # Initialize and run CMFDRun object + cmfd_run = openmc.CMFDRun() + cmfd_run.cmfd_mesh = cmfd_mesh + cmfd_run.cmfd_begin = 5 + cmfd_run.cmfd_display = 'dominance' + cmfd_run.cmfd_feedback = False + cmfd_run.gauss_seidel_tolerance = [1.e-15, 1.e-20] + cmfd_run.run() + + # Create output string of all CMFD results to pass into testing harness + outstr = 'cmfd indices\n' + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in cmfd_run._indices]) + outstr += '\nk cmfd\n' + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in cmfd_run._k_cmfd]) + outstr += '\ncmfd entropy\n' + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in cmfd_run._entropy]) + outstr += '\ncmfd balance\n' + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in cmfd_run._balance]) + outstr += '\ncmfd dominance ratio\n' + outstr += '\n'.join(['{0:10.3E}'.format(x) for x in cmfd_run._dom]) + outstr += '\ncmfd openmc source comparison\n' + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in cmfd_run._src_cmp]) + outstr += '\ncmfd source\n' + cmfdsrc = np.reshape(cmfd_run._cmfd_src, np.product(cmfd_run._indices), + order='F') + outstr += '\n'.join(['{0:12.6E}'.format(x) for x in cmfdsrc]) + outstr += '\n' + + # Initialize and run CMFD test harness + harness = CMFDTestHarness('statepoint.20.h5', cmfd_results=outstr) harness.main() diff --git a/tests/testing_harness.py b/tests/testing_harness.py index fb07575ce7..50f02ee63c 100644 --- a/tests/testing_harness.py +++ b/tests/testing_harness.py @@ -133,35 +133,37 @@ class HashedTestHarness(TestHarness): class CMFDTestHarness(TestHarness): """Specialized TestHarness for running OpenMC CMFD tests.""" - def _get_results(self): - """Digest info in the statepoint and return as a string.""" + def __init__(self, statepoint_name, cmfd_results=None): + self._sp_name = statepoint_name + self._cmfd_results = cmfd_results - # Write out the eigenvalue and tallies. - outstr = super()._get_results() + def execute_test(self): + """Don't call _run_openmc as OpenMC will be called through C API for + CMFD tests, and write CMFD results that were passsed as argument - # Read the statepoint file. - statepoint = glob.glob(self._sp_name)[0] - with openmc.StatePoint(statepoint) as sp: - # Write out CMFD data. - outstr += 'cmfd indices\n' - outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp.cmfd_indices]) - outstr += '\nk cmfd\n' - outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp.k_cmfd]) - outstr += '\ncmfd entropy\n' - outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp.cmfd_entropy]) - outstr += '\ncmfd balance\n' - outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp.cmfd_balance]) - outstr += '\ncmfd dominance ratio\n' - outstr += '\n'.join(['{0:10.3E}'.format(x) for x in sp.cmfd_dominance]) - outstr += '\ncmfd openmc source comparison\n' - outstr += '\n'.join(['{0:12.6E}'.format(x) for x in sp.cmfd_srccmp]) - outstr += '\ncmfd source\n' - cmfdsrc = np.reshape(sp.cmfd_src, np.product(sp.cmfd_indices), - order='F') - outstr += '\n'.join(['{0:12.6E}'.format(x) for x in cmfdsrc]) - outstr += '\n' + """ + try: + self._test_output_created() + results = self._get_results() + results += self._cmfd_results + self._write_results(results) + self._compare_results() + finally: + self._cleanup() - return outstr + def update_results(self): + """Don't call _run_openmc as OpenMC will be called through C API for + CMFD tests, and write CMFD results that were passsed as argument + + """ + try: + self._test_output_created() + results = self._get_results() + results += self._cmfd_results + self._write_results(results) + self._overwrite_results() + finally: + self._cleanup() class ParticleRestartTestHarness(TestHarness): diff --git a/tests/unit_tests/test_settings.py b/tests/unit_tests/test_settings.py index 30ec0e683c..a78f074c99 100644 --- a/tests/unit_tests/test_settings.py +++ b/tests/unit_tests/test_settings.py @@ -21,7 +21,6 @@ def test_export_to_xml(run_in_tmpdir): s.confidence_intervals = True s.cross_sections = '/path/to/cross_sections.xml' s.ptables = True - s.run_cmfd = False s.seed = 17 s.survival_biasing = True s.cutoff = {'weight': 0.25, 'weight_avg': 0.5, 'energy': 1.0e-5}