Skip to content

Commit

Permalink
Merge pull request #149 from PrincetonUniversity/issue-146
Browse files Browse the repository at this point in the history
Implements mesh reading as specfem::IO::read_mesh(...)
  • Loading branch information
lsawade authored Nov 20, 2024
2 parents f371196 + a2b2da2 commit e8d1d31
Show file tree
Hide file tree
Showing 32 changed files with 232 additions and 113 deletions.
30 changes: 5 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ else()
)
endif()

target_link_libraries(
IO
mesh
)

add_library(
point
src/point/coordinates.cpp
Expand Down Expand Up @@ -508,31 +513,6 @@ target_link_libraries(
Boost::program_options
)

add_executable(
homo2d
examples/homogeneous-medium-flat-topography/homo2d.cpp
)

target_link_libraries(
homo2d
specfem_mpi
Kokkos::kokkos
mesh
quadrature
compute
source_class
parameter_reader
receiver_class
writer
reader
domain
coupled_interface
kernels
solver
Boost::program_options
${HDF5_LIBRARIES}
)

# Include tests
if (BUILD_TESTS)
message("-- Including tests.")
Expand Down
1 change: 1 addition & 0 deletions docs/api/IO/Libraries/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ The snippet below shows how to use these modules to write and read a Kokkos::Vie
.. toctree::
:maxdepth: 1

mesh/index
ASCII/index
HDF5/index
33 changes: 33 additions & 0 deletions docs/api/IO/Libraries/mesh/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.. _mesh_reader:

Mesh Reader
===========

.. doxygenfunction:: specfem::IO::read_mesh


The above function reads the fortran binary mesh database and the following
functions are called in the order of appearance in the code:


.. doxygenfunction:: specfem::IO::mesh::fortran::read_mesh_database_header

.. doxygenfunction:: specfem::IO::mesh::fortran::read_coorg_elements

.. doxygenfunction:: specfem::IO::mesh::fortran::read_properties

.. doxygenfunction:: specfem::IO::mesh::fortran::read_mesh_database_attenuation

.. doxygenfunction:: specfem::IO::mesh::fortran::read_material_properties

.. doxygenfunction:: specfem::IO::mesh::fortran::read_boundaries

.. doxygenfunction:: specfem::IO::mesh::fortran::read_coupled_interfaces

.. doxygenfunction:: specfem::IO::mesh::fortran::read_tangential_elements

.. doxygenfunction:: specfem::IO::mesh::fortran::read_axial_elements

Finally, we add tags to the :cpp:struct:`specfem::mesh::mesh` using the
:cpp:struct:`specfem::mesh::tags` struct. The description of which can be found
here: :ref:`mesh_tags`.
2 changes: 1 addition & 1 deletion docs/api/IO/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Input/Output modules
:maxdepth: 2

fortran_io
Library/index
Libraries/index
writer/index
reader/index
1 change: 1 addition & 0 deletions docs/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ API documentation
datatypes/index
assembly/index
policies/index
IO/index
operators/index
compute_kernels/index
coupling_physics/coupled_interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.. _Chapter1:

Chapter 1: Generating the mesh, sources and receivers
====================================================
=====================================================

Before we start writing the solver, we need to generate an hexahedral mesh, and define our sources and receivers. To do this we will use the Fortran package ``MESHFEM2D``.

Expand All @@ -11,7 +11,7 @@ Before we start writing the solver, we need to generate an hexahedral mesh, and
Since ``MESHFEM2D`` is a dependency for SPECFEM++, it is should already be installed as part of the SPECFEM++ installation.

Defining the MESHFEM2D Parameter File
--------------------------------------
-------------------------------------

Let us generate a Hex mesh for 2D elastic domain using the following parameter file. You will also need a topography file to define the surface topography of the mesh, see :ref:`Topgraphy File <homogeneous-medium-flat-topography-topography-file>`

Expand Down
9 changes: 9 additions & 0 deletions include/IO/mesh/fortran/read_interfaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ specfem::mesh::interface_container<medium1, medium2>
read_interfaces(const int num_interfaces, std::ifstream &stream,
const specfem::MPI::MPI *mpi);

/* @brief Read the coupled interfaces from the database file
*
* @param stream input file stream
* @param num_interfaces_elastic_acoustic
* @param num_interfaces_acoustic_poroelastic
* @param num_interfaces_elastic_poroelastic
* @param mpi
* @return specfem::mesh::coupled_interfaces
*/
specfem::mesh::coupled_interfaces read_coupled_interfaces(
std::ifstream &stream, const int num_interfaces_elastic_acoustic,
const int num_interfaces_acoustic_poroelastic,
Expand Down
3 changes: 1 addition & 2 deletions include/IO/mesh/fortran/read_mesh_database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ read_mesh_database_header(std::ifstream &stream, const specfem::MPI::MPI *mpi);
* section
* @param npgeo Total number of control nodes in simulation box
* @param mpi Pointer to MPI object
* @return specfem::kokkos::HostView2d<type_real> coorg values as read from
* fortran binary database file
* @return std::tuple<int, int, int> nspec, npgeo, nproc values read from
*/
specfem::kokkos::HostView2d<type_real>
read_coorg_elements(std::ifstream &stream, const int npgeo,
Expand Down
2 changes: 1 addition & 1 deletion include/IO/mesh/fortran/read_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace fortran {
*
* @param stream Input stream
* @param mpi MPI object
* @return specfem::mesh::properties
* @return specfem::mesh::properties Property object
*/
specfem::mesh::properties read_properties(std::ifstream &stream,
const specfem::MPI::MPI *mpi);
Expand Down
21 changes: 21 additions & 0 deletions include/IO/mesh/read_mesh.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "mesh/mesh.hpp"
#include "specfem_mpi/interface.hpp"
#include "specfem_setup.hpp"

namespace specfem {

namespace IO {

/* @brief Construct a mesh object from a Fortran binary database file
*
* @param filename Fortran binary database filename
* @param mpi pointer to MPI object to manage communication
* @return specfem::mesh::mesh Specfem mesh object
*/
specfem::mesh::mesh read_mesh(const std::string filename,
const specfem::MPI::MPI *mpi);

} // namespace IO
} // namespace specfem
4 changes: 1 addition & 3 deletions include/policies/range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
namespace specfem {

namespace iterator {

namespace impl {

/**
* @brief Index type for the range iterator.
*
Expand All @@ -21,7 +19,7 @@ template <bool UseSIMD> struct range_index_type;
*
*/
template <> struct range_index_type<false> {
specfem::point::assembly_index index; ///< Assembly index
specfem::point::assembly_index<false> index; ///< Assembly index

KOKKOS_INLINE_FUNCTION
range_index_type(const specfem::point::assembly_index<false> index)
Expand Down
11 changes: 6 additions & 5 deletions src/IO/mesh/fortran/read_material_properties.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "IO/mesh/fortran/read_material_properties.hpp"
#include "IO/fortranio/interface.hpp"
#include "mesh/materials/materials.hpp"
// #include "mesh/materials/materials.hpp"
#include "mesh/materials/materials.tpp"
#include "specfem_mpi/interface.hpp"
#include "utilities/interface.hpp"
#include <memory>
Expand Down Expand Up @@ -184,12 +185,12 @@ specfem::mesh::materials specfem::IO::mesh::fortran::read_material_properties(

// Read material properties
auto index_mapping =
read_materials(stream, numat, materials.elastic_isotropic,
materials.acoustic_isotropic, mpi);
::read_materials(stream, numat, materials.elastic_isotropic,
materials.acoustic_isotropic, mpi);

// Read material indices
read_material_indices(stream, nspec, numat, index_mapping,
materials.material_index_mapping, knods, mpi);
::read_material_indices(stream, nspec, numat, index_mapping,
materials.material_index_mapping, knods, mpi);

return materials;
}
Loading

0 comments on commit e8d1d31

Please sign in to comment.