Skip to content

Commit

Permalink
Added compute struct for coupled interfaces
Browse files Browse the repository at this point in the history
Compute structs only store coupled ispecs and edges. ivalue_inverse and jvalue_inverse are calcuated on the fly using methods inside compute::iterator class. Computing these values on the fly would speed up computations on GPU vs pulling the values out of memory.
  • Loading branch information
Rohit-Kakodkar committed Aug 30, 2023
1 parent 723977c commit 1eef584
Show file tree
Hide file tree
Showing 19 changed files with 1,031 additions and 9 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ add_library(
src/compute/compute_properties.cpp
src/compute/compute_sources.cpp
src/compute/compute_receivers.cpp
src/compute/coupled_interfaces.cpp
)

target_link_libraries(
Expand Down
160 changes: 160 additions & 0 deletions include/compute/coupled_interfaces.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#ifndef _COMPUTE_COUPLED_INTERFACES_HPP
#define _COMPUTE_COUPLED_INTERFACES_HPP

#include "kokkos_abstractions.h"
#include "mesh/coupled_interfaces/coupled_interfaces.hpp"
#include "specfem_enums.hpp"

namespace specfem {
namespace compute {
namespace coupled_interfaces {
struct elastic_acoustic {
specfem::kokkos::HostMirror1d<int> h_elastic_ispec; ///< Index of the spectal
///< element on the
///< elastic side of the
///< interface (host
///< mirror)
specfem::kokkos::HostMirror1d<int> h_acoustic_ispec; ///< Index of the spectal
///< element on the
///< acoustic side of the
///< interface (host
///< mirror)
specfem::kokkos::DeviceView1d<int> elastic_ispec; ///< Index of the spectal
///< element on the elastic
///< side of the interface
specfem::kokkos::DeviceView1d<int> acoustic_ispec; ///< Index of the spectal
///< element on the
///< acoustic side of the
///< interface
specfem::kokkos::DeviceView1d<specfem::enums::coupling::edge::type>
elastic_edge; ///< Which edge of the element is coupled to the acoustic
///< element
specfem::kokkos::DeviceView1d<specfem::enums::coupling::edge::type>
acoustic_edge; ///< Which edge of the element is coupled to the elastic
///< element
specfem::kokkos::HostMirror1d<specfem::enums::coupling::edge::type>
h_elastic_edge; ///< Which edge of the element is coupled to the acoustic
///< element (host mirror)
specfem::kokkos::HostMirror1d<specfem::enums::coupling::edge::type>
h_acoustic_edge; ///< Which edge of the element is coupled to the elastic
///< element (host mirror)
int num_interfaces;

elastic_acoustic(
const specfem::kokkos::HostMirror3d<int> h_ibool,
const specfem::kokkos::HostView2d<type_real> coord,
const specfem::kokkos::HostView1d<specfem::enums::element::type>
h_ispec_type,
const specfem::mesh::coupled_interfaces::elastic_acoustic
&elastic_acoustic);
};
struct elastic_poroelastic {
specfem::kokkos::HostMirror1d<int> h_elastic_ispec; ///< Index of the spectal
///< element on the
///< elastic side of the
///< interface (host
///< mirror)
specfem::kokkos::HostMirror1d<int>
h_poroelastic_ispec; ///< Index of the spectal element on the poroelastic
///< side of the interface (host mirror)
specfem::kokkos::DeviceView1d<int> elastic_ispec; ///< Index of the spectal
///< element on the elastic
///< side of the interface
specfem::kokkos::DeviceView1d<int> poroelastic_ispec; ///< Index of the
///< spectal element on
///< the poroelastic
///< side of the
///< interface
specfem::kokkos::DeviceView1d<specfem::enums::coupling::edge::type>
elastic_edge; ///< Which edge of the element is coupled to the poroelastic
///< element
specfem::kokkos::DeviceView1d<specfem::enums::coupling::edge::type>
poroelastic_edge; ///< Which edge of the element is coupled to the elastic
///< element
specfem::kokkos::HostMirror1d<specfem::enums::coupling::edge::type>
h_elastic_edge; ///< Which edge of the element is coupled to the
///< poroelastic element (host mirror)
specfem::kokkos::HostMirror1d<specfem::enums::coupling::edge::type>
h_poroelastic_edge; ///< Which edge of the element is coupled to the
///< elastic element (host mirror)
int num_interfaces;

elastic_poroelastic(
const specfem::kokkos::HostMirror3d<int> h_ibool,
const specfem::kokkos::HostView2d<type_real> coord,
const specfem::kokkos::HostView1d<specfem::enums::element::type>
h_ispec_type,
const specfem::mesh::coupled_interfaces::elastic_poroelastic
&elastic_poroelastic);
};
struct acoustic_poroelastic {
specfem::kokkos::HostMirror1d<int> h_acoustic_ispec; ///< Index of the spectal
///< element on the
///< acoustic side of the
///< interface (host
///< mirror)
specfem::kokkos::HostMirror1d<int>
h_poroelastic_ispec; ///< Index of the spectal element on the poroelastic
///< side of the interface (host mirror)
specfem::kokkos::DeviceView1d<int> acoustic_ispec; ///< Index of the spectal
///< element on the
///< acoustic side of the
///< interface
specfem::kokkos::DeviceView1d<int> poroelastic_ispec; ///< Index of the
///< spectal element on
///< the poroelastic
///< side of the
///< interface
specfem::kokkos::DeviceView1d<specfem::enums::coupling::edge::type>
acoustic_edge; ///< Which edge of the element is coupled to the
///< poroelastic element
specfem::kokkos::DeviceView1d<specfem::enums::coupling::edge::type>
poroelastic_edge; ///< Which edge of the element is coupled to the
///< acoustic element
specfem::kokkos::HostMirror1d<specfem::enums::coupling::edge::type>
h_acoustic_edge; ///< Which edge of the element is coupled to the
///< poroelastic element (host mirror)
specfem::kokkos::HostMirror1d<specfem::enums::coupling::edge::type>
h_poroelastic_edge; ///< Which edge of the element is coupled to the
///< acoustic element (host mirror)
int num_interfaces;

acoustic_poroelastic(
const specfem::kokkos::HostMirror3d<int> h_ibool,
const specfem::kokkos::HostView2d<type_real> coord,
const specfem::kokkos::HostView1d<specfem::enums::element::type>
h_ispec_type,
const specfem::mesh::coupled_interfaces::acoustic_poroelastic
&acoustic_poroelastic);
};

struct coupled_interfaces {
public:
specfem::compute::coupled_interfaces::elastic_acoustic elastic_acoustic;
specfem::compute::coupled_interfaces::elastic_poroelastic elastic_poroelastic;
specfem::compute::coupled_interfaces::acoustic_poroelastic
acoustic_poroelastic;

coupled_interfaces(
const specfem::kokkos::HostMirror3d<int> h_ibool,
const specfem::kokkos::HostView2d<type_real> coord,
const specfem::kokkos::HostView1d<specfem::enums::element::type>
h_ispec_type,
const specfem::mesh::coupled_interfaces::coupled_interfaces
&coupled_interfaces);
};

namespace iterator {

int get_npoints(const specfem::enums::coupling::edge::type &edge,
const int ngllx, const int ngllz);

void get_points_along_the_edges(
const int &ipoint, const specfem::enums::coupling::edge::type &edge,
const int &ngllx, const int &ngllz, int &i, int &j);
} // namespace iterator
} // namespace coupled_interfaces
} // namespace compute
} // namespace specfem

#endif
1 change: 1 addition & 0 deletions include/compute/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
#include "compute_properties.hpp"
#include "compute_receivers.hpp"
#include "compute_sources.hpp"
#include "coupled_interfaces.hpp"

#endif
25 changes: 25 additions & 0 deletions include/macros.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef MACROS_HPP
#define MACROS_HPP

#ifndef NDEBUG
#define ASSERT(condition, message) \
do { \
if (!(condition)) { \
std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
<< " line " << __LINE__ << ": " << message << std::endl; \
std::terminate(); \
} \
} while (false)
#else
#define ASSERT(condition, message) \
do { \
} while (false)
#endif

// #ifndef NDEBUG
// #define DEVICE_ASSERT(condition) assert(condition)
// #else
// #define DEVICE_ASSERT(condition)
// #endif

#endif /* MACROS_HPP */
2 changes: 1 addition & 1 deletion include/mesh/coupled_interfaces/acoustic_poroelastic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct acoustic_poroelastic {
acoustic_poroelastic(){};
acoustic_poroelastic(const int num_interfaces, std::ifstream &stream,
const specfem::MPI::MPI *mpi);
int num_interfaces;
int num_interfaces = 0;
specfem::kokkos::HostView1d<int> acoustic_ispec;
specfem::kokkos::HostView1d<int> poroelastic_ispec;
};
Expand Down
2 changes: 1 addition & 1 deletion include/mesh/coupled_interfaces/elastic_acoustic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct elastic_acoustic {
elastic_acoustic(const int num_interfaces, std::ifstream &stream,
const specfem::MPI::MPI *mpi);

int num_interfaces;
int num_interfaces = 0;
specfem::kokkos::HostView1d<int> elastic_ispec;
specfem::kokkos::HostView1d<int> acoustic_ispec;
};
Expand Down
2 changes: 1 addition & 1 deletion include/mesh/coupled_interfaces/elastic_poroelastic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct elastic_poroelastic {
elastic_poroelastic(){};
elastic_poroelastic(const int num_interfaces, std::ifstream &stream,
const specfem::MPI::MPI *mpi);
int num_interfaces;
int num_interfaces = 0;
specfem::kokkos::HostView1d<int> elastic_ispec;
specfem::kokkos::HostView1d<int> poroelastic_ispec;
};
Expand Down
13 changes: 13 additions & 0 deletions include/specfem_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,19 @@ namespace property {
class isotropic {};
} // namespace property
} // namespace element

namespace coupling {
namespace edge {
enum type {
TOP, ///< Top edge
BOTTOM, ///< Bottom edge
LEFT, ///< Left edge
RIGHT ///< Right edge
};

constexpr int num_edges = 4;
} // namespace edge
} // namespace coupling
} // namespace enums
} // namespace specfem

Expand Down
Loading

0 comments on commit 1eef584

Please sign in to comment.