-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from PrincetonUniversity/adjoint-sources
Adjoint sources
- Loading branch information
Showing
41 changed files
with
655 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef _COMPUTE_SOURCES_IMPL_SOURCE_MEDIUM_HPP | ||
#define _COMPUTE_SOURCES_IMPL_SOURCE_MEDIUM_HPP | ||
|
||
#include "compute/compute_mesh.hpp" | ||
#include "source/source.hpp" | ||
#include "specfem_setup.hpp" | ||
#include <Kokkos_Core.hpp> | ||
|
||
namespace specfem { | ||
namespace compute { | ||
namespace impl { | ||
namespace sources { | ||
template <specfem::dimension::type Dimension, | ||
specfem::element::medium_tag Medium> | ||
struct source_medium { | ||
using medium_type = specfem::medium::medium<Dimension, Medium>; | ||
|
||
source_medium() = default; | ||
|
||
source_medium( | ||
const std::vector<std::shared_ptr<specfem::sources::source> > &sources, | ||
const specfem::compute::mesh &mesh, | ||
const specfem::compute::partial_derivatives &partial_derivatives, | ||
const specfem::compute::properties &properties, const type_real t0, | ||
const type_real dt, const int nsteps); | ||
|
||
specfem::kokkos::DeviceView1d<int> source_index_mapping; | ||
specfem::kokkos::HostMirror1d<int> h_source_index_mapping; | ||
specfem::kokkos::DeviceView3d<type_real> source_time_function; | ||
specfem::kokkos::HostMirror3d<type_real> h_source_time_function; | ||
specfem::kokkos::DeviceView4d<type_real> source_array; | ||
specfem::kokkos::HostMirror4d<type_real> h_source_array; | ||
}; | ||
} // namespace sources | ||
} // namespace impl | ||
} // namespace compute | ||
} // namespace specfem | ||
|
||
#endif /* _COMPUTE_SOURCES_IMPL_SOURCE_MEDIUM_HPP */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#ifndef _COMPUTE_SOURCES_IMPL_SOURCE_MEDIUM_TPP | ||
#define _COMPUTE_SOURCES_IMPL_SOURCE_MEDIUM_TPP | ||
|
||
#include "algorithms/locate_point.hpp" | ||
#include "point/coordinates.hpp" | ||
#include "source_medium.hpp" | ||
#include <Kokkos_Core.hpp> | ||
|
||
template <specfem::dimension::type Dimension, | ||
specfem::element::medium_tag Medium> | ||
specfem::compute::impl::sources::source_medium<Dimension, Medium>:: | ||
source_medium( | ||
const std::vector<std::shared_ptr<specfem::sources::source> > &sources, | ||
const specfem::compute::mesh &mesh, | ||
const specfem::compute::partial_derivatives &partial_derivatives, | ||
const specfem::compute::properties &properties, const type_real t0, | ||
const type_real dt, const int nsteps) | ||
: source_index_mapping("specfem::sources::source_index_mapping", | ||
sources.size()), | ||
h_source_index_mapping(Kokkos::create_mirror_view(source_index_mapping)), | ||
source_time_function("specfem::sources::source_time_function", nsteps, | ||
sources.size(), medium_type::components), | ||
h_source_time_function(Kokkos::create_mirror_view(source_time_function)), | ||
source_array("specfem::sources::source_array", sources.size(), | ||
medium_type::components, mesh.quadratures.gll.N, | ||
mesh.quadratures.gll.N), | ||
h_source_array(Kokkos::create_mirror_view(source_array)) { | ||
|
||
for (int isource = 0; isource < sources.size(); isource++) { | ||
auto sv_source_array = Kokkos::subview( | ||
this->h_source_array, isource, Kokkos::ALL, Kokkos::ALL, Kokkos::ALL); | ||
sources[isource]->compute_source_array(mesh, partial_derivatives, | ||
properties, sv_source_array); | ||
auto sv_stf_array = Kokkos::subview(this->h_source_time_function, | ||
Kokkos::ALL, isource, Kokkos::ALL); | ||
sources[isource]->compute_source_time_function(t0, dt, nsteps, | ||
sv_stf_array); | ||
specfem::point::gcoord2 coord(sources[isource]->get_x(), | ||
sources[isource]->get_z()); | ||
|
||
auto lcoord = specfem::algorithms::locate_point(coord, mesh); | ||
this->h_source_index_mapping(isource) = lcoord.ispec; | ||
} | ||
|
||
Kokkos::deep_copy(source_array, h_source_array); | ||
Kokkos::deep_copy(source_time_function, h_source_time_function); | ||
Kokkos::deep_copy(source_index_mapping, h_source_index_mapping); | ||
|
||
return; | ||
} | ||
|
||
#endif /* _COMPUTE_SOURCES_IMPL_SOURCE_MEDIUM_TPP */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#ifndef _COMPUTE_SOURCES_2_HPP | ||
#define _COMPUTE_SOURCES_2_HPP | ||
|
||
#include "compute/compute_mesh.hpp" | ||
#include "compute/compute_partial_derivatives.hpp" | ||
#include "compute/properties/properties.hpp" | ||
#include "enumerations/dimension.hpp" | ||
#include "enumerations/wavefield.hpp" | ||
#include "impl/source_medium.hpp" | ||
#include "kokkos_abstractions.h" | ||
#include "source/source.hpp" | ||
|
||
namespace specfem { | ||
namespace compute { | ||
struct sources { | ||
|
||
sources() = default; | ||
|
||
sources( | ||
const std::vector<std::shared_ptr<specfem::sources::source> > &sources, | ||
const specfem::compute::mesh &mesh, | ||
const specfem::compute::partial_derivatives &partial_derivatives, | ||
const specfem::compute::properties &properties, const type_real t0, | ||
const type_real dt, const int nsteps); | ||
|
||
template <specfem::element::medium_tag Medium> | ||
inline specfem::compute::impl::sources::source_medium< | ||
specfem::dimension::type::dim2, Medium> | ||
get_source_medium() const { | ||
if constexpr (Medium == specfem::element::medium_tag::acoustic) { | ||
return acoustic_sources; | ||
} else if constexpr (Medium == specfem::element::medium_tag::elastic) { | ||
return elastic_sources; | ||
} else { | ||
static_assert("Invalid medium type"); | ||
} | ||
} | ||
|
||
int nsources; | ||
specfem::kokkos::HostView1d<int> source_domain_index_mapping; | ||
specfem::kokkos::HostView1d<specfem::element::medium_tag> | ||
source_medium_mapping; | ||
specfem::kokkos::HostView1d<specfem::wavefield::type> | ||
source_wavefield_mapping; | ||
specfem::compute::impl::sources::source_medium< | ||
specfem::dimension::type::dim2, specfem::element::medium_tag::acoustic> | ||
acoustic_sources; | ||
specfem::compute::impl::sources::source_medium< | ||
specfem::dimension::type::dim2, specfem::element::medium_tag::elastic> | ||
elastic_sources; | ||
}; | ||
} // namespace compute | ||
} // namespace specfem | ||
|
||
#endif /* _COMPUTE_SOURCES_2_HPP */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.