Skip to content

Commit

Permalink
Merge pull request #210 from PrincetonUniversity/issue-202
Browse files Browse the repository at this point in the history
Implemented templates for specfem::mesh::parameters
  • Loading branch information
Rohit-Kakodkar authored Dec 3, 2024
2 parents b5f6350 + 9ef640d commit ff73bbb
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<specfem::dimension::type::dim2> Mesh
* parameters
*/
specfem::mesh::properties read_properties(std::ifstream &stream,
const specfem::MPI::MPI *mpi);
specfem::mesh::parameters<specfem::dimension::type::dim2>
read_mesh_parameters(std::ifstream &stream, const specfem::MPI::MPI *mpi);

} // namespace fortran
} // namespace impl
Expand Down
10 changes: 6 additions & 4 deletions include/mesh/mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Kokkos_Core.hpp>
Expand All @@ -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<specfem::dimension::type::dim2>
parameters; ///< Struct to store simulation launch
///< parameters (never used)

specfem::mesh::coupled_interfaces coupled_interfaces; ///< Struct to store
///< coupled interfaces
Expand Down Expand Up @@ -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 &parameters,
const specfem::mesh::parameters<specfem::dimension::type::dim2>
&parameters,
const specfem::mesh::coupled_interfaces &coupled_interfaces,
const specfem::mesh::boundaries &boundaries,
const specfem::mesh::tags &tags,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
#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 {
int numat; ///< Total number of different materials
int ngnod; ///< Number of control nodes
int nspec; ///< Number of spectral elements
template <specfem::dimension::type DimensionType> struct parameters;

/**
* @brief Template specialization for 2D mesh parameters
*/
template <> struct parameters<specfem::dimension::type::dim2> {
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
Expand All @@ -32,7 +40,7 @@ struct properties {
* @brief Default constructor
*
*/
properties(){};
parameters(){};

/**
* @brief Construct a properties object
Expand All @@ -52,7 +60,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,
Expand Down
4 changes: 2 additions & 2 deletions src/IO/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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::dimension::type::dim2>
specfem::IO::mesh::impl::fortran::read_mesh_parameters(
std::ifstream &stream, const specfem::MPI::MPI *mpi) {
// ---------------------------------------------------------------------
// reading mesh properties
Expand Down Expand Up @@ -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 };
}

0 comments on commit ff73bbb

Please sign in to comment.