mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 05:35:49 -04:00
Add regression test for new DAGUniverse constructor
This commit is contained in:
parent
5dd6da91c5
commit
86e44c4e4a
6 changed files with 252 additions and 0 deletions
0
tests/regression_tests/dagmc/external/__init__.py
vendored
Normal file
0
tests/regression_tests/dagmc/external/__init__.py
vendored
Normal file
1
tests/regression_tests/dagmc/external/dagmc.h5m
vendored
Symbolic link
1
tests/regression_tests/dagmc/external/dagmc.h5m
vendored
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../legacy/dagmc.h5m
|
||||
39
tests/regression_tests/dagmc/external/inputs_true.dat
vendored
Normal file
39
tests/regression_tests/dagmc/external/inputs_true.dat
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<geometry>
|
||||
<dagmc_universe filename="dagmc.h5m" id="1" />
|
||||
</geometry>
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<materials>
|
||||
<material depletable="true" id="40" name="no-void fuel">
|
||||
<density units="g/cc" value="11" />
|
||||
<nuclide ao="1.0" name="U235" />
|
||||
</material>
|
||||
<material id="41" name="water">
|
||||
<density units="g/cc" value="1.0" />
|
||||
<nuclide ao="2.0" name="H1" />
|
||||
<nuclide ao="1.0" name="O16" />
|
||||
<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>5</batches>
|
||||
<inactive>0</inactive>
|
||||
<source strength="1.0">
|
||||
<space type="box">
|
||||
<parameters>-4 -4 -4 4 4 4</parameters>
|
||||
</space>
|
||||
</source>
|
||||
</settings>
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<tallies>
|
||||
<filter id="1" type="cell">
|
||||
<bins>1</bins>
|
||||
</filter>
|
||||
<tally id="1">
|
||||
<filters>1</filters>
|
||||
<scores>total</scores>
|
||||
</tally>
|
||||
</tallies>
|
||||
80
tests/regression_tests/dagmc/external/main.cpp
vendored
Normal file
80
tests/regression_tests/dagmc/external/main.cpp
vendored
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#include "openmc/capi.h"
|
||||
#include "openmc/cross_sections.h"
|
||||
#include "openmc/dagmc.h"
|
||||
#include "openmc/error.h"
|
||||
#include "openmc/geometry.h"
|
||||
#include "openmc/geometry_aux.h"
|
||||
#include "openmc/nuclide.h"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
using namespace openmc;
|
||||
int openmc_err;
|
||||
|
||||
// Initialise OpenMC
|
||||
openmc_err = openmc_init(argc, argv, nullptr);
|
||||
if (openmc_err == -1) {
|
||||
// This happens for the -h and -v flags
|
||||
return EXIT_SUCCESS;
|
||||
} else if (openmc_err) {
|
||||
fatal_error(openmc_err_msg);
|
||||
}
|
||||
|
||||
// Create DAGMC ptr
|
||||
std::string filename = "dagmc.h5m";
|
||||
std::shared_ptr<moab::DagMC> dag_ptr = std::make_shared<moab::DagMC>();
|
||||
moab::ErrorCode rval = dag_ptr->load_file(filename.c_str());
|
||||
if (rval != moab::MB_SUCCESS) {
|
||||
fatal_error("Failed to load file");
|
||||
}
|
||||
|
||||
// Initialize acceleration data structures
|
||||
rval = dag_ptr->init_OBBTree();
|
||||
if (rval != moab::MB_SUCCESS) {
|
||||
fatal_error("Failed to initialise OBB tree");
|
||||
}
|
||||
|
||||
// Get rid of existing geometry
|
||||
std::unordered_map<std::string, int> nuclide_map_copy =
|
||||
openmc::data::nuclide_map;
|
||||
openmc::data::nuclides.clear();
|
||||
openmc::data::nuclide_map = nuclide_map_copy;
|
||||
openmc::model::surfaces.clear();
|
||||
openmc::model::surface_map.clear();
|
||||
openmc::model::cells.clear();
|
||||
openmc::model::cell_map.clear();
|
||||
openmc::model::universes.clear();
|
||||
openmc::model::universe_map.clear();
|
||||
|
||||
// Create new DAGMC universe
|
||||
openmc::model::universes.push_back(
|
||||
std::make_unique<openmc::DAGUniverse>(dag_ptr, ""));
|
||||
model::universe_map[model::universes.back()->id_] =
|
||||
model::universes.size() - 1;
|
||||
|
||||
// Add cells to universes
|
||||
openmc::populate_universes();
|
||||
|
||||
// Set root universe
|
||||
openmc::model::root_universe = openmc::find_root_universe();
|
||||
openmc::check_dagmc_root_univ();
|
||||
|
||||
// Final geometry setup and assign temperatures
|
||||
openmc::finalize_geometry();
|
||||
|
||||
// Finalize cross sections having assigned temperatures
|
||||
openmc::finalize_cross_sections();
|
||||
|
||||
// Run OpenMC
|
||||
openmc_err = openmc_run();
|
||||
if (openmc_err)
|
||||
fatal_error(openmc_err_msg);
|
||||
|
||||
// Deallocate memory
|
||||
openmc_err = openmc_finalize();
|
||||
if (openmc_err)
|
||||
fatal_error(openmc_err_msg);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
5
tests/regression_tests/dagmc/external/results_true.dat
vendored
Normal file
5
tests/regression_tests/dagmc/external/results_true.dat
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
k-combined:
|
||||
8.426936E-01 5.715847E-02
|
||||
tally 1:
|
||||
8.093843E+00
|
||||
1.328829E+01
|
||||
127
tests/regression_tests/dagmc/external/test.py
vendored
Normal file
127
tests/regression_tests/dagmc/external/test.py
vendored
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
from pathlib import Path
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
from subprocess import CalledProcessError
|
||||
import textwrap
|
||||
import glob
|
||||
from itertools import product
|
||||
|
||||
import openmc
|
||||
import openmc.lib
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from tests.regression_tests import config
|
||||
from tests.testing_harness import PyAPITestHarness
|
||||
|
||||
pytestmark = pytest.mark.skipif(
|
||||
not openmc.lib._dagmc_enabled(),
|
||||
reason="DAGMC is not enabled.")
|
||||
|
||||
TETS_PER_VOXEL = 12
|
||||
|
||||
# Test that an external DAGMC instance can be passed in through the C API
|
||||
|
||||
@pytest.fixture
|
||||
def cpp_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(main main.cpp)
|
||||
find_package(OpenMC REQUIRED HINTS {})
|
||||
target_link_libraries(main OpenMC::libopenmc)
|
||||
set_target_properties(main PROPERTIES CXX_STANDARD
|
||||
14 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO)
|
||||
set(CMAKE_CXX_FLAGS "-pedantic-errors")
|
||||
add_compile_definitions(DAGMC=1)
|
||||
""".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))
|
||||
|
||||
if config['mpi']:
|
||||
os.environ['CXX'] = 'mpicxx'
|
||||
|
||||
try:
|
||||
print("Building driver")
|
||||
# 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/main"
|
||||
|
||||
finally:
|
||||
# Remove local build directory when test is complete
|
||||
shutil.rmtree('build')
|
||||
os.remove('CMakeLists.txt')
|
||||
|
||||
@pytest.fixture
|
||||
def model():
|
||||
model = openmc.model.Model()
|
||||
|
||||
# Settings
|
||||
model.settings.batches = 5
|
||||
model.settings.inactive = 0
|
||||
model.settings.particles = 100
|
||||
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
|
||||
|
||||
# Geometry
|
||||
dag_univ = openmc.DAGMCUniverse("dagmc.h5m")
|
||||
model.geometry = openmc.Geometry(dag_univ)
|
||||
|
||||
# Tallies
|
||||
tally = openmc.Tally()
|
||||
tally.scores = ['total']
|
||||
tally.filters = [openmc.CellFilter(1)]
|
||||
model.tallies = [tally]
|
||||
|
||||
# Materials
|
||||
u235 = openmc.Material(name="no-void fuel")
|
||||
u235.add_nuclide('U235', 1.0, 'ao')
|
||||
u235.set_density('g/cc', 11)
|
||||
u235.id = 40
|
||||
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
|
||||
|
||||
return model
|
||||
|
||||
class ExternalDAGMCTest(PyAPITestHarness):
|
||||
def __init__(self, executable, statepoint_name, model):
|
||||
super().__init__(statepoint_name, model)
|
||||
self.executable = executable
|
||||
|
||||
def _run_openmc(self):
|
||||
if config['update']:
|
||||
# Generate the results file with internal python API
|
||||
openmc.run(openmc_exec=config['exe'], event_based=config['event'])
|
||||
elif config['mpi']:
|
||||
mpi_args = [config['mpiexec'], '-n', config['mpi_np']]
|
||||
openmc.run(openmc_exec=self.executable,
|
||||
mpi_args=mpi_args,
|
||||
event_based=config['event'])
|
||||
else:
|
||||
openmc.run(openmc_exec=self.executable,
|
||||
event_based=config['event'])
|
||||
|
||||
def test_external_dagmc(cpp_driver, model):
|
||||
harness = ExternalDAGMCTest(cpp_driver,'statepoint.5.h5',model)
|
||||
harness.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue