Adding test files for the cpp driver test.

This commit is contained in:
Patrick Shriwise 2020-05-11 17:52:28 -05:00
parent 5a7de406c4
commit bd6048bc28
7 changed files with 289 additions and 0 deletions

View file

@ -0,0 +1,35 @@
#include "openmc/capi.h"
#include "openmc/cell.h"
#include "openmc/tallies/filter.h"
#include "openmc/tallies/filter_cell.h"
#include "openmc/tallies/tally.h"
using namespace openmc;
int main(int argc, char** argv) {
openmc_init(argc, argv, nullptr);
// create a new cell filter
auto cell_filter = Filter::create<CellFilter>();
// add all cells to the cell filter
std::vector<int32_t> cell_indices;
for (auto& entry : openmc::model::cell_map) {
cell_indices.push_back(entry.second);
}
// sort to make sure the cell bins appear in the same
// order as the test relying on the openmc exe
std::sort(cell_indices.begin(), cell_indices.end());
cell_filter->set_cells(cell_indices);
// create a new tally
auto tally = Tally::create();
std::vector<Filter*> filters = {cell_filter};
tally->set_filters(filters);
tally->set_scores({"flux"});
openmc_run();
openmc_finalize();
return 0;
}

View file

@ -0,0 +1,60 @@
<?xml version='1.0' encoding='utf-8'?>
<geometry>
<cell id="1" material="1" name="Fuel" region="-1" universe="0" />
<cell id="2" material="2" name="Cladding" region="1 -2" universe="0" />
<cell id="3" material="3" name="Water" region="2 3 -4 5 -6" universe="0" />
<surface coeffs="0 0 0.39218" id="1" name="Fuel OR" type="z-cylinder" />
<surface coeffs="0 0 0.4572" id="2" name="Clad OR" type="z-cylinder" />
<surface boundary="reflective" coeffs="-0.63" id="3" name="left" type="x-plane" />
<surface boundary="reflective" coeffs="0.63" id="4" name="right" type="x-plane" />
<surface boundary="reflective" coeffs="-0.63" id="5" name="bottom" type="y-plane" />
<surface boundary="reflective" coeffs="0.63" id="6" name="top" type="y-plane" />
</geometry>
<?xml version='1.0' encoding='utf-8'?>
<materials>
<material depletable="true" id="1" name="UO2 (2.4%)">
<density units="g/cm3" value="10.29769" />
<nuclide ao="4.4843e-06" name="U234" />
<nuclide ao="0.00055815" name="U235" />
<nuclide ao="0.022408" name="U238" />
<nuclide ao="0.045829" name="O16" />
</material>
<material id="2" name="Zircaloy">
<density units="g/cm3" value="6.55" />
<nuclide ao="0.021827" name="Zr90" />
<nuclide ao="0.00476" name="Zr91" />
<nuclide ao="0.0072758" name="Zr92" />
<nuclide ao="0.0073734" name="Zr94" />
<nuclide ao="0.0011879" name="Zr96" />
</material>
<material id="3" name="Hot borated water">
<density units="g/cm3" value="0.740582" />
<nuclide ao="0.049457" name="H1" />
<nuclide ao="0.024672" name="O16" />
<nuclide ao="8.0042e-06" name="B10" />
<nuclide ao="3.2218e-05" name="B11" />
<sab name="c_H_in_H2O" />
</material>
</materials>
<?xml version='1.0' encoding='utf-8'?>
<settings>
<run_mode>eigenvalue</run_mode>
<particles>100</particles>
<batches>10</batches>
<inactive>1</inactive>
<source strength="1.0">
<space type="fission">
<parameters>-0.63 -0.63 -1 0.63 0.63 1</parameters>
</space>
</source>
</settings>
<?xml version='1.0' encoding='utf-8'?>
<tallies>
<filter id="2" type="cell">
<bins>1 2 3</bins>
</filter>
<tally id="2">
<filters>2</filters>
<scores>flux</scores>
</tally>
</tallies>

View file

@ -0,0 +1,50 @@
<?xml version='1.0' encoding='utf-8'?>
<geometry>
<cell id="1" material="1" name="Fuel" region="-1" universe="0" />
<cell id="2" material="2" name="Cladding" region="1 -2" universe="0" />
<cell id="3" material="3" name="Water" region="2 3 -4 5 -6" universe="0" />
<surface coeffs="0 0 0.39218" id="1" name="Fuel OR" type="z-cylinder" />
<surface coeffs="0 0 0.4572" id="2" name="Clad OR" type="z-cylinder" />
<surface boundary="reflective" coeffs="-0.63" id="3" name="left" type="x-plane" />
<surface boundary="reflective" coeffs="0.63" id="4" name="right" type="x-plane" />
<surface boundary="reflective" coeffs="-0.63" id="5" name="bottom" type="y-plane" />
<surface boundary="reflective" coeffs="0.63" id="6" name="top" type="y-plane" />
</geometry>
<?xml version='1.0' encoding='utf-8'?>
<materials>
<material depletable="true" id="1" name="UO2 (2.4%)">
<density units="g/cm3" value="10.29769" />
<nuclide ao="4.4843e-06" name="U234" />
<nuclide ao="0.00055815" name="U235" />
<nuclide ao="0.022408" name="U238" />
<nuclide ao="0.045829" name="O16" />
</material>
<material id="2" name="Zircaloy">
<density units="g/cm3" value="6.55" />
<nuclide ao="0.021827" name="Zr90" />
<nuclide ao="0.00476" name="Zr91" />
<nuclide ao="0.0072758" name="Zr92" />
<nuclide ao="0.0073734" name="Zr94" />
<nuclide ao="0.0011879" name="Zr96" />
</material>
<material id="3" name="Hot borated water">
<density units="g/cm3" value="0.740582" />
<nuclide ao="0.049457" name="H1" />
<nuclide ao="0.024672" name="O16" />
<nuclide ao="8.0042e-06" name="B10" />
<nuclide ao="3.2218e-05" name="B11" />
<sab name="c_H_in_H2O" />
</material>
</materials>
<?xml version='1.0' encoding='utf-8'?>
<settings>
<run_mode>eigenvalue</run_mode>
<particles>100</particles>
<batches>10</batches>
<inactive>1</inactive>
<source strength="1.0">
<space type="fission">
<parameters>-0.63 -0.63 -1 0.63 0.63 1</parameters>
</space>
</source>
</settings>

View file

@ -0,0 +1,60 @@
<?xml version='1.0' encoding='utf-8'?>
<geometry>
<cell id="4" material="4" name="Fuel" region="-7" universe="0" />
<cell id="5" material="5" name="Cladding" region="7 -8" universe="0" />
<cell id="6" material="6" name="Water" region="8 9 -10 11 -12" universe="0" />
<surface coeffs="0 0 0.39218" id="7" name="Fuel OR" type="z-cylinder" />
<surface coeffs="0 0 0.4572" id="8" name="Clad OR" type="z-cylinder" />
<surface boundary="reflective" coeffs="-0.63" id="9" name="left" type="x-plane" />
<surface boundary="reflective" coeffs="0.63" id="10" name="right" type="x-plane" />
<surface boundary="reflective" coeffs="-0.63" id="11" name="bottom" type="y-plane" />
<surface boundary="reflective" coeffs="0.63" id="12" name="top" type="y-plane" />
</geometry>
<?xml version='1.0' encoding='utf-8'?>
<materials>
<material depletable="true" id="4" name="UO2 (2.4%)">
<density units="g/cm3" value="10.29769" />
<nuclide ao="4.4843e-06" name="U234" />
<nuclide ao="0.00055815" name="U235" />
<nuclide ao="0.022408" name="U238" />
<nuclide ao="0.045829" name="O16" />
</material>
<material id="5" name="Zircaloy">
<density units="g/cm3" value="6.55" />
<nuclide ao="0.021827" name="Zr90" />
<nuclide ao="0.00476" name="Zr91" />
<nuclide ao="0.0072758" name="Zr92" />
<nuclide ao="0.0073734" name="Zr94" />
<nuclide ao="0.0011879" name="Zr96" />
</material>
<material id="6" name="Hot borated water">
<density units="g/cm3" value="0.740582" />
<nuclide ao="0.049457" name="H1" />
<nuclide ao="0.024672" name="O16" />
<nuclide ao="8.0042e-06" name="B10" />
<nuclide ao="3.2218e-05" name="B11" />
<sab name="c_H_in_H2O" />
</material>
</materials>
<?xml version='1.0' encoding='utf-8'?>
<settings>
<run_mode>eigenvalue</run_mode>
<particles>100</particles>
<batches>10</batches>
<inactive>1</inactive>
<source strength="1.0">
<space type="fission">
<parameters>-0.63 -0.63 -1 0.63 0.63 1</parameters>
</space>
</source>
</settings>
<?xml version='1.0' encoding='utf-8'?>
<tallies>
<filter id="2" type="cell">
<bins>4 5 6</bins>
</filter>
<tally id="2">
<filters>2</filters>
<scores>flux</scores>
</tally>
</tallies>

View file

@ -0,0 +1,9 @@
k-combined:
1.141180E+00 4.513757E-02
tally 1:
1.220313E+02
1.659250E+03
4.421703E+01
2.178300E+02
2.356492E+02
6.182509E+03

View file

@ -0,0 +1,75 @@
from pathlib import Path
import os
import shutil
import subprocess
import textwrap
import openmc
import pytest
from tests.testing_harness import PyAPITestHarness
@pytest.fixture
def driver(request):
"""Compile the external source"""
# Get build directory and write CMakeLists.txt file
openmc_dir = Path(str(request.config.rootdir)) / 'build'
with open('CMakeLists.txt', 'w') as f:
f.write(textwrap.dedent("""
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(openmc_cpp_driver CXX)
add_executable(cpp_driver driver.cpp)
find_package(OpenMC REQUIRED HINTS {})
target_link_libraries(cpp_driver OpenMC::libopenmc)
""".format(openmc_dir)))
# Create temporary build directory and change to there
local_builddir = Path('build')
local_builddir.mkdir(exist_ok=True)
os.chdir(str(local_builddir))
# Run cmake/make to build the shared libary
subprocess.run(['cmake', os.path.pardir], check=True)
subprocess.run(['make'], check=True)
os.chdir(os.path.pardir)
yield "./build/cpp_driver"
# Remove local build directory when test is complete
shutil.rmtree('build')
@pytest.fixture
def model():
model = openmc.examples.pwr_pin_cell()
model.settings.particles = 100
model.settings.batches = 10
model.settings.inactive = 1
return model
class ExternalDriverTestHarness(PyAPITestHarness):
def __init__(self, executable, statepoint_name, model=None, inputs_true=None):
super().__init__(statepoint_name, model, inputs_true)
self.executable = executable
def _run_openmc(self):
print("Running openmc")
openmc.run(openmc_exec=self.executable)
def test_cpp_driver(driver, model):
harness = ExternalDriverTestHarness(driver, 'statepoint.10.h5', model, 'inputs_true1.dat')
harness.main()
def test_openmc_run(driver, model):
# modify model and test again using the openmc exe
cell_filter = openmc.CellFilter(list(model.geometry.get_all_cells().values()))
tally = openmc.Tally()
tally.filters = [cell_filter]
tally.scores = ['flux']
model.tallies = [tally]
harness = PyAPITestHarness('statepoint.10.h5', model, 'inputs_true2.dat')
harness.main()