Skip to content

Commit 161c00e

Browse files
committed
Add periodicIndexSpace analogous to boundaryIndexSpace
1 parent c8d2b71 commit 161c00e

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

grid/src/Cabana_Grid_LocalGrid.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ class LocalGrid
254254

255255
private:
256256
// Helper functions
257-
zeroIndexSpace();
258-
setupHaloWidthImpl( const int halo_width );
259-
checkOffsets( const std::array<int, num_space_dim>& off_ijk );
257+
auto zeroIndexSpace();
258+
auto setupHaloWidth( const int halo_width );
259+
void checkOffsets( const std::array<int, num_space_dim>& off_ijk );
260260

261261
template <class OwnedIndexSpace>
262262
auto getBound( OwnedIndexSpace owned_space, const int upper_lower,

grid/src/Cabana_Grid_LocalGrid_impl.hpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ auto LocalGrid<MeshType>::setupHaloWidth( const int halo_width )
116116
return hw;
117117
}
118118

119-
auto LocalGrid<MeshType>::checkOffsets(
119+
void LocalGrid<MeshType>::checkOffsets(
120120
const std::array<int, num_space_dim>& off_ijk )
121121
{
122122
// Check that the offsets are valid.
@@ -238,6 +238,42 @@ LocalGrid<MeshType>::boundaryIndexSpace( DecompositionTag t1, EntityType t2,
238238
return boundaryIndexSpace( t1, t2, off_ijk, halo_width );
239239
}
240240

241+
//---------------------------------------------------------------------------//
242+
// Given the relative offsets of a boundary relative to this local grid's
243+
// indices get the set of local entity indices associated with that periodic
244+
// boundary in the given decomposition. Optionally provide a halo width for the
245+
// shared space. This halo width must be less than or equal to the halo width of
246+
// the local grid. The default behavior is to use the halo width of the local
247+
// grid. For example, if the Own decomposition is used, the interior entities
248+
// that would be affected by a periodic boundary operation are provided whereas
249+
// if the Ghost decomposition is used the halo entities on the boundary are
250+
// provided.
251+
template <class MeshType>
252+
template <class DecompositionTag, class EntityType>
253+
auto LocalGrid<MeshType>::periodicIndexSpace(
254+
DecompositionTag t1, EntityType t2,
255+
const std::array<int, num_space_dim>& off_ijk, const int halo_width ) const
256+
-> IndexSpace<num_space_dim>
257+
{
258+
auto hw = setupHaloWidth( halo_width );
259+
checkOffsets( off_ijk );
260+
261+
// Check to see if this is a periodic neighbor. If not, return a boundary
262+
// space of size 0 because there is no periodic boundary.
263+
bool periodic_ijk = true;
264+
for ( std::size_t d = 0; d < num_space_dim; ++d )
265+
if ( off_ijk[d] == 0 || !_global_grid->isPeriodic( d ) )
266+
periodic_ijk = false;
267+
if ( !periodic_ijk )
268+
{
269+
return zeroIndexSpace();
270+
}
271+
272+
// Periodic spaces equivalent to boundary except determining whether this
273+
// offset is valid (see above).
274+
return boundaryIndexSpaceImpl( t1, t2, off_ijk, hw );
275+
}
276+
241277
//---------------------------------------------------------------------------//
242278
// Get the local index space of the owned cells.
243279
template <class MeshType>

0 commit comments

Comments
 (0)