From 3bf445cd796b2dd5429a4e2d97f0dd91967f7026 Mon Sep 17 00:00:00 2001 From: Rohit Kakodkar Date: Mon, 2 Dec 2024 11:34:03 -0500 Subject: [PATCH 1/2] Implemented templates for specfem::mesh::parameters --- CMakeLists.txt | 2 +- ...ead_properties.hpp => read_parameters.hpp} | 11 ++++---- include/mesh/mesh.hpp | 10 +++++--- .../parameters.hpp} | 17 ++++++++----- src/IO/mesh.cpp | 4 +-- ...ead_properties.cpp => read_parameters.cpp} | 25 +++++++++++++------ 6 files changed, 43 insertions(+), 26 deletions(-) rename include/IO/mesh/impl/fortran/{read_properties.hpp => read_parameters.hpp} (53%) rename include/mesh/{properties/properties.hpp => parameters/parameters.hpp} (87%) rename src/IO/mesh/impl/fortran/{read_properties.cpp => read_parameters.cpp} (77%) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd1745c8..ddcd7ec6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,7 +137,7 @@ add_library( src/IO/mesh/impl/fortran/read_material_properties.cpp src/IO/mesh/impl/fortran/read_mesh_database.cpp src/IO/mesh/impl/fortran/read_interfaces.cpp - src/IO/mesh/impl/fortran/read_properties.cpp + src/IO/mesh/impl/fortran/read_parameters.cpp ) if (NOT HDF5_CXX_BUILD) diff --git a/include/IO/mesh/impl/fortran/read_properties.hpp b/include/IO/mesh/impl/fortran/read_parameters.hpp similarity index 53% rename from include/IO/mesh/impl/fortran/read_properties.hpp rename to include/IO/mesh/impl/fortran/read_parameters.hpp index 57f413fe..dfd36ccd 100644 --- a/include/IO/mesh/impl/fortran/read_properties.hpp +++ b/include/IO/mesh/impl/fortran/read_parameters.hpp @@ -1,7 +1,7 @@ #pragma once #include "IO/fortranio/interface.hpp" -#include "mesh/properties/properties.hpp" +#include "mesh/parameters/parameters.hpp" #include "specfem_mpi/interface.hpp" namespace specfem { @@ -11,14 +11,15 @@ namespace impl { namespace fortran { /* - * @brief Read properties from mesh database + * @brief Read paramters from 2D mesh database * * @param stream Input stream * @param mpi MPI object - * @return specfem::mesh::properties Property object + * @return specfem::mesh::parameters Mesh + * parameters */ -specfem::mesh::properties read_properties(std::ifstream &stream, - const specfem::MPI::MPI *mpi); +specfem::mesh::parameters +read_mesh_parameters(std::ifstream &stream, const specfem::MPI::MPI *mpi); } // namespace fortran } // namespace impl diff --git a/include/mesh/mesh.hpp b/include/mesh/mesh.hpp index 515760a8..2ea989c2 100644 --- a/include/mesh/mesh.hpp +++ b/include/mesh/mesh.hpp @@ -7,7 +7,7 @@ #include "elements/tangential_elements.hpp" #include "materials/materials.hpp" #include "mesh/tags/tags.hpp" -#include "properties/properties.hpp" +#include "parameters/parameters.hpp" #include "specfem_mpi/interface.hpp" #include "specfem_setup.hpp" #include @@ -26,8 +26,9 @@ struct mesh { int nproc; ///< Total number of processors specfem::mesh::control_nodes control_nodes; ///< Defines control nodes - specfem::mesh::properties parameters; ///< Struct to store simulation launch - ///< parameters (never used) + specfem::mesh::parameters + parameters; ///< Struct to store simulation launch + ///< parameters (never used) specfem::mesh::coupled_interfaces coupled_interfaces; ///< Struct to store ///< coupled interfaces @@ -60,7 +61,8 @@ struct mesh { mesh(const int npgeo, const int nspec, const int nproc, const specfem::mesh::control_nodes &control_nodes, - const specfem::mesh::properties ¶meters, + const specfem::mesh::parameters + ¶meters, const specfem::mesh::coupled_interfaces &coupled_interfaces, const specfem::mesh::boundaries &boundaries, const specfem::mesh::tags &tags, diff --git a/include/mesh/properties/properties.hpp b/include/mesh/parameters/parameters.hpp similarity index 87% rename from include/mesh/properties/properties.hpp rename to include/mesh/parameters/parameters.hpp index 5c2724da..7baa64f9 100644 --- a/include/mesh/properties/properties.hpp +++ b/include/mesh/parameters/parameters.hpp @@ -1,18 +1,23 @@ #ifndef _MESH_PROPERTIES_HPP #define _MESH_PROPERTIES_HPP +#include "enumerations/dimension.hpp" #include "specfem_mpi/interface.hpp" namespace specfem { namespace mesh { /** - * @brief Mesh properties + * @brief Mesh parameters * - * Mesh properties stores meta-data used to allocate other structs within the - * Mesh interface. + * @tparam DimensionType Dimension type for the mesh (2D or 3D) */ -struct properties { +template struct parameters; + +/** + * @brief Template specialization for 2D mesh parameters + */ +template <> struct parameters { int numat; ///< Total number of different materials int ngnod; ///< Number of control nodes int nspec; ///< Number of spectral elements @@ -32,7 +37,7 @@ struct properties { * @brief Default constructor * */ - properties(){}; + parameters(){}; /** * @brief Construct a properties object @@ -52,7 +57,7 @@ struct properties { * @param plot_lowerleft_corner_only Flag to plot only lower left corner */ - properties(const int numat, const int ngnod, const int nspec, + parameters(const int numat, const int ngnod, const int nspec, const int pointsdisp, const int nelemabs, const int nelem_acforcing, const int nelem_acoustic_surface, const int num_fluid_solid_edges, const int num_fluid_poro_edges, diff --git a/src/IO/mesh.cpp b/src/IO/mesh.cpp index c7428b8e..56d16d10 100644 --- a/src/IO/mesh.cpp +++ b/src/IO/mesh.cpp @@ -7,7 +7,7 @@ #include "IO/mesh/impl/fortran/read_interfaces.hpp" #include "IO/mesh/impl/fortran/read_material_properties.hpp" #include "IO/mesh/impl/fortran/read_mesh_database.hpp" -#include "IO/mesh/impl/fortran/read_properties.hpp" +#include "IO/mesh/impl/fortran/read_parameters.hpp" #include "enumerations/specfem_enums.hpp" #include "kokkos_abstractions.h" #include "material/material.hpp" @@ -60,7 +60,7 @@ specfem::mesh::mesh specfem::IO::read_mesh(const std::string filename, try { mesh.parameters = - specfem::IO::mesh::impl::fortran::read_properties(stream, mpi); + specfem::IO::mesh::impl::fortran::read_mesh_parameters(stream, mpi); } catch (std::runtime_error &e) { throw; } diff --git a/src/IO/mesh/impl/fortran/read_properties.cpp b/src/IO/mesh/impl/fortran/read_parameters.cpp similarity index 77% rename from src/IO/mesh/impl/fortran/read_properties.cpp rename to src/IO/mesh/impl/fortran/read_parameters.cpp index 70c51339..2680d06e 100644 --- a/src/IO/mesh/impl/fortran/read_properties.cpp +++ b/src/IO/mesh/impl/fortran/read_parameters.cpp @@ -1,8 +1,9 @@ -#include "IO/mesh/impl/fortran/read_properties.hpp" +#include "IO/mesh/impl/fortran/read_parameters.hpp" #include "IO/fortranio/interface.hpp" -#include "mesh/properties/properties.hpp" +#include "mesh/parameters/parameters.hpp" -specfem::mesh::properties specfem::IO::mesh::impl::fortran::read_properties( +specfem::mesh::parameters +specfem::IO::mesh::impl::fortran::read_mesh_parameters( std::ifstream &stream, const specfem::MPI::MPI *mpi) { // --------------------------------------------------------------------- // reading mesh properties @@ -42,9 +43,17 @@ specfem::mesh::properties specfem::IO::mesh::impl::fortran::read_properties( mpi->sync_all(); - return specfem::mesh::properties( - numat, ngnod, nspec, pointsdisp, nelemabs, nelem_acforcing, - nelem_acoustic_surface, num_fluid_solid_edges, num_fluid_poro_edges, - num_solid_poro_edges, nnodes_tangential_curve, nelem_on_the_axis, - plot_lowerleft_corner_only); + return { numat, + ngnod, + nspec, + pointsdisp, + nelemabs, + nelem_acforcing, + nelem_acoustic_surface, + num_fluid_solid_edges, + num_fluid_poro_edges, + num_solid_poro_edges, + nnodes_tangential_curve, + nelem_on_the_axis, + plot_lowerleft_corner_only }; } From 9ef640d0b390f6fd9dbe379d2119960a9e365d81 Mon Sep 17 00:00:00 2001 From: Rohit Kakodkar Date: Mon, 2 Dec 2024 13:49:22 -0500 Subject: [PATCH 2/2] Added constexpr dimension to parameters --- include/mesh/parameters/parameters.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/mesh/parameters/parameters.hpp b/include/mesh/parameters/parameters.hpp index 7baa64f9..028d9731 100644 --- a/include/mesh/parameters/parameters.hpp +++ b/include/mesh/parameters/parameters.hpp @@ -18,9 +18,12 @@ template struct parameters; * @brief Template specialization for 2D mesh parameters */ template <> struct parameters { - int numat; ///< Total number of different materials - int ngnod; ///< Number of control nodes - int nspec; ///< Number of spectral elements + constexpr static auto dimension = + specfem::dimension::type::dim2; ///< Dimension + ///< type + int numat; ///< Total number of different materials + int ngnod; ///< Number of control nodes + int nspec; ///< Number of spectral elements int pointsdisp; // Total number of points to display (Only used for // visualization) int nelemabs; ///< Number of elements on absorbing boundary