Skip to content

Commit

Permalink
Add periodicIndexSpace analogous to boundaryIndexSpace
Browse files Browse the repository at this point in the history
  • Loading branch information
streeve committed Aug 9, 2024
1 parent c8d2b71 commit 161c00e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
6 changes: 3 additions & 3 deletions grid/src/Cabana_Grid_LocalGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ class LocalGrid

private:
// Helper functions
zeroIndexSpace();
setupHaloWidthImpl( const int halo_width );
checkOffsets( const std::array<int, num_space_dim>& off_ijk );
auto zeroIndexSpace();
auto setupHaloWidth( const int halo_width );
void checkOffsets( const std::array<int, num_space_dim>& off_ijk );

template <class OwnedIndexSpace>
auto getBound( OwnedIndexSpace owned_space, const int upper_lower,
Expand Down
38 changes: 37 additions & 1 deletion grid/src/Cabana_Grid_LocalGrid_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ auto LocalGrid<MeshType>::setupHaloWidth( const int halo_width )
return hw;
}

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

//---------------------------------------------------------------------------//
// Given the relative offsets of a boundary relative to this local grid's
// indices get the set of local entity indices associated with that periodic
// boundary in the given decomposition. Optionally provide a halo width for the
// shared space. This halo width must be less than or equal to the halo width of
// the local grid. The default behavior is to use the halo width of the local
// grid. For example, if the Own decomposition is used, the interior entities
// that would be affected by a periodic boundary operation are provided whereas
// if the Ghost decomposition is used the halo entities on the boundary are
// provided.
template <class MeshType>
template <class DecompositionTag, class EntityType>
auto LocalGrid<MeshType>::periodicIndexSpace(
DecompositionTag t1, EntityType t2,
const std::array<int, num_space_dim>& off_ijk, const int halo_width ) const
-> IndexSpace<num_space_dim>
{
auto hw = setupHaloWidth( halo_width );
checkOffsets( off_ijk );

// Check to see if this is a periodic neighbor. If not, return a boundary
// space of size 0 because there is no periodic boundary.
bool periodic_ijk = true;
for ( std::size_t d = 0; d < num_space_dim; ++d )
if ( off_ijk[d] == 0 || !_global_grid->isPeriodic( d ) )
periodic_ijk = false;
if ( !periodic_ijk )
{
return zeroIndexSpace();
}

// Periodic spaces equivalent to boundary except determining whether this
// offset is valid (see above).
return boundaryIndexSpaceImpl( t1, t2, off_ijk, hw );
}

//---------------------------------------------------------------------------//
// Get the local index space of the owned cells.
template <class MeshType>
Expand Down

0 comments on commit 161c00e

Please sign in to comment.