diff --git a/CMakeLists.txt b/CMakeLists.txt index 0770a51..a8967b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,6 +148,40 @@ if (WONTON_ENABLE_Jali AND WONTON_ENABLE_MPI AND NOT Jali_LIBRARIES) endif () +#------------------------------------------------------------------------------# +# Locate Conduit +#------------------------------------------------------------------------------# + +set(WONTON_ENABLE_Conduit False CACHE BOOL "Conduit/Blueprint Interface enabled?") + +if (WONTON_ENABLE_Conduit AND NOT Conduit_LIBRARIES) + # Look for the Conduit package + + find_package(Conduit REQUIRED) # specify in Conduit_ROOT or CMAKE_PREFIX_PATH + + # Similar to Kokkos; Conduit doesn't set 'Conduit_LIBRARIES', so we set it manually + set(Conduit_LIBRARIES "conduit::conduit" CACHE STRING "Conduit top level target") + + message(STATUS "Located Conduit") + message(STATUS "Conduit_LIBRARIES ${Conduit_LIBRARIES}") + + target_link_libraries(wonton INTERFACE ${Conduit_LIBRARIES}) + + if (NOT Conduit_ROOT) + # Conduit_CONFIG should be the full path to where the config file was found + # which is typically SOMEDIR/lib/cmake - back out Conduit_ROOT from that + # until we fix ConduitConfig + get_filename_component(Conduit_CONFIGLOC ${Conduit_CONFIG} DIRECTORY) + get_filename_component(Conduit_CONFIGLOC_UP1 ${Conduit_CONFIGLOC} DIRECTORY) + get_filename_component(Conduit_CONFIGLOC_UP2 ${Conduit_CONFIGLOC_UP1} DIRECTORY) + get_filename_component(Conduit_ROOT ${Conduit_CONFIGLOC_UP2} DIRECTORY CACHE "Where Conduit lives") + endif () + message(STATUS "Conduit_ROOT ${Conduit_ROOT}") + + target_compile_definitions(wonton INTERFACE WONTON_ENABLE_Conduit) +endif () + + #----------------------------------------------------------------------------- # Thrust information #----------------------------------------------------------------------------- diff --git a/wonton/mesh/CMakeLists.txt b/wonton/mesh/CMakeLists.txt index b21179a..8d53749 100644 --- a/wonton/mesh/CMakeLists.txt +++ b/wonton/mesh/CMakeLists.txt @@ -34,6 +34,10 @@ if (WONTON_ENABLE_FleCSI) add_subdirectory(flecsi) endif () +if (WONTON_ENABLE_Conduit) + add_subdirectory(conduit) +endif () + add_subdirectory(simple) add_subdirectory(adaptive_refinement) diff --git a/wonton/mesh/conduit/CMakeLists.txt b/wonton/mesh/conduit/CMakeLists.txt new file mode 100644 index 0000000..77fe8f9 --- /dev/null +++ b/wonton/mesh/conduit/CMakeLists.txt @@ -0,0 +1,54 @@ +#[[ +This file is part of the Ristra Wonton project. +Please see the license file at the root of this repository, or at: + https://github.com/laristra/wonton/blob/master/LICENSE +]] +#-----------------------------------------------------------------------------~# + +if (WONTON_ENABLE_Conduit) + + add_library(conduit_mesh_wrapper INTERFACE) + + target_include_directories(conduit_mesh_wrapper INTERFACE + $ + $ + $) + + set(conduit_mesh_wrapper_HEADERS + conduit_mesh_wrapper.h + ) + + # Not yet allowed for INTERFACE libraries + # + # set_target_properties(conduit_mesh_wrapper install(DIRECTORY ${wonton_SOURCE_DIR}/include/SI DESTINATION include)PROPERTIES + # PUBLIC_HEADER "${conduit_mesh_wrapper_HEADERS}") + # + # Directly install files instead + install(FILES ${conduit_mesh_wrapper_HEADERS} + DESTINATION include/wonton/mesh/conduit) + + target_link_libraries(conduit_mesh_wrapper INTERFACE wonton_support) + + + # Conduit dependencies + target_link_libraries(conduit_mesh_wrapper INTERFACE ${Conduit_LIBRARIES}) + + target_link_libraries(wonton_mesh INTERFACE conduit_mesh_wrapper) + + install(TARGETS conduit_mesh_wrapper + EXPORT wonton_LIBRARIES + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin + PUBLIC_HEADER DESTINATION include/wonton/mesh/conduit + INCLUDES DESTINATION include/wonton/mesh/conduit + ) + + if (ENABLE_UNIT_TESTS) + wonton_add_unittest(test_conduit_mesh_wrapper + SOURCES test/test_conduit_mesh_wrapper.cc + LIBRARIES conduit_mesh_wrapper + POLICY SERIAL) + endif () + +endif() diff --git a/wonton/mesh/conduit/conduit_mesh_wrapper.h b/wonton/mesh/conduit/conduit_mesh_wrapper.h new file mode 100644 index 0000000..d51d26c --- /dev/null +++ b/wonton/mesh/conduit/conduit_mesh_wrapper.h @@ -0,0 +1,190 @@ +/* +This file is part of the Ristra Wonton project. +Please see the license file at the root of this repository, or at: + https://github.com/laristra/wonton/blob/master/LICENSE +*/ + +#ifndef CONDUIT_MESH_WRAPPER_H_ +#define CONDUIT_MESH_WRAPPER_H_ + +#include +#include +#include +#include +#include + +#include "conduit/conduit.hpp" // Conduit header +#include "conduit/conduit_blueprint.hpp" // Conduit header + +#include "wonton/support/wonton.h" +#include "wonton/support/Point.h" +#include "wonton/mesh/AuxMeshTopology.h" + +namespace Wonton { + +/** + * @brief An example of mesh wrapper for Wonton. + * + * It includes the minimal set of methods for mesh queries. + * It derives from Wonton::AuxMeshTopology which builds derived + * mesh entities and connectivities (such as corners and wedges) + * from the existing entities, and also helps to compute geometrical + * quantities such as cell volumes and centroids. + * It implements the "curiously recurring template pattern" to allow + * the mesh wrapper itself to answer queries within Wonton::AuxMeshTopology. + * see: https://en.m.wikipedia.org/wiki/Curiously_recurring_template_pattern + * + * @tparam Mesh: the type of the mesh to be wrapped. + */ +class Conduit_Mesh_Wrapper : public AuxMeshTopology { +public: + /** + * @brief Create an instance. + * + * @param mesh: the mesh to be wrapped. + */ + Conduit_Mesh_Wrapper(conduit::Node const& mesh) : mesh_(mesh) {} + + /** + * @brief Delete the instance. + */ + ~Conduit_Mesh_Wrapper() = default; + + /** + * @brief Get the mesh dimension. + * + * @return the mesh dimension. + */ + int space_dimension() const { return 0; } + + /** + * @brief Get the number of owned cells. + * + * @return the number of cells owned by the current MPI rank. + */ + int num_owned_cells() const { return 0; } + + /** + * @brief Get the number of owned faces. + * + * @return the number of faces owned by the current MPI rank. + */ + int num_owned_faces() const { return 0; } + + /** + * @brief Get the number of owned nodes. + * + * @return the number of nodes owned by the current MPI rank. + */ + int num_owned_nodes() const { return 0; } + + /** + * @brief Get the number of ghost cells. + * + * @return the number of ghost cells stored by the current MPI rank. + */ + int num_ghost_cells() const { return 0; } + + /** + * @brief Get the number of ghost faces. + * + * @return the number of ghost faces stored by the current MPI rank. + */ + int num_ghost_faces() const { return 0; } + + /** + * @brief Get the number of ghost nodes. + * + * @return the number of ghost nodes stored by the current MPI rank. + */ + int num_ghost_nodes() const { return 0; } + + /** + * @brief Get the type of the given cell which can be owned or ghost + * + * @param cellid: the ID of the cell. + * @return Entity_type::PARALLEL_OWNED|Entity_type::PARALLEL_GHOST + */ + Entity_type cell_get_type(int const cellid) const { return PARALLEL_OWNED; } + + /** + * @brief Get the type of the given node which can be owned or ghost + * + * @param nodeid: the ID of the node. + * @return Entity_type::PARALLEL_OWNED|Entity_type::PARALLEL_GHOST + */ + Entity_type node_get_type(int const nodeid) const { return PARALLEL_OWNED; } + + /** + * @brief Get the element type of the given cell. + * + * @param cellid: the ID of the cell. + * @return Element_type::TRI|QUAD|POLYGON|TET|PRISM|PYRAMID|HEX|POLYHEDRON + */ + Element_type cell_get_element_type(int const cellid) const { return QUAD; } + + /** + * @brief Get the list of faces and their normal directions for a given cell. + * + * @param[in] cellid: the ID of the cell. + * @param[out] cfaces: list of ID of all faces that compose the cell. + * @param[out] cfdirs: list of normal directions for those faces. + */ + void cell_get_faces_and_dirs(int const cellid, + std::vector *cfaces, + std::vector *cfdirs) const { /* TODO */ } + + /** + * @brief Get the nodes of the given cell. + * + * @param[in] cellid: the ID of the cell. + * @param[out] nodes: the list of its nodes. + */ + void cell_get_nodes(int const cellid, std::vector *nodes) const { /* TODO */ } + + /** + * @brief Get the nodes of the given face. + * + * @param[in] faceid: the ID of the face + * @param[out] nodes: the list of its nodes. + */ + void face_get_nodes(int const faceid, std::vector *nodes) const { /* TODO */ } + + /** + * @brief Get the list of all cells incident to a node. + * + * @param[in] nodeid: the ID of the node. + * @param[in] ptype: the entity type (PARALLEL_OWNED|PARALLEL_GHOST) + * @param[out] nodecells: the list of cells ID that are incident to the node. + */ + void node_get_cells(int const nodeid, + Entity_type const ptype, + std::vector *nodecells) const { /* TODO */ } + + /** + * @brief Get the global ID of the given entity. + * + * @param id: the local ID of the entity. + * @param kind: the entity kind NODE|FACE|CELL etc. + * @return its global ID. + */ + GID_t get_global_id(int const id, Entity_kind const kind) const { return 0; } + + /** + * @brief Get the coordinates of the given node. + * + * @tparam dim: the dimension of the node. + * @param[in] nodeid: the ID of the node. + * @param[out] p: its coordinates. + */ + template + void node_get_coordinates(int const nodeid, Point *p) const { /* TODO */ } + +private: + /** a reference to the mesh to be wrapped */ + conduit::Node const& mesh_; +}; + +} // namespace Wonton + +#endif // CONDUIT_MESH_WRAPPER_H_ diff --git a/wonton/mesh/conduit/test/test_conduit_mesh_wrapper.cc b/wonton/mesh/conduit/test/test_conduit_mesh_wrapper.cc new file mode 100644 index 0000000..b16f7c0 --- /dev/null +++ b/wonton/mesh/conduit/test/test_conduit_mesh_wrapper.cc @@ -0,0 +1,26 @@ +/* +This file is part of the Ristra Wonton project. +Please see the license file at the root of this repository, or at: + https://github.com/laristra/wonton/blob/master/LICENSE +*/ + +#include "wonton/mesh/conduit/conduit_mesh_wrapper.h" + +#include + +#include "gtest/gtest.h" + +#include "wonton/support/Point.h" + +/*! + file test_conduit_mesh_wrapper.cc + @brief Unit tests for the Conduit mesh wrapper class + */ + +TEST(Conduit_Mesh_Wrapper, Sanity_Test) { + conduit::Node mesh; + conduit::blueprint::mesh::examples::basic("uniform", 2, 2, 2, mesh); + + Wonton::Conduit_Mesh_Wrapper mesh_wrapper(mesh); + ASSERT_EQ(mesh_wrapper.space_dimension(), 0); +}