diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index 51d97d737..052e53d51 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -26,15 +26,10 @@ extern moab::DagMC* DAG; extern "C" void load_dagmc_geometry(); extern "C" void free_memory_dagmc(); - +extern "C" pugi::xml_document* read_uwuw_materials(); +std::string get_uwuw_materials_xml(); } // namespace openmc #endif // DAGMC #endif // OPENMC_DAGMC_H - -#ifdef DAGMC -extern "C" constexpr bool dagmc_enabled = true; -#else -extern "C" constexpr bool dagmc_enabled = false; -#endif diff --git a/include/openmc/settings.h b/include/openmc/settings.h index e95bcb107..c44c8edb1 100644 --- a/include/openmc/settings.h +++ b/include/openmc/settings.h @@ -16,6 +16,8 @@ namespace openmc { +extern "C" bool dagmc_enabled; + //============================================================================== // Global variable declarations //============================================================================== diff --git a/src/cross_sections.cpp b/src/cross_sections.cpp index ed963b23f..5c2e7cb50 100644 --- a/src/cross_sections.cpp +++ b/src/cross_sections.cpp @@ -2,6 +2,9 @@ #include "openmc/constants.h" #include "openmc/container_util.h" +#ifdef DAGMC +#include "openmc/dagmc.h" +#endif #include "openmc/error.h" #include "openmc/file_utils.h" #include "openmc/settings.h" @@ -81,14 +84,27 @@ extern "C" void read_mg_cross_sections_header(); void read_cross_sections_xml() { - // Check if materials.xml exists + pugi::xml_document doc; std::string filename = settings::path_input + "materials.xml"; - if (!file_exists(filename)) { - fatal_error("Material XML file '" + filename + "' does not exist."); +#ifdef DAGMC + std::string s; + if (settings::dagmc) { + s = get_uwuw_materials_xml(); } + if(s != "") { + doc.load_file(s.c_str()); + } else { +#endif + // Check if materials.xml exists + if (!file_exists(filename)) { + fatal_error("Material XML file '" + filename + "' does not exist."); + } + +#ifdef DAGMC + } +#endif // Parse materials.xml file - pugi::xml_document doc; doc.load_file(filename.c_str()); auto root = doc.document_element(); diff --git a/src/dagmc.cpp b/src/dagmc.cpp index bc3362892..cb0ce476f 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -12,6 +12,16 @@ #include #include +namespace openmc { + +#ifdef DAGMC +bool dagmc_enabled = true; +#else +bool dagmc_enabled = false; +#endif + +} + #ifdef DAGMC #include "uwuw.hpp" @@ -27,20 +37,53 @@ 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(); + +std::string get_uwuw_materials_xml() { + UWUW uwuw(DAGMC_FILENAME); + + std::stringstream ss; + if (uwuw.material_library.size() != 0) { + // write header + ss << "\n"; + ss << "\n"; + std::map ml = uwuw.material_library; + std::map::iterator it; + // write materials + for (it = ml.begin(); it != ml.end(); it++) { + ss << it->second.openmc("atom"); + } + // write footer + ss << ""; + } + + return ss.str(); +} + +pugi::xml_document* read_uwuw_materials() { + pugi::xml_document* doc = NULL; + + std::string ss = get_uwuw_materials_xml(); + if(ss != "") { + doc = new pugi::xml_document(); + pugi::xml_parse_result result = doc->load_string(ss.c_str()); + } + + return doc; +} + +bool write_uwuw_materials_xml() { + bool found_mats; + std::string ss = get_uwuw_materials_xml(); + // if there is a material library in the file + if (ss != "") { + // write a material.xml file + std::ofstream mats_xml("materials.xml"); + mats_xml << get_uwuw_materials_xml(); + mats_xml.close(); + found_mats = true; + } + + return found_mats; } void load_dagmc_geometry() @@ -63,7 +106,7 @@ void load_dagmc_geometry() err_msg << "A materials.xml file is present along with UWUW material definitions"; fatal_error(err_msg.str()); } - write_materials_xml(uwuw); + // write_materials_xml(uwuw); } int32_t dagmc_univ_id = 0; // universe is always 0 for DAGMC runs @@ -78,14 +121,14 @@ void load_dagmc_geometry() 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); @@ -174,8 +217,8 @@ void load_dagmc_geometry() if (model::DAG->has_prop(surf_handle, "boundary")) { 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") { @@ -207,5 +250,6 @@ void free_memory_dagmc() delete model::DAG; } + } #endif diff --git a/src/dagmc_header.F90 b/src/dagmc_header.F90 index 9895791ac..4a97f7f0c 100644 --- a/src/dagmc_header.F90 +++ b/src/dagmc_header.F90 @@ -13,6 +13,11 @@ module dagmc_header subroutine free_memory_dagmc() bind(C) end subroutine free_memory_dagmc + function read_uwuw_materials() result(doc) bind(C) + import C_PTR + type(C_PTR) :: doc + end function read_uwuw_materials + end interface end module dagmc_header diff --git a/src/input_xml.F90 b/src/input_xml.F90 index c497c79b9..496f42f76 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -520,18 +520,30 @@ contains ! Display output message call write_message("Reading materials XML file...", 5) +#ifdef DAGMC + if (dagmc) then + doc % ptr = read_uwuw_materials() + end if + + if (.not. c_associated(doc % ptr)) then +#endif + ! Check if materials.xml exists filename = trim(path_input) // "materials.xml" inquire(FILE=filename, EXIST=file_exists) if (.not. file_exists) then call fatal_error("Material XML file '" // trim(filename) // "' does not & &exist!") - end if + end if ! Parse materials.xml file call doc % load_file(filename) - root = doc % document_element() +#ifdef DAGMC + end if +#endif + + root = doc % document_element() call read_materials(root % ptr) ! Get pointer to list of XML