Fix bug with clearing k_generation and entropy

This commit is contained in:
Paul Romano 2018-02-08 14:32:28 -06:00
parent 4cff8d92fb
commit dacf650eaf
3 changed files with 37 additions and 13 deletions

View file

@ -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

View file

@ -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)

View file

@ -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]