mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Fix locating h5m files references in DAGMC universes (#2842)
This commit is contained in:
parent
5549b58e1f
commit
d7d2230e5f
6 changed files with 70 additions and 15 deletions
|
|
@ -16,6 +16,11 @@ bool dir_exists(const std::string& path);
|
|||
//! \return Whether file exists
|
||||
bool file_exists(const std::string& filename);
|
||||
|
||||
//! Determine directory containing given file
|
||||
//! \param[in] filename Path to file
|
||||
//! \return Name of directory containing file
|
||||
std::string dir_name(const std::string& filename);
|
||||
|
||||
// Gets the file extension of whatever string is passed in. This is defined as
|
||||
// a sequence of strictly alphanumeric characters which follow the last period,
|
||||
// i.e. at least one alphabet character is present, and zero or more numbers.
|
||||
|
|
|
|||
|
|
@ -49,8 +49,8 @@ DAGUniverse::DAGUniverse(pugi::xml_node node)
|
|||
|
||||
if (check_for_node(node, "filename")) {
|
||||
filename_ = get_node_value(node, "filename");
|
||||
if (!file_exists(filename_)) {
|
||||
fatal_error(fmt::format("DAGMC file '{}' could not be found", filename_));
|
||||
if (!starts_with(filename_, "/")) {
|
||||
filename_ = dir_name(settings::path_input) + filename_;
|
||||
}
|
||||
} else {
|
||||
fatal_error("Must specify a file for the DAGMC universe");
|
||||
|
|
@ -123,7 +123,6 @@ void DAGUniverse::init_dagmc()
|
|||
dagmc_instance_ = std::make_shared<moab::DagMC>();
|
||||
|
||||
// load the DAGMC geometry
|
||||
filename_ = settings::path_input + filename_;
|
||||
if (!file_exists(filename_)) {
|
||||
fatal_error("Geometry DAGMC file '" + filename_ + "' does not exist!");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,12 @@ bool file_exists(const std::string& filename)
|
|||
return s.good();
|
||||
}
|
||||
|
||||
std::string dir_name(const std::string& filename)
|
||||
{
|
||||
size_t pos = filename.find_last_of("\\/");
|
||||
return (std::string::npos == pos) ? "" : filename.substr(0, pos + 1);
|
||||
}
|
||||
|
||||
std::string get_file_extension(const std::string& filename)
|
||||
{
|
||||
// try our best to work on windows...
|
||||
|
|
|
|||
|
|
@ -88,17 +88,27 @@ int openmc_finalize()
|
|||
settings::legendre_to_tabular = true;
|
||||
settings::legendre_to_tabular_points = -1;
|
||||
settings::material_cell_offsets = true;
|
||||
settings::max_lost_particles = 10;
|
||||
settings::max_order = 0;
|
||||
settings::max_particles_in_flight = 100000;
|
||||
settings::max_splits = 1000;
|
||||
settings::max_tracks = 1000;
|
||||
settings::max_write_lost_particles = -1;
|
||||
settings::n_log_bins = 8000;
|
||||
settings::n_inactive = 0;
|
||||
settings::n_particles = -1;
|
||||
settings::output_summary = true;
|
||||
settings::output_tallies = true;
|
||||
settings::particle_restart_run = false;
|
||||
settings::path_cross_sections.clear();
|
||||
settings::path_input.clear();
|
||||
settings::path_output.clear();
|
||||
settings::path_particle_restart.clear();
|
||||
settings::path_sourcepoint.clear();
|
||||
settings::path_statepoint.clear();
|
||||
settings::photon_transport = false;
|
||||
settings::reduce_tallies = true;
|
||||
settings::rel_max_lost_particles = 1.0e-6;
|
||||
settings::res_scat_on = false;
|
||||
settings::res_scat_method = ResScatMethod::rvs;
|
||||
settings::res_scat_energy_min = 0.01;
|
||||
|
|
@ -123,6 +133,7 @@ int openmc_finalize()
|
|||
settings::verbosity = 7;
|
||||
settings::weight_cutoff = 0.25;
|
||||
settings::weight_survive = 1.0;
|
||||
settings::weight_windows_file.clear();
|
||||
settings::weight_windows_on = false;
|
||||
settings::write_all_tracks = false;
|
||||
settings::write_initial_source = false;
|
||||
|
|
|
|||
|
|
@ -304,8 +304,9 @@ int parse_command_line(int argc, char* argv[])
|
|||
settings::path_input));
|
||||
}
|
||||
|
||||
// Add slash at end of directory if it isn't the
|
||||
if (!ends_with(settings::path_input, "/")) {
|
||||
// Add slash at end of directory if it isn't there
|
||||
if (!ends_with(settings::path_input, "/") &&
|
||||
dir_exists(settings::path_input)) {
|
||||
settings::path_input += "/";
|
||||
}
|
||||
}
|
||||
|
|
@ -315,18 +316,11 @@ int parse_command_line(int argc, char* argv[])
|
|||
|
||||
bool read_model_xml()
|
||||
{
|
||||
std::string model_filename =
|
||||
settings::path_input.empty() ? "." : settings::path_input;
|
||||
|
||||
// some string cleanup
|
||||
// a trailing "/" is applied to path_input if it's specified,
|
||||
// remove it for the first attempt at reading the input file
|
||||
if (ends_with(model_filename, "/"))
|
||||
model_filename.pop_back();
|
||||
std::string model_filename = settings::path_input;
|
||||
|
||||
// if the current filename is a directory, append the default model filename
|
||||
if (dir_exists(model_filename))
|
||||
model_filename += "/model.xml";
|
||||
if (model_filename.empty() || dir_exists(model_filename))
|
||||
model_filename += "model.xml";
|
||||
|
||||
// if this file doesn't exist, stop here
|
||||
if (!file_exists(model_filename))
|
||||
|
|
|
|||
40
tests/unit_tests/dagmc/test_h5m_subdir.py
Normal file
40
tests/unit_tests/dagmc/test_h5m_subdir.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
import openmc
|
||||
import openmc.lib
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.skipif(
|
||||
not openmc.lib._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled."
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("absolute", [True, False])
|
||||
def test_model_h5m_in_subdirectory(run_in_tmpdir, request, absolute):
|
||||
# Create new subdirectory and copy h5m file there
|
||||
h5m = Path(request.fspath).parent / "dagmc.h5m"
|
||||
subdir = Path("h5m")
|
||||
subdir.mkdir()
|
||||
shutil.copy(h5m, subdir)
|
||||
|
||||
# Create simple model with h5m file in subdirectory
|
||||
if absolute:
|
||||
dag_univ = openmc.DAGMCUniverse((subdir / "dagmc.h5m").absolute())
|
||||
else:
|
||||
dag_univ = openmc.DAGMCUniverse(subdir / "dagmc.h5m")
|
||||
model = openmc.Model()
|
||||
model.geometry = openmc.Geometry(dag_univ.bounded_universe())
|
||||
mat1 = openmc.Material(name="41")
|
||||
mat1.add_nuclide("H1", 1.0)
|
||||
mat2 = openmc.Material(name="no-void fuel")
|
||||
mat2.add_nuclide("U235", 1.0)
|
||||
model.materials = [mat1, mat2]
|
||||
model.settings.batches = 10
|
||||
model.settings.inactive = 5
|
||||
model.settings.particles = 1000
|
||||
|
||||
# Make sure model can load
|
||||
model.export_to_model_xml()
|
||||
openmc.lib.init(["model.xml"])
|
||||
openmc.lib.finalize()
|
||||
Loading…
Add table
Add a link
Reference in a new issue