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 394 src rcv python #397

Open
wants to merge 25 commits into
base: issue-228-anisotropy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5b14db7
Added overload to read_sources()
lsawade Jan 14, 2025
485666c
Added test to read moment tensor source.
lsawade Jan 14, 2025
a58f60d
Forgot to add the test to the google_test_discover part
lsawade Jan 15, 2025
1502880
Merge pull request #401 from PrincetonUniversity/issue-395
lsawade Jan 15, 2025
5039c13
Fixed installables for the python installation
lsawade Jan 15, 2025
a87e246
Conflicts resolved..
lsawade Jan 15, 2025
9e22d75
this adds capability to add a source into the yaml tree
lsawade Jan 15, 2025
4ac2762
Merge branch 'issue-228-anisotropy' into issue-394-src-rcv-python
lsawade Jan 15, 2025
3262476
Merge branch 'issue-394-src-rcv-python' of github.com:PrincetonUniver…
lsawade Jan 15, 2025
bda25d2
Merge branch 'issue-394-src-rcv-python' into issue-395
lsawade Jan 15, 2025
be31354
Merge pull request #403 from PrincetonUniversity/issue-395
lsawade Jan 16, 2025
a9e95af
first commit to add receiver reading through YAML
lsawade Jan 16, 2025
2f73146
Merge branch 'issue-394-src-rcv-python' into issue-406
lsawade Jan 16, 2025
cf1c2ca
Merged upstream
lsawade Jan 16, 2025
c85f503
I really do not like the way this is done. receivers can now have a s…
lsawade Jan 16, 2025
e6862aa
Put the onus of deciding what format the stations-file is into the re…
lsawade Jan 16, 2025
57abbcc
Fixed grabbing the stations-file from the stations-node.
lsawade Jan 16, 2025
b232002
merged upstream updates
lsawade Jan 16, 2025
87f5c8f
Complete merge
lsawade Jan 16, 2025
070b27e
Updated wavefield snapshot naming, to zero pad for easier globbing
lsawade Jan 17, 2025
b8da2f7
Updated the docs to only refer to the read function that read from fi…
lsawade Jan 17, 2025
9e3190e
Updated source-file to always be called sources. It can now be define…
lsawade Jan 17, 2025
35f2ecd
Moved sources from databases to its own space in the runtime config
lsawade Jan 17, 2025
7beffb0
Removed the -file from the stations-file descriptor
lsawade Jan 17, 2025
0c96a69
Fixed kernel example
lsawade Jan 17, 2025
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
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ if (NOT HDF5_CXX_BUILD)
mesh
source_class
receiver_class
yaml-cpp
${BOOST_LIBS}
Kokkos::kokkos)
else()
Expand All @@ -224,8 +225,9 @@ else()
mesh
source_class
receiver_class

Kokkos::kokkos
yaml-cpp
${BOOST_LIBS}
${HDF5_LIBRARIES}
)
endif()
Expand Down
17 changes: 17 additions & 0 deletions include/IO/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "source/interface.hpp"
#include "specfem_mpi/interface.hpp"
#include "specfem_setup.hpp"
#include <yaml-cpp/yaml.h>

namespace specfem {

Expand Down Expand Up @@ -53,5 +54,21 @@ 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);

/**
* @brief Read sources file written in .yml format
*
* Parse source specification file written in yaml format and create a vector of
* specfem::source::source * object
*
* @param yaml YAML node containing source information
* @param mpi Pointer to specfem MPI object
* @return std::vector<specfem::sources::source *> vector of instantiated source
* objects
*/
std::tuple<std::vector<std::shared_ptr<specfem::sources::source> >, type_real>
read_sources(const YAML::Node yaml, const int nsteps, const type_real user_t0,
const type_real dt,
const specfem::simulation::type simulation_type);

} // namespace IO
} // namespace specfem
20 changes: 20 additions & 0 deletions include/source/moment_tensor_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ class moment_tensor : public source {
*
*/
moment_tensor(){};

/**
* @brief Get the Mxx component of the moment tensor
*
* @return type_real x-coordinate
*/
type_real get_Mxx() const { return Mxx; }
/**
* @brief Get the Mxz component of the moment tensor
*
* @return type_real z-coordinate
*/
type_real get_Mxz() const { return Mxz; }
/**
* @brief Get the Mzz component of the moment tensor
*
* @return type_real z-coordinate
*/
type_real get_Mzz() const { return Mzz; }

/**
* @brief Construct a new moment tensor force object
*
Expand Down
15 changes: 11 additions & 4 deletions src/IO/sources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ 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) {

return read_sources(YAML::LoadFile(sources_file), nsteps, user_t0, dt,
simulation_type);
}

std::tuple<std::vector<std::shared_ptr<specfem::sources::source> >, type_real>
specfem::IO::read_sources(const YAML::Node yaml, 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 All @@ -34,7 +43,6 @@ specfem::IO::read_sources(const std::string sources_file, const int nsteps,

// read sources file
std::vector<std::shared_ptr<specfem::sources::source> > sources;
YAML::Node yaml = YAML::LoadFile(sources_file);
int nsources = yaml["number-of-sources"].as<int>();
YAML::Node Node = yaml["sources"];
assert(Node.IsSequence());
Expand Down Expand Up @@ -89,9 +97,8 @@ specfem::IO::read_sources(const std::string sources_file, const int nsteps,
if (sources.size() != nsources) {
std::ostringstream message;
message << "Found only " << sources.size()
<< " number of sources. Total number of sources in " << sources_file
<< " are" << nsources
<< " Please check if there is a error in sources file.";
<< " number of sources. Found total number of sources in are "
<< nsources << " Please check if there is a error in sources file.";
throw std::runtime_error(message.str());
}

Expand Down
14 changes: 14 additions & 0 deletions tests/unit-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ add_executable(
assembly/sources/sources.cpp
)


target_link_libraries(
assembly_tests
reader
Expand All @@ -218,6 +219,19 @@ target_link_libraries(
-lpthread -lm
)

add_executable(
IO_tests
IO/sources/test_read_sources.cpp
)

target_link_libraries(
IO_tests
IO
gtest_main
kokkos_environment
yaml-cpp
Boost::filesystem
)

add_executable(
locate_point
Expand Down
13 changes: 13 additions & 0 deletions tests/unit-tests/IO/sources/data/single_moment_tensor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
number-of-sources: 1
sources:
- moment-tensor:
x: 2000.0
z: 3000.0
Mxx: 1.0
Mzz: 1.0
Mxz: 0.0
angle: 0.0
Ricker:
factor: 1.0e10
tshift: 30.0
f0: 1.0
49 changes: 49 additions & 0 deletions tests/unit-tests/IO/sources/test_read_sources.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "../../Kokkos_Environment.hpp"
#include "IO/interface.hpp"
#include "enumerations/specfem_enums.hpp"
#include "enumerations/wavefield.hpp"
#include "source/interface.hpp"
#include <Kokkos_Core.hpp>
#include <gtest/gtest.h>
#include <yaml-cpp/yaml.h>

TEST(read_sources, READ_SOURCES) {
/**
* This test checks whether a moment tensor source is read correctly
*/

std::string sources_file =
"../../../tests/unit-tests/IO/sources/data/single_moment_tensor.yml";

int nsteps = 100;
type_real t0 = 0.0;
type_real dt = 0.01;
type_real f0 = 1.0;
type_real tshift = 30.0;
type_real factor = 1.0e10;
// This is from the definition of the STF such that it is zero at t=0
type_real hdur = 1.0 / f0;
type_real t0_final = -1.2 * hdur + tshift;

auto [sources, user_t0] = specfem::IO::read_sources(
sources_file, nsteps, t0, dt, specfem::simulation::type::forward);

ASSERT_EQ(sources.size(), 1);
auto source = sources[0];
auto mt = std::dynamic_pointer_cast<specfem::sources::moment_tensor>(source);
ASSERT_EQ(mt->get_wavefield_type(),
specfem::wavefield::simulation_field::forward);
ASSERT_EQ(mt->get_Mxx(), 1.0);
ASSERT_EQ(mt->get_Mxz(), 0.0);
ASSERT_EQ(mt->get_Mzz(), 1.0);
EXPECT_NEAR(mt->get_x(), 2000.0, 1e-10);
EXPECT_NEAR(mt->get_z(), 3000.0, 1e-10);
ASSERT_EQ(source->get_t0(), t0_final);
ASSERT_EQ(source->get_tshift(), 0.0); // tshift is adjusted to be 0.0
}

int main(int argc, char *argv[]) {
::testing::InitGoogleTest(&argc, argv);
::testing::AddGlobalTestEnvironment(new KokkosEnvironment);
return RUN_ALL_TESTS();
}
Loading