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
9namespace amrex {
10
25class Mask final
26 :
27 public BaseFab<int>
28{
29public:
30
31 Mask () noexcept = default;
32
33 explicit Mask (Arena* ar) noexcept;
34
35 Mask (const Box& bx, int nc, Arena* ar);
36
37 explicit Mask (const Box& bx,
38 int nc = 1,
39 bool alloc=true,
40 bool shared=false,
41 Arena* ar = nullptr);
42
46 explicit Mask (std::istream& is);
47
48 explicit Mask (Array4<int> const& a) noexcept : BaseFab<int>(a) {}
49
50 explicit Mask (Array4<int> const& a, IndexType t) noexcept : BaseFab<int>(a,t) {}
51
52 explicit Mask (Array4<int const> const& a) noexcept : BaseFab<int>(a) {}
53
54 explicit Mask (Array4<int const> const& a, IndexType t) noexcept : BaseFab<int>(a,t) {}
55
56 ~Mask () noexcept override = default;
57
58 Mask (Mask&& rhs) noexcept = default;
59
60 Mask (Mask const& rhs, MakeType make_type, int scomp, int ncomp);
61
62 Mask (const Mask&) = delete;
63 Mask& operator= (const Mask&) = delete;
64 Mask& operator= (Mask&&) = delete;
65
66
71 friend std::istream& operator>> (std::istream&, Mask&);
72
77 void readFrom (std::istream&);
78
83 friend std::ostream& operator<< (std::ostream&, const Mask&);
84
89 void writeOn (std::ostream&) const;
90 //
92 template <RunOn run_on AMREX_DEFAULT_RUNON>
93 Mask& operator&= (const Mask& src) noexcept { return And<run_on>(src); }
94
100 template <RunOn run_on AMREX_DEFAULT_RUNON>
101 Mask& And (const Mask& src) noexcept;
102
111 template <RunOn run_on AMREX_DEFAULT_RUNON>
112 Mask& And (const Mask& src,
113 int srccomp,
114 int destcomp,
115 int numcomp = 1) noexcept;
125 template <RunOn run_on AMREX_DEFAULT_RUNON>
126 Mask& And (const Mask& src,
127 const Box& subbox,
128 int srccomp,
129 int destcomp,
130 int numcomp = 1) noexcept;
142 template <RunOn run_on AMREX_DEFAULT_RUNON>
143 Mask& And (const Mask& src,
144 const Box& srcbox,
145 const Box& destbox,
146 int srccomp,
147 int destcomp,
148 int numcomp = 1) noexcept;
149
151 template <RunOn run_on AMREX_DEFAULT_RUNON>
152 Mask& operator|= (const Mask& src) noexcept { return Or<run_on>(src); }
153
159 template <RunOn run_on AMREX_DEFAULT_RUNON>
160 Mask& Or (const Mask& src) noexcept;
161
170 template <RunOn run_on AMREX_DEFAULT_RUNON>
171 Mask& Or (const Mask& src,
172 int srccomp,
173 int destcomp,
174 int numcomp = 1) noexcept;
184 template <RunOn run_on AMREX_DEFAULT_RUNON>
185 Mask& Or (const Mask& src,
186 const Box& subbox,
187 int srccomp,
188 int destcomp,
189 int numcomp = 1) noexcept;
201 template <RunOn run_on AMREX_DEFAULT_RUNON>
202 Mask& Or (const Mask& src,
203 const Box& srcbox,
204 const Box& destbox,
205 int srccomp,
206 int destcomp,
207 int numcomp = 1) noexcept;
208};
209
210template <RunOn run_on>
211Mask&
212Mask::And (const Mask& src) noexcept
213{
214 return this->And<run_on>(src,domain,domain,0,0,nvar);
215}
216
217template <RunOn run_on>
218Mask&
219Mask::And (const Mask& src,
220 int srccomp,
221 int destcomp,
222 int numcomp) noexcept
223{
224 return this->And<run_on>(src,domain,domain,srccomp,destcomp,numcomp);
225}
226
227template <RunOn run_on>
228Mask&
229Mask::And (const Mask& src,
230 const Box& subbox,
231 int srccomp,
232 int destcomp,
233 int numcomp) noexcept
234{
235 return this->And<run_on>(src,subbox,subbox,srccomp,destcomp,numcomp);
236}
237
238template <RunOn run_on>
239Mask&
240Mask::And (const Mask& src,
241 const Box& srcbox,
242 const Box& destbox,
243 int srccomp,
244 int destcomp,
245 int numcomp) noexcept
246{
247 auto const& d = this->array();
248 auto const& s = src.const_array();
249 const auto dlo = amrex::lbound(destbox);
250 const auto slo = amrex::lbound(srcbox);
251 const Dim3 offset{slo.x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
252 AMREX_HOST_DEVICE_PARALLEL_FOR_4D_FLAG(run_on, destbox, numcomp, i, j, k, n,
253 {
254 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;
255 });
256 return *this;
257}
258
259template <RunOn run_on>
260Mask&
261Mask::Or (const Mask& src) noexcept
262{
263 return this->Or<run_on>(src,domain,domain,0,0,nvar);
264}
265
266template <RunOn run_on>
267Mask&
268Mask::Or (const Mask& src,
269 int srccomp,
270 int destcomp,
271 int numcomp) noexcept
272{
273 return this->Or<run_on>(src,domain,domain,srccomp,destcomp,numcomp);
274}
275
276template <RunOn run_on>
277Mask&
278Mask::Or (const Mask& src,
279 const Box& subbox,
280 int srccomp,
281 int destcomp,
282 int numcomp) noexcept
283{
284 return this->Or<run_on>(src,subbox,subbox,srccomp,destcomp,numcomp);
285}
286
287template <RunOn run_on>
288Mask&
289Mask::Or (const Mask& src,
290 const Box& srcbox,
291 const Box& destbox,
292 int srccomp,
293 int destcomp,
294 int numcomp) noexcept
295{
296 auto const& d = this->array();
297 auto const& s = src.const_array();
298 const auto dlo = amrex::lbound(destbox);
299 const auto slo = amrex::lbound(srcbox);
300 const Dim3 offset{slo.x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
301 AMREX_HOST_DEVICE_PARALLEL_FOR_4D_FLAG(run_on, destbox, numcomp, i, j, k, n,
302 {
303 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);
304 });
305 return *this;
306}
307
308}
309
310#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:1089
A virtual base class for objects that manage their own dynamic memory allocation.
Definition AMReX_Arena.H:105
A FortranArrayBox(FAB)-like object.
Definition AMReX_BaseFab.H:183
Array4< int const > array() const noexcept
Definition AMReX_BaseFab.H:375
Box domain
My index space.
Definition AMReX_BaseFab.H:1158
int nvar
Number components.
Definition AMReX_BaseFab.H:1159
Definition AMReX_Mask.H:28
Mask & Or(const Mask &src) noexcept
in-place Or
Definition AMReX_Mask.H:261
Mask & And(const Mask &src) noexcept
in-place And
Definition AMReX_Mask.H:212
Mask(Array4< int const > const &a, IndexType t) noexcept
Definition AMReX_Mask.H:54
~Mask() noexcept override=default
Mask(Array4< int > const &a, IndexType t) noexcept
Definition AMReX_Mask.H:50
void writeOn(std::ostream &) const
output to stream, FAB-style
Definition AMReX_Mask.cpp:78
Mask(Array4< int const > const &a) noexcept
Definition AMReX_Mask.H:52
void readFrom(std::istream &)
initialize from stream, FAB-style
Definition AMReX_Mask.cpp:88
Mask() noexcept=default
Definition AMReX_Amr.cpp:49
MakeType
Definition AMReX_MakeType.H:7
RunOn
Definition AMReX_GpuControl.H:69
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Definition AMReX_Array4.H:312
Definition AMReX_Array4.H:61
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