diff --git a/src/dagmc.cpp b/src/dagmc.cpp index e6ccee24d5..bc33628925 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -2,6 +2,7 @@ #include "openmc/cell.h" #include "openmc/error.h" +#include "openmc/file_utils.h" #include "openmc/string_utils.h" #include "openmc/settings.h" #include "openmc/geometry.h" @@ -9,9 +10,15 @@ #include #include #include +#include #ifdef DAGMC +#include "uwuw.hpp" +#include "dagmcmetadata.hpp" + +#define DAGMC_FILENAME "dagmc.h5m" + namespace openmc { namespace model { @@ -20,28 +27,65 @@ moab::DagMC* DAG; } // namespace model +bool write_materials_xml(UWUW uwuw) { + // if there is a material library in the file, + // write a material.xml file + std::ofstream mats_xml("materials.xml"); + // write header + mats_xml << "\n"; + mats_xml << "\n"; + std::map ml = uwuw.material_library; + std::map::iterator it; + // write materials + for (it = ml.begin(); it != ml.end(); it++) { mats_xml << it->second.openmc("atom"); } + // write footer + mats_xml << ""; + mats_xml.close(); +} + void load_dagmc_geometry() { if (!model::DAG) { model::DAG = new moab::DagMC(); } - int32_t dagmc_univ_id = 0; // universe is always 0 for DAGMC + // create uwuw instance + UWUW uwuw(DAGMC_FILENAME); - moab::ErrorCode rval = model::DAG->load_file("dagmc.h5m"); + // check for uwuw material definitions + bool using_uwuw = (uwuw.material_library.size() == 0) ? false : true; + + if (using_uwuw) { + std::cout << "Found UWUW Materials in the DAGMC geometry file." << std::endl; + // don't overwrite an existing materials.xml file + if (file_exists("materials.xml")) { + std::stringstream err_msg; + err_msg << "A materials.xml file is present along with UWUW material definitions"; + fatal_error(err_msg.str()); + } + write_materials_xml(uwuw); + } + + int32_t dagmc_univ_id = 0; // universe is always 0 for DAGMC runs + + moab::ErrorCode rval = model::DAG->load_file(DAGMC_FILENAME); MB_CHK_ERR_CONT(rval); rval = model::DAG->init_OBBTree(); MB_CHK_ERR_CONT(rval); - std::vector prop_keywords; - prop_keywords.push_back("mat"); - prop_keywords.push_back("boundary"); - - std::map ph; - model::DAG->parse_properties(prop_keywords, ph, ":"); - MB_CHK_ERR_CONT(rval); - + dagmcMetaData DMD(model::DAG); + if (using_uwuw) { + DMD.load_property_data(); + } + + std::vector keywords; + keywords.push_back("mat"); + keywords.push_back("density"); + keywords.push_back("boundary"); + std::map dum; + rval = model::DAG->parse_properties(keywords, dum, ":/"); + // initialize cell objects model::n_cells = model::DAG->num_entities(3); @@ -75,22 +119,38 @@ void load_dagmc_geometry() continue; } - if (model::DAG->has_prop(vol_handle, "mat")){ - std::string mat_value; + std::string mat_value; + if (model::DAG->has_prop(vol_handle, "mat")) { rval = model::DAG->prop_value(vol_handle, "mat", mat_value); MB_CHK_ERR_CONT(rval); - to_lower(mat_value); - - if (mat_value == "void" || mat_value == "vacuum") { - c->material_.push_back(MATERIAL_VOID); - } else { - c->material_.push_back(std::stoi(mat_value)); - } } else { std::stringstream err_msg; err_msg << "Volume " << c->id_ << " has no material assignment."; fatal_error(err_msg.str()); } + + std::string cmp_str = mat_value; + to_lower(cmp_str); + if (cmp_str.find("void") != std::string::npos || + cmp_str.find("vacuum") != std::string::npos || + cmp_str.find("graveyard") != std::string::npos) { + c->material_.push_back(MATERIAL_VOID); + } else { + if (using_uwuw) { + std::string uwuw_mat = DMD.volume_material_property_data_eh[vol_handle]; + if (uwuw.material_library.count(uwuw_mat) != 0) { + int matnumber = uwuw.material_library[uwuw_mat].metadata["mat_number"].asInt(); + c->material_.push_back(matnumber); + } else { + std::stringstream err_msg; + err_msg << "Material with value " << mat_value << " not found "; + err_msg << "in the material library"; + fatal_error(err_msg.str()); + } + } else { + c->material_.push_back(std::stoi(mat_value)); + } + } } // Allocate the cell overlap count if necessary. @@ -110,12 +170,12 @@ void load_dagmc_geometry() s->id_ = model::DAG->id_by_index(2, i+1); s->dagmc_ptr_ = model::DAG; + std::string bc_value; if (model::DAG->has_prop(surf_handle, "boundary")) { - std::string bc_value; rval = model::DAG->prop_value(surf_handle, "boundary", bc_value); MB_CHK_ERR_CONT(rval); - to_lower(bc_value); - + to_lower(bc_value); + if (bc_value == "transmit" || bc_value == "transmission") { s->bc_ = BC_TRANSMIT; } else if (bc_value == "vacuum") { @@ -130,7 +190,7 @@ void load_dagmc_geometry() << "\" specified on surface " << s->id_; fatal_error(err_msg); } - } else { // if no BC property is found, set to transmit + } else { // if no condition is found, set to transmit s->bc_ = BC_TRANSMIT; } diff --git a/src/input_xml.F90 b/src/input_xml.F90 index 0883776247..c497c79b9a 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -124,9 +124,9 @@ contains type(VectorReal), allocatable :: sab_temps(:) ! List of T to read for each S(a,b) call read_settings_xml() + call read_geometry_xml() call read_cross_sections_xml() call read_materials_xml() - call read_geometry_xml() ! Convert user IDs -> indices, assign temperatures call finalize_geometry(nuc_temps, sab_temps) diff --git a/tests/regression_tests/dagmc/dagmc.h5m b/tests/regression_tests/dagmc/dagmc.h5m index 5f84286de2..7fb43ad4d9 100644 Binary files a/tests/regression_tests/dagmc/dagmc.h5m and b/tests/regression_tests/dagmc/dagmc.h5m differ diff --git a/tests/regression_tests/dagmc/inputs_true.dat b/tests/regression_tests/dagmc/inputs_true.dat index df8e3267e7..d88072223d 100644 --- a/tests/regression_tests/dagmc/inputs_true.dat +++ b/tests/regression_tests/dagmc/inputs_true.dat @@ -8,7 +8,6 @@ - diff --git a/tests/regression_tests/dagmc/results_true.dat b/tests/regression_tests/dagmc/results_true.dat index fc13a9cdaf..134cab089e 100644 --- a/tests/regression_tests/dagmc/results_true.dat +++ b/tests/regression_tests/dagmc/results_true.dat @@ -1,5 +1,5 @@ k-combined: -1.115067E+00 5.423808E-02 +8.847913E-01 1.700903E-02 tally 1: -8.543144E+00 -1.530584E+01 +8.016189E+00 +1.358910E+01 diff --git a/tests/regression_tests/dagmc/test.py b/tests/regression_tests/dagmc/test.py index 9766c9732f..34fdbbdd79 100644 --- a/tests/regression_tests/dagmc/test.py +++ b/tests/regression_tests/dagmc/test.py @@ -38,7 +38,6 @@ def test_dagmc(): water = openmc.Material() water.add_nuclide('H1', 2.0, 'ao') water.add_nuclide('O16', 1.0, 'ao') - water.add_s_alpha_beta('c_H_in_H2O') water.set_density('g/cc', 1.0) water.id = 41 diff --git a/tests/regression_tests/uwuw/__init__.py b/tests/regression_tests/uwuw/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regression_tests/uwuw/dagmc.h5m b/tests/regression_tests/uwuw/dagmc.h5m new file mode 100644 index 0000000000..6aa6f058a1 Binary files /dev/null and b/tests/regression_tests/uwuw/dagmc.h5m differ diff --git a/tests/regression_tests/uwuw/inputs_true.dat b/tests/regression_tests/uwuw/inputs_true.dat new file mode 100644 index 0000000000..87ceb944d8 --- /dev/null +++ b/tests/regression_tests/uwuw/inputs_true.dat @@ -0,0 +1,23 @@ + + + eigenvalue + 100 + 5 + 0 + + + -4 -4 -4 4 4 4 + + + true + + + + + 1 + + + 1 + total + + diff --git a/tests/regression_tests/uwuw/results_true.dat b/tests/regression_tests/uwuw/results_true.dat new file mode 120000 index 0000000000..3711895aba --- /dev/null +++ b/tests/regression_tests/uwuw/results_true.dat @@ -0,0 +1 @@ +../dagmc/results_true.dat \ No newline at end of file diff --git a/tests/regression_tests/uwuw/test.py b/tests/regression_tests/uwuw/test.py new file mode 100644 index 0000000000..d9ce4ccf94 --- /dev/null +++ b/tests/regression_tests/uwuw/test.py @@ -0,0 +1,41 @@ +import openmc +import openmc.capi +from openmc.stats import Box +from openmc.material import Materials + +import pytest +from tests.testing_harness import PyAPITestHarness + +pytestmark = pytest.mark.skipif( + not openmc.capi.dagmc_enabled, + reason="DAGMC CAD geometry is not enabled.") + +class UWUWTest(PyAPITestHarness): + + def _build_inputs(self): + model = openmc.model.Model() + + # settings + model.settings.batches = 5 + model.settings.inactive = 0 + model.settings.particles = 100 + + source = openmc.Source(space=Box([-4, -4, -4], + [ 4, 4, 4])) + model.settings.source = source + + model.settings.dagmc = True + + model.settings.export_to_xml() + + # tally + tally = openmc.Tally() + tally.scores = ['total'] + tally.filters = [openmc.CellFilter(1)] + model.tallies = [tally] + + model.tallies.export_to_xml() + +def test_uwuw(): + harness = UWUWTest('statepoint.5.h5') + harness._build_inputs()