Skip to content

Commit

Permalink
Merge pull request #772 from streeve/fixup_rename_particlegrid
Browse files Browse the repository at this point in the history
Simplify naming of particle migration through grid
  • Loading branch information
streeve authored Sep 16, 2024
2 parents 38e9378 + 5f17f67 commit 0c37ccb
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 52 deletions.
2 changes: 1 addition & 1 deletion grid/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ set(HEADERS_PUBLIC
Cabana_Grid_LocalMesh.hpp
Cabana_Grid_MpiTraits.hpp
Cabana_Grid_Parallel.hpp
Cabana_Grid_ParticleGridDistributor.hpp
Cabana_Grid_ParticleDistributor.hpp
Cabana_Grid_ParticleInit.hpp
Cabana_Grid_ParticleList.hpp
Cabana_Grid_Partitioner.hpp
Expand Down
2 changes: 1 addition & 1 deletion grid/src/Cabana_Grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <Cabana_Grid_LocalMesh.hpp>
#include <Cabana_Grid_MpiTraits.hpp>
#include <Cabana_Grid_Parallel.hpp>
#include <Cabana_Grid_ParticleGridDistributor.hpp>
#include <Cabana_Grid_ParticleDistributor.hpp>
#include <Cabana_Grid_ParticleInit.hpp>
#include <Cabana_Grid_ParticleList.hpp>
#include <Cabana_Grid_Partitioner.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
****************************************************************************/

/*!
\file Cabana_Grid_ParticleGridDistributor.hpp
\file Cabana_Grid_ParticleDistributor.hpp
\brief Multi-node particle redistribution using the grid halo.
*/
#ifndef CABANA_PARTICLEGRIDDISTRIBUTOR_HPP
Expand Down Expand Up @@ -239,8 +239,8 @@ int migrateCount( const LocalGridType& local_grid,
*/
template <class LocalGridType, class PositionSliceType>
Cabana::Distributor<typename PositionSliceType::memory_space>
createParticleGridDistributor( const LocalGridType& local_grid,
PositionSliceType& positions )
createParticleDistributor( const LocalGridType& local_grid,
PositionSliceType& positions )
{
using memory_space = typename PositionSliceType::memory_space;

Expand Down Expand Up @@ -286,11 +286,10 @@ createParticleGridDistributor( const LocalGridType& local_grid,
\return Whether any particle migration occurred.
*/
template <class LocalGridType, class ParticlePositions, class ParticleContainer>
bool particleGridMigrate( const LocalGridType& local_grid,
const ParticlePositions& positions,
ParticleContainer& particles,
const int min_halo_width,
const bool force_migrate = false )
bool particleMigrate( const LocalGridType& local_grid,
const ParticlePositions& positions,
ParticleContainer& particles, const int min_halo_width,
const bool force_migrate = false )
{
// When false, this option checks that any particles are nearly outside the
// ghosted halo region (outside the min_halo_width) before initiating
Expand All @@ -306,7 +305,7 @@ bool particleGridMigrate( const LocalGridType& local_grid,
return false;
}

auto distributor = createParticleGridDistributor( local_grid, positions );
auto distributor = createParticleDistributor( local_grid, positions );

// Redistribute the particles.
migrate( distributor, particles );
Expand Down Expand Up @@ -335,12 +334,12 @@ bool particleGridMigrate( const LocalGridType& local_grid,
\return Whether any particle migration occurred.
*/
template <class LocalGridType, class ParticlePositions, class ParticleContainer>
bool particleGridMigrate( const LocalGridType& local_grid,
const ParticlePositions& positions,
const ParticleContainer& src_particles,
ParticleContainer& dst_particles,
const int min_halo_width,
const bool force_migrate = false )
bool particleMigrate( const LocalGridType& local_grid,
const ParticlePositions& positions,
const ParticleContainer& src_particles,
ParticleContainer& dst_particles,
const int min_halo_width,
const bool force_migrate = false )
{
// When false, this option checks that any particles are nearly outside the
// ghosted halo region (outside the min_halo_width) before initiating
Expand All @@ -359,7 +358,7 @@ bool particleGridMigrate( const LocalGridType& local_grid,
}
}

auto distributor = createParticleGridDistributor( local_grid, positions );
auto distributor = createParticleDistributor( local_grid, positions );

// Resize as needed.
dst_particles.resize( distributor.totalNumImport() );
Expand All @@ -369,6 +368,28 @@ bool particleGridMigrate( const LocalGridType& local_grid,
return true;
}

//! \cond Deprecated
template <class... Args>
[[deprecated( "Cabana::Grid::particleGridMigrate is now "
"Cabana::Grid::particleMigrate. This function wrapper will be "
"removed in a future release." )]] void
particleGridMigrate( Args&&... args )
{
return Cabana::Grid::particleMigrate( std::forward<Args>( args )... );
}

template <class... Args>
[[deprecated(
"Cabana::Grid::createParticleGridDistributor is now "
"Cabana::Grid::createParticleDistributor. This function wrapper will be "
"removed in a future release." )]] void
createParticleGridDistributor( Args&&... args )
{
return Cabana::Grid::createParticleDistributor(
std::forward<Args>( args )... );
}
//! \endcond

} // namespace Grid
} // namespace Cabana

Expand Down
8 changes: 4 additions & 4 deletions grid/src/Cabana_Grid_ParticleList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <Cabana_Tuple.hpp>
#include <Cabana_Utils.hpp> // FIXME: remove after next release.

#include <Cabana_Grid_ParticleGridDistributor.hpp>
#include <Cabana_Grid_ParticleDistributor.hpp>

#include <memory>
#include <string>
Expand Down Expand Up @@ -91,9 +91,9 @@ class ParticleList
bool redistribute( const LocalGridType& local_grid, PositionFieldTag,
const bool force_redistribute = false )
{
return particleGridMigrate(
local_grid, this->slice( PositionFieldTag() ), _aosoa,
local_grid.haloCellWidth(), force_redistribute );
return particleMigrate( local_grid, this->slice( PositionFieldTag() ),
_aosoa, local_grid.haloCellWidth(),
force_redistribute );
}

protected:
Expand Down
4 changes: 2 additions & 2 deletions grid/unit_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ set(MPI_TESTS
Halo3d
Halo2d
ParticleInit
ParticleGridDistributor2d
ParticleGridDistributor3d
ParticleDistributor2d
ParticleDistributor3d
SplineEvaluation3d
SplineEvaluation2d
Interpolation3d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <Cabana_Grid_GlobalMesh.hpp>
#include <Cabana_Grid_LocalGrid.hpp>
#include <Cabana_Grid_LocalMesh.hpp>
#include <Cabana_Grid_ParticleGridDistributor.hpp>
#include <Cabana_Grid_ParticleDistributor.hpp>
#include <Cabana_Grid_Partitioner.hpp>
#include <Cabana_Grid_Types.hpp>

Expand Down Expand Up @@ -109,9 +109,8 @@ void migrateTest( const GridType global_grid, const double cell_size,
// Redistribute the particle AoSoA in place.
if ( test_type == 0 )
{
Cabana::Grid::particleGridMigrate( *block, coords_mirror,
particles_mirror, test_halo_size,
force_comm );
Cabana::Grid::particleMigrate( *block, coords_mirror, particles_mirror,
test_halo_size, force_comm );

// Copy back to check.
particles = Cabana::create_mirror_view_and_copy( Kokkos::HostSpace(),
Expand All @@ -122,9 +121,9 @@ void migrateTest( const GridType global_grid, const double cell_size,
{
auto particles_dst =
Cabana::create_mirror_view( TEST_MEMSPACE(), particles_mirror );
Cabana::Grid::particleGridMigrate( *block, coords_mirror,
particles_mirror, particles_dst,
test_halo_size, force_comm );
Cabana::Grid::particleMigrate( *block, coords_mirror, particles_mirror,
particles_dst, test_halo_size,
force_comm );
// Copy back to check.
particles = Cabana::create_mirror_view_and_copy( Kokkos::HostSpace(),
particles_dst );
Expand Down Expand Up @@ -220,8 +219,8 @@ void localOnlyTest( const GridType global_grid, const double cell_size )

// Redistribute the particles.
auto coords_mirror = Cabana::slice<0>( particles_mirror, "coords" );
Cabana::Grid::particleGridMigrate( *block, coords_mirror, particles_mirror,
0, true );
Cabana::Grid::particleMigrate( *block, coords_mirror, particles_mirror, 0,
true );

// Copy back to check.
particles = Cabana::create_mirror_view_and_copy( Kokkos::HostSpace(),
Expand Down Expand Up @@ -319,8 +318,8 @@ void removeOutsideTest( const GridType global_grid )

// Redistribute the particles.
auto coords_mirror = Cabana::slice<0>( particles_mirror, "coords" );
Cabana::Grid::particleGridMigrate( *block, coords_mirror, particles_mirror,
0, true );
Cabana::Grid::particleMigrate( *block, coords_mirror, particles_mirror, 0,
true );

// Check that all particles were removed.
EXPECT_EQ( particles_mirror.size(), 0 );
Expand All @@ -343,7 +342,7 @@ auto createGrid( const Cabana::Grid::ManualBlockPartitioner<2>& partitioner,
return global_grid;
}

void testParticleGridMigrate( const bool periodic )
void testParticleMigrate( const bool periodic )
{
// Let MPI compute the partitioning for this test.
int comm_size;
Expand Down Expand Up @@ -385,10 +384,10 @@ void testParticleGridMigrate( const bool periodic )
//---------------------------------------------------------------------------//
// RUN TESTS
//---------------------------------------------------------------------------//
TEST( TEST_CATEGORY, not_periodic_test ) { testParticleGridMigrate( false ); }
TEST( TEST_CATEGORY, not_periodic_test ) { testParticleMigrate( false ); }

//---------------------------------------------------------------------------//
TEST( TEST_CATEGORY, periodic_test ) { testParticleGridMigrate( true ); }
TEST( TEST_CATEGORY, periodic_test ) { testParticleMigrate( true ); }

//---------------------------------------------------------------------------//
TEST( TEST_CATEGORY, local_only_test )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <Cabana_Grid_GlobalMesh.hpp>
#include <Cabana_Grid_LocalGrid.hpp>
#include <Cabana_Grid_LocalMesh.hpp>
#include <Cabana_Grid_ParticleGridDistributor.hpp>
#include <Cabana_Grid_ParticleDistributor.hpp>
#include <Cabana_Grid_Partitioner.hpp>
#include <Cabana_Grid_Types.hpp>

Expand Down Expand Up @@ -117,9 +117,8 @@ void migrateTest( const GridType global_grid, const double cell_size,
// Redistribute the particle AoSoA in place.
if ( test_type == 0 )
{
Cabana::Grid::particleGridMigrate( *block, coords_mirror,
particles_mirror, test_halo_size,
force_comm );
Cabana::Grid::particleMigrate( *block, coords_mirror, particles_mirror,
test_halo_size, force_comm );

// Copy back to check.
particles = Cabana::create_mirror_view_and_copy( Kokkos::HostSpace(),
Expand All @@ -130,9 +129,9 @@ void migrateTest( const GridType global_grid, const double cell_size,
{
auto particles_dst =
Cabana::create_mirror_view( TEST_MEMSPACE(), particles_mirror );
Cabana::Grid::particleGridMigrate( *block, coords_mirror,
particles_mirror, particles_dst,
test_halo_size, force_comm );
Cabana::Grid::particleMigrate( *block, coords_mirror, particles_mirror,
particles_dst, test_halo_size,
force_comm );
// Copy back to check.
particles = Cabana::create_mirror_view_and_copy( Kokkos::HostSpace(),
particles_dst );
Expand Down Expand Up @@ -234,8 +233,8 @@ void localOnlyTest( const GridType global_grid, const double cell_size )

// Redistribute the particles.
auto coords_mirror = Cabana::slice<0>( particles_mirror, "coords" );
Cabana::Grid::particleGridMigrate( *block, coords_mirror, particles_mirror,
0, true );
Cabana::Grid::particleMigrate( *block, coords_mirror, particles_mirror, 0,
true );

// Copy back to check.
particles = Cabana::create_mirror_view_and_copy( Kokkos::HostSpace(),
Expand Down Expand Up @@ -335,8 +334,8 @@ void removeOutsideTest( const GridType global_grid )

// Redistribute the particles.
auto coords_mirror = Cabana::slice<0>( particles_mirror, "coords" );
Cabana::Grid::particleGridMigrate( *block, coords_mirror, particles_mirror,
0, true );
Cabana::Grid::particleMigrate( *block, coords_mirror, particles_mirror, 0,
true );

// Check that all particles were removed.
EXPECT_EQ( particles_mirror.size(), 0 );
Expand All @@ -360,7 +359,7 @@ auto createGrid( const Cabana::Grid::ManualBlockPartitioner<3>& partitioner,
return global_grid;
}

void testParticleGridMigrate( const bool periodic )
void testParticleMigrate( const bool periodic )
{
// Let MPI compute the partitioning for this test.
int comm_size;
Expand Down Expand Up @@ -414,10 +413,10 @@ void testParticleGridMigrate( const bool periodic )
//---------------------------------------------------------------------------//
// RUN TESTS
//---------------------------------------------------------------------------//
TEST( TEST_CATEGORY, not_periodic_test ) { testParticleGridMigrate( false ); }
TEST( TEST_CATEGORY, not_periodic_test ) { testParticleMigrate( false ); }

//---------------------------------------------------------------------------//
TEST( TEST_CATEGORY, periodic_test ) { testParticleGridMigrate( true ); }
TEST( TEST_CATEGORY, periodic_test ) { testParticleMigrate( true ); }

//---------------------------------------------------------------------------//
TEST( TEST_CATEGORY, local_only_test )
Expand Down

0 comments on commit 0c37ccb

Please sign in to comment.