Skip to content

Commit

Permalink
Use updated random init in tests/examples
Browse files Browse the repository at this point in the history
  • Loading branch information
streeve committed Feb 20, 2023
1 parent aa97bf5 commit 7b4d8e1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
5 changes: 4 additions & 1 deletion benchmark/core/Cabana_LinkedCellPerformance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
7 changes: 4 additions & 3 deletions benchmark/core/Cabana_NeighborArborXPerformance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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<Device> linked_cell_list(
x, sort_delta, grid_min, grid_max );
Expand Down
7 changes: 4 additions & 3 deletions benchmark/core/Cabana_NeighborVerletPerformance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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<Device> linked_cell_list(
x, sort_delta, grid_min, grid_max );
Cabana::permute( linked_cell_list, aosoas[p] );
Expand Down
4 changes: 2 additions & 2 deletions core/unit_test/neighbor_unit_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
25 changes: 13 additions & 12 deletions core/unit_test/tstParticleInit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
#include <gtest/gtest.h>

template <class PositionType>
void checkRandomParticles( const int num_particle, const double box_min,
const double box_max,
void checkRandomParticles( const int num_particle,
const std::array<double, 3> box_min,
const std::array<double, 3> box_max,
const PositionType host_positions )
{
// Check that we got as many particles as we should have.
Expand All @@ -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] );
}
}

Expand Down Expand Up @@ -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<double, 3> box_min = { -9.5, -4.7, 0.5 };
std::array<double, 3> 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 );
Expand All @@ -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<double, 3> box_min = { -9.5, -4.7, 0.5 };
std::array<double, 3> 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 );
Expand Down

0 comments on commit 7b4d8e1

Please sign in to comment.