Skip to content

Commit

Permalink
Added GaussDer to the compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
lsawade committed Jan 10, 2025
1 parent 515dd1b commit 1a17da6
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ target_link_libraries(
add_library(
source_time_function
src/source_time_function/dirac.cpp
src/source_time_function/gaussiander.cpp
src/source_time_function/ricker.cpp
src/source_time_function/external.cpp
)
Expand Down
67 changes: 67 additions & 0 deletions include/source_time_function/gaussiander.hpp
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
73 changes: 73 additions & 0 deletions src/source_time_function/gaussiander.cpp
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();
}

0 comments on commit 1a17da6

Please sign in to comment.