Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_EBCellFlag.H
Go to the documentation of this file.
1#ifndef AMREX_EBCELLFLAG_H_
2#define AMREX_EBCELLFLAG_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_Array.H>
6#include <AMReX_IntVect.H>
7#include <AMReX_BaseFab.H>
8#include <AMReX_FabFactory.H>
9
10#include <cstdint>
11#include <map>
12#include <iosfwd>
13
20namespace amrex {
21
24{
25public:
26
28 constexpr EBCellFlag () noexcept = default;
29 ~EBCellFlag () noexcept = default;
30 constexpr EBCellFlag (const EBCellFlag& rhs) noexcept = default;
31 constexpr EBCellFlag (EBCellFlag&& rhs) noexcept = default;
32 constexpr EBCellFlag& operator= (const EBCellFlag& rhs) noexcept = default;
33 constexpr EBCellFlag& operator= (EBCellFlag&& rhs) noexcept = default;
34
36 explicit constexpr EBCellFlag (uint32_t i) noexcept : flag(i) {}
37
39 constexpr EBCellFlag& operator= (uint32_t i) noexcept { flag = i; return *this; }
40
43 EBCellFlag& operator+= (const EBCellFlag& /* rhs */) {
44 amrex::Abort("EBCellFlag::operator+= not supported");
45 return *this;
46 }
47
50 void setRegular () noexcept {
51 flag &= zero_lower_mask;
52 flag |= regular_bits;
53 flag |= single_vof_bits;
54 }
55
58 void setCovered () noexcept {
59 flag = covered_value;
60 }
61
64 void setSingleValued () noexcept {
65 flag &= zero_lower_mask;
66 flag |= single_valued_bits;
67 flag |= single_vof_bits;
68 }
69
72 void setMultiValued (int n) noexcept {
73 flag &= zero_lower_mask;
74 flag |= multi_valued_bits;
75 AMREX_ASSERT(n >= 2 && n <= 7);
76 flag |= static_cast<uint32_t>(n) << pos_numvofs;
77 }
78
81 bool operator==(const EBCellFlag& a_input) const noexcept
82 {
83 return (flag == (a_input.flag));
84 }
85
88 bool operator!=(const EBCellFlag& a_input) const noexcept
89 {
90 return (flag != (a_input.flag));
91 }
92
95 int getNumVoFs () const noexcept
96 {
97 return static_cast<int>((flag & one_numvofs_mask) >> pos_numvofs);
98 }
99
102 bool isRegular () const noexcept {
103 return (flag & one_type_mask) == regular_bits;
104 }
105
108 bool isSingleValued () const noexcept {
109 return (flag & one_type_mask) == single_valued_bits;
110 }
111
114 bool isMultiValued () const noexcept {
115 return (flag & one_type_mask) == multi_valued_bits;
116 }
117
120 bool isCovered () const noexcept {
121 return (flag & one_type_mask) == covered_bits;
122 }
123
126 bool isConnected (const IntVect& iv) const noexcept {
127 int i=0, j=0, k=0;
128 AMREX_D_TERM(i=iv[0];, j=iv[1];, k=iv[2]);
129 const int n = w_lower_mask + 13 + i + 3*j + k*9; // pos_ngbr[k+1,j+1,i+1]
130 return flag & (1 << n);
131 }
132
135 bool isConnected (int i, int j, int k) const noexcept {
136 const int n = w_lower_mask + 13 + i + 3*j + k*9; // pos_ngbr[k+1,j+1,i+1]
137 return flag & (1 << n);
138 }
139
142 bool isDisconnected (const IntVect& iv) const noexcept {
143 int i=0, j=0, k=0;
144 AMREX_D_TERM(i=iv[0];, j=iv[1];, k=iv[2]);
145 const int n = w_lower_mask + 13 + i + 3*j + k*9; // pos_ngbr[k+1,j+1,i+1]
146 return !(flag & (1 << n));
147 }
148
151 bool isDisconnected (int i, int j, int k) const noexcept {
152 const int n = w_lower_mask + 13 + i + 3*j + k*9; // pos_ngbr[k+1,j+1,i+1]
153 return !(flag & (1 << n));
154 }
155
158 void setDisconnected () noexcept {
159 flag &= one_lower_mask;
160 }
161
164 void setDisconnected (const IntVect& iv) noexcept {
165 int i=0, j=0, k=0;
166 AMREX_D_TERM(i=iv[0];, j=iv[1];, k=iv[2]);
167 const int n = w_lower_mask + 13 + i + 3*j + k*9; // pos_ngbr[k+1,j+1,i+1]
168 flag &= ~(1 << n);
169 }
170
173 void setDisconnected (int i, int j, int k) noexcept {
174 const int n = w_lower_mask + 13 + i + 3*j + k*9; // pos_ngbr[k+1,j+1,i+1]
175 flag &= ~(1 << n);
176 }
177
180 void setConnected () noexcept {
181 flag |= zero_lower_mask;
182 }
183
186 void setConnected (const IntVect& iv) noexcept {
187 int i=0, j=0, k=0;
188 AMREX_D_TERM(i=iv[0];, j=iv[1];, k=iv[2]);
189 const int n = w_lower_mask + 13 + i + 3*j + k*9; // pos_ngbr[k+1,j+1,i+1]
190 flag |= 1 << n;
191 }
192
195 void setConnected (int i, int j, int k) noexcept {
196 const int n = w_lower_mask + 13 + i + 3*j + k*9; // pos_ngbr[k+1,j+1,i+1]
197 flag |= 1 << n;
198 }
199
202 int numNeighbors () const noexcept {
203 int n = 1;
204 n += isConnected(-1,-1, 0);
205 n += isConnected( 0,-1, 0);
206 n += isConnected( 1,-1, 0);
207 //
208 n += isConnected(-1, 0, 0);
209 n += isConnected( 1, 0, 0);
210 //
211 n += isConnected(-1, 1, 0);
212 n += isConnected( 0, 1, 0);
213 n += isConnected( 1, 1, 0);
214#if (AMREX_SPACEDIM == 3)
215 n += isConnected(-1,-1,-1);
216 n += isConnected( 0,-1,-1);
217 n += isConnected( 1,-1,-1);
218 //
219 n += isConnected(-1, 0,-1);
220 n += isConnected( 0, 0,-1);
221 n += isConnected( 1, 0,-1);
222 //
223 n += isConnected(-1, 1,-1);
224 n += isConnected( 0, 1,-1);
225 n += isConnected( 1, 1,-1);
226 //
227 n += isConnected(-1,-1, 1);
228 n += isConnected( 0,-1, 1);
229 n += isConnected( 1,-1, 1);
230 //
231 n += isConnected(-1, 0, 1);
232 n += isConnected( 0, 0, 1);
233 n += isConnected( 1, 0, 1);
234 //
235 n += isConnected(-1, 1, 1);
236 n += isConnected( 0, 1, 1);
237 n += isConnected( 1, 1, 1);
238#endif
239 return n;
240 }
241
244 uint32_t getValue() const noexcept
245 {
246 return flag;
247 }
248
251 static constexpr EBCellFlag TheDefaultCell () { return EBCellFlag{default_value}; }
252
253 // DO NOT test covered cells using cell == TheCoveredCell()
254 // Use cell.isCovered() instead.
255 // Each covered cell is covered in its own way.
258 static constexpr EBCellFlag TheCoveredCell () { return EBCellFlag{covered_value}; }
259
260private:
261
263 static constexpr uint32_t one_lower_mask = 0x1f;
264 static constexpr uint32_t zero_lower_mask = ~0x1f;
265
267 static constexpr uint32_t one_type_mask = 0x3;
268 static constexpr uint32_t zero_type_mask = ~0x3;
269
271 static constexpr uint32_t one_numvofs_mask = 0x1c;
272 static constexpr uint32_t zero_numvofs_mask = ~0x1c;
273
276 static constexpr uint32_t regular_bits = 0x0;
277 static constexpr uint32_t single_valued_bits = 0x1;
278 static constexpr uint32_t multi_valued_bits = 0x2;
279 static constexpr uint32_t covered_bits = 0x3;
280
282 static constexpr uint32_t single_vof_bits = 0x4;
283
288
289 static constexpr int w_lower_mask = 5;
290 static constexpr int w_type = 2;
291 static constexpr int w_numvofs = 3;
292 static constexpr int pos_numvofs = 2;
293#if 0
294 static constexpr std::array<std::array<std::array<int,3>,3>,3> pos_ngbr
295 {{ std::array<std::array<int,3>,3>{{{ w_lower_mask , w_lower_mask+ 1, w_lower_mask+ 2 },
296 { w_lower_mask+ 3, w_lower_mask+ 4, w_lower_mask+ 5 },
297 { w_lower_mask+ 6, w_lower_mask+ 7, w_lower_mask+ 8 }}},
298 std::array<std::array<int,3>,3>{{{ w_lower_mask+ 9, w_lower_mask+10, w_lower_mask+11 },
299 { w_lower_mask+12, w_lower_mask+13, w_lower_mask+14 },
300 { w_lower_mask+15, w_lower_mask+16, w_lower_mask+17 }}},
301 std::array<std::array<int,3>,3>{{{ w_lower_mask+18, w_lower_mask+19, w_lower_mask+20 },
302 { w_lower_mask+21, w_lower_mask+22, w_lower_mask+23 },
303 { w_lower_mask+24, w_lower_mask+25, w_lower_mask+26 }}} }};
304#endif
305
307#if AMREX_SPACEDIM == 3
308 static constexpr uint32_t default_value = zero_lower_mask | regular_bits | single_vof_bits;
309#else
310 static constexpr uint32_t default_value = 0x7fc004;
311#endif
312// static constexpr uint32_t covered_value = zero_lower_mask | covered_bits;
313 static constexpr uint32_t covered_value = 0x40003;
314
315 uint32_t flag = default_value;
316};
317
318template <>
319struct IsStoreAtomic<EBCellFlag> : std::true_type {};
320
322class EBCellFlagFab final
323 : public BaseFab<EBCellFlag>
324{
325public:
326
328 explicit EBCellFlagFab (Arena* ar) noexcept;
329
331 explicit EBCellFlagFab (const Box& b, int ncomp, Arena* ar);
332
334 explicit EBCellFlagFab (const Box& b,
335 int ncomp=1,
336 bool alloc=true,
337 bool shared=false,
338 Arena* ar = nullptr);
339
341 EBCellFlagFab (const EBCellFlagFab& rhs, MakeType make_type, int scomp, int ncomp);
342
343 EBCellFlagFab () = default;
344 EBCellFlagFab (EBCellFlagFab&& rhs) = default;
345 ~EBCellFlagFab () override = default;
346
347 EBCellFlagFab (const EBCellFlagFab&) = delete;
350
352 FabType getType () const noexcept { return m_type; }
353
355 FabType getType (const Box& bx) const noexcept;
356
358 void resetType (int ng);
359
361 int getNumRegularCells (const Box& bx) const noexcept;
362
364 int getNumCutCells (const Box& bx) const noexcept;
365
367 int getNumCoveredCells (const Box& bx) const noexcept;
368
370 void setType (FabType t) noexcept { m_type = t; }
371
372 struct NumCells {
373 int nregular = 0;
374 int nsingle = 0;
375 int nmulti = 0;
376 int ncovered = 0;
378 };
379
380private:
382 mutable std::map<Box,NumCells> m_typemap;
383};
384
386std::ostream& operator<< (std::ostream& os, const EBCellFlag& flag);
387
388}
389
390#endif
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
A virtual base class for objects that manage their own dynamic memory allocation.
Definition AMReX_Arena.H:132
A FortranArrayBox(FAB)-like object.
Definition AMReX_BaseFab.H:190
FAB storing EBCellFlag data per cell.
Definition AMReX_EBCellFlag.H:324
int getNumRegularCells(const Box &bx) const noexcept
Count regular cells within bx.
Definition AMReX_EBCellFlag.cpp:147
~EBCellFlagFab() override=default
void setType(FabType t) noexcept
Manually override the cached FabType.
Definition AMReX_EBCellFlag.H:370
void resetType(int ng)
Recompute FabType using the given number of grow cells.
Definition AMReX_EBCellFlag.cpp:132
EBCellFlagFab & operator=(const EBCellFlagFab &)=delete
EBCellFlagFab(EBCellFlagFab &&rhs)=default
int getNumCutCells(const Box &bx) const noexcept
Count cut cells within bx.
Definition AMReX_EBCellFlag.cpp:188
int getNumCoveredCells(const Box &bx) const noexcept
Count covered cells within bx.
Definition AMReX_EBCellFlag.cpp:226
FabType getType() const noexcept
Returns FabType (regular, covered, etc.) for the entire FAB.
Definition AMReX_EBCellFlag.H:352
EBCellFlagFab(const EBCellFlagFab &)=delete
Bit-coded helper that classifies EB cells and neighbor connectivity.
Definition AMReX_EBCellFlag.H:24
__host__ __device__ bool isConnected(int i, int j, int k) const noexcept
Return whether the EB cut connects to neighbor at offset (i,j,k).
Definition AMReX_EBCellFlag.H:135
__host__ __device__ void setDisconnected(int i, int j, int k) noexcept
Clear connectivity to neighbor at offset (i,j,k).
Definition AMReX_EBCellFlag.H:173
__host__ __device__ int getNumVoFs() const noexcept
Number of volume-of-fluid entries for this cell (1 for regular or single-valued, 0 for covered).
Definition AMReX_EBCellFlag.H:95
__host__ __device__ void setMultiValued(int n) noexcept
Mark the cell as multi-valued and store the number of VoFs (n).
Definition AMReX_EBCellFlag.H:72
__host__ __device__ void setCovered() noexcept
Mark the cell as completely covered (solid).
Definition AMReX_EBCellFlag.H:58
__host__ __device__ void setConnected() noexcept
Mark all neighbors as connected.
Definition AMReX_EBCellFlag.H:180
__host__ __device__ void setSingleValued() noexcept
Mark the cell as single-valued (one cut)
Definition AMReX_EBCellFlag.H:64
__host__ __device__ EBCellFlag & operator+=(const EBCellFlag &)
Disabled on purpose—EBCellFlag values are not additive.
Definition AMReX_EBCellFlag.H:43
__host__ __device__ void setConnected(const IntVect &iv) noexcept
Mark connectivity to neighbor offset by iv.
Definition AMReX_EBCellFlag.H:186
__host__ __device__ int numNeighbors() const noexcept
Count how many neighbors are connected (including itself).
Definition AMReX_EBCellFlag.H:202
__host__ __device__ void setDisconnected(const IntVect &iv) noexcept
Clear connectivity to neighbor at offset iv.
Definition AMReX_EBCellFlag.H:164
__host__ __device__ void setDisconnected() noexcept
Clear all neighbor-connection bits.
Definition AMReX_EBCellFlag.H:158
__host__ __device__ void setRegular() noexcept
Mark this cell as purely regular (single volume fraction, no cuts).
Definition AMReX_EBCellFlag.H:50
constexpr EBCellFlag() noexcept=default
Default-construct a flag with all bits cleared (treated as regular).
__host__ __device__ bool isSingleValued() const noexcept
True if the cell stores a single cut (one VoF).
Definition AMReX_EBCellFlag.H:108
__host__ __device__ bool isDisconnected(int i, int j, int k) const noexcept
Inverse of isConnected(i,j,k).
Definition AMReX_EBCellFlag.H:151
__host__ __device__ bool operator!=(const EBCellFlag &a_input) const noexcept
Compare two flags for inequality.
Definition AMReX_EBCellFlag.H:88
__host__ __device__ bool isCovered() const noexcept
True if the cell is fully covered (solid).
Definition AMReX_EBCellFlag.H:120
__host__ __device__ bool isDisconnected(const IntVect &iv) const noexcept
Inverse of isConnected(IntVect).
Definition AMReX_EBCellFlag.H:142
__host__ __device__ bool operator==(const EBCellFlag &a_input) const noexcept
Compare two flags for bitwise equality.
Definition AMReX_EBCellFlag.H:81
__host__ __device__ bool isConnected(const IntVect &iv) const noexcept
Return whether the EB cut is connected to the neighbor offset by iv.
Definition AMReX_EBCellFlag.H:126
__host__ static __device__ constexpr EBCellFlag TheDefaultCell()
Convenience flag representing a completely regular cell.
Definition AMReX_EBCellFlag.H:251
__host__ __device__ bool isMultiValued() const noexcept
True if the cell has multiple VoFs.
Definition AMReX_EBCellFlag.H:114
__host__ __device__ void setConnected(int i, int j, int k) noexcept
Mark connectivity to neighbor at offset (i,j,k).
Definition AMReX_EBCellFlag.H:195
__host__ static __device__ constexpr EBCellFlag TheCoveredCell()
Convenience flag representing a fully covered cell.
Definition AMReX_EBCellFlag.H:258
__host__ __device__ bool isRegular() const noexcept
True if the stored type bits correspond to a regular cell.
Definition AMReX_EBCellFlag.H:102
constexpr EBCellFlag & operator=(const EBCellFlag &rhs) noexcept=default
__host__ __device__ uint32_t getValue() const noexcept
Raw 32-bit encoding stored in this flag.
Definition AMReX_EBCellFlag.H:244
Definition AMReX_Amr.cpp:49
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Stream helper; forwards to the friend declared inside AmrMesh.
Definition AMReX_AmrMesh.cpp:1306
MakeType
Definition AMReX_MakeType.H:7
FabType
Definition AMReX_FabFactory.H:18
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:240
void * alloc(std::size_t sz) const noexcept
Definition AMReX_DataAllocator.H:16
Definition AMReX_EBCellFlag.H:372
FabType type
Definition AMReX_EBCellFlag.H:377
int nmulti
Definition AMReX_EBCellFlag.H:375
int nsingle
Definition AMReX_EBCellFlag.H:374
int ncovered
Definition AMReX_EBCellFlag.H:376
int nregular
Definition AMReX_EBCellFlag.H:373
Definition AMReX_TypeTraits.H:282