Cabana 0.8.0-dev
 
Loading...
Searching...
No Matches
Cabana_Index.hpp
Go to the documentation of this file.
1/****************************************************************************
2 * Copyright (c) 2018-2023 by the Cabana authors *
3 * All rights reserved. *
4 * *
5 * This file is part of the Cabana library. Cabana is distributed under a *
6 * BSD 3-clause license. For the licensing terms see the LICENSE file in *
7 * the top-level directory. *
8 * *
9 * SPDX-License-Identifier: BSD-3-Clause *
10 ****************************************************************************/
11
16#ifndef CABANA_INDEX_HPP
17#define CABANA_INDEX_HPP
18
19#include <impl/Cabana_TypeTraits.hpp>
20
21#include <Kokkos_Core.hpp>
22
23#include <type_traits>
24
25namespace Cabana
26{
27namespace Impl
28{
29
30//---------------------------------------------------------------------------//
36template <int VectorLength>
37class Index
38{
39 public:
40 // Validate the inner array size.
41 static_assert( Impl::IsVectorLengthValid<VectorLength>::value,
42 "Invalid vector length" );
43
45 static constexpr int vector_length = VectorLength;
46
48 static constexpr int vector_length_offset = ( vector_length - 1 );
49
51 static constexpr int vector_length_binary_bits =
52 Impl::LogBase2<vector_length>::value;
53
61 KOKKOS_FORCEINLINE_FUNCTION
62 static constexpr std::size_t s( const std::size_t i )
63 {
64 return ( i - ( i & vector_length_offset ) ) >>
66 }
67
76 KOKKOS_FORCEINLINE_FUNCTION
77 static constexpr std::size_t a( const std::size_t i )
78 {
79 return i & vector_length_offset;
80 }
81
92 KOKKOS_FORCEINLINE_FUNCTION
93 static constexpr std::size_t i( const std::size_t s, const std::size_t a )
94 {
95 return ( s << vector_length_binary_bits ) + a;
96 }
97};
98
99//---------------------------------------------------------------------------//
100
101} // end namespace Impl
102
103} // end namespace Cabana
104
105#endif // end CABANA_INDEX_HPP
Class for converting between 1d and 2d aosoa indices.
Definition Cabana_Index.hpp:38
static constexpr int vector_length_offset
Definition Cabana_Index.hpp:48
static KOKKOS_FORCEINLINE_FUNCTION constexpr std::size_t a(const std::size_t i)
Given a tuple index get the AoSoA array index.
Definition Cabana_Index.hpp:77
static KOKKOS_FORCEINLINE_FUNCTION constexpr std::size_t i(const std::size_t s, const std::size_t a)
Definition Cabana_Index.hpp:93
static KOKKOS_FORCEINLINE_FUNCTION constexpr std::size_t s(const std::size_t i)
Given a tuple index get the AoSoA struct index.
Definition Cabana_Index.hpp:62
static constexpr int vector_length_binary_bits
Definition Cabana_Index.hpp:51
static constexpr int vector_length
Definition Cabana_Index.hpp:45
Core: particle data structures and algorithms.
Definition Cabana_AoSoA.hpp:36