-
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.
- Methods to read adjoint source file - User Defined sources
- Loading branch information
1 parent
409a352
commit 90129c9
Showing
15 changed files
with
189 additions
and
20 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
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 _SPECFEM_SOURCES_EXTERNAL_HPP1_ | ||
#define _SPECFEM_SOURCES_EXTERNAL_HPP1_ | ||
|
||
#include "compute/compute_mesh.hpp" | ||
#include "compute/compute_partial_derivatives.hpp" | ||
#include "compute/properties/properties.hpp" | ||
#include "source.hpp" | ||
#include "yaml-cpp/yaml.h" | ||
|
||
namespace specfem { | ||
namespace sources { | ||
class external : public source { | ||
public: | ||
external(){}; | ||
|
||
external(YAML::Node &Node, const int nsteps, const type_real dt, | ||
const specfem::wavefield::type wavefield_type) | ||
: wavefield_type(wavefield_type), specfem::sources::source(Node, nsteps, | ||
dt){}; | ||
|
||
void compute_source_array( | ||
const specfem::compute::mesh &mesh, | ||
const specfem::compute::partial_derivatives &partial_derivatives, | ||
const specfem::compute::properties &properties, | ||
specfem::kokkos::HostView3d<type_real> source_array) override; | ||
|
||
specfem::wavefield::type get_wavefield_type() const override { | ||
return wavefield_type; | ||
} | ||
|
||
std::string print() const override; | ||
|
||
private: | ||
specfem::wavefield::type wavefield_type; | ||
}; | ||
} // namespace sources | ||
} // namespace specfem | ||
|
||
#endif /* _SPECFEM_SOURCES_EXTERNAL_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include "algorithms/locate_point.hpp" | ||
#include "compute/compute_mesh.hpp" | ||
#include "compute/compute_partial_derivatives.hpp" | ||
#include "compute/properties/properties.hpp" | ||
#include "enumerations/specfem_enums.hpp" | ||
#include "globals.h" | ||
#include "kokkos_abstractions.h" | ||
#include "point/coordinates.hpp" | ||
#include "quadrature/interface.hpp" | ||
#include "source/interface.hpp" | ||
#include "source_time_function/interface.hpp" | ||
#include "specfem_mpi/interface.hpp" | ||
#include "specfem_setup.hpp" | ||
// #include "utilities.cpp" | ||
#include "yaml-cpp/yaml.h" | ||
#include <cmath> | ||
|
||
void specfem::sources::external::compute_source_array( | ||
const specfem::compute::mesh &mesh, | ||
const specfem::compute::partial_derivatives &partial_derivatives, | ||
const specfem::compute::properties &properties, | ||
specfem::kokkos::HostView3d<type_real> source_array) { | ||
|
||
specfem::point::gcoord2 coord = specfem::point::gcoord2(this->x, this->z); | ||
auto lcoord = specfem::algorithms::locate_point(coord, mesh); | ||
|
||
const auto xi = mesh.quadratures.gll.h_xi; | ||
const auto gamma = mesh.quadratures.gll.h_xi; | ||
const auto N = mesh.quadratures.gll.N; | ||
|
||
const auto el_type = properties.h_element_types(lcoord.ispec); | ||
const int ncomponents = source_array.extent(0); | ||
|
||
// Compute lagrange interpolants at the source location | ||
auto [hxi_source, hpxi_source] = | ||
specfem::quadrature::gll::Lagrange::compute_lagrange_interpolants( | ||
lcoord.xi, N, xi); | ||
auto [hgamma_source, hpgamma_source] = | ||
specfem::quadrature::gll::Lagrange::compute_lagrange_interpolants( | ||
lcoord.gamma, N, gamma); | ||
|
||
type_real hlagrange; | ||
|
||
for (int iz = 0; iz < N; ++iz) { | ||
for (int ix = 0; ix < N; ++ix) { | ||
hlagrange = hxi_source(ix) * hgamma_source(iz); | ||
|
||
if (el_type == specfem::element::medium_tag::acoustic) { | ||
if (ncomponents != 1) { | ||
throw std::runtime_error( | ||
"Force source requires 1 component for acoustic medium"); | ||
} | ||
source_array(0, iz, ix) = hlagrange; | ||
} else if ((el_type == specfem::element::medium_tag::elastic) || | ||
(el_type == specfem::element::medium_tag::poroelastic)) { | ||
if (ncomponents != 2) { | ||
throw std::runtime_error( | ||
"Force source requires 2 components for elastic medium"); | ||
} | ||
if (specfem::globals::simulation_wave == specfem::wave::sh) { | ||
source_array(0, iz, ix) = hlagrange; | ||
source_array(1, iz, ix) = 0; | ||
} else { | ||
source_array(0, iz, ix) = hlagrange; | ||
source_array(1, iz, ix) = hlagrange; | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
std::string specfem::sources::external::print() const { | ||
|
||
std::ostringstream message; | ||
message << "- External Source: \n" | ||
<< " Source Location: \n" | ||
<< " x = " << type_real(this->x) << "\n" | ||
<< " z = " << type_real(this->z) << "\n" | ||
<< " Source Time Function: \n" | ||
<< this->forcing_function->print() << "\n"; | ||
|
||
return message.str(); | ||
} |
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