4#include "../../quadrature/quadrature.hpp"
31template <
typename ScalarT,
int VecDim = 3 >
46 BoundaryConditions bcs_;
64 BoundaryConditions bcs,
72 , boundary_mask_data_( boundary_mask_data )
74 , operator_apply_mode_( operator_apply_mode )
75 , operator_communication_mode_( operator_communication_mode )
77 , send_buffers_( domain )
78 , recv_buffers_( domain )
88 operator_apply_mode_ = operator_apply_mode;
89 operator_communication_mode_ = operator_communication_mode;
104 if ( src_.extent( 0 ) != dst_.extent( 0 ) || src_.extent( 1 ) != dst_.extent( 1 ) ||
105 src_.extent( 2 ) != dst_.extent( 2 ) || src_.extent( 3 ) != dst_.extent( 3 ) )
107 throw std::runtime_error(
"VectorLaplace: src/dst mismatch" );
110 if ( src_.extent( 1 ) != grid_.extent( 1 ) || src_.extent( 2 ) != grid_.extent( 2 ) )
112 throw std::runtime_error(
"VectorLaplace: src/dst mismatch" );
115 util::Timer timer_kernel(
"vector_laplace_kernel" );
125 domain_, dst_, send_buffers_, recv_buffers_ );
130 KOKKOS_INLINE_FUNCTION
void
131 operator()(
const int local_subdomain_id,
const int x_cell,
const int y_cell,
const int r_cell )
const
138 const ScalarT r_1 = radii_( local_subdomain_id, r_cell );
139 const ScalarT r_2 = radii_( local_subdomain_id, r_cell + 1 );
145 ScalarT quad_weights[num_quad_points];
152 ScalarType src_local_hex[8][VecDim] = { { 0 } };
153 ScalarType dst_local_hex[8][VecDim] = { { 0 } };
155 for (
int i = 0; i < 8; i++ )
157 for (
int d = 0; d < VecDim; d++ )
159 constexpr int hex_offset_x[8] = { 0, 1, 0, 1, 0, 1, 0, 1 };
160 constexpr int hex_offset_y[8] = { 0, 0, 1, 1, 0, 0, 1, 1 };
161 constexpr int hex_offset_r[8] = { 0, 0, 0, 0, 1, 1, 1, 1 };
163 src_local_hex[i][d] = src_(
165 x_cell + hex_offset_x[i],
166 y_cell + hex_offset_y[i],
167 r_cell + hex_offset_r[i],
174 for (
int q = 0; q < num_quad_points; q++ )
176 const auto quad_point = quad_points[q];
177 const auto quad_weight = quad_weights[q];
181 const auto J =
jac( wedge_phy_surf[wedge], r_1, r_2, quad_points[q] );
182 const auto det = J.det();
183 const auto abs_det = Kokkos::abs( det );
184 const auto J_inv_transposed = J.inv_transposed( det );
190 grad_phy[k] = J_inv_transposed *
grad_shape( k, quad_point );
194 boundary_mask_data_( local_subdomain_id, x_cell, y_cell, r_cell ),
198 BoundaryConditionFlag bcf = get_boundary_condition_flag( bcs_, sbf );
202 diagonal( src_local_hex, dst_local_hex, wedge, quad_weight, abs_det, grad_phy );
204 else if ( sbf == CMB && bcf == DIRICHLET )
207 dirichlet_bot( src_local_hex, dst_local_hex, wedge, quad_weight, abs_det, grad_phy );
209 else if ( sbf == SURFACE && bcf == DIRICHLET )
212 dirichlet_top( src_local_hex, dst_local_hex, wedge, quad_weight, abs_det, grad_phy );
214 else if ( bcf == NEUMANN )
216 neumann( src_local_hex, dst_local_hex, wedge, quad_weight, abs_det, grad_phy );
220 Kokkos::abort(
"Unexpected." );
225 for (
int i = 0; i < 8; i++ )
227 for (
int d = 0; d < VecDim; d++ )
229 constexpr int hex_offset_x[8] = { 0, 1, 0, 1, 0, 1, 0, 1 };
230 constexpr int hex_offset_y[8] = { 0, 0, 1, 1, 0, 0, 1, 1 };
231 constexpr int hex_offset_r[8] = { 0, 0, 0, 0, 1, 1, 1, 1 };
236 x_cell + hex_offset_x[i],
237 y_cell + hex_offset_y[i],
238 r_cell + hex_offset_r[i],
240 dst_local_hex[i][d] );
253 constexpr int offset_x[2][6] = { { 0, 1, 0, 0, 1, 0 }, { 1, 0, 1, 1, 0, 1 } };
254 constexpr int offset_y[2][6] = { { 0, 0, 1, 0, 0, 1 }, { 1, 1, 0, 1, 1, 0 } };
255 constexpr int offset_r[2][6] = { { 0, 0, 0, 1, 1, 1 }, { 0, 0, 0, 1, 1, 1 } };
259 for (
int d = 0; d < VecDim; d++ )
261 grad_u[d].fill( 0.0 );
266 for (
int d = 0; d < VecDim; d++ )
269 grad_u[d] + src_local_hex[4 * offset_r[wedge][j] + 2 * offset_y[wedge][j] + offset_x[wedge][j]][d] *
277 for (
int d = 0; d < VecDim; d++ )
279 dst_local_hex[4 * offset_r[wedge][i] + 2 * offset_y[wedge][i] + offset_x[wedge][i]][d] +=
280 quad_weight * grad_phy[i].
dot( grad_u[d] ) * abs_det;
293 constexpr int offset_x[2][6] = { { 0, 1, 0, 0, 1, 0 }, { 1, 0, 1, 1, 0, 1 } };
294 constexpr int offset_y[2][6] = { { 0, 0, 1, 0, 0, 1 }, { 1, 1, 0, 1, 1, 0 } };
295 constexpr int offset_r[2][6] = { { 0, 0, 0, 1, 1, 1 }, { 0, 0, 0, 1, 1, 1 } };
299 for (
int d = 0; d < VecDim; d++ )
301 grad_u[d].fill( 0.0 );
306 for (
int d = 0; d < VecDim; d++ )
309 grad_u[d] + src_local_hex[4 * offset_r[wedge][j] + 2 * offset_y[wedge][j] + offset_x[wedge][j]][d] *
317 for (
int d = 0; d < VecDim; d++ )
319 dst_local_hex[4 * offset_r[wedge][i] + 2 * offset_y[wedge][i] + offset_x[wedge][i]][d] +=
320 quad_weight * grad_phy[i].
dot( grad_u[d] ) * abs_det;
325 for (
int i = 0; i < 3; i++ )
327 for (
int d = 0; d < VecDim; d++ )
329 const auto grad_u_diag =
330 src_local_hex[4 * offset_r[wedge][i] + 2 * offset_y[wedge][i] + offset_x[wedge][i]][d] *
333 dst_local_hex[4 * offset_r[wedge][i] + 2 * offset_y[wedge][i] + offset_x[wedge][i]][d] +=
334 quad_weight * grad_phy[i].
dot( grad_u_diag ) * abs_det;
347 constexpr int offset_x[2][6] = { { 0, 1, 0, 0, 1, 0 }, { 1, 0, 1, 1, 0, 1 } };
348 constexpr int offset_y[2][6] = { { 0, 0, 1, 0, 0, 1 }, { 1, 1, 0, 1, 1, 0 } };
349 constexpr int offset_r[2][6] = { { 0, 0, 0, 1, 1, 1 }, { 0, 0, 0, 1, 1, 1 } };
353 for (
int d = 0; d < VecDim; d++ )
355 grad_u[d].fill( 0.0 );
358 for (
int j = 0; j < 3; j++ )
360 for (
int d = 0; d < VecDim; d++ )
363 grad_u[d] + src_local_hex[4 * offset_r[wedge][j] + 2 * offset_y[wedge][j] + offset_x[wedge][j]][d] *
369 for (
int i = 0; i < 3; i++ )
371 for (
int d = 0; d < VecDim; d++ )
373 dst_local_hex[4 * offset_r[wedge][i] + 2 * offset_y[wedge][i] + offset_x[wedge][i]][d] +=
374 quad_weight * grad_phy[i].
dot( grad_u[d] ) * abs_det;
381 for (
int d = 0; d < VecDim; d++ )
383 const auto grad_u_diag =
384 src_local_hex[4 * offset_r[wedge][i] + 2 * offset_y[wedge][i] + offset_x[wedge][i]][d] *
387 dst_local_hex[4 * offset_r[wedge][i] + 2 * offset_y[wedge][i] + offset_x[wedge][i]][d] +=
388 quad_weight * grad_phy[i].
dot( grad_u_diag ) * abs_det;
401 constexpr int offset_x[2][6] = { { 0, 1, 0, 0, 1, 0 }, { 1, 0, 1, 1, 0, 1 } };
402 constexpr int offset_y[2][6] = { { 0, 0, 1, 0, 0, 1 }, { 1, 1, 0, 1, 1, 0 } };
403 constexpr int offset_r[2][6] = { { 0, 0, 0, 1, 1, 1 }, { 0, 0, 0, 1, 1, 1 } };
409 for (
int d = 0; d < VecDim; d++ )
412 src_local_hex[4 * offset_r[wedge][i] + 2 * offset_y[wedge][i] + offset_x[wedge][i]][d] *
415 dst_local_hex[4 * offset_r[wedge][i] + 2 * offset_y[wedge][i] + offset_x[wedge][i]][d] +=
416 quad_weight * grad_phy[i].
dot( grad_u ) * abs_det;
Send and receive buffers for all process-local subdomain boundaries.
Definition communication.hpp:56
Definition vector_laplace.hpp:33
VectorLaplace(const grid::shell::DistributedDomain &domain, const grid::Grid3DDataVec< ScalarT, 3 > &grid, const grid::Grid2DDataScalar< ScalarT > &radii, const grid::Grid4DDataScalar< grid::shell::ShellBoundaryFlag > &boundary_mask_data, BoundaryConditions bcs, bool diagonal, linalg::OperatorApplyMode operator_apply_mode=linalg::OperatorApplyMode::Replace, linalg::OperatorCommunicationMode operator_communication_mode=linalg::OperatorCommunicationMode::CommunicateAdditively)
Definition vector_laplace.hpp:59
void neumann(ScalarType src_local_hex[8][VecDim], ScalarType dst_local_hex[8][VecDim], const int wedge, const ScalarType quad_weight, const ScalarType abs_det, const dense::Vec< ScalarType, 3 > *grad_phy) const
Definition vector_laplace.hpp:245
void operator()(const int local_subdomain_id, const int x_cell, const int y_cell, const int r_cell) const
Definition vector_laplace.hpp:131
void dirichlet_bot(ScalarType src_local_hex[8][VecDim], ScalarType dst_local_hex[8][VecDim], const int wedge, const ScalarType quad_weight, const ScalarType abs_det, const dense::Vec< ScalarType, 3 > *grad_phy) const
Definition vector_laplace.hpp:285
void apply_impl(const SrcVectorType &src, DstVectorType &dst)
Definition vector_laplace.hpp:92
void set_operator_apply_and_communication_modes(const linalg::OperatorApplyMode operator_apply_mode, const linalg::OperatorCommunicationMode operator_communication_mode)
Definition vector_laplace.hpp:84
void diagonal(ScalarType src_local_hex[8][VecDim], ScalarType dst_local_hex[8][VecDim], const int wedge, const ScalarType quad_weight, const ScalarType abs_det, const dense::Vec< ScalarType, 3 > *grad_phy) const
Definition vector_laplace.hpp:393
void dirichlet_top(ScalarType src_local_hex[8][VecDim], ScalarType dst_local_hex[8][VecDim], const int wedge, const ScalarType quad_weight, const ScalarType abs_det, const dense::Vec< ScalarType, 3 > *grad_phy) const
Definition vector_laplace.hpp:339
ScalarT ScalarType
Definition vector_laplace.hpp:37
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
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 behave like linear operators.
Definition operator.hpp:57
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
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
constexpr int num_wedges_per_hex_cell
Definition kernel_helpers.hpp:5
constexpr int num_nodes_per_wedge
Definition kernel_helpers.hpp:7
constexpr dense::Vec< T, 3 > grad_shape(const int node_idx, const T xi, const T eta, const T zeta)
Gradient of the full shape function:
Definition integrands.hpp:228
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
BoundaryConditionMapping[2] BoundaryConditions
Definition shell/bit_masks.hpp:37
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
BoundaryConditionFlag
FlagLike that indicates the type of boundary condition
Definition shell/bit_masks.hpp:25
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.
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
T dot(const Vec &other) const
Definition vec.hpp:39