15template <
typename ScalarT >
25 bool storeLMatrices_ =
27 bool applyStoredLMatrices_ =
45 : grid_fine_( grid_fine )
46 , radii_fine_( radii_fine )
47 , operator_apply_mode_( operator_apply_mode )
52 if ( storeLMatrices_ or applyStoredLMatrices_ )
53 assert( LMatrices_.data() !=
nullptr );
63 if ( dst_.extent( 1 ) != grid_fine_.extent( 1 ) )
65 throw std::runtime_error(
66 "Prolongation: dst and grid_fine must have the same number of cells in the x direction." );
69 if ( dst_.extent( 3 ) != radii_fine_.extent( 1 ) )
71 throw std::runtime_error(
72 "Prolongation: dst and radii_fine must have the same number of cells in the r direction." );
75 if ( src_.extent( 0 ) != dst_.extent( 0 ) )
77 throw std::runtime_error(
"Prolongation: src and dst must have the same number of subdomains." );
80 for (
int i = 1; i <= 3; i++ )
82 if ( 2 * ( src_.extent( i ) - 1 ) != dst_.extent( i ) - 1 )
84 throw std::runtime_error(
"Prolongation: src and dst must have a compatible number of cells." );
91 Kokkos::MDRangePolicy< Kokkos::Rank< 4 > >(
104 KOKKOS_INLINE_FUNCTION
void
105 operator()(
const int local_subdomain_id,
const int x_fine,
const int y_fine,
const int r_fine )
const
108 (void) fine_hex_fine;
110 if ( x_fine % 2 == 0 && y_fine % 2 == 0 && r_fine % 2 == 0 )
112 const auto x_coarse = x_fine / 2;
113 const auto y_coarse = y_fine / 2;
114 const auto r_coarse = r_fine / 2;
116 dst_( local_subdomain_id, x_fine, y_fine, r_fine ) +=
117 src_( local_subdomain_id, x_coarse, y_coarse, r_coarse );
122 const auto r_coarse_bot = r_fine < dst_.extent( 3 ) - 1 ? r_fine / 2 : r_fine / 2 - 1;
123 const auto r_coarse_top = r_coarse_bot + 1;
125 if ( x_fine % 2 == 0 && y_fine % 2 == 0 )
127 const auto x_coarse = x_fine / 2;
128 const auto y_coarse = y_fine / 2;
136 dst_( local_subdomain_id, x_fine, y_fine, r_fine ) +=
137 weights( 0 ) * src_( local_subdomain_id, x_coarse, y_coarse, r_coarse_bot ) +
138 weights( 1 ) * src_( local_subdomain_id, x_coarse, y_coarse, r_coarse_top );
149 if ( x_fine % 2 == 0 )
152 x_coarse_0 = x_fine / 2;
153 x_coarse_1 = x_fine / 2;
155 y_coarse_0 = y_fine / 2;
156 y_coarse_1 = y_fine / 2 + 1;
158 else if ( y_fine % 2 == 0 )
161 x_coarse_0 = x_fine / 2;
162 x_coarse_1 = x_fine / 2 + 1;
164 y_coarse_0 = y_fine / 2;
165 y_coarse_1 = y_fine / 2;
170 x_coarse_0 = x_fine / 2 + 1;
171 x_coarse_1 = x_fine / 2;
173 y_coarse_0 = y_fine / 2;
174 y_coarse_1 = y_fine / 2 + 1;
184 dst_( local_subdomain_id, x_fine, y_fine, r_fine ) +=
185 weights( 0 ) * src_( local_subdomain_id, x_coarse_0, y_coarse_0, r_coarse_bot ) +
186 weights( 0 ) * src_( local_subdomain_id, x_coarse_1, y_coarse_1, r_coarse_bot ) +
187 weights( 1 ) * src_( local_subdomain_id, x_coarse_0, y_coarse_0, r_coarse_top ) +
188 weights( 1 ) * src_( local_subdomain_id, x_coarse_1, y_coarse_1, r_coarse_top );
192template <
typename ScalarT >
202 bool storeLMatrices_ =
204 bool applyStoredLMatrices_ =
222 : grid_fine_( grid_fine )
223 , radii_fine_( radii_fine )
224 , operator_apply_mode_( operator_apply_mode )
229 if ( storeLMatrices_ or applyStoredLMatrices_ )
230 assert( LMatrices_.data() !=
nullptr );
240 if ( dst_.extent( 1 ) != grid_fine_.extent( 1 ) )
242 throw std::runtime_error(
243 "Prolongation: dst and grid_fine must have the same number of cells in the x direction." );
246 if ( dst_.extent( 3 ) != radii_fine_.extent( 1 ) )
248 throw std::runtime_error(
249 "Prolongation: dst and radii_fine must have the same number of cells in the r direction." );
252 if ( src_.extent( 0 ) != dst_.extent( 0 ) )
254 throw std::runtime_error(
"Prolongation: src and dst must have the same number of subdomains." );
257 for (
int i = 1; i <= 3; i++ )
259 if ( 2 * ( src_.extent( i ) - 1 ) != dst_.extent( i ) - 1 )
261 throw std::runtime_error(
"Prolongation: src and dst must have a compatible number of cells." );
266 Kokkos::parallel_for(
268 Kokkos::MDRangePolicy< Kokkos::Rank< 4 > >(
281 KOKKOS_INLINE_FUNCTION
void
282 operator()(
const int local_subdomain_id,
const int x_fine,
const int y_fine,
const int r_fine )
const
284 for (
int dim = 0; dim < 3; ++dim )
287 (void) fine_hex_fine;
289 if ( x_fine % 2 == 0 && y_fine % 2 == 0 && r_fine % 2 == 0 )
291 const auto x_coarse = x_fine / 2;
292 const auto y_coarse = y_fine / 2;
293 const auto r_coarse = r_fine / 2;
295 dst_( local_subdomain_id, x_fine, y_fine, r_fine, dim ) +=
296 src_( local_subdomain_id, x_coarse, y_coarse, r_coarse, dim );
301 const auto r_coarse_bot = r_fine < dst_.extent( 3 ) - 1 ? r_fine / 2 : r_fine / 2 - 1;
302 const auto r_coarse_top = r_coarse_bot + 1;
304 if ( x_fine % 2 == 0 && y_fine % 2 == 0 )
306 const auto x_coarse = x_fine / 2;
307 const auto y_coarse = y_fine / 2;
315 dst_( local_subdomain_id, x_fine, y_fine, r_fine, dim ) +=
316 weights( 0 ) * src_( local_subdomain_id, x_coarse, y_coarse, r_coarse_bot, dim ) +
317 weights( 1 ) * src_( local_subdomain_id, x_coarse, y_coarse, r_coarse_top, dim );
328 if ( x_fine % 2 == 0 )
331 x_coarse_0 = x_fine / 2;
332 x_coarse_1 = x_fine / 2;
334 y_coarse_0 = y_fine / 2;
335 y_coarse_1 = y_fine / 2 + 1;
337 else if ( y_fine % 2 == 0 )
340 x_coarse_0 = x_fine / 2;
341 x_coarse_1 = x_fine / 2 + 1;
343 y_coarse_0 = y_fine / 2;
344 y_coarse_1 = y_fine / 2;
349 x_coarse_0 = x_fine / 2 + 1;
350 x_coarse_1 = x_fine / 2;
352 y_coarse_0 = y_fine / 2;
353 y_coarse_1 = y_fine / 2 + 1;
363 dst_( local_subdomain_id, x_fine, y_fine, r_fine, dim ) +=
364 weights( 0 ) * src_( local_subdomain_id, x_coarse_0, y_coarse_0, r_coarse_bot, dim ) +
365 weights( 0 ) * src_( local_subdomain_id, x_coarse_1, y_coarse_1, r_coarse_bot, dim ) +
366 weights( 1 ) * src_( local_subdomain_id, x_coarse_0, y_coarse_0, r_coarse_top, dim ) +
367 weights( 1 ) * src_( local_subdomain_id, x_coarse_1, y_coarse_1, r_coarse_top, dim );
Definition prolongation_linear.hpp:17
void operator()(const int local_subdomain_id, const int x_fine, const int y_fine, const int r_fine) const
Definition prolongation_linear.hpp:105
void apply_impl(const SrcVectorType &src, DstVectorType &dst)
Definition prolongation_linear.hpp:50
ScalarT ScalarType
Definition prolongation_linear.hpp:21
terra::grid::Grid4DDataMatrices< ScalarType, 6, 6, 2 > Grid4DDataLocalMatrices
Definition prolongation_linear.hpp:22
ProlongationLinear(const grid::Grid3DDataVec< ScalarType, 3 > &grid_fine, const grid::Grid2DDataScalar< ScalarType > &radii_fine, linalg::OperatorApplyMode operator_apply_mode=linalg::OperatorApplyMode::Replace)
Definition prolongation_linear.hpp:41
Definition prolongation_linear.hpp:194
void apply_impl(const SrcVectorType &src, DstVectorType &dst)
Definition prolongation_linear.hpp:227
ScalarT ScalarType
Definition prolongation_linear.hpp:198
terra::grid::Grid4DDataMatrices< ScalarType, 6, 6, 2 > Grid4DDataLocalMatrices
Definition prolongation_linear.hpp:199
ProlongationVecLinear(const grid::Grid3DDataVec< ScalarType, 3 > &grid_fine, const grid::Grid2DDataScalar< ScalarType > &radii_fine, linalg::OperatorApplyMode operator_apply_mode=linalg::OperatorApplyMode::Replace)
Definition prolongation_linear.hpp:218
void operator()(const int local_subdomain_id, const int x_fine, const int y_fine, const int r_fine) const
Definition prolongation_linear.hpp:282
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
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
Definition boundary_mass.hpp:14
constexpr dense::Vec< ScalarType, 2 > prolongation_linear_weights(const dense::Vec< int, 4 > &idx_fine, const dense::Vec< int, 4 > &idx_coarse_bot, const grid::Grid3DDataVec< ScalarType, 3 > &subdomain_shell_coords_fine, const grid::Grid2DDataScalar< ScalarType > subdomain_radii_fine)
Computes prolongation weights for the spherical shell.
Definition grid_transfer_linear.hpp:14
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.