From dacf650eaf74ce6b138c0225cfcc83d4c622a39d Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 8 Feb 2018 14:32:28 -0600 Subject: [PATCH 1/3] Fix bug with clearing k_generation and entropy --- src/simulation.F90 | 2 ++ tests/__init__.py | 15 +++++++++++++++ tests/unit_tests/test_capi.py | 33 ++++++++++++++++++++------------- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/simulation.F90 b/src/simulation.F90 index 424c55e9bd..0204aaf796 100644 --- a/src/simulation.F90 +++ b/src/simulation.F90 @@ -454,6 +454,8 @@ contains ! Reset global variables current_batch = 0 + call k_generation % clear() + call entropy % clear() need_depletion_rx = .false. ! Set flag indicating initialization is done diff --git a/tests/__init__.py b/tests/__init__.py index e69de29bb2..5c21cd9380 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,15 @@ +from contextlib import contextmanager +import os +import tempfile + + +@contextmanager +def cdtemp(): + """Context manager to change to/return from a tmpdir.""" + with tempfile.TemporaryDirectory() as tmpdir: + cwd = os.getcwd() + try: + os.chdir(tmpdir) + yield + finally: + os.chdir(cwd) diff --git a/tests/unit_tests/test_capi.py b/tests/unit_tests/test_capi.py index e1e87e27b3..618f54e4f9 100644 --- a/tests/unit_tests/test_capi.py +++ b/tests/unit_tests/test_capi.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - from collections import Mapping import os @@ -8,12 +6,15 @@ import pytest import openmc import openmc.capi +from tests import cdtemp + @pytest.fixture(scope='module') def pincell_model(): """Set up a model to test with and delete files when done""" openmc.reset_auto_ids() pincell = openmc.examples.pwr_pin_cell() + pincell.settings.verbosity = 1 # Add a tally filter1 = openmc.MaterialFilter(pincell.materials) @@ -24,17 +25,10 @@ def pincell_model(): mat_tally.scores = ['total', 'elastic', '(n,gamma)'] pincell.tallies.append(mat_tally) - # Write XML files - pincell.export_to_xml() - - yield - - # Delete generated files - files = ['geometry.xml', 'materials.xml', 'settings.xml', 'tallies.xml', - 'statepoint.10.h5', 'summary.h5', 'test_sp.h5'] - for f in files: - if os.path.exists(f): - os.remove(f) + # Write XML files in tmpdir + with cdtemp(): + pincell.export_to_xml() + yield @pytest.fixture(scope='module') @@ -229,6 +223,19 @@ def test_by_batch(capi_run): openmc.capi.simulation_finalize() +def test_reproduce_keff(capi_init): + # Get k-effective after run + openmc.capi.hard_reset() + openmc.capi.run() + keff0 = openmc.capi.keff() + + # Reset, run again, and get k-effective again. they should match + openmc.capi.hard_reset() + openmc.capi.run() + keff1 = openmc.capi.keff() + assert keff0 == pytest.approx(keff1) + + def test_find_cell(capi_init): cell, instance = openmc.capi.find_cell((0., 0., 0.)) assert cell is openmc.capi.cells[1] From 899b6b67996489ae6e3369156ce7017e902031a1 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 8 Feb 2018 15:34:39 -0600 Subject: [PATCH 2/3] Make sure k_generation and entropy are cleared before loading state point --- src/simulation.F90 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/simulation.F90 b/src/simulation.F90 index 0204aaf796..34c4336944 100644 --- a/src/simulation.F90 +++ b/src/simulation.F90 @@ -434,6 +434,13 @@ contains allocate(filter_matches(n_filters)) !$omp end parallel + ! Reset global variables -- this is done before loading state point (as that + ! will potentially populate k_generation and entropy) + current_batch = 0 + call k_generation % clear() + call entropy % clear() + need_depletion_rx = .false. + ! If this is a restart run, load the state point data and binary source ! file if (restart_run) then @@ -452,12 +459,6 @@ contains end if end if - ! Reset global variables - current_batch = 0 - call k_generation % clear() - call entropy % clear() - need_depletion_rx = .false. - ! Set flag indicating initialization is done simulation_initialized = .true. From 4298c50c3fdf2796b0d6020b00889b8c1db691d9 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 9 Feb 2018 09:28:09 -0600 Subject: [PATCH 3/3] Use numpy 1.13 when testing since float formatting changed in 1.14 --- tools/ci/travis-install.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/ci/travis-install.sh b/tools/ci/travis-install.sh index 3efadd6f36..4921534db9 100755 --- a/tools/ci/travis-install.sh +++ b/tools/ci/travis-install.sh @@ -4,8 +4,11 @@ set -ex # Install NJOY 2016 ./tools/ci/travis-install-njoy.sh -# Running OpenMC's setup.py requires numpy/cython already -pip install numpy cython +# Running OpenMC's setup.py requires numpy/cython already. NumPy float +# formatting changed in version 1.14, so stick with a lower version until we can +# handle it in our test suite +pip install 'numpy<1.14' +pip install cython # pytest installed by default -- make sure we get latest pip install --upgrade pytest