From 26fafd319e8bc5a94952fffed20e95b661c6b2e0 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 5 Dec 2019 22:29:47 -0600 Subject: [PATCH] Start of libmesh implementation. --- CMakeLists.txt | 16 ++++++++++++++++ src/mesh.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 499e006a01..d104405424 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,16 @@ if(libmesh) find_package(LIBMESH REQUIRED) endif() +#=============================================================================== +# libmesh Unstructured Mesh Support +#=============================================================================== +if(libmesh) + find_package(LIBMESH REQUIRED) + set(LIBMESH_LIBRARIES mesh_opt) + set(LIBMESH_INCLUDE_DIRS "${LIBMESH}/../include/") + link_directories(${LIBMESH}) +endif() + #=============================================================================== # HDF5 for binary output #=============================================================================== @@ -418,6 +428,12 @@ if(libmesh) target_link_libraries(libopenmc PkgConfig::LIBMESH) endif() +if(libmesh) + target_compile_definitions(libopenmc PRIVATE LIBMESH) + target_link_libraries(libopenmc ${LIBMESH_LIBRARIES}) + target_include_directories(libopenmc PRIVATE ${LIBMESH_INCLUDE_DIRS}) +endif() + #=============================================================================== # openmc executable #=============================================================================== diff --git a/src/mesh.cpp b/src/mesh.cpp index 1fc5169c52..47f9a1d611 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2372,6 +2372,37 @@ double LibMesh::volume(int bin) const { return m_->elem_ref(bin).volume(); } #endif // LIBMESH +UnstructuredMeshBase::UnstructuredMeshBase(pugi::xml_node node) : Mesh(node) { + // check the mesh type + if (check_for_node(node, "type")) { + auto temp = get_node_value(node, "type", true, true); + if (temp != "unstructured") { + fatal_error("Invalid mesh type: " + temp); + } + } + + // get the filename of the unstructured mesh to load + if (check_for_node(node, "mesh_file")) { + filename_ = get_node_value(node, "mesh_file"); + } + else { + fatal_error("No filename supplied for unstructured mesh with ID: " + + std::to_string(id_)); + } +} + +#ifdef LIBMESH +LibMesh::LibMesh(pugi::xml_node node) : UnstructuredMeshBase(node) { + libMesh::LibMeshInit init(0, NULL); + + m_ = std::unique_ptr(new libMesh::Mesh(init.comm(), 3)); + m_->read(filename_); + + point_locator_ = m_->sub_point_locator(); + m_->find_neighbors(); +} +#endif + //============================================================================== // Non-member functions //==============================================================================