Skip to content

Commit

Permalink
Fix halo test
Browse files Browse the repository at this point in the history
  • Loading branch information
streeve committed Sep 22, 2020
1 parent d519cc0 commit e322c43
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
3 changes: 2 additions & 1 deletion core/src/Cabana_ParticleGridCommunication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,10 @@ void getHaloIds( const LocalGridType &local_grid, CountView &send_count,

// Determine if this ghost particle needs to be
// shifted through the periodic boundary.
const std::array<int, 3> ijk = {i, j, k};
for ( int d = 0; d < 3; ++d )
{
if ( periodic[d] )
if ( periodic[d] && ijk[d] )
{
if ( pos[d] > global_high[d] )
shifts( sc, d ) -= global_extent[d];
Expand Down
40 changes: 30 additions & 10 deletions core/unit_test/tstParticleGridCommunication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ void testHalo( const int halo_width, const int test_type )
Cajita::UniformDimPartitioner partitioner;

// Create the global MPI decomposition mesh.
std::array<double, 3> lo_corner = {0, 0, 0};
std::array<double, 3> hi_corner = {1, 1, 1};
std::array<double, 3> lo_corner = {-3.2, -0.5, 2.2};
std::array<double, 3> hi_corner = {-0.2, 5.9, 4.2};
std::array<int, 3> num_cell = {10, 10, 10};
auto global_mesh =
Cajita::createUniformGlobalMesh( lo_corner, hi_corner, num_cell );
Expand Down Expand Up @@ -325,9 +325,9 @@ void testHalo( const int halo_width, const int test_type )
auto ghost_x = halo_width * dx;
auto ghost_y = halo_width * dy;
auto ghost_z = halo_width * dz;
auto hi_x = local_mesh.highCorner( Cajita::Ghost(), Cajita::Dim::I );
auto hi_y = local_mesh.highCorner( Cajita::Ghost(), Cajita::Dim::J );
auto hi_z = local_mesh.highCorner( Cajita::Ghost(), Cajita::Dim::K );
auto hi_x = local_mesh.highCorner( Cajita::Own(), Cajita::Dim::I );
auto hi_y = local_mesh.highCorner( Cajita::Own(), Cajita::Dim::J );
auto hi_z = local_mesh.highCorner( Cajita::Own(), Cajita::Dim::K );

// Make sure owned particles haven't changed.
for ( int i = 0; i < local_num_data; ++i )
Expand All @@ -341,37 +341,57 @@ void testHalo( const int halo_width, const int test_type )
}
for ( int i = local_num_data; i < new_num_data; ++i )
{
bool within_x = true;
bool within_y = true;
bool within_z = true;
// Make sure all ghosts are in halo region in at least one direction.
if ( pos_host( i, Cajita::Dim::I ) < lo_x )
{
EXPECT_LE( pos_host( i, Cajita::Dim::I ), lo_x );
EXPECT_GE( pos_host( i, Cajita::Dim::I ), lo_x - ghost_x );
}
else if ( pos_host( i, Cajita::Dim::I ) < hi_x )
else if ( pos_host( i, Cajita::Dim::I ) > hi_x )
{

EXPECT_GE( pos_host( i, Cajita::Dim::I ), hi_x );
EXPECT_LE( pos_host( i, Cajita::Dim::I ), hi_x + ghost_x );
}
else if ( pos_host( i, Cajita::Dim::J ) < lo_y )
else
{
within_x = false;
}
if ( pos_host( i, Cajita::Dim::J ) < lo_y )
{
EXPECT_LE( pos_host( i, Cajita::Dim::J ), lo_y );
EXPECT_GE( pos_host( i, Cajita::Dim::J ), lo_y - ghost_y );
}
else if ( pos_host( i, Cajita::Dim::J ) < hi_y )
else if ( pos_host( i, Cajita::Dim::J ) > hi_y )
{
EXPECT_GE( pos_host( i, Cajita::Dim::J ), hi_y );
EXPECT_LE( pos_host( i, Cajita::Dim::J ), hi_y + ghost_y );
}
else if ( pos_host( i, Cajita::Dim::K ) < lo_z )
else
{
within_y = false;
}
if ( pos_host( i, Cajita::Dim::K ) < lo_z )
{
EXPECT_LE( pos_host( i, Cajita::Dim::K ), lo_z );
EXPECT_GE( pos_host( i, Cajita::Dim::K ), lo_z - ghost_z );
}
else if ( pos_host( i, Cajita::Dim::K ) < hi_z )
else if ( pos_host( i, Cajita::Dim::K ) > hi_z )
{
EXPECT_GE( pos_host( i, Cajita::Dim::K ), hi_z );
EXPECT_LE( pos_host( i, Cajita::Dim::K ), hi_z + ghost_z );
}
else
{
within_z = false;
}
if ( !within_x && !within_y && !within_z )
{
FAIL() << "Ghost particle outside ghost region.";
}
}

// TODO: check number of ghosts created.
Expand Down

0 comments on commit e322c43

Please sign in to comment.