mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 21:25:36 -04:00
Getting UWUW XML file read from memory.
This commit is contained in:
parent
37276daea2
commit
20b8da1f24
6 changed files with 106 additions and 32 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
namespace openmc {
|
||||
|
||||
extern "C" bool dagmc_enabled;
|
||||
|
||||
//==============================================================================
|
||||
// Global variable declarations
|
||||
//==============================================================================
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,16 @@
|
|||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
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 << "<?xml version=\"1.0\"?>\n";
|
||||
mats_xml << "<materials>\n";
|
||||
std::map<std::string, pyne::Material> ml = uwuw.material_library;
|
||||
std::map<std::string, pyne::Material>::iterator it;
|
||||
// write materials
|
||||
for (it = ml.begin(); it != ml.end(); it++) { mats_xml << it->second.openmc("atom"); }
|
||||
// write footer
|
||||
mats_xml << "</materials>";
|
||||
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 << "<?xml version=\"1.0\"?>\n";
|
||||
ss << "<materials>\n";
|
||||
std::map<std::string, pyne::Material> ml = uwuw.material_library;
|
||||
std::map<std::string, pyne::Material>::iterator it;
|
||||
// write materials
|
||||
for (it = ml.begin(); it != ml.end(); it++) {
|
||||
ss << it->second.openmc("atom");
|
||||
}
|
||||
// write footer
|
||||
ss << "</materials>";
|
||||
}
|
||||
|
||||
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<std::string> keywords;
|
||||
keywords.push_back("mat");
|
||||
keywords.push_back("density");
|
||||
keywords.push_back("boundary");
|
||||
std::map<std::string, std::string> 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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 <material>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue