specfem::sources

namespace sources

Namespace for structures that hold data related to sources.

This namespace contains source classes in a hierarchical structure. The base class is specfem::sources::source, with second-level specfem::sources::vector_source and specfem::sources::tensor_source, abstractions followed by their specific implementations.

2D specfem::sources::vector_source implementations

3D specfem::sources::vector_source implementations

2D specfem::sources::tensor_source implementations

See also

Need forward declaration of the main templates prior to specialization of the dimension specific source implementations.

specfem::sources::source

template<specfem::dimension::type DimensionTag>
class source

Base class for all source types.

It is a container for source time functions, coordinates, and the medium that the source is located in. This class provides the fundamental interface common to all sources in SPECFEM++ simulations.

Sources that inherit from this class:

Common Usage Pattern
// All sources require a source time function
auto stf = std::make_unique<specfem::source_time_functions::Ricker>(
    10.0,  // dominant frequency (Hz)
    0.01,  // time factor
    1.0,   // amplitude
    0.0,   // time shift
    1.0,   // normalization factor
    false  // do not reverse
);

// Create any source (example with 2D force source)
auto source = specfem::sources::force<specfem::dimension::type::dim2>(
    5.0, 10.0,  // coordinates (x, z)
    0.0,        // angle
    std::move(stf),
    specfem::wavefield::simulation_field::forward
);

// Common operations available for all sources:
source.set_medium_tag(specfem::element::medium_tag::elastic_psv);

// Access coordinates
auto coords = source.get_global_coordinates();

// Access timing information
type_real t0 = source.get_t0();
type_real tshift = source.get_tshift();

// Update timing
source.update_tshift(1.5);

// Check medium compatibility
auto supported_media = source.get_supported_media();

Template Parameters:

DimensionTag – The dimension specification (dim2 or dim3)

Subclassed by specfem::sources::tensor_source< specfem::dimension::type::dim2 >, specfem::sources::tensor_source< specfem::dimension::type::dim3 >, specfem::sources::vector_source< specfem::dimension::type::dim2 >, specfem::sources::vector_source< specfem::dimension::type::dim3 >, specfem::sources::tensor_source< DimensionTag >, specfem::sources::vector_source< DimensionTag >

2D Constructors

template<specfem::dimension::type U = DimensionTag, typename std::enable_if<U == specfem::dimension::type::dim2>::type* = nullptr>
inline source(type_real x, type_real z, std::unique_ptr<specfem::source_time_functions::stf> source_time_function)

Construct a new 2D source object using the forcing function.

Parameters:
  • x – x-coordinate of source

  • z – z-coordinate of source

  • source_time_function – pointer to source time function

template<specfem::dimension::type U = DimensionTag, typename std::enable_if<U == specfem::dimension::type::dim2>::type* = nullptr>
source(YAML::Node &Node, const int nsteps, const type_real dt)

Construct a new 2D source object from a YAML node and time steps.

Parameters:
  • Node – YAML node containing source configuration

  • nsteps – number of time steps

  • dt – time step size

3D Constructors

template<specfem::dimension::type U = DimensionTag, typename std::enable_if<U == specfem::dimension::type::dim3>::type* = nullptr>
source(YAML::Node &Node, const int nsteps, const type_real dt)

Construct a new 3D source object from a YAML node and time steps.

Parameters:
  • Node – YAML node containing source configuration

  • nsteps – number of time steps

  • dt – time step size

template<specfem::dimension::type U = DimensionTag, typename std::enable_if<U == specfem::dimension::type::dim3>::type* = nullptr>
inline source(type_real x, type_real y, type_real z, std::unique_ptr<specfem::source_time_functions::stf> source_time_function)

Construct a new 3D source object using the forcing function.

Parameters:
  • x – x-coordinate of source

  • y – y-coordinate of source

  • z – z-coordinate of source

  • source_time_function – pointer to source time function

Public Functions

inline source()

Default source constructor.

inline type_real get_t0() const

Get the value of t0 from the specfem::stf::stf object.

Returns:

value of t0

inline void update_tshift(type_real tshift)

Update the value of tshift for specfem::stf::stf object.

Returns:

new value of tshift

inline virtual std::string print() const

User output.

void set_source_time_function(YAML::Node &Node, const int nsteps, const type_real dt)

Set the forcing function for the source.

This function initializes the source time function based on the configuration provided in the YAML node. It supports various types of source time functions such as Dirac, Gaussian, Ricker, dGaussian, Heaviside, and External. If the specified source time function is not recognized, an exception is thrown.

This method also is responsible for setting up the start time of the source time function depending on dimension (dim2, dim3) and forcing function type.

Parameters:
  • Node – YAML node containing source time function configuration

  • nsteps – number of time steps

  • dt – time step size

inline std::unique_ptr<specfem::source_time_functions::stf> &get_source_time_function()

Get the forcing function object.

Returns:

std::unique_ptr<specfem::source_time_functions::stf>&

inline void set_local_coordinates(const specfem::point::local_coordinates<dimension_tag> &local_coordinates)

Set the local xi coordinates of the source in the local coordinate system.

Parameters:

specfem::point::local_coordinates<dimension_tag> – local_coordinates

inline specfem::point::local_coordinates<dimension_tag> get_local_coordinates() const

Get the local coordinates of the source in the local coordinate system.

Returns:

specfem::point::local_coordinates<dimension_tag>

inline void set_global_coordinates(const specfem::point::global_coordinates<dimension_tag> &global_coordinates)

Set the global coordinates of the source in the global coordinate system.

Parameters:

specfem::point::global_coordinates<dimension_tag> – global_coordinates

inline specfem::point::global_coordinates<dimension_tag> get_global_coordinates() const

Get the global coordinates of the source in the global coordinate system.

Returns:

specfem::point::global_coordinates<dimension_tag>

void set_medium_tag(specfem::element::medium_tag medium_tag)

Set the medium tag for the source.

This needs to be set inside the since each medium requires a separate implementation for each medium and some source do not have implementations for certain media at all. E.g., if you want to assign a moment tensor to an element in the water column (acoustic), it does not make sense, or rather it is unphysical.

Parameters:

medium_tag – medium tag

virtual std::vector<specfem::element::medium_tag> get_supported_media() const = 0

Get the list of supported media for this source type.

Returns:

std::vector<specfem::element::medium_tag> list of supported media

inline specfem::element::medium_tag get_medium_tag() const

Get the medium tag for the source.

Returns:

specfem::medium::medium_tag medium tag