Cabana 0.8.0-dev
 
Loading...
Searching...
No Matches
Cabana_TypeTraits.hpp
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
12#ifndef CABANA_TYPETRAITS_HPP
13#define CABANA_TYPETRAITS_HPP
14
15#include <Kokkos_Core.hpp>
16
17#include <type_traits>
18
19namespace Cabana
20{
21namespace Impl
22{
24
25//---------------------------------------------------------------------------//
26// Checks if an integer is a power of two. N must be greater than 0.
27template <int N>
28struct IsPowerOfTwo
29{
30 static_assert( N > 0, "Vector length must be greater than 0" );
31 static constexpr bool value = ( ( N & ( N - 1 ) ) == 0 );
32};
33
34//---------------------------------------------------------------------------//
35// Calculate the base-2 logarithm of an integer which must be a power of 2 and
36// greater than 0.
37template <int N>
38struct LogBase2
39{
40 static_assert( IsPowerOfTwo<N>::value,
41 "Vector length must be a power of two" );
42 static constexpr int value = 1 + LogBase2<( N >> 1U )>::value;
43};
44
45template <>
46struct LogBase2<1>
47{
48 static constexpr int value = 0;
49};
50
51//---------------------------------------------------------------------------//
52// Check that the provided vector length is valid.
53template <int N>
54struct IsVectorLengthValid
55{
56 static constexpr bool value = ( IsPowerOfTwo<N>::value && N > 0 );
57};
58
59//---------------------------------------------------------------------------//
60
62} // end namespace Impl
63} // end namespace Cabana
64
65#endif // CABANA_TYPETRAITS_HPP
KOKKOS_INLINE_FUNCTION std::enable_if_t< 3==SplineDataType::num_space_dim, void > value(const ViewType &view, const SplineDataType &sd, PointDataType &result, typename std::enable_if<(std::rank< PointDataType >::value==0), void * >::type=0)
Interpolate a scalar value to a point. 3D specialization.
Definition Cabana_Grid_Interpolation.hpp:56
Core: particle data structures and algorithms.
Definition Cabana_AoSoA.hpp:36