-
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.
- Loading branch information
Showing
3 changed files
with
141 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#pragma once | ||
#include "source_time_function.hpp" | ||
#include "specfem_setup.hpp" | ||
#include "yaml-cpp/yaml.h" | ||
#include <Kokkos_Core.hpp> | ||
#include <ostream> | ||
|
||
namespace specfem { | ||
namespace forcing_function { | ||
class GaussianDer : public stf { | ||
|
||
public: | ||
/** | ||
* @brief Contruct a GaussianDer source time function object | ||
* | ||
* @param f0 frequency f0 | ||
* @param tshift tshift value | ||
* @param factor factor to scale source time function | ||
* @param use_trick_for_better_pressure | ||
*/ | ||
GaussianDer(const int nsteps, const type_real dt, const type_real f0, | ||
const type_real tshift, const type_real factor, | ||
const bool use_trick_for_better_pressure); | ||
|
||
GaussianDer(YAML::Node &GaussianDer, const int nsteps, const type_real dt, | ||
const bool use_trick_for_better_pressure); | ||
|
||
/** | ||
* @brief compute the value of stf at time t | ||
* | ||
* @param t | ||
* @return value of source time function at time t | ||
*/ | ||
type_real compute(type_real t); | ||
/** | ||
* @brief update the time shift value | ||
* | ||
* @param tshift new tshift value | ||
*/ | ||
void update_tshift(type_real tshift) override { this->__tshift = tshift; } | ||
/** | ||
* @brief Get the t0 value | ||
* | ||
* @return t0 value | ||
*/ | ||
type_real get_t0() const override { return this->__t0; } | ||
|
||
type_real get_tshift() const override { return this->__tshift; } | ||
|
||
std::string print() const override; | ||
|
||
void compute_source_time_function( | ||
const type_real t0, const type_real dt, const int nsteps, | ||
specfem::kokkos::HostView2d<type_real> source_time_function) override; | ||
|
||
private: | ||
int __nsteps; | ||
type_real __f0; ///< frequence f0 | ||
type_real __tshift; ///< value of tshit | ||
type_real __t0; ///< t0 value | ||
type_real __factor; ///< scaling factor | ||
bool __use_trick_for_better_pressure; | ||
type_real __dt; | ||
}; | ||
|
||
} // namespace forcing_function | ||
} // namespace specfem |
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,73 @@ | ||
#include "source_time_function/interface.hpp" | ||
#include "specfem_setup.hpp" | ||
#include "utilities.cpp" | ||
#include <Kokkos_Core.hpp> | ||
#include <cmath> | ||
|
||
specfem::forcing_function::GaussianDer::GaussianDer( | ||
const int nsteps, const type_real dt, const type_real f0, | ||
const type_real tshift, const type_real factor, | ||
bool use_trick_for_better_pressure) | ||
: __nsteps(nsteps), __dt(dt), __f0(f0), __factor(factor), __tshift(tshift), | ||
__use_trick_for_better_pressure(use_trick_for_better_pressure) { | ||
|
||
type_real hdur = 1.0 / this->__f0; | ||
|
||
this->__t0 = -1.2 * hdur + this->__tshift; | ||
} | ||
|
||
specfem::forcing_function::GaussianDer::GaussianDer( | ||
YAML::Node &GaussianDer, const int nsteps, const type_real dt, | ||
const bool use_trick_for_better_pressure) { | ||
type_real f0 = GaussianDer["f0"].as<type_real>(); | ||
type_real tshift = [GaussianDer]() -> type_real { | ||
if (GaussianDer["tshift"]) { | ||
return GaussianDer["tshift"].as<type_real>(); | ||
} else { | ||
return 0.0; | ||
} | ||
}(); | ||
type_real factor = GaussianDer["factor"].as<type_real>(); | ||
|
||
*this = specfem::forcing_function::GaussianDer(nsteps, dt, f0, tshift, factor, | ||
use_trick_for_better_pressure); | ||
} | ||
|
||
type_real specfem::forcing_function::GaussianDer::compute(type_real t) { | ||
|
||
type_real val; | ||
|
||
if (this->__use_trick_for_better_pressure) { | ||
val = -1.0 * this->__factor * d3gaussian(t - this->__tshift, this->__f0); | ||
} else { | ||
val = -1.0 * this->__factor * d1gaussian(t - this->__tshift, this->__f0); | ||
} | ||
|
||
return val; | ||
} | ||
|
||
void specfem::forcing_function::GaussianDer::compute_source_time_function( | ||
const type_real t0, const type_real dt, const int nsteps, | ||
specfem::kokkos::HostView2d<type_real> source_time_function) { | ||
|
||
const int ncomponents = source_time_function.extent(1); | ||
|
||
for (int i = 0; i < nsteps; i++) { | ||
for (int icomp = 0; icomp < ncomponents; ++icomp) { | ||
source_time_function(i, icomp) = this->compute(t0 + i * dt); | ||
} | ||
} | ||
} | ||
|
||
std::string specfem::forcing_function::GaussianDer::print() const { | ||
std::stringstream ss; | ||
ss << " GaussianDer source time function:\n" | ||
<< " f0: " << this->__f0 << "\n" | ||
<< " tshift: " << this->__tshift << "\n" | ||
<< " factor: " << this->__factor << "\n" | ||
<< " t0: " << this->__t0 << "\n" | ||
<< " use_trick_for_better_pressure: " | ||
<< this->__use_trick_for_better_pressure << "\n"; | ||
|
||
return ss.str(); | ||
} |