Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 150 -- Implements read sources under the IO module. #162

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,16 @@ add_library(
IO
src/IO/fortranio/fortran_io.cpp
src/IO/HDF5/native_type.cpp
src/IO/ASCII/native_type.cpp
# src/IO/ASCII/native_type.cpp
src/IO/mesh/read_mesh.cpp
src/IO/mesh/fortran/read_boundaries.cpp
src/IO/mesh/fortran/read_elements.cpp
src/IO/mesh/fortran/read_material_properties.cpp
src/IO/mesh/fortran/read_mesh_database.cpp
src/IO/mesh/fortran/read_interfaces.cpp
src/IO/mesh/fortran/read_properties.cpp
src/IO/sources/read_sources.cpp
# src/IO/receivers/read_receivers.cpp
)

if (NOT HDF5_CXX_BUILD)
Expand Down Expand Up @@ -142,6 +144,11 @@ target_link_libraries(
mesh
)

target_link_libraries(
IO
source_class
)

add_library(
point
src/point/coordinates.cpp
Expand Down Expand Up @@ -210,7 +217,6 @@ target_link_libraries(
Kokkos::kokkos
specfem_mpi
# material_class
IO
yaml-cpp
)

Expand Down Expand Up @@ -238,16 +244,26 @@ target_link_libraries(
# specfem_mpi
# )

add_library(
read_seismogram
src/reader/seismogram.cpp
)

target_link_libraries(
read_seismogram
Kokkos::kokkos
)

add_library(
reader
src/reader/wavefield.cpp
src/reader/seismogram.cpp
)

target_link_libraries(
reader
compute
IO
read_seismogram
)

add_library(
Expand All @@ -271,7 +287,7 @@ add_library(

target_link_libraries(
source_time_function
reader
read_seismogram
Kokkos::kokkos
point
)
Expand All @@ -283,7 +299,6 @@ add_library(
src/source/moment_tensor_source.cpp
src/source/adjoint_source.cpp
src/source/external.cpp
src/source/read_sources.cpp
)

target_link_libraries(
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,6 +39,7 @@ The snippet below shows how to use these modules to write and read a Kokkos::Vie
.. toctree::
:maxdepth: 1

sources/index
mesh/index
ASCII/index
HDF5/index
14 changes: 13 additions & 1 deletion docs/api/IO/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@
Input/Output modules
====================

There are three high-level functions that are essential for the SPECFEM++
codebase: :cpp:function:`specfem::IO::mesh::read_mesh`,
:cpp:function:`specfem::IO::sources::read_sources`, and
:cpp:function:`specfem::IO::receivers::read_receivers`. These functions are
used to read the mesh, sources and receivers from disk. The undelying
implementations are not expose to the user. Currently supporte
formats for the reading of the mesh is binary, and for sources and receivers it
is yaml.

The slightly-lower level functions to read and write data to and from disk are
exposed through the following abstractions.

.. toctree::
:maxdepth: 2

fortran_io
Libraries/index
fortran_io
writer/index
reader/index
5 changes: 0 additions & 5 deletions docs/api/sources/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,3 @@ Types of sources

force_source
moment_tensor_source

Auxiliary functions
-------------------

.. doxygenfunction:: specfem::sources::read_sources
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Finally, we have all the components that we need to put together to create a com
specfem::mesh::mesh mesh("OUTPUT_FILES/database.bin", mpi);

// Read the sources
const auto sources = specfem::sources::read_sources(
const auto sources = specfem::IO::sources::read_sources(
"OUTPUT_FILES/sources.yaml",
simulation_params.nsteps,
simulation_params.t0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Next we will read the sources and receivers generated in :ref:`Chapter1 <Chapter
const auto simulation_type = specfem::simulation::type::forward;

// Read the sources and receivers
const auto sources = specfem::sources::read_sources(sources_filename, nsteps, t0, dt, simulation_type);
const auto sources = specfem::IO::sources::read_sources(sources_filename, nsteps, t0, dt, simulation_type);
const auto receivers = specfem::receivers::read_receivers(receivers_filename, angle);

// Output source information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#define _READ_SOURCES_HPP

#include "enumerations/simulation.hpp"
#include "source.hpp"
#include "source/interface.hpp"
#include <memory>

namespace specfem {
namespace sources {
namespace IO {
/**
* @brief Read sources file written in .yml format
*
Expand All @@ -23,7 +23,7 @@ read_sources(const std::string sources_file, const int nsteps,
const type_real user_t0, const type_real dt,
const specfem::simulation::type simulation_type);

} // namespace sources
} // namespace IO
} // namespace specfem

#endif
1 change: 1 addition & 0 deletions include/enumerations/simulation.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <string>

namespace specfem {
namespace simulation {
Expand Down
1 change: 1 addition & 0 deletions include/reader/seismogram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace reader {

class seismogram : public reader {
public:
seismogram(){};
seismogram(const char *filename,
const specfem::enums::seismogram::format type,
specfem::kokkos::HostView2d<type_real> source_time_function)
Expand Down
1 change: 0 additions & 1 deletion include/source/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "external.hpp"
#include "force_source.hpp"
#include "moment_tensor_source.hpp"
#include "read_sources.hpp"
#include "source.hpp"

#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "IO/sources/read_sources.hpp"
#include "source/interface.hpp"
#include "specfem_setup.hpp"
#include "utilities/interface.hpp"
Expand All @@ -9,9 +10,9 @@
#include <vector>

std::tuple<std::vector<std::shared_ptr<specfem::sources::source> >, type_real>
specfem::sources::read_sources(
const std::string sources_file, const int nsteps, const type_real user_t0,
const type_real dt, const specfem::simulation::type simulation_type) {
specfem::IO::read_sources(const std::string sources_file, const int nsteps,
const type_real user_t0, const type_real dt,
const specfem::simulation::type simulation_type) {

const bool user_defined_start_time =
(std::abs(user_t0) > std::numeric_limits<type_real>::epsilon());
Expand Down
9 changes: 2 additions & 7 deletions src/specfem2d.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#include "compute/interface.hpp"
// #include "coupled_interface/interface.hpp"
// #include "domain/interface.hpp"
#include "IO/mesh/fortran/read_boundaries.hpp"
#include "IO/mesh/fortran/read_elements.hpp"
#include "IO/mesh/fortran/read_interfaces.hpp"
#include "IO/mesh/fortran/read_material_properties.hpp"
#include "IO/mesh/fortran/read_mesh_database.hpp"
#include "IO/mesh/fortran/read_properties.hpp"
#include "IO/mesh/read_mesh.hpp"
#include "IO/sources/read_sources.hpp"
#include "kokkos_abstractions.h"
#include "mesh/mesh.hpp"
#include "parameter_parser/interface.hpp"
Expand Down Expand Up @@ -113,7 +108,7 @@ void execute(const std::string &parameter_file, const std::string &default_file,
// --------------------------------------------------------------
const int nsteps = setup.get_nsteps();
const specfem::simulation::type simulation_type = setup.get_simulation_type();
auto [sources, t0] = specfem::sources::read_sources(
auto [sources, t0] = specfem::IO::read_sources(
source_filename, nsteps, setup.get_t0(), setup.get_dt(), simulation_type);
setup.update_t0(t0); // Update t0 in case it was changed

Expand Down
6 changes: 6 additions & 0 deletions tests/unit-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ target_link_libraries(
mpi_environment
kokkos_environment
yaml-cpp
IO
# material_class
-lpthread -lm
)
Expand Down Expand Up @@ -175,6 +176,7 @@ target_link_libraries(
kokkos_environment
yaml-cpp
compare_arrays
IO
Boost::filesystem
# material_class
-lpthread -lm
Expand All @@ -192,6 +194,7 @@ target_link_libraries(
compute
quadrature
mpi_environment
IO
kokkos_environment
yaml-cpp
Boost::filesystem
Expand All @@ -213,6 +216,7 @@ target_link_libraries(
kokkos_environment
algorithms
point
IO
Boost::filesystem
)

Expand All @@ -229,6 +233,7 @@ target_link_libraries(
mpi_environment
kokkos_environment
algorithms
IO
Boost::filesystem
point
)
Expand Down Expand Up @@ -288,6 +293,7 @@ target_link_libraries(
point
algorithms
domain
IO
coupled_interface
-lpthread -lm
)
Expand Down
3 changes: 2 additions & 1 deletion tests/unit-tests/assembly/test_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "../MPI_environment.hpp"
#include "IO/mesh/read_mesh.hpp"
#include "IO/sources/read_sources.hpp"
#include "compute/assembly/assembly.hpp"
#include "enumerations/specfem_enums.hpp"
#include "mesh/mesh.hpp"
Expand Down Expand Up @@ -148,7 +149,7 @@ class ASSEMBLY : public ::testing::Test {
Test.get_databases();
specfem::mesh::mesh mesh = specfem::IO::read_mesh(database_file, mpi);

const auto [sources, t0] = specfem::sources::read_sources(
const auto [sources, t0] = specfem::IO::read_sources(
sources_file, 0, 0, 0, specfem::simulation::type::forward);

const auto receivers =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ TEST(DISPLACEMENT_TESTS, newmark_scheme_tests) {
// if start time is not explicitly specified then t0 is determined using
// source frequencies and time shift
auto [sources, t0] =
specfem::sources::read_sources(sources_file, setup.get_dt(), mpi);
specfem::IO::read_sources(sources_file, setup.get_dt(), mpi);

// Generate compute structs to be used by the solver
specfem::compute::compute compute(mesh.coorg, mesh.material_ind.knods, gllx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ TEST(DISPLACEMENT_TESTS, newmark_scheme_tests) {
// if start time is not explicitly specified then t0 is determined using
// source frequencies and time shift
auto [sources, t0] =
specfem::sources::read_sources(sources_file, setup.get_dt(), mpi);
specfem::IO::read_sources(sources_file, setup.get_dt(), mpi);

// Generate compute structs to be used by the solver
specfem::compute::compute compute(mesh.coorg, mesh.material_ind.knods, gllx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../../MPI_environment.hpp"
#include "../../utilities/include/interface.hpp"
#include "IO/mesh/read_mesh.hpp"
#include "IO/sources/read_sources.hpp"
#include "compute/interface.hpp"
#include "constants.hpp"
#include "domain/domain.hpp"
Expand Down Expand Up @@ -182,7 +183,7 @@ TEST(DISPLACEMENT_TESTS, newmark_scheme_tests) {
// Read sources
// if start time is not explicitly specified then t0 is determined using
// source frequencies and time shift
auto [sources, t0] = specfem::sources::read_sources(
auto [sources, t0] = specfem::IO::read_sources(
sources_file, nsteps, setup.get_t0(), dt, setup.get_simulation_type());

for (auto &source : sources) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-tests/domain/acoustic/rmass_inverse_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ TEST(DOMAIN_TESTS, rmass_inverse_elastic_test) {
// Read sources
// if start time is not explicitly specified then t0 is determined using
// source frequencies and time shift
auto [sources, t0] = specfem::sources::read_sources(sources_file, 1e-5, mpi);
auto [sources, t0] = specfem::IO::read_sources(sources_file, 1e-5, mpi);

// Generate compute structs to be used by the solver
specfem::compute::compute compute(mesh.coorg, mesh.material_ind.knods, gllx,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-tests/domain/elastic/rmass_inverse_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ TEST(DOMAIN_TESTS, rmass_inverse_elastic_test) {
// Read sources
// if start time is not explicitly specified then t0 is determined using
// source frequencies and time shift
auto [sources, t0] = specfem::sources::read_sources(sources_file, 1e-5, mpi);
auto [sources, t0] = specfem::IO::read_sources(sources_file, 1e-5, mpi);

// Generate compute structs to be used by the solver
specfem::compute::compute compute(mesh.coorg, mesh.material_ind.knods, gllx,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-tests/source/source_location_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ TEST(SOURCE_LOCATION_TESTS, compute_source_locations) {

// read sources file
auto [sources, t0] =
specfem::sources::read_sources(test_config.sources_file, 1.0, mpi);
specfem::IO::read_sources(test_config.sources_file, 1.0, mpi);

// setup compute struct for future use
specfem::compute::compute compute(mesh.coorg, mesh.material_ind.knods, gllx,
Expand Down