Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_Mask.H
Go to the documentation of this file.
1
2#ifndef AMREX_MASK_H_
3#define AMREX_MASK_H_
4#include <AMReX_Config.H>
5
6#include <AMReX_BaseFab.H>
7#include <AMReX_FArrayBox.H>
8
14namespace amrex {
15
30class Mask final
31 :
32 public BaseFab<int>
33{
34public:
35
37 Mask () noexcept = default;
38
40 explicit Mask (Arena* ar) noexcept;
41
43 Mask (const Box& bx, int nc, Arena* ar);
44
54 explicit Mask (const Box& bx,
55 int nc = 1,
56 bool alloc=true,
57 bool shared=false,
58 Arena* ar = nullptr);
59
61 explicit Mask (std::istream& is);
62
64 explicit Mask (Array4<int> const& a) noexcept : BaseFab<int>(a) {}
65
67 explicit Mask (Array4<int> const& a, IndexType t) noexcept : BaseFab<int>(a,t) {}
68
70 explicit Mask (Array4<int const> const& a) noexcept : BaseFab<int>(a) {}
71
73 explicit Mask (Array4<int const> const& a, IndexType t) noexcept : BaseFab<int>(a,t) {}
74
75 ~Mask () noexcept override = default;
76
77 Mask (Mask&& rhs) noexcept = default;
78
80 Mask (Mask const& rhs, MakeType make_type, int scomp, int ncomp);
81
82 Mask (const Mask&) = delete;
83 Mask& operator= (const Mask&) = delete;
84 Mask& operator= (Mask&&) = delete;
85
86
94 friend std::istream& operator>> (std::istream& is, Mask& m);
95
101 void readFrom (std::istream& is);
102
109 friend std::ostream& operator<< (std::ostream& os, const Mask& m);
110
116 void writeOn (std::ostream& os) const;
117 //
119 template <RunOn run_on AMREX_DEFAULT_RUNON>
120 Mask& operator&= (const Mask& src) noexcept { return And<run_on>(src); }
121
127 template <RunOn run_on AMREX_DEFAULT_RUNON>
128 Mask& And (const Mask& src) noexcept;
129
138 template <RunOn run_on AMREX_DEFAULT_RUNON>
139 Mask& And (const Mask& src,
140 int srccomp,
141 int destcomp,
142 int numcomp = 1) noexcept;
152 template <RunOn run_on AMREX_DEFAULT_RUNON>
153 Mask& And (const Mask& src,
154 const Box& subbox,
155 int srccomp,
156 int destcomp,
157 int numcomp = 1) noexcept;
168 template <RunOn run_on AMREX_DEFAULT_RUNON>
169 Mask& And (const Mask& src,
170 const Box& srcbox,
171 const Box& destbox,
172 int srccomp,
173 int destcomp,
174 int numcomp = 1) noexcept;
175
177 template <RunOn run_on AMREX_DEFAULT_RUNON>
178 Mask& operator|= (const Mask& src) noexcept { return Or<run_on>(src); }
179
185 template <RunOn run_on AMREX_DEFAULT_RUNON>
186 Mask& Or (const Mask& src) noexcept;
187
196 template <RunOn run_on AMREX_DEFAULT_RUNON>
197 Mask& Or (const Mask& src,
198 int srccomp,
199 int destcomp,
200 int numcomp = 1) noexcept;
210 template <RunOn run_on AMREX_DEFAULT_RUNON>
211 Mask& Or (const Mask& src,
212 const Box& subbox,
213 int srccomp,
214 int destcomp,
215 int numcomp = 1) noexcept;
226 template <RunOn run_on AMREX_DEFAULT_RUNON>
227 Mask& Or (const Mask& src,
228 const Box& srcbox,
229 const Box& destbox,
230 int srccomp,
231 int destcomp,
232 int numcomp = 1) noexcept;
233};
234
235template <RunOn run_on>
236Mask&
237Mask::And (const Mask& src) noexcept
238{
239 return this->And<run_on>(src,domain,domain,0,0,nvar);
240}
241
242template <RunOn run_on>
243Mask&
244Mask::And (const Mask& src,
245 int srccomp,
246 int destcomp,
247 int numcomp) noexcept
248{
249 return this->And<run_on>(src,domain,domain,srccomp,destcomp,numcomp);
250}
251
252template <RunOn run_on>
253Mask&
254Mask::And (const Mask& src,
255 const Box& subbox,
256 int srccomp,
257 int destcomp,
258 int numcomp) noexcept
259{
260 return this->And<run_on>(src,subbox,subbox,srccomp,destcomp,numcomp);
261}
262
263template <RunOn run_on>
264Mask&
265Mask::And (const Mask& src,
266 const Box& srcbox,
267 const Box& destbox,
268 int srccomp,
269 int destcomp,
270 int numcomp) noexcept
271{
272 auto const& d = this->array();
273 auto const& s = src.const_array();
274 const auto dlo = amrex::lbound(destbox);
275 const auto slo = amrex::lbound(srcbox);
276 const Dim3 offset{slo.x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
277 AMREX_HOST_DEVICE_PARALLEL_FOR_4D_FLAG(run_on, destbox, numcomp, i, j, k, n,
278 {
279 d(i,j,k,n+destcomp) = d(i,j,k,n+destcomp) ? s(i+offset.x,j+offset.y,k+offset.z,n+srccomp) : 0;
280 });
281 return *this;
282}
283
284template <RunOn run_on>
285Mask&
286Mask::Or (const Mask& src) noexcept
287{
288 return this->Or<run_on>(src,domain,domain,0,0,nvar);
289}
290
291template <RunOn run_on>
292Mask&
293Mask::Or (const Mask& src,
294 int srccomp,
295 int destcomp,
296 int numcomp) noexcept
297{
298 return this->Or<run_on>(src,domain,domain,srccomp,destcomp,numcomp);
299}
300
301template <RunOn run_on>
302Mask&
303Mask::Or (const Mask& src,
304 const Box& subbox,
305 int srccomp,
306 int destcomp,
307 int numcomp) noexcept
308{
309 return this->Or<run_on>(src,subbox,subbox,srccomp,destcomp,numcomp);
310}
311
312template <RunOn run_on>
313Mask&
314Mask::Or (const Mask& src,
315 const Box& srcbox,
316 const Box& destbox,
317 int srccomp,
318 int destcomp,
319 int numcomp) noexcept
320{
321 auto const& d = this->array();
322 auto const& s = src.const_array();
323 const auto dlo = amrex::lbound(destbox);
324 const auto slo = amrex::lbound(srcbox);
325 const Dim3 offset{slo.x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
326 AMREX_HOST_DEVICE_PARALLEL_FOR_4D_FLAG(run_on, destbox, numcomp, i, j, k, n,
327 {
328 d(i,j,k,n+destcomp) = d(i,j,k,n+destcomp) ? 1: s(i+offset.x,j+offset.y,k+offset.z,n+srccomp);
329 });
330 return *this;
331}
332
333}
334
335#endif /*_MASK_H_*/
#define AMREX_DEFAULT_RUNON
Definition AMReX_GpuControl.H:73
#define AMREX_HOST_DEVICE_PARALLEL_FOR_4D_FLAG(where_to_run, box, nc, i, j, k, n, block)
Definition AMReX_GpuLaunch.nolint.H:73
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1139
A virtual base class for objects that manage their own dynamic memory allocation.
Definition AMReX_Arena.H:127
A FortranArrayBox(FAB)-like object.
Definition AMReX_BaseFab.H:190
Array4< int const > array() const noexcept
Definition AMReX_BaseFab.H:382
Box domain
My index space.
Definition AMReX_BaseFab.H:1165
int nvar
Number components.
Definition AMReX_BaseFab.H:1166
Definition AMReX_Mask.H:33
Mask & Or(const Mask &src) noexcept
In-place logical OR over every component.
Definition AMReX_Mask.H:286
Mask & And(const Mask &src) noexcept
In-place logical AND over every component.
Definition AMReX_Mask.H:237
Mask(Array4< int const > const &a, IndexType t) noexcept
Wrap a const Array4 a with IndexType t.
Definition AMReX_Mask.H:73
void readFrom(std::istream &is)
Initialize from stream, FAB-style.
Definition AMReX_Mask.cpp:89
void writeOn(std::ostream &os) const
Output to stream in FAB binary format.
Definition AMReX_Mask.cpp:78
~Mask() noexcept override=default
Mask(Array4< int > const &a, IndexType t) noexcept
Wrap an existing Array4 a with IndexType t.
Definition AMReX_Mask.H:67
Mask(Array4< int const > const &a) noexcept
Wrap a const Array4 a without taking ownership.
Definition AMReX_Mask.H:70
Mask() noexcept=default
Construct an empty mask with no allocation.
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Return the inclusive lower bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1317
Definition AMReX_Amr.cpp:49
MakeType
Definition AMReX_MakeType.H:7
RunOn
Definition AMReX_GpuControl.H:69
A multidimensional array accessor.
Definition AMReX_Array4.H:283
void * alloc(std::size_t sz) const noexcept
Definition AMReX_DataAllocator.H:16
Definition AMReX_Dim3.H:12
int x
Definition AMReX_Dim3.H:12