3#include "../../quadrature/quadrature.hpp"
17template <
typename ScalarT,
int VecDim = 3 >
75 , treat_boundary_( treat_boundary )
76 , diagonal_( diagonal )
77 , operator_apply_mode_( operator_apply_mode )
78 , operator_communication_mode_( operator_communication_mode )
79 , operator_stored_matrix_mode_( operator_stored_matrix_mode )
81 , send_buffers_( domain )
82 , recv_buffers_( domain )
92 operator_apply_mode_ = operator_apply_mode;
93 operator_communication_mode_ = operator_communication_mode;
112 KOKKOS_INLINE_FUNCTION
114 const int local_subdomain_id,
120 return util::has_flag( mask_( local_subdomain_id, x_cell, y_cell, r_cell ), flag );
125 std::optional< int > level_range,
128 operator_stored_matrix_mode_ = operator_stored_matrix_mode;
134 domain_, operator_stored_matrix_mode_, level_range, GCAElements );
141 KOKKOS_INLINE_FUNCTION
143 const int local_subdomain_id,
151 local_matrix_storage_.
set_matrix( local_subdomain_id, x_cell, y_cell, r_cell, wedge, mat );
157 KOKKOS_INLINE_FUNCTION
159 const int local_subdomain_id,
163 const int wedge )
const
168 if ( !local_matrix_storage_.
has_matrix( local_subdomain_id, x_cell, y_cell, r_cell, wedge ) )
170 Kokkos::abort(
"No matrix found at that spatial index." );
172 return local_matrix_storage_.
get_matrix( local_subdomain_id, x_cell, y_cell, r_cell, wedge );
192 if ( src_.extent( 0 ) != dst_.extent( 0 ) || src_.extent( 1 ) != dst_.extent( 1 ) ||
193 src_.extent( 2 ) != dst_.extent( 2 ) || src_.extent( 3 ) != dst_.extent( 3 ) )
195 throw std::runtime_error(
"EpsilonDivDiv: src/dst mismatch" );
198 if ( src_.extent( 1 ) != grid_.extent( 1 ) || src_.extent( 2 ) != grid_.extent( 2 ) )
200 throw std::runtime_error(
"EpsilonDivDiv: src/dst mismatch" );
203 util::Timer timer_kernel(
"epsilon_divdiv_kernel" );
213 domain_, dst_, send_buffers_, recv_buffers_ );
218 KOKKOS_INLINE_FUNCTION
void
219 operator()(
const int local_subdomain_id,
const int x_cell,
const int y_cell,
const int r_cell )
const
232 A[0] = local_matrix_storage_.
get_matrix( local_subdomain_id, x_cell, y_cell, r_cell, 0 );
233 A[1] = local_matrix_storage_.
get_matrix( local_subdomain_id, x_cell, y_cell, r_cell, 1 );
237 if ( local_matrix_storage_.
has_matrix( local_subdomain_id, x_cell, y_cell, r_cell, 0 ) &&
238 local_matrix_storage_.
has_matrix( local_subdomain_id, x_cell, y_cell, r_cell, 1 ) )
240 A[0] = local_matrix_storage_.
get_matrix( local_subdomain_id, x_cell, y_cell, r_cell, 0 );
241 A[1] = local_matrix_storage_.
get_matrix( local_subdomain_id, x_cell, y_cell, r_cell, 1 );
259 for (
int dimj = 0; dimj < 3; dimj++ )
263 src_d, local_subdomain_id, x_cell, y_cell, r_cell, dimj, src_ );
276 dst[0] = A[0] * src[0];
277 dst[1] = A[1] * src[1];
279 for (
int dimi = 0; dimi < 3; dimi++ )
286 dst_, local_subdomain_id, x_cell, y_cell, r_cell, dimi, dst_d );
296 const ScalarT r_1 = radii_( local_subdomain_id, r_cell );
297 const ScalarT r_2 = radii_( local_subdomain_id, r_cell + 1 );
302 constexpr int hex_offset_x[8] = { 0, 1, 0, 1, 0, 1, 0, 1 };
303 constexpr int hex_offset_y[8] = { 0, 0, 1, 1, 0, 0, 1, 1 };
304 constexpr int hex_offset_r[8] = { 0, 0, 0, 0, 1, 1, 1, 1 };
308 for (
int dimi = 0; dimi < 3; ++dimi )
310 for (
int dimj = 0; dimj < 3; ++dimj )
312 if ( diagonal_ and dimi != dimj )
318 for (
int i = 0; i < 8; i++ )
320 src_local_hex[i] = src_(
322 x_cell + hex_offset_x[i],
323 y_cell + hex_offset_y[i],
324 r_cell + hex_offset_r[i],
329 for (
int q = 0; q < num_quad_points; q++ )
349 jdet_keval_quadweight );
355 jdet_keval_quadweight,
364 for (
int i = 0; i < 8; i++ )
369 x_cell + hex_offset_x[i],
370 y_cell + hex_offset_y[i],
371 r_cell + hex_offset_r[i],
410 const auto det = J.det();
411 const auto abs_det = Kokkos::abs( det );
418 k_eval +=
shape( k, quad_point ) * k_local_hex[wedge]( k );
423 sym_grad_i[k] =
symmetric_grad( J_inv_transposed, quad_point, k, dimi );
424 sym_grad_j[k] =
symmetric_grad( J_inv_transposed, quad_point, k, dimj );
426 jdet_keval_quadweight = quad_weight * k_eval * abs_det;
431 KOKKOS_INLINE_FUNCTION
433 const int local_subdomain_id,
437 const int wedge )
const
445 const ScalarT r_1 = radii_( local_subdomain_id, r_cell );
446 const ScalarT r_2 = radii_( local_subdomain_id, r_cell + 1 );
453 for (
int dimi = 0; dimi < 3; ++dimi )
455 for (
int dimj = 0; dimj < 3; ++dimj )
458 for (
int q = 0; q < num_quad_points; q++ )
475 jdet_keval_quadweight );
483 jdet_keval_quadweight *
485 2.0 / 3.0 * sym_grad_j[j]( dimj, dimj ) * sym_grad_i[i]( dimi, dimi ) );
493 if ( treat_boundary_ )
496 boundary_mask.
fill( 1.0 );
498 for (
int dimi = 0; dimi < 3; ++dimi )
500 for (
int dimj = 0; dimj < 3; ++dimj )
505 for (
int i = 0; i < 6; i++ )
507 for (
int j = 0; j < 6; j++ )
510 if ( ( dimi == dimj && i != j && ( i < 3 || j < 3 ) ) or
511 ( dimi != dimj && ( i < 3 || j < 3 ) ) )
520 if ( r_cell + 1 == radii_.extent( 1 ) - 1 )
523 for (
int i = 0; i < 6; i++ )
525 for (
int j = 0; j < 6; j++ )
528 if ( ( dimi == dimj && i != j && ( i >= 3 || j >= 3 ) ) or
529 ( dimi != dimj && ( i >= 3 || j >= 3 ) ) )
557 constexpr int offset_x[2][6] = { { 0, 1, 0, 0, 1, 0 }, { 1, 0, 1, 1, 0, 1 } };
558 constexpr int offset_y[2][6] = { { 0, 0, 1, 0, 0, 1 }, { 1, 1, 0, 1, 1, 0 } };
559 constexpr int offset_r[2][6] = { { 0, 0, 0, 1, 1, 1 }, { 0, 0, 0, 1, 1, 1 } };
565 const bool at_cmb = r_cell == 0;
566 const bool at_surface = r_cell + 1 == radii_.extent( 1 ) - 1;
568 int surface_shift = 0;
573 if ( treat_boundary_ && at_cmb )
578 else if ( treat_boundary_ && at_surface )
590 sym_grad_i[i] * src_local_hex[4 * offset_r[wedge][i] + 2 * offset_y[wedge][i] + offset_x[wedge][i]];
591 divu += sym_grad_i[i]( dimi, dimi ) *
592 src_local_hex[4 * offset_r[wedge][i] + 2 * offset_y[wedge][i] + offset_x[wedge][i]];
601 dst_local_hex[4 * offset_r[wedge][j] + 2 * offset_y[wedge][j] + offset_x[wedge][j]] +=
602 jdet_keval_quadweight * ( 2 * ( sym_grad_j[j] ).double_contract( grad_u ) -
603 2.0 / 3.0 * sym_grad_j[j]( dimj, dimj ) * divu );
609 if ( diagonal_ || ( dimi == dimj && ( treat_boundary_ && ( at_cmb || at_surface ) ) ) )
614 const auto grad_u_diag =
615 sym_grad_i[i] * src_local_hex[4 * offset_r[wedge][i] + 2 * offset_y[wedge][i] + offset_x[wedge][i]];
616 const auto div_u_diag =
617 sym_grad_i[i]( dimi, dimi ) *
618 src_local_hex[4 * offset_r[wedge][i] + 2 * offset_y[wedge][i] + offset_x[wedge][i]];
620 dst_local_hex[4 * offset_r[wedge][i] + 2 * offset_y[wedge][i] + offset_x[wedge][i]] +=
621 jdet_keval_quadweight * ( 2 * ( sym_grad_j[i] ).double_contract( grad_u_diag ) -
622 2.0 / 3.0 * sym_grad_j[i]( dimj, dimj ) * div_u_diag );
Send and receive buffers for all process-local subdomain boundaries.
Definition communication.hpp:56
Definition epsilon_divdiv.hpp:19
void operator()(const int local_subdomain_id, const int x_cell, const int y_cell, const int r_cell) const
Definition epsilon_divdiv.hpp:219
linalg::OperatorStoredMatrixMode get_stored_matrix_mode()
Definition epsilon_divdiv.hpp:138
bool has_flag(const int local_subdomain_id, const int x_cell, const int y_cell, const int r_cell, grid::shell::ShellBoundaryFlag flag) const
Getter for mask member.
Definition epsilon_divdiv.hpp:113
static constexpr int LocalMatrixDim
Definition epsilon_divdiv.hpp:24
void assemble_trial_test_vecs(const int wedge, const dense::Vec< ScalarType, VecDim > &quad_point, const ScalarType quad_weight, const ScalarT r_1, const ScalarT r_2, dense::Vec< ScalarT, 3 >(*wedge_phy_surf)[3], const dense::Vec< ScalarT, 6 > *k_local_hex, const int dimi, const int dimj, dense::Mat< ScalarType, VecDim, VecDim > *sym_grad_i, dense::Mat< ScalarType, VecDim, VecDim > *sym_grad_j, ScalarType &jdet_keval_quadweight) const
: For both trial and test space this function sets up a vector: each vector element holds the symmetr...
Definition epsilon_divdiv.hpp:395
ScalarT ScalarType
Definition epsilon_divdiv.hpp:23
grid::Grid2DDataScalar< ScalarT > get_radii() const
Getter for radii member.
Definition epsilon_divdiv.hpp:106
EpsilonDivDiv(const grid::shell::DistributedDomain &domain, const grid::Grid3DDataVec< ScalarT, 3 > &grid, const grid::Grid2DDataScalar< ScalarT > &radii, const grid::Grid4DDataScalar< grid::shell::ShellBoundaryFlag > &mask, const grid::Grid4DDataScalar< ScalarT > &k, bool treat_boundary, bool diagonal, linalg::OperatorApplyMode operator_apply_mode=linalg::OperatorApplyMode::Replace, linalg::OperatorCommunicationMode operator_communication_mode=linalg::OperatorCommunicationMode::CommunicateAdditively, linalg::OperatorStoredMatrixMode operator_stored_matrix_mode=linalg::OperatorStoredMatrixMode::Off)
Definition epsilon_divdiv.hpp:58
void fused_local_mv(ScalarType src_local_hex[8], ScalarType dst_local_hex[8], const int wedge, const ScalarType jdet_keval_quadweight, dense::Mat< ScalarType, 3, 3 > *sym_grad_i, dense::Mat< ScalarType, 3, 3 > *sym_grad_j, const int dimi, const int dimj, int r_cell) const
Definition epsilon_divdiv.hpp:546
void set_operator_apply_and_communication_modes(const linalg::OperatorApplyMode operator_apply_mode, const linalg::OperatorCommunicationMode operator_communication_mode)
Definition epsilon_divdiv.hpp:88
void set_stored_matrix_mode(linalg::OperatorStoredMatrixMode operator_stored_matrix_mode, std::optional< int > level_range, std::optional< grid::Grid4DDataScalar< ScalarType > > GCAElements)
allocates memory for the local matrices
Definition epsilon_divdiv.hpp:123
const grid::shell::DistributedDomain & get_domain() const
Getter for domain member.
Definition epsilon_divdiv.hpp:103
grid::Grid3DDataVec< ScalarT, 3 > get_grid()
Getter for grid member.
Definition epsilon_divdiv.hpp:109
void set_local_matrix(const int local_subdomain_id, const int x_cell, const int y_cell, const int r_cell, const int wedge, const dense::Mat< ScalarT, LocalMatrixDim, LocalMatrixDim > &mat) const
Set the local matrix stored in the operator.
Definition epsilon_divdiv.hpp:142
dense::Mat< ScalarT, LocalMatrixDim, LocalMatrixDim > assemble_local_matrix(const int local_subdomain_id, const int x_cell, const int y_cell, const int r_cell, const int wedge) const
assemble the local matrix and return it for a given element, wedge, and vectorial component (determin...
Definition epsilon_divdiv.hpp:432
void apply_impl(const SrcVectorType &src, DstVectorType &dst)
Definition epsilon_divdiv.hpp:180
dense::Mat< ScalarT, LocalMatrixDim, LocalMatrixDim > get_local_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 epsilon_divdiv.hpp:158
terra::grid::Grid4DDataMatrices< ScalarType, LocalMatrixDim, LocalMatrixDim, 2 > Grid4DDataLocalMatrices
Definition epsilon_divdiv.hpp:25
void set_diagonal(bool v)
S/Getter for diagonal member.
Definition epsilon_divdiv.hpp:97
const grid::Grid4DDataScalar< ScalarType > & k_grid_data()
Getter for coefficient.
Definition epsilon_divdiv.hpp:100
Parallel data structure organizing the thick spherical shell metadata for distributed (MPI parallel) ...
Definition spherical_shell.hpp:2498
Static assertion: VectorQ1Scalar satisfies VectorLike concept.
Definition vector_q1.hpp:162
const grid::Grid4DDataVec< ScalarType, VecDim > & grid_data() const
Get const reference to grid data.
Definition vector_q1.hpp:280
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
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
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
Timer supporting RAII scope or manual stop.
Definition timer.hpp:270
void stop()
Stop the timer and record elapsed time.
Definition timer.hpp:289
Concept for types that can be used as Galerkin coarse-grid operators in a multigrid hierarchy....
Definition operator.hpp:81
void unpack_and_reduce_local_subdomain_boundaries(const grid::shell::DistributedDomain &domain, const GridDataType &data, SubdomainNeighborhoodSendRecvBuffer< typename GridDataType::value_type, grid::grid_data_vec_dim< GridDataType >() > &boundary_recv_buffers, CommunicationReduction reduction=CommunicationReduction::SUM)
Unpacks and reduces local subdomain boundaries.
Definition communication.hpp:672
void pack_send_and_recv_local_subdomain_boundaries(const grid::shell::DistributedDomain &domain, const GridDataType &data, SubdomainNeighborhoodSendRecvBuffer< typename GridDataType::value_type, grid::grid_data_vec_dim< GridDataType >() > &boundary_send_buffers, SubdomainNeighborhoodSendRecvBuffer< typename GridDataType::value_type, grid::grid_data_vec_dim< GridDataType >() > &boundary_recv_buffers)
Packs, sends and recvs local subdomain boundaries using two sets of buffers.
Definition communication.hpp:242
Definition boundary_mass.hpp:14
constexpr void quad_felippa_3x2_quad_weights(T(&quad_weights)[quad_felippa_3x2_num_quad_points])
Definition wedge/quadrature/quadrature.hpp:93
constexpr int quad_felippa_3x2_num_quad_points
Definition wedge/quadrature/quadrature.hpp:66
constexpr void quad_felippa_3x2_quad_points(dense::Vec< T, 3 >(&quad_points)[quad_felippa_3x2_num_quad_points])
Definition wedge/quadrature/quadrature.hpp:70
constexpr int num_nodes_per_wedge_surface
Definition kernel_helpers.hpp:6
constexpr dense::Mat< T, 3, 3 > symmetric_grad(const dense::Mat< T, 3, 3 > &J_inv_transposed, const dense::Vec< T, 3 > &quad_point, const int dof, const int dim)
Returns the symmetric gradient of the shape function of a dof at a quadrature point.
Definition integrands.hpp:671
void wedge_surface_physical_coords(dense::Vec< T, 3 >(&wedge_surf_phy_coords)[num_wedges_per_hex_cell][num_nodes_per_wedge_surface], const grid::Grid3DDataVec< T, 3 > &lateral_grid, const int local_subdomain_id, const int x_cell, const int y_cell)
Extracts the (unit sphere) surface vertex coords of the two wedges of a hex cell.
Definition kernel_helpers.hpp:26
void atomically_add_local_wedge_vector_coefficients(const grid::Grid4DDataVec< T, VecDim > &global_coefficients, const int local_subdomain_id, const int x_cell, const int y_cell, const int r_cell, const int d, const dense::Vec< T, 6 > local_coefficients[2])
Performs an atomic add of the two local wedge coefficient vectors of a hex cell into the global coeff...
Definition kernel_helpers.hpp:465
constexpr int num_wedges_per_hex_cell
Definition kernel_helpers.hpp:5
void extract_local_wedge_scalar_coefficients(dense::Vec< T, 6 >(&local_coefficients)[2], const int local_subdomain_id, const int x_cell, const int y_cell, const int r_cell, const grid::Grid4DDataScalar< T > &global_coefficients)
Extracts the local vector coefficients for the two wedges of a hex cell from the global coefficient v...
Definition kernel_helpers.hpp:306
void extract_local_wedge_vector_coefficients(dense::Vec< T, 6 >(&local_coefficients)[2], const int local_subdomain_id, const int x_cell, const int y_cell, const int r_cell, const int d, const grid::Grid4DDataVec< T, VecDim > &global_coefficients)
Extracts the local vector coefficients for the two wedges of a hex cell from the global coefficient v...
Definition kernel_helpers.hpp:356
constexpr int num_nodes_per_wedge
Definition kernel_helpers.hpp:7
constexpr T shape(const int node_idx, const T xi, const T eta, const T zeta)
(Tensor-product) Shape function.
Definition integrands.hpp:146
constexpr dense::Mat< T, 3, 3 > jac(const dense::Vec< T, 3 > &p1_phy, const dense::Vec< T, 3 > &p2_phy, const dense::Vec< T, 3 > &p3_phy, const T r_1, const T r_2, const T xi, const T eta, const T zeta)
Definition integrands.hpp:643
ShellBoundaryFlag
FlagLike that indicates boundary types for the thick spherical shell.
Definition shell/bit_masks.hpp:12
Kokkos::MDRangePolicy< Kokkos::Rank< 4 > > local_domain_md_range_policy_cells(const DistributedDomain &distributed_domain)
Definition spherical_shell.hpp:2668
Kokkos::View< dense::Mat< ScalarType, Rows, Cols > ****[NumMatrices], Layout > Grid4DDataMatrices
Definition grid_types.hpp:46
Kokkos::View< ScalarType ***[VecDim], Layout > Grid3DDataVec
Definition grid_types.hpp:40
Kokkos::View< ScalarType ****[VecDim], Layout > Grid4DDataVec
Definition grid_types.hpp:43
Kokkos::View< ScalarType ****, Layout > Grid4DDataScalar
Definition grid_types.hpp:25
Kokkos::View< ScalarType **, Layout > Grid2DDataScalar
Definition grid_types.hpp:19
OperatorApplyMode
Modes for applying an operator to a vector.
Definition operator.hpp:30
@ Replace
Overwrite the destination vector.
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.
@ Off
Do not use stored matrices.
OperatorCommunicationMode
Modes for communication during operator application.
Definition operator.hpp:40
@ CommunicateAdditively
Communicate and add results.
constexpr bool has_flag(E mask_value, E flag) noexcept
Checks if a bitmask value contains a specific flag.
Definition bit_masking.hpp:43
void fill(const T value)
Definition mat.hpp:201
constexpr Mat diagonal() const
Definition mat.hpp:377
Mat & hadamard_product(const Mat &mat)
Definition mat.hpp:213
T double_contract(const Mat &mat)
Definition mat.hpp:226