Block-Structured AMR Software Framework
AMReX_MultiCutFab.H
Go to the documentation of this file.
1 #ifndef AMREX_MULTICUTFAB_H_
2 #define AMREX_MULTICUTFAB_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_FabArray.H>
6 #include <AMReX_FArrayBox.H>
7 #include <AMReX_EBCellFlag.H>
8 
9 namespace amrex {
10 
11 class CutFab final
12  : public FArrayBox
13 {
14 public:
15 
16  CutFab () = default;
17 
18  explicit CutFab (Arena* ar) : FArrayBox(ar) {}
19 
20  CutFab (const Box& b, int n, Arena* ar)
21  : FArrayBox(b, n, ar) {}
22 
23  CutFab (const Box& b, int ncomps, bool alloc=true,
24  bool shared=false, Arena* ar = nullptr)
25  : FArrayBox(b, ncomps, alloc, shared, ar) {}
26 
27  CutFab (CutFab const& rhs, MakeType make_type, int scomp, int ncomp)
28  : FArrayBox(rhs, make_type, scomp, ncomp) {}
29 
30  ~CutFab () noexcept override = default;
31 
32  CutFab (CutFab&& rhs) noexcept = default;
33 
34  CutFab (const CutFab&) = delete;
35  CutFab& operator= (const CutFab&) = delete;
36  CutFab& operator= (CutFab&&) = delete;
37 
38  template <RunOn run_on, typename BUF = CutFab::value_type>
39  std::size_t copyFromMem (const void* src) {
40  return copyFromMem<run_on, BUF>(box(), 0, nComp(), src);
41  }
42 
43  template <RunOn run_on, typename BUF = CutFab::value_type>
44  std::size_t copyFromMem (const Box& dstbox,
45  int dstcomp,
46  int numcomp,
47  const void* src)
48  {
49  if (dptr != nullptr) {
50  return FArrayBox::copyFromMem<run_on, BUF>(dstbox, dstcomp, numcomp, src);
51  } else {
52  return sizeof(BUF)*static_cast<std::size_t>(dstbox.numPts()*numcomp);
53  }
54  }
55 
56  template <RunOn run_on>
57  CutFab& copy (const CutFab & src,
58  const Box& srcbox,
59  int srccomp,
60  const Box& destbox,
61  int destcomp,
62  int numcomp)
63  {
64  if (dptr != nullptr) {
65  FArrayBox::copy<run_on>(src,srcbox,srccomp,destbox,destcomp,numcomp);
66  }
67  return *this;
68  }
69 
70  template <RunOn run_on>
71  CutFab& copy (const CutFab & src, const Box& bx, SrcComp scomp, DestComp dcomp, NumComps ncomp)
72  {
73  if (dptr != nullptr) {
74  FArrayBox::copy<run_on>(src, bx, scomp, dcomp, ncomp);
75  }
76  return *this;
77  }
78 };
79 
81 {
82 public:
83 
85 
86  MultiCutFab (const BoxArray& ba, const DistributionMapping& dm,
87  int ncomp, int ngrow, const FabArray<EBCellFlagFab>& cellflags);
88 
90 
91  MultiCutFab (MultiCutFab&& rhs) noexcept = default;
92 
93  MultiCutFab (const MultiCutFab& rhs) = delete;
94  MultiCutFab& operator= (const MultiCutFab& rhs) = delete;
96 
97  void define (const BoxArray& ba, const DistributionMapping& dm,
98  int ncomp, int ngrow, const FabArray<EBCellFlagFab>& cellflags);
99 
100  const CutFab& operator[] (const MFIter& mfi) const noexcept;
101  CutFab& operator[] (const MFIter& mfi) noexcept;
102 
103  const CutFab& operator[] (int global_box_index) const noexcept;
104  CutFab& operator[] (int global_box_index) noexcept;
105 
106  Array4<Real > array (const MFIter& mfi) noexcept;
107  Array4<Real const> array (const MFIter& mfi) const noexcept;
108  Array4<Real const> const_array (const MFIter& mfi) const noexcept;
109 
110  MultiArray4<Real> arrays () noexcept {
111  return m_data.arrays();
112  }
113 
114  MultiArray4<Real const> arrays () const noexcept {
115  return m_data.const_arrays();
116  }
117 
119  return m_data.const_arrays();
120  }
121 
123  bool ok (const MFIter& mfi) const noexcept;
124 
126  bool ok (int global_box_index) const noexcept;
127 
128  void setVal (Real val);
129 
130  FabArray<CutFab>& data () noexcept { return m_data; }
131  const FabArray<CutFab>& data () const noexcept { return m_data; }
132 
133  const BoxArray& boxArray () const noexcept { return m_data.boxArray(); }
134  const DistributionMapping& DistributionMap () const noexcept { return m_data.DistributionMap(); }
135  int nComp () const noexcept { return m_data.nComp(); }
136  int nGrow () const noexcept { return m_data.nGrow(); }
137 
138  void ParallelCopy (const MultiCutFab& src, int scomp, int dcomp, int ncomp, int sng, int dng,
139  const Periodicity& period = Periodicity::NonPeriodic());
140 
141  MultiFab ToMultiFab (Real regular_value, Real covered_value) const;
142 
143 private:
144 
147 };
148 
149 }
150 
151 #endif
A virtual base class for objects that manage their own dynamic memory allocation.
Definition: AMReX_Arena.H:100
Real value_type
Definition: AMReX_BaseFab.H:188
Real * dptr
The data pointer.
Definition: AMReX_BaseFab.H:1649
const Box & box() const noexcept
Returns the domain (box) where the array is defined.
Definition: AMReX_BaseFab.H:291
int nComp() const noexcept
Returns the number of components.
Definition: AMReX_BaseFab.H:277
A collection of Boxes stored in an Array.
Definition: AMReX_BoxArray.H:549
AMREX_GPU_HOST_DEVICE Long numPts() const noexcept
Returns the number of points contained in the BoxND.
Definition: AMReX_Box.H:346
Definition: AMReX_MultiCutFab.H:13
CutFab & copy(const CutFab &src, const Box &bx, SrcComp scomp, DestComp dcomp, NumComps ncomp)
Definition: AMReX_MultiCutFab.H:71
CutFab(Arena *ar)
Definition: AMReX_MultiCutFab.H:18
~CutFab() noexcept override=default
CutFab(const Box &b, int n, Arena *ar)
Definition: AMReX_MultiCutFab.H:20
CutFab(CutFab const &rhs, MakeType make_type, int scomp, int ncomp)
Definition: AMReX_MultiCutFab.H:27
CutFab & copy(const CutFab &src, const Box &srcbox, int srccomp, const Box &destbox, int destcomp, int numcomp)
Definition: AMReX_MultiCutFab.H:57
CutFab(const Box &b, int ncomps, bool alloc=true, bool shared=false, Arena *ar=nullptr)
Definition: AMReX_MultiCutFab.H:23
std::size_t copyFromMem(const Box &dstbox, int dstcomp, int numcomp, const void *src)
Definition: AMReX_MultiCutFab.H:44
CutFab()=default
std::size_t copyFromMem(const void *src)
Definition: AMReX_MultiCutFab.H:39
Calculates the distribution of FABs to MPI processes.
Definition: AMReX_DistributionMapping.H:41
A Fortran Array of REALs.
Definition: AMReX_FArrayBox.H:229
An Array of FortranArrayBox(FAB)-like Objects.
Definition: AMReX_FabArray.H:344
Definition: AMReX_MFIter.H:57
Definition: AMReX_MultiCutFab.H:81
const FabArray< CutFab > & data() const noexcept
Definition: AMReX_MultiCutFab.H:131
MultiCutFab(const MultiCutFab &rhs)=delete
FabArray< CutFab > & data() noexcept
Definition: AMReX_MultiCutFab.H:130
void ParallelCopy(const MultiCutFab &src, int scomp, int dcomp, int ncomp, int sng, int dng, const Periodicity &period=Periodicity::NonPeriodic())
Definition: AMReX_MultiCutFab.cpp:149
void setVal(Real val)
Definition: AMReX_MultiCutFab.cpp:130
Array4< Real > array(const MFIter &mfi) noexcept
Definition: AMReX_MultiCutFab.cpp:111
const CutFab & operator[](const MFIter &mfi) const noexcept
Definition: AMReX_MultiCutFab.cpp:69
const DistributionMapping & DistributionMap() const noexcept
Definition: AMReX_MultiCutFab.H:134
int nComp() const noexcept
Definition: AMReX_MultiCutFab.H:135
const BoxArray & boxArray() const noexcept
Definition: AMReX_MultiCutFab.H:133
Array4< Real const > const_array(const MFIter &mfi) const noexcept
Definition: AMReX_MultiCutFab.cpp:97
MultiCutFab(MultiCutFab &&rhs) noexcept=default
MultiArray4< Real > arrays() noexcept
Definition: AMReX_MultiCutFab.H:110
MultiCutFab & operator=(const MultiCutFab &rhs)=delete
FabArray< CutFab > m_data
Definition: AMReX_MultiCutFab.H:145
void define(const BoxArray &ba, const DistributionMapping &dm, int ncomp, int ngrow, const FabArray< EBCellFlagFab > &cellflags)
Definition: AMReX_MultiCutFab.cpp:61
MultiFab ToMultiFab(Real regular_value, Real covered_value) const
Definition: AMReX_MultiCutFab.cpp:155
MultiArray4< Real const > const_arrays() const noexcept
Definition: AMReX_MultiCutFab.H:118
const FabArray< EBCellFlagFab > * m_cellflags
Definition: AMReX_MultiCutFab.H:146
MultiArray4< Real const > arrays() const noexcept
Definition: AMReX_MultiCutFab.H:114
bool ok(const MFIter &mfi) const noexcept
Is it OK to call operator[] with this MFIter?
Definition: AMReX_MultiCutFab.cpp:118
int nGrow() const noexcept
Definition: AMReX_MultiCutFab.H:136
A collection (stored as an array) of FArrayBox objects.
Definition: AMReX_MultiFab.H:38
This provides length of period for periodic domains. 0 means it is not periodic in that direction....
Definition: AMReX_Periodicity.H:17
static const Periodicity & NonPeriodic() noexcept
Definition: AMReX_Periodicity.cpp:52
Definition: AMReX_Amr.cpp:49
MakeType
Definition: AMReX_MakeType.H:7
RunOn
Definition: AMReX_GpuControl.H:69
Definition: AMReX_Array4.H:61
void * alloc(std::size_t sz) const noexcept
Definition: AMReX_DataAllocator.H:16
Definition: AMReX_BaseFab.H:72
Definition: AMReX_FabArray.H:152
Definition: AMReX_BaseFab.H:78
Definition: AMReX_BaseFab.H:66