From 7b4d8e1dcf3f3d59847131c6170e3f38e1453c09 Mon Sep 17 00:00:00 2001 From: Sam Reeve <6740307+streeve@users.noreply.github.com> Date: Mon, 20 Feb 2023 18:26:13 -0500 Subject: [PATCH] Use updated random init in tests/examples --- .../core/Cabana_LinkedCellPerformance.cpp | 5 +++- .../core/Cabana_NeighborArborXPerformance.cpp | 7 +++--- .../core/Cabana_NeighborVerletPerformance.cpp | 7 +++--- core/unit_test/neighbor_unit_test.hpp | 4 +-- core/unit_test/tstParticleInit.hpp | 25 ++++++++++--------- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/benchmark/core/Cabana_LinkedCellPerformance.cpp b/benchmark/core/Cabana_LinkedCellPerformance.cpp index f5e8390e4..ef53827a5 100644 --- a/benchmark/core/Cabana_LinkedCellPerformance.cpp +++ b/benchmark/core/Cabana_LinkedCellPerformance.cpp @@ -55,9 +55,12 @@ void performanceTest( std::ostream& stream, const std::string& test_prefix, // Define problem grid. x_min[p] = 0.0; x_max[p] = 1.3 * std::pow( num_p, 1.0 / 3.0 ); + double grid_min[3] = { x_min[p], x_min[p], x_min[p] }; + double grid_max[3] = { x_max[p], x_max[p], x_max[p] }; aosoas[p].resize( num_p ); auto x = Cabana::slice<0>( aosoas[p], "position" ); - Cabana::createRandomParticles( x, x.size(), x_min[p], x_max[p] ); + Cabana::createParticles( Cabana::InitRandom(), x, x.size(), grid_min, + grid_max ); } // Loop over number of ratios (neighbors per particle). diff --git a/benchmark/core/Cabana_NeighborArborXPerformance.cpp b/benchmark/core/Cabana_NeighborArborXPerformance.cpp index 25071bd4c..dde030a00 100644 --- a/benchmark/core/Cabana_NeighborArborXPerformance.cpp +++ b/benchmark/core/Cabana_NeighborArborXPerformance.cpp @@ -62,9 +62,12 @@ void performanceTest( std::ostream& stream, const std::string& test_prefix, // Define problem grid. x_min[p] = 0.0; x_max[p] = 1.3 * std::pow( num_p, 1.0 / 3.0 ); + double grid_min[3] = { x_min[p], x_min[p], x_min[p] }; + double grid_max[3] = { x_max[p], x_max[p], x_max[p] }; aosoas[p].resize( num_p ); auto x = Cabana::slice<0>( aosoas[p], "position" ); - Cabana::createRandomParticles( x, x.size(), x_min[p], x_max[p] ); + Cabana::createParticles( Cabana::InitRandom(), x, x.size(), grid_min, + grid_max ); if ( sort ) { @@ -74,8 +77,6 @@ void performanceTest( std::ostream& stream, const std::string& test_prefix, // in cells the size of the smallest cutoff distance. double cutoff = cutoff_ratios.front(); double sort_delta[3] = { cutoff, cutoff, cutoff }; - double grid_min[3] = { x_min[p], x_min[p], x_min[p] }; - double grid_max[3] = { x_max[p], x_max[p], x_max[p] }; auto x = Cabana::slice<0>( aosoas[p], "position" ); Cabana::LinkedCellList linked_cell_list( x, sort_delta, grid_min, grid_max ); diff --git a/benchmark/core/Cabana_NeighborVerletPerformance.cpp b/benchmark/core/Cabana_NeighborVerletPerformance.cpp index b2f491a65..695101f0b 100644 --- a/benchmark/core/Cabana_NeighborVerletPerformance.cpp +++ b/benchmark/core/Cabana_NeighborVerletPerformance.cpp @@ -68,9 +68,12 @@ void performanceTest( std::ostream& stream, const std::string& test_prefix, // Define problem grid. x_min[p] = 0.0; x_max[p] = 1.3 * std::pow( num_p, 1.0 / 3.0 ); + double grid_min[3] = { x_min[p], x_min[p], x_min[p] }; + double grid_max[3] = { x_max[p], x_max[p], x_max[p] }; aosoas[p].resize( num_p ); auto x = Cabana::slice<0>( aosoas[p], "position" ); - Cabana::createRandomParticles( x, x.size(), x_min[p], x_max[p] ); + Cabana::createParticles( Cabana::InitRandom(), x, x.size(), grid_min, + grid_max ); if ( sort ) { @@ -80,8 +83,6 @@ void performanceTest( std::ostream& stream, const std::string& test_prefix, // in cells the size of the smallest cutoff distance. double cutoff = cutoff_ratios.front(); double sort_delta[3] = { cutoff, cutoff, cutoff }; - double grid_min[3] = { x_min[p], x_min[p], x_min[p] }; - double grid_max[3] = { x_max[p], x_max[p], x_max[p] }; Cabana::LinkedCellList linked_cell_list( x, sort_delta, grid_min, grid_max ); Cabana::permute( linked_cell_list, aosoas[p] ); diff --git a/core/unit_test/neighbor_unit_test.hpp b/core/unit_test/neighbor_unit_test.hpp index 3656ff4fc..4981c83e7 100644 --- a/core/unit_test/neighbor_unit_test.hpp +++ b/core/unit_test/neighbor_unit_test.hpp @@ -965,8 +965,8 @@ struct NeighborListTestData auto positions = Cabana::slice<0>( aosoa ); #endif - Cabana::createRandomParticles( positions, positions.size(), box_min, - box_max ); + Cabana::createParticles( Cabana::InitRandom(), positions, + positions.size(), grid_min, grid_max ); #ifdef KOKKOS_ENABLE_OPENMPTARGET // FIXME_OPENMPTARGET Cabana::deep_copy( aosoa, aosoa_copy ); diff --git a/core/unit_test/tstParticleInit.hpp b/core/unit_test/tstParticleInit.hpp index 910dc1c8c..99a52497c 100644 --- a/core/unit_test/tstParticleInit.hpp +++ b/core/unit_test/tstParticleInit.hpp @@ -18,8 +18,9 @@ #include template -void checkRandomParticles( const int num_particle, const double box_min, - const double box_max, +void checkRandomParticles( const int num_particle, + const std::array box_min, + const std::array box_max, const PositionType host_positions ) { // Check that we got as many particles as we should have. @@ -29,8 +30,8 @@ void checkRandomParticles( const int num_particle, const double box_min, for ( int p = 0; p < num_particle; ++p ) for ( int d = 0; d < 3; ++d ) { - EXPECT_GE( host_positions( p, d ), box_min ); - EXPECT_LE( host_positions( p, d ), box_max ); + EXPECT_GE( host_positions( p, d ), box_min[d] ); + EXPECT_LE( host_positions( p, d ), box_max[d] ); } } @@ -62,10 +63,10 @@ void testRandomCreationMinDistance() auto positions = Cabana::slice<0>( aosoa ); double min_dist = 0.47; - double box_min = -9.5; - double box_max = 7.6; - Cabana::createRandomParticlesMinDistance( positions, positions.size(), - box_min, box_max, min_dist ); + std::array box_min = { -9.5, -4.7, 0.5 }; + std::array box_max = { 7.6, -1.5, 5.5 }; + Cabana::createParticles( Cabana::InitRandom(), positions, positions.size(), + box_min, box_max, min_dist ); auto host_aosoa = Cabana::create_mirror_view_and_copy( Kokkos::HostSpace(), aosoa ); auto host_positions = Cabana::slice<0>( host_aosoa ); @@ -81,10 +82,10 @@ void testRandomCreation() "random", num_particle ); auto positions = Cabana::slice<0>( aosoa ); - double box_min = -9.5; - double box_max = 7.6; - Cabana::createRandomParticles( positions, positions.size(), box_min, - box_max ); + std::array box_min = { -9.5, -4.7, 0.5 }; + std::array box_max = { 7.6, -1.5, 5.5 }; + Cabana::createParticles( Cabana::InitRandom(), positions, positions.size(), + box_min, box_max ); auto host_aosoa = Cabana::create_mirror_view_and_copy( Kokkos::HostSpace(), aosoa ); auto host_positions = Cabana::slice<0>( host_aosoa );