16#ifndef CABANA_GRID_INDEXSPACE_HPP
17#define CABANA_GRID_INDEXSPACE_HPP
21#include <Kokkos_Core.hpp>
40 static constexpr long Rank = N;
52 template <
typename Scalar>
62 template <
typename Scalar>
64 const std::initializer_list<Scalar>&
max )
66 std::copy(
min.begin(),
min.end(),
_min.data() );
67 std::copy(
max.begin(),
max.end(),
_max.data() );
84 std::copy(
min.begin(),
min.end(),
_min.data() );
85 std::copy(
max.begin(),
max.end(),
_max.data() );
89 KOKKOS_INLINE_FUNCTION
92 for (
long i = 0; i < N; ++i )
94 if (
min( i ) != rhs.
min( i ) ||
max( i ) != rhs.
max( i ) )
101 KOKKOS_INLINE_FUNCTION
108 KOKKOS_INLINE_FUNCTION
109 long min(
const long dim )
const {
return _min[dim]; }
112 KOKKOS_INLINE_FUNCTION
113 Kokkos::Array<long, Rank>
min()
const {
return _min; }
116 KOKKOS_INLINE_FUNCTION
117 long max(
const long dim )
const {
return _max[dim]; }
120 KOKKOS_INLINE_FUNCTION
121 Kokkos::Array<long, Rank>
max()
const {
return _max; }
124 KOKKOS_INLINE_FUNCTION
125 Kokkos::pair<long, long>
range(
const long dim )
const
127 return Kokkos::tie(
_min[dim],
_max[dim] );
131 KOKKOS_INLINE_FUNCTION
135 KOKKOS_INLINE_FUNCTION
139 KOKKOS_INLINE_FUNCTION
143 for (
long d = 0; d <
Rank; ++d )
149 KOKKOS_INLINE_FUNCTION
153 for (
long i = 0; i < N; ++i )
155 result && (
_min[i] <= index[i] ) && ( index[i] <
_max[i] );
161 Kokkos::Array<long, Rank>
_min;
164 Kokkos::Array<long, Rank>
_max;
173template <
class ExecutionSpace>
174Kokkos::RangePolicy<ExecutionSpace>
176 const ExecutionSpace& exec_space )
178 return Kokkos::RangePolicy<ExecutionSpace>(
179 exec_space, index_space.
min( 0 ), index_space.
max( 0 ) );
189template <
class ExecutionSpace,
class WorkTag>
190Kokkos::RangePolicy<ExecutionSpace, WorkTag>
192 const ExecutionSpace& exec_space,
const WorkTag& )
194 return Kokkos::RangePolicy<ExecutionSpace, WorkTag>(
195 exec_space, index_space.
min( 0 ), index_space.
max( 0 ) );
203template <
class IndexSpace_t,
class ExecutionSpace>
204Kokkos::MDRangePolicy<ExecutionSpace, Kokkos::Rank<IndexSpace_t::Rank>>
206 const ExecutionSpace& exec_space )
208 return Kokkos::MDRangePolicy<ExecutionSpace,
209 Kokkos::Rank<IndexSpace_t::Rank>>(
210 exec_space, index_space.min(), index_space.max() );
219template <
class IndexSpace_t,
class ExecutionSpace,
class WorkTag>
220Kokkos::MDRangePolicy<ExecutionSpace, WorkTag, Kokkos::Rank<IndexSpace_t::Rank>>
222 const ExecutionSpace& exec_space,
const WorkTag& )
224 return Kokkos::MDRangePolicy<ExecutionSpace, WorkTag,
225 Kokkos::Rank<IndexSpace_t::Rank>>(
226 exec_space, index_space.min(), index_space.max() );
236template <
class Scalar,
class... Params>
237Kokkos::View<Scalar*, Params...>
createView(
const std::string& label,
240 return Kokkos::View<Scalar*, Params...>(
241 Kokkos::ViewAllocateWithoutInitializing( label ),
242 index_space.
extent( 0 ) );
253template <
class Scalar,
class... Params>
254Kokkos::View<Scalar*, Params..., Kokkos::MemoryUnmanaged>
257 return Kokkos::View<Scalar*, Params..., Kokkos::MemoryUnmanaged>(
258 data, index_space.
extent( 0 ) );
269template <
class Scalar,
class... Params>
270Kokkos::View<Scalar**, Params...>
createView(
const std::string& label,
273 return Kokkos::View<Scalar**, Params...>(
274 Kokkos::ViewAllocateWithoutInitializing( label ),
286template <
class Scalar,
class... Params>
287Kokkos::View<Scalar**, Params..., Kokkos::MemoryUnmanaged>
290 return Kokkos::View<Scalar**, Params..., Kokkos::MemoryUnmanaged>(
291 data, index_space.
extent( 0 ), index_space.
extent( 1 ) );
302template <
class Scalar,
class... Params>
303Kokkos::View<Scalar***, Params...>
306 return Kokkos::View<Scalar***, Params...>(
307 Kokkos::ViewAllocateWithoutInitializing( label ),
309 index_space.
extent( 2 ) );
320template <
class Scalar,
class... Params>
321Kokkos::View<Scalar***, Params..., Kokkos::MemoryUnmanaged>
324 return Kokkos::View<Scalar***, Params..., Kokkos::MemoryUnmanaged>(
326 index_space.
extent( 2 ) );
336template <
class Scalar,
class... Params>
337Kokkos::View<Scalar****, Params...>
340 return Kokkos::View<Scalar****, Params...>(
341 Kokkos::ViewAllocateWithoutInitializing( label ),
354template <
class Scalar,
class... Params>
355Kokkos::View<Scalar****, Params..., Kokkos::MemoryUnmanaged>
358 return Kokkos::View<Scalar****, Params..., Kokkos::MemoryUnmanaged>(
370template <
class ViewType>
373 ->
decltype( Kokkos::subview( view, index_space.range( 0 ) ) )
375 static_assert( 1 == ViewType::rank,
"Incorrect view rank" );
376 return Kokkos::subview( view, index_space.range( 0 ) );
386template <
class ViewType>
389 ->
decltype( Kokkos::subview( view, index_space.range( 0 ),
390 index_space.range( 1 ) ) )
392 static_assert( 2 == ViewType::rank,
"Incorrect view rank" );
393 return Kokkos::subview( view, index_space.range( 0 ),
394 index_space.range( 1 ) );
404template <
class ViewType>
407 ->
decltype( Kokkos::subview( view, index_space.range( 0 ),
408 index_space.range( 1 ),
409 index_space.range( 2 ) ) )
411 static_assert( 3 == ViewType::rank,
"Incorrect view rank" );
412 return Kokkos::subview( view, index_space.range( 0 ),
413 index_space.range( 1 ), index_space.range( 2 ) );
423template <
class ViewType>
426 ->
decltype( Kokkos::subview( view, index_space.range( 0 ),
427 index_space.range( 1 ),
428 index_space.range( 2 ),
429 index_space.range( 3 ) ) )
431 static_assert( 4 == ViewType::rank,
"Incorrect view rank" );
432 return Kokkos::subview( view, index_space.range( 0 ),
433 index_space.range( 1 ), index_space.range( 2 ),
434 index_space.range( 3 ) );
447 std::array<long, N + 1> min;
448 for (
int d = 0; d < N; ++d )
449 min[d] = index_space.
min( d );
452 std::array<long, N + 1> max;
453 for (
int d = 0; d < N; ++d )
454 max[d] = index_space.
max( d );
468 const long min,
const long max )
470 std::array<long, N + 1> range_min;
471 for (
int d = 0; d < N; ++d )
472 range_min[d] = index_space.
min( d );
475 std::array<long, N + 1> range_max;
476 for (
int d = 0; d < N; ++d )
477 range_max[d] = index_space.
max( d );
KOKKOS_INLINE_FUNCTION auto createSubview(const ViewType &view, const IndexSpace< 1 > &index_space) -> decltype(Kokkos::subview(view, index_space.range(0)))
Given a view create a subview over the given index space.
Definition Cabana_Grid_IndexSpace.hpp:371
Kokkos::View< Scalar *, Params... > createView(const std::string &label, const IndexSpace< 1 > &index_space)
Given an index space create a view over the extent of that index space.
Definition Cabana_Grid_IndexSpace.hpp:237
Kokkos::RangePolicy< ExecutionSpace > createExecutionPolicy(const IndexSpace< 1 > &index_space, const ExecutionSpace &exec_space)
Create a multi-dimensional execution policy over an index space.
Definition Cabana_Grid_IndexSpace.hpp:175
IndexSpace< N+1 > appendDimension(const IndexSpace< N > &index_space, const long size)
Given an N-dimensional index space append an additional dimension with the given size.
Definition Cabana_Grid_IndexSpace.hpp:444
Structured index space.
Definition Cabana_Grid_IndexSpace.hpp:37
KOKKOS_INLINE_FUNCTION bool inRange(const long index[N]) const
Determine if a set of indices is within the range of the index space.
Definition Cabana_Grid_IndexSpace.hpp:150
KOKKOS_INLINE_FUNCTION Kokkos::Array< long, Rank > max() const
Get the maximum indices in all dimensions.
Definition Cabana_Grid_IndexSpace.hpp:121
KOKKOS_INLINE_FUNCTION Kokkos::Array< long, Rank > min() const
Get the minimum indices in all dimensions.
Definition Cabana_Grid_IndexSpace.hpp:113
Kokkos::Array< long, Rank > _max
Maximum index bounds.
Definition Cabana_Grid_IndexSpace.hpp:164
IndexSpace(const std::array< long, N > &min, const std::array< long, N > &max)
Vector range constructor.
Definition Cabana_Grid_IndexSpace.hpp:82
KOKKOS_INLINE_FUNCTION long max(const long dim) const
Get the maximum index in a given dimension.
Definition Cabana_Grid_IndexSpace.hpp:117
KOKKOS_INLINE_FUNCTION long min(const long dim) const
Get the minimum index in a given dimension.
Definition Cabana_Grid_IndexSpace.hpp:109
KOKKOS_INLINE_FUNCTION bool operator==(const IndexSpace< N > &rhs) const
Comparison operator.
Definition Cabana_Grid_IndexSpace.hpp:90
static constexpr long Rank
Number of dimensions.
Definition Cabana_Grid_IndexSpace.hpp:40
KOKKOS_INLINE_FUNCTION Kokkos::pair< long, long > range(const long dim) const
Get the range of a given dimension.
Definition Cabana_Grid_IndexSpace.hpp:125
Kokkos::Array< long, Rank > _min
Minimum index bounds.
Definition Cabana_Grid_IndexSpace.hpp:161
KOKKOS_INLINE_FUNCTION bool operator!=(const IndexSpace< N > &rhs) const
Comparison operator.
Definition Cabana_Grid_IndexSpace.hpp:102
KOKKOS_INLINE_FUNCTION long size() const
Get the total size of the index space.
Definition Cabana_Grid_IndexSpace.hpp:140
KOKKOS_INLINE_FUNCTION long rank() const
Get the number of dimensions.
Definition Cabana_Grid_IndexSpace.hpp:132
KOKKOS_INLINE_FUNCTION long extent(const long dim) const
Get the extent of a given dimension.
Definition Cabana_Grid_IndexSpace.hpp:136
IndexSpace(const std::initializer_list< Scalar > &min, const std::initializer_list< Scalar > &max)
Initializer list range constructor.
Definition Cabana_Grid_IndexSpace.hpp:63
IndexSpace()
Default constructor.
Definition Cabana_Grid_IndexSpace.hpp:43
IndexSpace(const std::initializer_list< Scalar > &size)
Initializer list size constructor.
Definition Cabana_Grid_IndexSpace.hpp:53
IndexSpace(const std::array< long, N > &size)
Vector size constructor.
Definition Cabana_Grid_IndexSpace.hpp:73
Core: particle data structures and algorithms.
Definition Cabana_AoSoA.hpp:36
auto size(SliceType slice, typename std::enable_if< is_slice< SliceType >::value, int >::type *=0)
Check slice size (differs from Kokkos View).
Definition Cabana_Slice.hpp:1019