mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 13:45:36 -04:00
Separating dagmc cell temperature checks into unit tests.
This commit is contained in:
parent
89c75a7b82
commit
347f4d7dd5
7 changed files with 106 additions and 39 deletions
|
|
@ -35,10 +35,9 @@ const bool dagmc_enabled = false;
|
|||
|
||||
#ifdef DAGMC
|
||||
|
||||
const std::string DAGMC_FILENAME = "dagmc.h5m";
|
||||
|
||||
namespace openmc {
|
||||
|
||||
const std::string DAGMC_FILENAME = settings::path_input + "dagmc.h5m";
|
||||
|
||||
namespace simulation {
|
||||
|
||||
|
|
@ -54,8 +53,16 @@ moab::DagMC* DAG;
|
|||
} // namespace model
|
||||
|
||||
|
||||
void check_dagmc_file() {
|
||||
if (!file_exists(DAGMC_FILENAME)) {
|
||||
fatal_error("Geometry DAGMC file '" + DAGMC_FILENAME + "' does not exist!");
|
||||
}
|
||||
}
|
||||
|
||||
bool get_uwuw_materials_xml(std::string& s) {
|
||||
UWUW uwuw(DAGMC_FILENAME.c_str());
|
||||
check_dagmc_file();
|
||||
|
||||
UWUW uwuw((settings::path_input + DAGMC_FILENAME).c_str());
|
||||
|
||||
std::stringstream ss;
|
||||
bool uwuw_mats_present = false;
|
||||
|
|
@ -376,11 +383,7 @@ void load_dagmc_geometry()
|
|||
void read_geometry_dagmc()
|
||||
{
|
||||
// Check if dagmc.h5m exists
|
||||
std::string filename = settings::path_input + "dagmc.h5m";
|
||||
if (!file_exists(filename)) {
|
||||
fatal_error("Geometry DAGMC file '" + filename + "' does not exist!");
|
||||
}
|
||||
|
||||
check_dagmc_file();
|
||||
write_message("Reading DAGMC geometry...", 5);
|
||||
load_dagmc_geometry();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<materials>
|
||||
<material depletable="true" id="40" name="fuel" temperature="320">
|
||||
<material depletable="true" id="40" name="fuel">
|
||||
<density units="g/cc" value="11" />
|
||||
<nuclide ao="1.0" name="U235" />
|
||||
</material>
|
||||
|
|
@ -22,7 +22,6 @@
|
|||
<parameters>-4 -4 -4 4 4 4</parameters>
|
||||
</space>
|
||||
</source>
|
||||
<temperature_tolerance>50.0</temperature_tolerance>
|
||||
<dagmc>true</dagmc>
|
||||
</settings>
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
|
|
|
|||
|
|
@ -1,28 +1,25 @@
|
|||
import openmc
|
||||
import openmc.capi
|
||||
from openmc.stats import Box
|
||||
|
||||
import pytest
|
||||
from tests.testing_harness import PyAPITestHarness
|
||||
|
||||
import numpy as np
|
||||
|
||||
pytestmark = pytest.mark.skipif(
|
||||
not openmc.capi._dagmc_enabled(),
|
||||
reason="DAGMC CAD geometry is not enabled.")
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def dagmc_model():
|
||||
def test_dagmc():
|
||||
model = openmc.model.Model()
|
||||
|
||||
# settings
|
||||
model.settings.batches = 5
|
||||
model.settings.inactive = 0
|
||||
model.settings.particles = 100
|
||||
model.settings.temperature = {'tolerance': 50.0}
|
||||
|
||||
source = openmc.Source(space=Box([-4, -4, -4],
|
||||
[ 4, 4, 4]))
|
||||
source_box = openmc.stats.Box([-4, -4, -4],
|
||||
[ 4, 4, 4])
|
||||
source = openmc.Source(space=source_box)
|
||||
|
||||
model.settings.source = source
|
||||
|
||||
model.settings.dagmc = True
|
||||
|
|
@ -38,7 +35,6 @@ def dagmc_model():
|
|||
u235.add_nuclide('U235', 1.0, 'ao')
|
||||
u235.set_density('g/cc', 11)
|
||||
u235.id = 40
|
||||
u235.temperature = 320
|
||||
|
||||
water = openmc.Material(name="water")
|
||||
water.add_nuclide('H1', 2.0, 'ao')
|
||||
|
|
@ -50,24 +46,5 @@ def dagmc_model():
|
|||
mats = openmc.Materials([u235, water])
|
||||
model.materials = mats
|
||||
|
||||
yield model
|
||||
|
||||
def test_dagmc_temps(dagmc_model):
|
||||
dagmc_model.export_to_xml()
|
||||
|
||||
# check cell temps as well here
|
||||
openmc.capi.init([])
|
||||
|
||||
expected_temps = { 1 : 320.0, # assigned by material
|
||||
2 : 300.0, # assigned in dagmc file
|
||||
3 : 293.6 } # assigned by default
|
||||
|
||||
for cell_id, temp in expected_temps.items():
|
||||
capi_cell = openmc.capi.cells[cell_id]
|
||||
assert np.isclose(capi_cell.get_temperature(), temp)
|
||||
|
||||
openmc.capi.finalize()
|
||||
|
||||
def test_dagmc(dagmc_model):
|
||||
harness = PyAPITestHarness('statepoint.5.h5', model=dagmc_model)
|
||||
harness = PyAPITestHarness('statepoint.5.h5', model=model)
|
||||
harness.main()
|
||||
|
|
|
|||
0
tests/unit_tests/dagmc/__init__.py
Normal file
0
tests/unit_tests/dagmc/__init__.py
Normal file
12
tests/unit_tests/dagmc/conftest.py
Normal file
12
tests/unit_tests/dagmc/conftest.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
import pytest
|
||||
|
||||
@pytest.fixture(scope='module', autouse=True)
|
||||
def setup_dagmc_unit_test(request):
|
||||
|
||||
# Change to test directory
|
||||
olddir = request.fspath.dirpath().chdir()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
olddir.chdir()
|
||||
1
tests/unit_tests/dagmc/dagmc.h5m
Symbolic link
1
tests/unit_tests/dagmc/dagmc.h5m
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../regression_tests/dagmc/legacy/dagmc.h5m
|
||||
75
tests/unit_tests/dagmc/test.py
Normal file
75
tests/unit_tests/dagmc/test.py
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import glob
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import openmc
|
||||
import openmc.capi
|
||||
|
||||
from tests import cdtemp
|
||||
|
||||
pytestmark = pytest.mark.skipif(
|
||||
not openmc.capi._dagmc_enabled(),
|
||||
reason="DAGMC CAD geometry is not enabled.")
|
||||
|
||||
def test_dagmc_temperatures():
|
||||
model = openmc.model.Model()
|
||||
|
||||
# settings
|
||||
model.settings.batches = 5
|
||||
model.settings.inactive = 0
|
||||
model.settings.particles = 100
|
||||
model.settings.temperature = {'tolerance': 50.0}
|
||||
model.settings.verbosity = 1
|
||||
source_box = openmc.stats.Box([-4, -4, -4],
|
||||
[ 4, 4, 4])
|
||||
source = openmc.Source(space=source_box)
|
||||
model.settings.source = source
|
||||
|
||||
model.settings.dagmc = True
|
||||
|
||||
# tally
|
||||
tally = openmc.Tally()
|
||||
tally.scores = ['total']
|
||||
tally.filters = [openmc.CellFilter(1)]
|
||||
model.tallies = [tally]
|
||||
|
||||
# materials
|
||||
u235 = openmc.Material(name="fuel")
|
||||
u235.add_nuclide('U235', 1.0, 'ao')
|
||||
u235.set_density('g/cc', 11)
|
||||
u235.id = 40
|
||||
u235.temperature = 320
|
||||
|
||||
water = openmc.Material(name="water")
|
||||
water.add_nuclide('H1', 2.0, 'ao')
|
||||
water.add_nuclide('O16', 1.0, 'ao')
|
||||
water.set_density('g/cc', 1.0)
|
||||
water.add_s_alpha_beta('c_H_in_H2O')
|
||||
water.id = 41
|
||||
|
||||
mats = openmc.Materials([u235, water])
|
||||
model.materials = mats
|
||||
|
||||
model.export_to_xml()
|
||||
|
||||
# check cell temps as well here
|
||||
openmc.capi.init()
|
||||
|
||||
expected_temps = { 1 : 320.0, # assigned by material
|
||||
2 : 300.0, # assigned in dagmc file
|
||||
3 : 293.6 } # assigned by default
|
||||
|
||||
for cell_id, temp in expected_temps.items():
|
||||
capi_cell = openmc.capi.cells[cell_id]
|
||||
assert np.isclose(capi_cell.get_temperature(), temp)
|
||||
|
||||
openmc.capi.finalize()
|
||||
|
||||
# cleanup
|
||||
input_files = glob.glob("*.xml")
|
||||
input_files += glob.glob("*.h5")
|
||||
for f in input_files:
|
||||
if os.path.exists(f):
|
||||
os.remove(f)
|
||||
Loading…
Add table
Add a link
Reference in a new issue