Block-Structured AMR Software Framework
 
Loading...
Searching...
No Matches
AMReX_BoxIterator.H
Go to the documentation of this file.
1#ifndef AMREX_BOXITERATOR_H_
2#define AMREX_BOXITERATOR_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_BLassert.H>
6#include <AMReX_REAL.H>
7#include <AMReX_SPACE.H>
8#include <AMReX_IntVect.H>
9
10#include <cstdlib>
11
12namespace amrex
13{
14
15template<int dim>
16class BoxND;
17
49template<int dim>
51{
52public:
53
58 BoxIteratorND () noexcept = default;
59
65 explicit BoxIteratorND (const BoxND<dim>& a_bx) noexcept {
66 define(a_bx);
67 }
68
69 void setBox (const BoxND<dim>& a_bx) noexcept {
70 define(a_bx);
71 }
72
78 void define (const BoxND<dim>& a_bx) noexcept {
79 if (a_bx.ok()) {
80 m_current = a_bx.smallEnd();
81 m_boxLo = a_bx.smallEnd();
82 m_boxHi = a_bx.bigEnd();
83 } else {
87 }
88 }
89
94 BoxIteratorND begin () noexcept {
96 return *this;
97 }
98
103 [[nodiscard]] BoxIteratorND end () const noexcept {
104 BoxIteratorND ret = *this;
105 // set current of end to the past-the-end IntVect
106 ret.m_current = m_boxLo;
107 if (m_boxLo.allLE(m_boxHi)) {
108 ret.m_current[dim-1] = m_boxHi[dim-1] + 1;
109 }
110 return ret;
111 }
112
117 void reset () noexcept {
118 begin();
119 }
120
125 next();
126 return *this;
127 }
128
132 void next () noexcept {
133 for (int i=0; i<dim; ++i) {
134 ++m_current[i];
135 if ((i+1<dim) && m_current[i] > m_boxHi[i]) {
136 m_current[i] = m_boxLo[i];
137 continue;
138 }
139 break;
140 }
141 }
142
146 [[nodiscard]] const IntVectND<dim>& operator () () const noexcept {
149 return m_current;
150 }
151
155 [[nodiscard]] IntVectND<dim> operator* () const noexcept {
158 // Returning by value gives cleaner assembly output.
159 return m_current;
160 }
161
165 [[nodiscard]] bool ok () const noexcept {
166 return m_current.allLE(m_boxHi);
167 }
168
174 [[nodiscard]] friend
175 bool operator != (const BoxIteratorND& b1, const BoxIteratorND& b2) noexcept {
176 // Only check one value for better performance.
177 return b1.m_current[dim-1] != b2.m_current[dim-1];
178 }
179
180private:
184};
185
187
188}
189#endif
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
iterates through the IntVects of a Box
Definition AMReX_BoxIterator.H:51
IntVectND< dim > m_current
Definition AMReX_BoxIterator.H:181
friend bool operator!=(const BoxIteratorND &b1, const BoxIteratorND &b2) noexcept
Definition AMReX_BoxIterator.H:175
BoxIteratorND() noexcept=default
BoxIteratorND begin() noexcept
Definition AMReX_BoxIterator.H:94
IntVectND< dim > m_boxHi
Definition AMReX_BoxIterator.H:183
IntVectND< dim > operator*() const noexcept
Definition AMReX_BoxIterator.H:155
void next() noexcept
Definition AMReX_BoxIterator.H:132
void setBox(const BoxND< dim > &a_bx) noexcept
Definition AMReX_BoxIterator.H:69
void define(const BoxND< dim > &a_bx) noexcept
Definition AMReX_BoxIterator.H:78
const IntVectND< dim > & operator()() const noexcept
Definition AMReX_BoxIterator.H:146
bool ok() const noexcept
Definition AMReX_BoxIterator.H:165
IntVectND< dim > m_boxLo
Definition AMReX_BoxIterator.H:182
BoxIteratorND end() const noexcept
Definition AMReX_BoxIterator.H:103
BoxIteratorND & operator++() noexcept
Definition AMReX_BoxIterator.H:124
void reset() noexcept
Definition AMReX_BoxIterator.H:117
A Rectangular Domain on an Integer Lattice.
Definition AMReX_Box.H:49
An Integer Vector in dim-Dimensional Space.
Definition AMReX_IntVect.H:57
__host__ static __device__ constexpr IntVectND< dim > TheUnitVector() noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition AMReX_IntVect.H:690
__host__ static __device__ constexpr IntVectND< dim > TheZeroVector() noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition AMReX_IntVect.H:680
Definition AMReX_Amr.cpp:49