4#include <AMReX_Config.H>
38 static_assert(1 <= dim && dim <= 31,
"The number of dimensions of IndexTypeND must be positive"
47 for (
int i=0; i<dim; ++i) {
48 itype |= (iv[i] ? 1U : 0U) << i;
56 template <
class...Args,
58 (
sizeof...(Args)+1 == dim) &&
64 for (
int s=0; s<dim; ++s) {
87 bool any () const noexcept {
return itype != 0; }
90 bool ok () const noexcept {
return itype < (1U << dim); }
124 template<std::
size_t i>
131 for (
int i=0; i<dim; ++i) {
140 for (
int i=0; i<dim; ++i) {
170 static constexpr std::size_t
size () noexcept {
171 return static_cast<std::size_t
>(dim);
176 static constexpr int isize () noexcept {
186 template<
int new_dim>
189 static_assert(new_dim <= dim);
199 template<
int new_dim>
202 static_assert(new_dim >= dim);
206 retval.getBits() |= (1U << new_dim) - (1U << dim);
215 template<
int new_dim>
218 if constexpr (new_dim > dim) {
219 return expand<new_dim>(fill_extra);
221 return shrink<new_dim>();
236 static constexpr unsigned int mask (
int k)
noexcept {
return 1U<<k; }
243using IndexType = IndexTypeND<AMREX_SPACEDIM>;
251template <
class...Args,
260 std::ostream& index_type_write (std::ostream& os,
const unsigned int& iv,
int dim);
261 std::istream& index_type_read (std::istream& is,
unsigned int& iv,
int dim);
263 template<
class T, std::size_t...Ns>
265 T IndexTypeSplit_imp (T& retval, std::index_sequence<Ns...>,
unsigned int src)
noexcept {
269 amrex::get<Ns>(retval).getBits() =
270 (src >> dim_shift) & ((1U << amrex::get<Ns>(retval).isize()) - 1),
271 dim_shift += amrex::get<Ns>(retval).isize()
282 return detail::index_type_write(os, it.
getBits(), dim);
287 return detail::index_type_read(is, it.
getBits(), dim);
294template<
int d,
int...dims>
296constexpr IndexTypeND<detail::get_sum<d, dims...>()>
298 IndexTypeND<detail::get_sum<d, dims...>()> retval{};
300 int dim_shift = v.
isize();
303 retval.getBits() |= (vects.
getBits() << dim_shift),
304 dim_shift += vects.
isize()
314template<
int d,
int...dims>
316constexpr GpuTuple<IndexTypeND<d>, IndexTypeND<dims>...>
319 return detail::IndexTypeSplit_imp(retval,
320 std::make_index_sequence<1 +
sizeof...(dims)>(),
328template<
int new_dim,
int old_dim>
330constexpr IndexTypeND<new_dim>
332 return v.template shrink<new_dim>();
339template<
int new_dim,
int old_dim>
341constexpr IndexTypeND<new_dim>
344 return v.template expand<new_dim>(fill_extra);
351template<
int new_dim,
int old_dim>
353constexpr IndexTypeND<new_dim>
356 return v.template resize<new_dim>(fill_extra);
363struct std::tuple_size<
amrex::IndexTypeND<dim>> {
364 static constexpr std::size_t value = dim;
368template<std::
size_t s,
int dim>
369struct std::tuple_element<s,
amrex::IndexTypeND<dim>> {
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
Array4< int const > mask
Definition AMReX_InterpFaceRegister.cpp:93
GPU-compatible tuple.
Definition AMReX_Tuple.H:98
Cell-Based or Node-Based Indices.
Definition AMReX_IndexType.H:36
__host__ __device__ constexpr CellIndex ixType(int dir) const noexcept
Returns the CellIndex in direction dir.
Definition AMReX_IndexType.H:119
__host__ __device__ bool operator==(const IndexTypeND &t) const noexcept
True if IndexTypeNDs are identical.
Definition AMReX_IndexType.H:96
__host__ __device__ bool test(int dir) const noexcept
True if IndexTypeND is NODE based in direction dir.
Definition AMReX_IndexType.H:78
__host__ __device__ bool cellCentered() const noexcept
True if the IndexTypeND is CELL based in all directions.
Definition AMReX_IndexType.H:104
__host__ __device__ IndexTypeND< new_dim > expand(CellIndex fill_extra=CellIndex::CELL) const noexcept
Returns a new IndexTypeND of size new_dim and assigns all values of this IndexTypeND to it and fill_e...
Definition AMReX_IndexType.H:201
__host__ __device__ void flip(int i) noexcept
Change from CELL to NODE or NODE to CELL in direction dir.
Definition AMReX_IndexType.H:93
unsigned int itype
An integer holding the CellIndex in bits 0 - dim-1.
Definition AMReX_IndexType.H:238
__host__ static __device__ constexpr std::size_t size() noexcept
Return the size of this IndexTypeND.
Definition AMReX_IndexType.H:170
__host__ __device__ IntVectND< dim > toIntVect() const noexcept
Fill an IntVectND of size dim with IndexTypeNDs.
Definition AMReX_IndexType.H:138
__host__ static __device__ constexpr int isize() noexcept
Return the size of this IndexTypeND.
Definition AMReX_IndexType.H:176
__host__ __device__ IntVectND< dim > ixType() const noexcept
Fill an IntVectND of size dim with IndexTypeNDs.
Definition AMReX_IndexType.H:129
__host__ __device__ constexpr CellIndex get() const noexcept
Returns the i'th CellIndex of the IndexTypeND. Used by structured bindings.
Definition AMReX_IndexType.H:126
__host__ __device__ constexpr const unsigned int & getBits() const noexcept
Return the bit field representing the underlying data.
Definition AMReX_IndexType.H:231
__host__ __device__ void setType(int dir, CellIndex t) noexcept
Set IndexTypeND to CellIndex type t in direction dir.
Definition AMReX_IndexType.H:116
__host__ __device__ bool any() const noexcept
True if this IndexTypeND is NODE based in any direction.
Definition AMReX_IndexType.H:87
__host__ __device__ constexpr void setall() noexcept
Set NODE based in all directions.
Definition AMReX_IndexType.H:81
__host__ __device__ constexpr unsigned int & getBits() noexcept
Return the bit field representing the underlying data.
Definition AMReX_IndexType.H:227
__host__ __device__ bool ok() const noexcept
True if IndexTypeND is valid.
Definition AMReX_IndexType.H:90
__host__ __device__ bool cellCentered(int dir) const noexcept
True if the IndexTypeND is CELL based in dir-direction.
Definition AMReX_IndexType.H:107
__host__ __device__ IndexTypeND< new_dim > shrink() const noexcept
Returns a new IndexTypeND of size new_dim and assigns the first new_dim values of this IndexTypeND to...
Definition AMReX_IndexType.H:188
__host__ __device__ bool nodeCentered(int dir) const noexcept
True if the IndexTypeND is NODE based in dir-direction.
Definition AMReX_IndexType.H:113
__host__ __device__ void set(int dir) noexcept
Set IndexTypeND to be NODE based in direction dir.
Definition AMReX_IndexType.H:72
__host__ __device__ int operator[](int dir) const noexcept
Return an integer representing the IndexTypeND in direction dir.
Definition AMReX_IndexType.H:122
__host__ __device__ constexpr IndexTypeND(CellIndex i, Args...js) noexcept
Construct an IndexTypeND given an explicit CellIndex for each direction. The inputs for this construc...
Definition AMReX_IndexType.H:62
__host__ static __device__ constexpr IndexTypeND< dim > TheCellType() noexcept
This static member function returns an IndexTypeND object of value IndexTypeND::CELL....
Definition AMReX_IndexType.H:152
__host__ static __device__ constexpr unsigned int mask(int k) noexcept
Returns 1<<k.
Definition AMReX_IndexType.H:236
__host__ __device__ bool nodeCentered() const noexcept
True if the IndexTypeND is NODE based in all directions.
Definition AMReX_IndexType.H:110
__host__ __device__ IndexTypeND< new_dim > resize(CellIndex fill_extra=CellIndex::CELL) const noexcept
Returns a new IndexTypeND of size new_dim by either shrinking or expanding this IndexTypeND.
Definition AMReX_IndexType.H:217
__host__ __device__ bool operator!=(const IndexTypeND &t) const noexcept
True if IndexTypeNDs are not identical.
Definition AMReX_IndexType.H:99
__host__ __device__ bool operator<(const IndexTypeND &t) const noexcept
Definition AMReX_IndexType.H:101
__host__ __device__ constexpr IndexTypeND() noexcept=default
The default constructor.
__host__ __device__ void clear() noexcept
Set CELL based in all directions.
Definition AMReX_IndexType.H:84
__host__ __device__ void unset(int dir) noexcept
Set IndexTypeND to be CELL based in direction dir.
Definition AMReX_IndexType.H:75
__host__ static __device__ constexpr IndexTypeND< dim > TheNodeType() noexcept
This static member function returns an IndexTypeND object of value IndexTypeND::NODE....
Definition AMReX_IndexType.H:162
An Integer Vector in dim-Dimensional Space.
Definition AMReX_IntVect.H:57
Definition AMReX_Amr.cpp:49
constexpr bool IsConvertible_v
Definition AMReX_TypeTraits.H:276
IndexTypeND< 3 > IndexType
IndexType is an alias for amrex::IndexTypeND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:33
__host__ __device__ constexpr IndexTypeND< detail::get_sum< d, dims... >()> IndexTypeCat(const IndexTypeND< d > &v, const IndexTypeND< dims > &...vects) noexcept
Returns a IndexTypeND obtained by concatenating the input IndexTypeNDs. The dimension of the return v...
Definition AMReX_IndexType.H:297
__host__ __device__ constexpr IndexTypeND< new_dim > IndexTypeShrink(const IndexTypeND< old_dim > &v) noexcept
Returns a new IndexTypeND of size new_dim and assigns the first new_dim values of v to it.
Definition AMReX_IndexType.H:331
__host__ __device__ constexpr IndexTypeND< new_dim > IndexTypeResize(const IndexTypeND< old_dim > &v, IndexType::CellIndex fill_extra=IndexType::CellIndex::CELL) noexcept
Returns a new IndexTypeND of size new_dim by either shrinking or expanding iv.
Definition AMReX_IndexType.H:354
__host__ __device__ constexpr IndexTypeND< new_dim > IndexTypeExpand(const IndexTypeND< old_dim > &v, IndexType::CellIndex fill_extra=IndexType::CellIndex::CELL) noexcept
Returns a new IndexTypeND of size new_dim and assigns all values of iv to it and fill_extra to the re...
Definition AMReX_IndexType.H:342
std::istream & operator>>(std::istream &is, BoxND< dim > &bx)
Read from istream.
Definition AMReX_Box.H:1825
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Definition AMReX_AmrMesh.cpp:1236
__host__ __device__ constexpr GpuTuple< IndexTypeND< d >, IndexTypeND< dims >... > IndexTypeSplit(const IndexTypeND< detail::get_sum< d, dims... >()> &v) noexcept
Returns a tuple of IndexTypeND obtained by splitting the input IndexTypeND according to the dimension...
Definition AMReX_IndexType.H:317
Type for defining CellIndex so that all IndexTypeND with different dimensions have the same CellIndex...
Definition AMReX_IndexType.H:19
CellIndex
The cell index type: one of CELL or NODE.
Definition AMReX_IndexType.H:21
@ CELL
Definition AMReX_IndexType.H:21
@ NODE
Definition AMReX_IndexType.H:21
typename amrex::IndexTypeND< dim >::CellIndex type
Definition AMReX_IndexType.H:370