4#include <Kokkos_UnorderedMap.hpp>
28template <
typename ScalarT,
int LocalMatrixDim >
41 Kokkos::View< dense::Mat< ScalarType, LocalMatrixDim, LocalMatrixDim >*,
terra::grid::Layout >
42 local_matrices_selective_;
45 Kokkos::View< int > nMatrices_;
66 : operator_stored_matrix_mode_( operator_stored_matrix_mode )
70 level_range_ = level_range;
71 GCAElements_ = GCAElements;
75 capacity_ = 2 * nGCAElements * Kokkos::pow( 2, ( 3 * level_range_ ) );
76 std::cout <<
"Number of GCA coarse elements: " << nGCAElements <<
"/"
77 << GCAElements_.extent( 0 ) * ( GCAElements_.extent( 1 ) - 1 ) *
78 ( GCAElements_.extent( 2 ) - 1 ) * ( GCAElements_.extent( 2 ) - 1 )
79 <<
", capacity: " << capacity_ << std::endl;
80 local_matrices_selective_ =
81 Kokkos::View< dense::Mat< ScalarType, LocalMatrixDim, LocalMatrixDim >*,
terra::grid::Layout >(
82 "local_matrices_selective_", capacity_ );
96 nMatrices_ = Kokkos::View< int >(
"nMatrices_" );
97 Kokkos::deep_copy( nMatrices_, 0 );
104 "local_matrices_full",
112 Kokkos::abort(
"LocalMatrixStorage() not implemented." );
117 KOKKOS_INLINE_FUNCTION
119 const int local_subdomain_id,
128 for (
int i = 0; i < LocalMatrixDim; ++i )
130 for (
int j = 0; j < LocalMatrixDim; ++j )
132 local_matrices_full_( local_subdomain_id, x_cell, y_cell, r_cell, wedge )( i, j ) = mat( i, j );
139 if ( indices_( local_subdomain_id, x_cell, y_cell, r_cell, wedge ) == -1 )
143 indices_( local_subdomain_id, x_cell, y_cell, r_cell, wedge ) =
144 Kokkos::atomic_fetch_add( &nMatrices_(), 1 );
148 Kokkos::abort(
"Trying to write matrix that is already present." );
150 if ( nMatrices_() >= capacity_ + 1 )
152 Kokkos::abort(
"Too many matrices to store." );
155 for (
int i = 0; i < LocalMatrixDim; ++i )
157 for (
int j = 0; j < LocalMatrixDim; ++j )
160 local_matrices_selective_( indices_( local_subdomain_id, x_cell, y_cell, r_cell, wedge ) )( i, j ) =
167 Kokkos::abort(
"set_matrix() not implemented." );
174 KOKKOS_INLINE_FUNCTION
176 const int local_subdomain_id,
180 const int wedge )
const
185 for (
int i = 0; i < LocalMatrixDim; ++i )
187 for (
int j = 0; j < LocalMatrixDim; ++j )
189 ijslice( i, j ) = local_matrices_full_( local_subdomain_id, x_cell, y_cell, r_cell, wedge )( i, j );
196 if ( indices_( local_subdomain_id, x_cell, y_cell, r_cell, wedge ) == -1 )
198 Kokkos::abort(
"Matrix not found." );
200 if ( indices_( local_subdomain_id, x_cell, y_cell, r_cell, wedge ) >= capacity_ )
202 Kokkos::abort(
"Too many matrices." );
205 for (
int i = 0; i < LocalMatrixDim; ++i )
207 for (
int j = 0; j < LocalMatrixDim; ++j )
209 ijslice( i, j ) = local_matrices_selective_(
210 indices_( local_subdomain_id, x_cell, y_cell, r_cell, wedge ) )( i, j );
216 Kokkos::abort(
"get_matrix() not implemented." );
222 KOKKOS_INLINE_FUNCTION
224 const int local_subdomain_id,
228 const int wedge )
const
236 return indices_( local_subdomain_id, x_cell, y_cell, r_cell, wedge ) != -1;
240 Kokkos::abort(
"This should not happen." );
Parallel data structure organizing the thick spherical shell metadata for distributed (MPI parallel) ...
Definition spherical_shell.hpp:2498
const std::map< SubdomainInfo, std::tuple< LocalSubdomainIdx, SubdomainNeighborhood > > & subdomains() const
Definition spherical_shell.hpp:2580
const DomainInfo & domain_info() const
Returns a const reference.
Definition spherical_shell.hpp:2577
int subdomain_num_nodes_radially() const
Equivalent to calling subdomain_num_nodes_radially( subdomain_refinement_level() )
Definition spherical_shell.hpp:861
int subdomain_num_nodes_per_side_laterally() const
Equivalent to calling subdomain_num_nodes_per_side_laterally( subdomain_refinement_level() )
Definition spherical_shell.hpp:852
Definition local_matrix_storage.hpp:30
bool has_matrix(const int local_subdomain_id, const int x_cell, const int y_cell, const int r_cell, const int wedge) const
Checks for presence of a local matrix for a certain element.
Definition local_matrix_storage.hpp:223
ScalarT ScalarType
Definition local_matrix_storage.hpp:32
LocalMatrixStorage(grid::shell::DistributedDomain domain, linalg::OperatorStoredMatrixMode operator_stored_matrix_mode, int level_range, grid::Grid4DDataScalar< ScalarType > GCAElements)
Definition local_matrix_storage.hpp:55
dense::Mat< ScalarT, LocalMatrixDim, LocalMatrixDim > get_matrix(const int local_subdomain_id, const int x_cell, const int y_cell, const int r_cell, const int wedge) const
Retrives the local matrix if there is stored local matrices, the desired local matrix is loaded and r...
Definition local_matrix_storage.hpp:175
LocalMatrixStorage()
Definition local_matrix_storage.hpp:52
void set_matrix(const int local_subdomain_id, const int x_cell, const int y_cell, const int r_cell, const int wedge, dense::Mat< ScalarT, LocalMatrixDim, LocalMatrixDim > mat) const
Set the local matrix stored in the operator.
Definition local_matrix_storage.hpp:118
constexpr int num_wedges_per_hex_cell
Definition kernel_helpers.hpp:5
constexpr int num_nodes_per_wedge
Definition kernel_helpers.hpp:7
Kokkos::View< ScalarType *****, Layout > Grid5DDataScalar
Definition grid_types.hpp:28
Kokkos::View< dense::Mat< ScalarType, Rows, Cols > ****[NumMatrices], Layout > Grid4DDataMatrices
Definition grid_types.hpp:46
Kokkos::LayoutRight Layout
Definition grid_types.hpp:10
Kokkos::View< ScalarType ****, Layout > Grid4DDataScalar
Definition grid_types.hpp:25
ScalarType dot_product(const grid::Grid4DDataScalar< ScalarType > &x, const grid::Grid4DDataScalar< ScalarType > &y)
Definition grid_operations.hpp:668
void set_constant(const grid::Grid2DDataScalar< ScalarType > &x, ScalarType value)
Definition grid_operations.hpp:12
Definition block_preconditioner_2x2.hpp:7
OperatorStoredMatrixMode
Modes for applying stored matrices.
Definition operator.hpp:47
@ Selective
Use stored matrices on selected, marked elements only, assemble on all others.
@ Full
Use stored matrices on all elements.
Definition local_matrix_storage.hpp:23
int local_subdomain_id
Definition local_matrix_storage.hpp:24
int wedge
Definition local_matrix_storage.hpp:24
int y_cell
Definition local_matrix_storage.hpp:24
int r_cell
Definition local_matrix_storage.hpp:24
int x_cell
Definition local_matrix_storage.hpp:24