4 #include <AMReX_Config.H>
35 static_assert(1 <= dim && dim <= 31,
"The number of dimensions of IndexTypeND must be positive"
44 for (
int i=0; i<dim; ++i) {
45 itype |= (iv[i] ? 1U : 0U) << i;
53 template <
class...Args,
55 (
sizeof...(Args)+1 == dim) &&
61 for (
int s=0; s<dim; ++s) {
84 bool any () const noexcept {
return itype != 0; }
87 bool ok () const noexcept {
return itype < (1U << dim); }
121 template<std::
size_t i>
128 for (
int i=0; i<dim; ++i) {
137 for (
int i=0; i<dim; ++i) {
167 static constexpr std::size_t
size () noexcept {
168 return static_cast<std::size_t
>(dim);
173 static constexpr
int isize () noexcept {
183 template<
int new_dim>
186 static_assert(new_dim <= dim);
196 template<
int new_dim>
199 static_assert(new_dim >= dim);
203 retval.getBits() |= (1U << new_dim) - (1U << dim);
212 template<
int new_dim>
215 if constexpr (new_dim > dim) {
216 return expand<new_dim>(fill_extra);
218 return shrink<new_dim>();
233 static constexpr
unsigned int mask (
int k) noexcept {
return 1U<<k; }
238 using IndexType = IndexTypeND<AMREX_SPACEDIM>;
246 template <
class...Args,
254 std::ostream&
index_type_write (std::ostream& os,
const unsigned int& iv,
int dim);
255 std::istream&
index_type_read (std::istream& is,
unsigned int& iv,
int dim);
257 template<
class T, std::size_t...Ns>
263 amrex::get<Ns>(retval).getBits() =
264 (src >> dim_shift) & ((1U << amrex::get<Ns>(retval).isize()) - 1),
265 dim_shift += amrex::get<Ns>(retval).isize()
287 template<
int d,
int...dims>
292 retval.getBits() |= v.
getBits();
293 int dim_shift = v.
isize();
296 retval.getBits() |= (vects.
getBits() << dim_shift),
297 dim_shift += vects.
isize()
307 template<
int d,
int...dims>
309 constexpr GpuTuple<IndexTypeND<d>, IndexTypeND<dims>...>
313 std::make_index_sequence<1 +
sizeof...(dims)>(),
321 template<
int new_dim,
int old_dim>
323 constexpr IndexTypeND<new_dim>
325 return v.template shrink<new_dim>();
332 template<
int new_dim,
int old_dim>
334 constexpr IndexTypeND<new_dim>
337 return v.template expand<new_dim>(fill_extra);
344 template<
int new_dim,
int old_dim>
346 constexpr IndexTypeND<new_dim>
349 return v.template resize<new_dim>(fill_extra);
357 static constexpr std::size_t value = dim;
361 template<std::
size_t s,
int dim>
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
@ NODE
Definition: amrex_iparser.tab.h:65
Definition: AMReX_Tuple.H:93
Cell-Based or Node-Based Indices.
Definition: AMReX_IndexType.H:33
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool cellCentered() const noexcept
True if the IndexTypeND is CELL based in all directions.
Definition: AMReX_IndexType.H:101
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int operator[](int dir) const noexcept
Return an integer representing the IndexTypeND in direction dir.
Definition: AMReX_IndexType.H:119
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void flip(int i) noexcept
Change from CELL to NODE or NODE to CELL in direction dir.
Definition: AMReX_IndexType.H:90
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool operator!=(const IndexTypeND &t) const noexcept
True if IndexTypeNDs are not identical.
Definition: AMReX_IndexType.H:96
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool operator<(const IndexTypeND &t) const noexcept
Definition: AMReX_IndexType.H:98
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE std::size_t size() noexcept
Return the size of this IndexTypeND.
Definition: AMReX_IndexType.H:167
unsigned int itype
An integer holding the CellIndex in bits 0 - dim-1.
Definition: AMReX_IndexType.H:235
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void unset(int dir) noexcept
Set IndexTypeND to be CELL based in direction dir.
Definition: AMReX_IndexType.H:72
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE IntVectND< dim > toIntVect() const noexcept
Fill an IntVectND of size dim with IndexTypeNDs.
Definition: AMReX_IndexType.H:135
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const unsigned int & getBits() const noexcept
Return the bit field representing the underlying data.
Definition: AMReX_IndexType.H:228
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE IntVectND< dim > ixType() const noexcept
Fill an IntVectND of size dim with IndexTypeNDs.
Definition: AMReX_IndexType.H:126
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int isize() noexcept
Return the size of this IndexTypeND.
Definition: AMReX_IndexType.H:173
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE void setall() noexcept
Set NODE based in all directions.
Definition: AMReX_IndexType.H:78
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE CellIndex get() const noexcept
Returns the i'th CellIndex of the IndexTypeND. Used by structured bindings.
Definition: AMReX_IndexType.H:123
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void clear() noexcept
Set CELL based in all directions.
Definition: AMReX_IndexType.H:81
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE 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:185
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool cellCentered(int dir) const noexcept
True if the IndexTypeND is CELL based in dir-direction.
Definition: AMReX_IndexType.H:104
constexpr AMREX_GPU_HOST_DEVICE 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:59
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE IndexTypeND< dim > TheNodeType() noexcept
This static member function returns an IndexTypeND object of value IndexTypeND::NODE....
Definition: AMReX_IndexType.H:159
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool nodeCentered() const noexcept
True if the IndexTypeND is NODE based in all directions.
Definition: AMReX_IndexType.H:107
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void setType(int dir, CellIndex t) noexcept
Set IndexTypeND to CellIndex type t in direction dir.
Definition: AMReX_IndexType.H:113
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE 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:198
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE 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:214
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool test(int dir) const noexcept
True if IndexTypeND is NODE based in direction dir.
Definition: AMReX_IndexType.H:75
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE unsigned int & getBits() noexcept
Return the bit field representing the underlying data.
Definition: AMReX_IndexType.H:224
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE CellIndex ixType(int dir) const noexcept
Returns the CellIndex in direction dir.
Definition: AMReX_IndexType.H:116
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool operator==(const IndexTypeND &t) const noexcept
True if IndexTypeNDs are identical.
Definition: AMReX_IndexType.H:93
constexpr AMREX_GPU_HOST_DEVICE IndexTypeND() noexcept=default
The default constructor.
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool ok() const noexcept
True if IndexTypeND is valid.
Definition: AMReX_IndexType.H:87
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void set(int dir) noexcept
Set IndexTypeND to be NODE based in direction dir.
Definition: AMReX_IndexType.H:69
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE unsigned int mask(int k) noexcept
Returns 1<<k.
Definition: AMReX_IndexType.H:233
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE IndexTypeND< dim > TheCellType() noexcept
This static member function returns an IndexTypeND object of value IndexTypeND::CELL....
Definition: AMReX_IndexType.H:149
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool any() const noexcept
True if this IndexTypeND is NODE based in any direction.
Definition: AMReX_IndexType.H:84
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool nodeCentered(int dir) const noexcept
True if the IndexTypeND is NODE based in dir-direction.
Definition: AMReX_IndexType.H:110
Definition: AMReX_IntVect.H:48
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE int get_sum()
Definition: AMReX_IntVect.H:1132
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE T IndexTypeSplit_imp(T &retval, std::index_sequence< Ns... >, unsigned int src) noexcept
Definition: AMReX_IndexType.H:259
std::ostream & index_type_write(std::ostream &os, const unsigned int &iv, int dim)
Definition: AMReX_IndexType.cpp:10
std::istream & index_type_read(std::istream &is, unsigned int &iv, int dim)
Definition: AMReX_IndexType.cpp:31
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE IndexTypeND(const IntVectND< dim > &) -> IndexTypeND< dim >
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE 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:335
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE 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:290
constexpr bool IsConvertible_v
Definition: AMReX_TypeTraits.H:262
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE 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:324
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE 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:347
AMREX_GPU_HOST_DEVICE IndexTypeND(IndexType::CellIndex, Args...) -> IndexTypeND< sizeof...(Args)+1 >
IndexTypeND< AMREX_SPACEDIM > IndexType
Definition: AMReX_BaseFwd.H:33
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE 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:310
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Definition: AMReX_AmrMesh.cpp:1236
std::istream & operator>>(std::istream &is, BoxND< dim > &bx)
Read from istream.
Definition: AMReX_Box.H:1700
Definition: AMReX_FabArrayCommI.H:841
Type for defining CellIndex so that all IndexTypeND with different dimensions have the same CellIndex...
Definition: AMReX_IndexType.H:18
CellIndex
The cell index type: one of CELL or NODE.
Definition: AMReX_IndexType.H:20
@ CELL
Definition: AMReX_IndexType.H:20
@ NODE
Definition: AMReX_IndexType.H:20
typename amrex::IndexTypeND< dim >::CellIndex type
Definition: AMReX_IndexType.H:363