diff --git a/CMakeLists.txt b/CMakeLists.txt index 6008b8ad1..5f734b6d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ option(debug "Compile with debug flags" OFF) option(optimize "Turn on all compiler optimization flags" OFF) option(coverage "Compile with coverage analysis flags" OFF) option(dagmc "Enable support for DAGMC (CAD) geometry" OFF) +option(libmesh "Enable support for libmesh unstructured mesh tallies" OFF) #=============================================================================== # MPI for distributed-memory parallelism @@ -65,6 +66,14 @@ if(pugixml_FOUND) message(STATUS "Found pugixml: ${pugixml_DIR}") else() message(STATUS "Did not find pugixml, will use submodule instead") +#=============================================================================== +# 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() #=============================================================================== @@ -405,6 +414,12 @@ if(dagmc) target_link_libraries(libopenmc dagmc-shared uwuw-shared) 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/cmake/Modules/FindLIBMESH.cmake b/cmake/Modules/FindLIBMESH.cmake new file mode 100644 index 000000000..3e813e9d7 --- /dev/null +++ b/cmake/Modules/FindLIBMESH.cmake @@ -0,0 +1,21 @@ +# Try to find LIBMESH +# +# Once done this will define +# +# LIBMESH_FOUND - system has LIBMESH +# LIBMESH_INCLUDE_DIRS - the LIBMESH include directory +# LIBMESH_LIBRARIES - Link these to use LIBMESH +# LIBMESH_DEFINITIONS - Compiler switches required for using LIBMESH + +find_path(LIBMESH NAMES libmesh_opt.so + HINTS ${LIBMESH_ROOT} $ENV{LIBMESH_ROOT} + PATHS ENV LD_LIBRARY_PATH + PATH_SUFFIXES lib Lib + NO_DEFAULT_PATH) + +if(DEFINED LIBMESH) + set(LIBMESH_FOUND TRUE) +endif() + + +message(STATUS "Found LIBMESH in ${LIBMESH}") diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index 7149dfa09..c8641dab9 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -22,6 +22,11 @@ #include "moab/GeomUtil.hpp" #endif +#ifdef LIBMESH +#include "libmesh/libmesh.h" +#include "libmesh/mesh.h" +#endif + namespace openmc { //============================================================================== @@ -251,6 +256,12 @@ public: int set_grid(); }; +class UnstructuredMeshBase : public Mesh { +public: + UnstructuredMeshBase(pugi::xml_node node); + std::string filename_; +}; + #ifdef DAGMC class UnstructuredMesh : public Mesh { @@ -422,6 +433,19 @@ private: #endif +#ifdef LIBMESH +class LibMesh : public UnstructuredMeshBase { + +public: + // constructor + LibMesh(pugi::xml_node node); + +private: + std::unique_ptr m_; + std::unique_ptr point_locator_; +}; +#endif + //============================================================================== // Non-member functions //============================================================================== diff --git a/src/mesh.cpp b/src/mesh.cpp index dc1f14d6e..b26633500 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2027,6 +2027,37 @@ double UnstructuredMesh::get_volume_frac(int bin = -1) const { #endif +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 //==============================================================================