4#include "../../quadrature/quadrature.hpp"
17template <
typename ScalarT >
28 bool storeLMatrices_ =
30 bool applyStoredLMatrices_ =
33 bool single_quadpoint_ =
false;
74 , treat_boundary_( treat_boundary )
75 , diagonal_( diagonal )
76 , operator_apply_mode_( operator_apply_mode )
77 , operator_communication_mode_( operator_communication_mode )
79 , send_buffers_( domain )
80 , recv_buffers_( domain )
104 KOKKOS_INLINE_FUNCTION
106 const int local_subdomain_id,
112 assert( lmatrices_.data() !=
nullptr );
114 return lmatrices_( local_subdomain_id, x_cell, y_cell, r_cell, wedge );
118 KOKKOS_INLINE_FUNCTION
120 const int local_subdomain_id,
126 { Kokkos::abort(
"Not implemented." ); }
137 storeLMatrices_ =
true;
138 if ( lmatrices_.data() ==
nullptr )
141 "LaplaceSimple::lmatrices_",
146 Kokkos::parallel_for(
150 storeLMatrices_ =
false;
151 applyStoredLMatrices_ =
true;
156 if ( storeLMatrices_ or applyStoredLMatrices_ )
157 assert( lmatrices_.data() !=
nullptr );
167 if ( src_.extent( 0 ) != dst_.extent( 0 ) || src_.extent( 1 ) != dst_.extent( 1 ) ||
168 src_.extent( 2 ) != dst_.extent( 2 ) || src_.extent( 3 ) != dst_.extent( 3 ) )
170 throw std::runtime_error(
"LaplaceSimple: src/dst mismatch" );
173 if ( src_.extent( 1 ) != grid_.extent( 1 ) || src_.extent( 2 ) != grid_.extent( 2 ) )
175 throw std::runtime_error(
"LaplaceSimple: src/dst mismatch" );
183 domain_, dst_, send_buffers_, recv_buffers_ );
188 KOKKOS_INLINE_FUNCTION
void
189 operator()(
const int local_subdomain_id,
const int x_cell,
const int y_cell,
const int r_cell )
const
192 if ( !applyStoredLMatrices_ )
199 const ScalarT r_1 = radii_( local_subdomain_id, r_cell );
200 const ScalarT r_2 = radii_( local_subdomain_id, r_cell + 1 );
211 for (
int q = 0; q < num_quad_points; q++ )
213 const auto w = single_quadpoint_ ? quad_weights_1x1_[q] : quad_weights_3x2_[q];
214 const auto qp = single_quadpoint_ ? quad_points_1x1_[q] : quad_points_3x2_[q];
218 const auto J =
jac( wedge_phy_surf[wedge], r_1, r_2, qp );
219 const auto det = Kokkos::abs( J.det() );
220 const auto J_inv_transposed = J.inv().transposed();
224 k_eval +=
shape( j, qp ) * k[wedge]( j );
236 w * k_eval * ( ( J_inv_transposed * grad_i ).dot( J_inv_transposed * grad_j ) * det );
242 if ( treat_boundary_ )
247 boundary_mask.
fill( 1.0 );
251 for (
int i = 0; i < 6; i++ )
253 for (
int j = 0; j < 6; j++ )
255 if ( i != j && ( i < 3 || j < 3 ) )
257 boundary_mask( i, j ) = 0.0;
263 if ( r_cell + 1 == radii_.extent( 1 ) - 1 )
266 for (
int i = 0; i < 6; i++ )
268 for (
int j = 0; j < 6; j++ )
270 if ( i != j && ( i >= 3 || j >= 3 ) )
272 boundary_mask( i, j ) = 0.0;
285 A[0] = lmatrices_( local_subdomain_id, x_cell, y_cell, r_cell, 0 );
286 A[1] = lmatrices_( local_subdomain_id, x_cell, y_cell, r_cell, 1 );
295 if ( storeLMatrices_ )
298 lmatrices_( local_subdomain_id, x_cell, y_cell, r_cell, 0 ) = A[0];
299 lmatrices_( local_subdomain_id, x_cell, y_cell, r_cell, 1 ) = A[1];
309 dst[0] = A[0] * src[0];
310 dst[1] = A[1] * src[1];
Definition div_k_grad_simple.hpp:19
void operator()(const int local_subdomain_id, const int x_cell, const int y_cell, const int r_cell) const
Definition div_k_grad_simple.hpp:189
grid::Grid3DDataVec< ScalarT, 3 > get_grid() const
Getter for grid member.
Definition div_k_grad_simple.hpp:95
void setApplyStoredLMatrices(bool v)
Setter/Getter for app applyStoredLMatrices_: usage of stored local matrices during apply.
Definition div_k_grad_simple.hpp:129
const grid::shell::DistributedDomain & get_domain() const
Getter for domain member.
Definition div_k_grad_simple.hpp:89
void store_lmatrices()
allocates memory for the local matrices calls kernel with storeLMatrices_ = true to assemble and stor...
Definition div_k_grad_simple.hpp:135
void set_single_quadpoint(bool v)
S/Getter for quadpoint member.
Definition div_k_grad_simple.hpp:101
grid::Grid2DDataScalar< ScalarT > get_radii() const
Getter for radii member.
Definition div_k_grad_simple.hpp:92
dense::Mat< ScalarT, 6, 6 > get_local_matrix(const int local_subdomain_id, const int x_cell, const int y_cell, const int r_cell, const int wedge)
Retrives the local matrix stored in the operator.
Definition div_k_grad_simple.hpp:105
DivKGradSimple(const grid::shell::DistributedDomain &domain, const grid::Grid3DDataVec< ScalarT, 3 > &grid, const grid::Grid2DDataScalar< ScalarT > &radii, const grid::Grid4DDataScalar< ScalarType > &k, bool treat_boundary, bool diagonal, linalg::OperatorApplyMode operator_apply_mode=linalg::OperatorApplyMode::Replace, linalg::OperatorCommunicationMode operator_communication_mode=linalg::OperatorCommunicationMode::CommunicateAdditively)
Definition div_k_grad_simple.hpp:60
ScalarT ScalarType
Definition div_k_grad_simple.hpp:23
void set_diagonal(bool v)
S/Getter for diagonal member.
Definition div_k_grad_simple.hpp:98
terra::grid::Grid4DDataMatrices< ScalarType, 6, 6, 2 > Grid4DDataLocalMatrices
Definition div_k_grad_simple.hpp:24
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 div_k_grad_simple.hpp:119
void apply_impl(const SrcVectorType &src, DstVectorType &dst)
Definition div_k_grad_simple.hpp:154
static constexpr int LocalMatrixDim
Definition div_k_grad_simple.hpp:25
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
Q1 scalar finite element vector on a distributed shell grid.
Definition vector_q1.hpp:21
const grid::Grid4DDataScalar< ScalarType > & grid_data() const
Get const reference to grid data.
Definition vector_q1.hpp:137
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 void quad_felippa_1x1_quad_points(dense::Vec< T, 3 >(&quad_points)[quad_felippa_1x1_num_quad_points])
Definition wedge/quadrature/quadrature.hpp:36
constexpr void quad_felippa_1x1_quad_weights(T(&quad_weights)[quad_felippa_1x1_num_quad_points])
Definition wedge/quadrature/quadrature.hpp:43
constexpr int quad_felippa_1x1_num_quad_points
Definition wedge/quadrature/quadrature.hpp:32
constexpr int num_nodes_per_wedge_surface
Definition kernel_helpers.hpp:6
void atomically_add_local_wedge_scalar_coefficients(const grid::Grid4DDataScalar< T > &global_coefficients, const int local_subdomain_id, const int x_cell, const int y_cell, const int r_cell, 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:407
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
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
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 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
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 ****, 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.
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