Move read_materials_xml and read_plots_xml to C++

This commit is contained in:
Paul Romano 2019-02-20 15:45:30 -06:00
parent 3eea8311d3
commit 627ee79f0c
11 changed files with 80 additions and 148 deletions

View file

@ -304,7 +304,6 @@ target_compile_options(faddeeva PRIVATE ${cxxflags})
add_library(libopenmc SHARED
src/bank_header.F90
src/api.F90
src/dagmc_header.F90
src/constants.F90
src/dict_header.F90
src/error.F90

View file

@ -15,19 +15,17 @@ extern "C" const bool dagmc_enabled;
namespace openmc {
namespace model {
extern moab::DagMC* DAG;
} // namespace model
extern moab::DagMC* DAG;
}
//==============================================================================
// Non-member functions
//==============================================================================
extern "C" void load_dagmc_geometry();
void load_dagmc_geometry();
extern "C" void free_memory_dagmc();
void read_geometry_dagmc();
extern "C" pugi::xml_document* read_uwuw_materials();
bool read_uwuw_materials(pugi::xml_document& doc);
bool get_uwuw_materials_xml(std::string& s);
} // namespace openmc

View file

@ -109,6 +109,13 @@ private:
// Fortran compatibility
//==============================================================================
//! Read material data from materials.xml
void read_materials_xml();
//==============================================================================
// Fortran compatibility
//==============================================================================
extern "C" int* material_element(int i_material);
extern "C" bool material_isotropic(int i_material, int i_nuc_mat);

View file

@ -4,6 +4,7 @@
#include <unordered_map>
#include <sstream>
#include "pugixml.hpp"
#include "xtensor/xarray.hpp"
#include "hdf5.h"
@ -160,9 +161,8 @@ void voxel_finalize(hid_t dspace, hid_t dset, hid_t memspace);
// External functions
//===============================================================================
//! Read plots from plots.xml node
//! \param[in] plot node of plots.xml
extern "C" void read_plots(pugi::xml_node* plot_node);
//! Read plot specifications from a plots.xml file
void read_plots_xml();
//! Create a ppm image for a plot object
//! \param[in] plot object

View file

@ -104,6 +104,11 @@ contains
subroutine nuclides_clear() bind(C)
end subroutine
#ifdef DAGMC
subroutine free_memory_dagmc() bind(C)
end subroutine
#endif
end interface
call free_memory_geometry()

View file

@ -65,16 +65,13 @@ bool get_uwuw_materials_xml(std::string& s) {
return uwuw_mats_present;
}
pugi::xml_document* read_uwuw_materials() {
pugi::xml_document* doc = nullptr;
bool read_uwuw_materials(pugi::xml_document& doc) {
std::string s;
bool found_uwuw_mats = get_uwuw_materials_xml(s);
if (found_uwuw_mats) {
doc = new pugi::xml_document();
pugi::xml_parse_result result = doc->load_string(s.c_str());
pugi::xml_parse_result result = doc.load_string(s.c_str());
}
return doc;
return found_uwuw_mats;
}
bool write_uwuw_materials_xml() {

View file

@ -1,25 +0,0 @@
#ifdef DAGMC
module dagmc_header
use, intrinsic :: ISO_C_BINDING
implicit none
interface
subroutine load_dagmc_geometry() bind(C)
end subroutine load_dagmc_geometry
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
#endif

View file

@ -17,10 +17,12 @@
#include "openmc/error.h"
#include "openmc/geometry_aux.h"
#include "openmc/hdf5_interface.h"
#include "openmc/material.h"
#include "openmc/message_passing.h"
#include "openmc/mgxs_interface.h"
#include "openmc/nuclide.h"
#include "openmc/output.h"
#include "openmc/plot.h"
#include "openmc/random_lcg.h"
#include "openmc/settings.h"
#include "openmc/simulation.h"
@ -31,8 +33,6 @@
// data/functions from Fortran side
extern "C" void read_command_line();
extern "C" void read_materials_xml();
extern "C" void read_plots_xml();
extern "C" void read_tallies_xml();
// Paths to various files

View file

@ -4,9 +4,6 @@ module input_xml
use constants
use error, only: fatal_error, warning, write_message, openmc_err_msg
#ifdef DAGMC
use dagmc_header
#endif
use material_header
use message_passing
use settings
@ -23,59 +20,8 @@ module input_xml
implicit none
save
interface
subroutine read_materials(node_ptr) bind(C)
import C_PTR
type(C_PTR) :: node_ptr
end subroutine read_materials
subroutine read_plots(node_ptr) bind(C)
import C_PTR
type(C_PTR) :: node_ptr
end subroutine read_plots
end interface
contains
subroutine read_materials_xml() bind(C)
logical :: file_exists ! does materials.xml exist?
character(MAX_LINE_LEN) :: filename ! absolute path to materials.xml
type(XMLDocument) :: doc
type(XMLNode) :: root
! Display output message
call write_message("Reading materials XML file...", 5)
doc % ptr = C_NULL_PTR
#ifdef DAGMC
if (dagmc) then
doc % ptr = read_uwuw_materials()
end if
#endif
if (.not. c_associated(doc % ptr)) then
! 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
! Parse materials.xml file
call doc % load_file(filename)
end if
root = doc % document_element()
call read_materials(root % ptr)
! Close materials XML file
call doc % clear()
end subroutine read_materials_xml
!===============================================================================
! READ_TALLIES_XML reads data from a tallies.xml file and parses it, checking
! for errors and placing properly-formatted data in the right data structures
@ -522,37 +468,4 @@ contains
end subroutine read_tallies_xml
!===============================================================================
! READ_PLOTS_XML reads data from a plots.xml file
!===============================================================================
subroutine read_plots_xml() bind(C)
logical :: file_exists ! does plots.xml file exist?
character(MAX_LINE_LEN) :: filename ! absolute path to plots.xml
type(XMLDocument) :: doc
type(XMLNode) :: root
! Check if plots.xml exists
filename = trim(path_input) // "plots.xml"
inquire(FILE=filename, EXIST=file_exists)
if (.not. file_exists) then
call fatal_error("Plots XML file '" // trim(filename) &
// "' does not exist!")
end if
! Display output message
call write_message("Reading plot XML file...", 5)
! Parse plots.xml file
call doc % load_file(filename)
root = doc % document_element()
call read_plots(root % ptr)
! Close plots XML file
call doc % clear()
end subroutine read_plots_xml
end module input_xml

View file

@ -13,7 +13,9 @@
#include "openmc/capi.h"
#include "openmc/cross_sections.h"
#include "openmc/container_util.h"
#include "openmc/dagmc.h"
#include "openmc/error.h"
#include "openmc/file_utils.h"
#include "openmc/hdf5_interface.h"
#include "openmc/math_functions.h"
#include "openmc/message_passing.h"
@ -865,11 +867,34 @@ void Material::to_hdf5(hid_t group) const
// Non-method functions
//==============================================================================
extern "C" void
read_materials(pugi::xml_node* node)
void read_materials_xml()
{
write_message("Reading materials XML file...", 5);
pugi::xml_document doc;
bool using_dagmc_mats = false;
#ifdef DAGMC
if (settings::dagmc) {
using_dagmc_mats = read_uwuw_materials(doc);
}
#endif
if (!using_dagmc_mats) {
// Check if materials.xml exists
std::string filename = settings::path_input + "materials.xml";
if (!file_exists(filename)) {
fatal_error("Material XML file '" + filename + "' does not exist!");
}
// Parse materials.xml file and get root element
doc.load_file(filename.c_str());
}
// Loop over XML material elements and populate the array.
for (pugi::xml_node material_node : node->children("material")) {
pugi::xml_node root = doc.document_element();
for (pugi::xml_node material_node : root.children("material")) {
model::materials.push_back(new Material(material_node));
}
model::materials.shrink_to_fit();

View file

@ -1,22 +1,23 @@
#include "openmc/plot.h"
#include <fstream>
#include <sstream>
#include "openmc/plot.h"
#include "openmc/constants.h"
#include "openmc/settings.h"
#include "openmc/error.h"
#include "openmc/particle.h"
#include "openmc/geometry.h"
#include "openmc/cell.h"
#include "openmc/material.h"
#include "openmc/message_passing.h"
#include "openmc/string_utils.h"
#include "openmc/mesh.h"
#include "openmc/output.h"
#include "openmc/constants.h"
#include "openmc/file_utils.h"
#include "openmc/geometry.h"
#include "openmc/error.h"
#include "openmc/hdf5_interface.h"
#include "openmc/random_lcg.h"
#include "openmc/material.h"
#include "openmc/mesh.h"
#include "openmc/message_passing.h"
#include "openmc/output.h"
#include "openmc/particle.h"
#include "openmc/progress_bar.h"
#include "openmc/random_lcg.h"
#include "openmc/settings.h"
#include "openmc/string_utils.h"
namespace openmc {
@ -65,10 +66,22 @@ int openmc_plot_geometry()
}
void
read_plots(pugi::xml_node* plots_node)
void read_plots_xml()
{
for (auto node : plots_node->children("plot")) {
// Check if plots.xml exists
std::string filename = settings::path_input + "plots.xml";
if (!file_exists(filename)) {
fatal_error("Plots XML file '" + filename + "' does not exist!");
}
write_message("Reading plot XML file...", 5);
// Parse plots.xml file
pugi::xml_document doc;
doc.load_file(filename.c_str());
pugi::xml_node root = doc.document_element();
for (auto node : root.children("plot")) {
Plot pl(node);
model::plots.push_back(pl);
model::plot_map[pl.id_] = model::plots.size() - 1;