From 2af18d70e6d7752078c2fd6a35132dc3d19f0aa9 Mon Sep 17 00:00:00 2001 From: Sam Reeve <6740307+streeve@users.noreply.github.com> Date: Tue, 29 Aug 2023 09:52:03 -0400 Subject: [PATCH] Calculate x+u automatically inside slice --- src/CabanaPD_Particles.hpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/CabanaPD_Particles.hpp b/src/CabanaPD_Particles.hpp index ded0430d..f0c80227 100644 --- a/src/CabanaPD_Particles.hpp +++ b/src/CabanaPD_Particles.hpp @@ -88,6 +88,7 @@ class Particles using self_type = Particles; using device_type = DeviceType; using memory_space = typename device_type::memory_space; + using execution_space = typename memory_space::execution_space; static constexpr int dim = Dimension; // Per particle. @@ -308,10 +309,14 @@ class Particles } auto sliceCurrentPosition() { + // Update before returning data. + updateCurrentPosition(); return Cabana::slice<0>( _aosoa_y, "current_positions" ); } auto sliceCurrentPosition() const { + // Update before returning data. + updateCurrentPosition(); return Cabana::slice<0>( _aosoa_y, "current_positions" ); } auto sliceDisplacement() @@ -373,6 +378,22 @@ class Particles return Cabana::slice<0>( _aosoa_nofail, "no_fail_region" ); } + void updateCurrentPosition() + { + // Not using slice function because this is called inside. + auto y = Cabana::slice<0>( _aosoa_y, "current_positions" ); + auto x = sliceReferencePosition(); + auto u = sliceDisplacement(); + Kokkos::RangePolicy policy( 0, n_local + n_ghost ); + auto sum_x_u = KOKKOS_LAMBDA( const std::size_t pid ) + { + for ( int d = 0; d < 3; d++ ) + y( pid, d ) = x( pid, d ) + u( pid, d ); + }; + Kokkos::parallel_for( "CabanaPD::CalculateCurrentPositions", policy, + sum_x_u ); + } + void resize( int new_local, int new_ghost ) { n_local = new_local;