Skip to content
Snippets Groups Projects

Particle Data Structure

Merged Slattery, Stuart requested to merge (removed):particle_api into master
1 file
+ 33
16
Compare changes
  • Side-by-side
  • Inline
@@ -9,6 +9,23 @@
namespace Cabana
{
//---------------------------------------------------------------------------//
// Type traits.
template<typename Device, std::size_t ArraySize, typename... Types>
class AoSoA;
template<typename >
struct is_aosoa
: public std::false_type {};
template<typename Device, std::size_t ArraySize, typename... Types>
struct is_aosoa<AoSoA<Device,ArraySize,Types...> >
: public std::true_type {};
template<typename Device, std::size_t ArraySize, typename... Types>
struct is_aosoa<const AoSoA<Device,ArraySize,Types...> >
: public std::true_type {};
//---------------------------------------------------------------------------//
/*!
\class AoSoA
@@ -83,7 +100,7 @@ class AoSoA
inline std::size_t s() const
{ return _s; }
// Get the struct offset.
// Get the array offset in the struct.
inline std::size_t i() const
{ return _i; }
@@ -122,9 +139,9 @@ class AoSoA
AoSoA( const std::size_t size )
: _size( size )
{
_num_struct = std::floor(_size / soa_array_size);
if ( 0 < _size % soa_array_size ) ++_num_struct;
Device::allocate( _data, _num_struct );
_num_soa = std::floor(_size / soa_array_size);
if ( 0 < _size % soa_array_size ) ++_num_soa;
Device::allocate( _data, _num_soa );
}
// Destructor.
@@ -143,10 +160,10 @@ class AoSoA
// elements). This may or not be equal to the total number of requested
// elements in the AoSoA if the size of the struct arrays is not evenly
// divisible by the requested size.
std::size_t allocatedSize() const { return _num_struct * soa_array_size; }
std::size_t allocatedSize() const { return _num_soa * soa_array_size; }
// Get the number of structs in the array.
std::size_t numStruct() const { return _num_struct; }
// Get the number of structs-of-arrays in the array.
std::size_t numSoA() const { return _num_soa; }
// Access the data array at a given struct member index.
template<std::size_t I>
@@ -161,19 +178,19 @@ class AoSoA
return getStructMember<I>( _data[s] );
}
// Get the index at the beginning of the array.
// Get the index at the beginning of the entire AoSoA.
Index begin() const
{
return Index( 0, 0 );
}
// Get the index at end of the array.
// Get the index at end of the entire AoSoA.
Index end() const
{
return Index( _num_struct - 1, _size % soa_array_size );
return Index( _num_soa - 1, _size % soa_array_size );
}
// Access the data value at a given struct member index and offset index
// Access the data value at a given struct member index and array index
// for Rank 0 data.
template<std::size_t I>
inline
@@ -193,7 +210,7 @@ class AoSoA
return array<I>(idx.s())[idx.i()];
}
// Access the data value at a given struct member index and offset index
// Access the data value at a given struct member index and array index
// for Rank 1 data.
template<std::size_t I>
inline
@@ -215,7 +232,7 @@ class AoSoA
return array<I>(idx.s())[idx.i()][d0];
}
// Access the data value at a given struct member index and offset index
// Access the data value at a given struct member index and array index
// for Rank 2 data.
template<std::size_t I>
inline
@@ -239,7 +256,7 @@ class AoSoA
return array<I>(idx.s())[idx.i()][d0][d1];
}
// Access the data value at a given struct member index and offset index
// Access the data value at a given struct member index and array index
// for Rank 3 data.
template<std::size_t I>
inline
@@ -270,8 +287,8 @@ class AoSoA
// Total size of the array.
std::size_t _size;
// Number of structs in the array.
std::size_t _num_struct;
// Number of structs-of-arrays in the array.
std::size_t _num_soa;
// Structs-of-Arrays.
soa_type* _data;
Loading