Block-Structured AMR Software Framework
AMReX_LayoutData.H
Go to the documentation of this file.
1 #ifndef AMREX_LayoutData_H_
2 #define AMREX_LayoutData_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_FabArrayBase.H>
6 #include <AMReX_MFIter.H>
7 
8 namespace amrex
9 {
11  template <class T>
12  class LayoutData: public FabArrayBase
13  {
14  public:
15 
17  LayoutData() = default;
18 
19  LayoutData(const BoxArray & a_grids,
20  const DistributionMapping & a_dm)
21  {
22  define(a_grids, a_dm);
23  }
24 
25  void define(const BoxArray & a_grids,
26  const DistributionMapping & a_dm)
27  {
28  FabArrayBase::define(a_grids, a_dm, 1, 0);
29  m_need_to_clear_bd = true;
30  addThisBD();
31  m_data.resize(local_size());
32  }
33 
35 
36  LayoutData (const LayoutData& rhs) noexcept
37  : FabArrayBase(rhs),
38  m_data(rhs.m_data),
39  m_need_to_clear_bd(rhs.m_need_to_clear_bd)
40  {
41  if (m_need_to_clear_bd) { addThisBD(); }
42  }
43 
44  LayoutData (LayoutData&& rhs) noexcept
45  : FabArrayBase(static_cast<FabArrayBase&&>(rhs)),
46  m_data(std::move(rhs.m_data)),
47  m_need_to_clear_bd(rhs.m_need_to_clear_bd)
48  {
49  rhs.m_need_to_clear_bd = false;
50  }
51 
52  LayoutData& operator= (const LayoutData& rhs) noexcept
53  {
54  if (&rhs != this)
55  {
56  m_data.clear();
58 
60  m_data = rhs.m_data;
61  m_need_to_clear_bd = rhs.m_need_to_clear_bd;
62 
63  if (m_need_to_clear_bd) { addThisBD(); }
64  }
65  return *this;
66  }
67 
68  LayoutData& operator= (LayoutData&& rhs) noexcept
69  {
70  if (&rhs != this)
71  {
72  m_data.clear();
74 
75  FabArrayBase::operator=(static_cast<FabArrayBase&&>(rhs));
76  m_data = std::move(rhs.m_data);
77  m_need_to_clear_bd = rhs.m_need_to_clear_bd;
78 
79  rhs.m_need_to_clear_bd = false;
80  }
81  return *this;
82  }
83 
84  T& operator[](const MFIter& a_mfi) noexcept
85  {
86  int local_index = a_mfi.LocalIndex();
87  BL_ASSERT(local_index >= 0 && local_index < m_data.size() &&
88  DistributionMap() == a_mfi.DistributionMap());
89  return m_data[local_index];
90  }
91 
92 
93  const T& operator[](const MFIter& a_mfi) const noexcept
94  {
95  int local_index = a_mfi.LocalIndex();
96  BL_ASSERT(local_index >= 0 && local_index < m_data.size() &&
97  DistributionMap() == a_mfi.DistributionMap());
98  return m_data[local_index];
99  }
100 
101  T& operator[](int a_box_index) noexcept
102  {
103  int local_index = this->localindex(a_box_index);
104  BL_ASSERT(local_index >= 0 && local_index < m_data.size());
105  return m_data[local_index];
106  }
107 
108 
109  const T& operator[](int a_box_index) const noexcept
110  {
111  int local_index = this->localindex(a_box_index);
112  BL_ASSERT(local_index >= 0 && local_index < m_data.size());
113  return m_data[local_index];
114  }
115 
116  const T* data () const noexcept { return m_data.data(); }
117  T* data () noexcept { return m_data.data(); }
118 
119  private:
121  bool m_need_to_clear_bd = false;
122  };
123 }
124 #endif
#define BL_ASSERT(EX)
Definition: AMReX_BLassert.H:39
A collection of Boxes stored in an Array.
Definition: AMReX_BoxArray.H:550
Calculates the distribution of FABs to MPI processes.
Definition: AMReX_DistributionMapping.H:41
Base class for FabArray.
Definition: AMReX_FabArrayBase.H:41
void clearThisBD(bool no_assertion=false) const
clear BD count and caches associated with this BD, if no other is using this BD.
FabArrayBase()=default
FabArrayBase & operator=(const FabArrayBase &rhs)=default
void addThisBD()
add the current BD into BD count database
void define(const BoxArray &bxs, const DistributionMapping &dm, int nvar, int ngrow)
int localindex(int K) const noexcept
Return local index in the vector of FABs.
Definition: AMReX_FabArrayBase.H:118
int local_size() const noexcept
Return the number of local FABs in the FabArray.
Definition: AMReX_FabArrayBase.H:112
const DistributionMapping & DistributionMap() const noexcept
Return constant reference to associated DistributionMapping.
Definition: AMReX_FabArrayBase.H:130
a one-thingy-per-box distributed object
Definition: AMReX_LayoutData.H:13
T & operator[](int a_box_index) noexcept
Definition: AMReX_LayoutData.H:101
LayoutData(LayoutData &&rhs) noexcept
Definition: AMReX_LayoutData.H:44
Vector< T > m_data
Definition: AMReX_LayoutData.H:120
const T * data() const noexcept
Definition: AMReX_LayoutData.H:116
bool m_need_to_clear_bd
Definition: AMReX_LayoutData.H:121
LayoutData()=default
const T & operator[](int a_box_index) const noexcept
Definition: AMReX_LayoutData.H:109
~LayoutData()
Definition: AMReX_LayoutData.H:34
T * data() noexcept
Definition: AMReX_LayoutData.H:117
LayoutData(const LayoutData &rhs) noexcept
Definition: AMReX_LayoutData.H:36
void define(const BoxArray &a_grids, const DistributionMapping &a_dm)
Definition: AMReX_LayoutData.H:25
LayoutData & operator=(const LayoutData &rhs) noexcept
Definition: AMReX_LayoutData.H:52
LayoutData(const BoxArray &a_grids, const DistributionMapping &a_dm)
Definition: AMReX_LayoutData.H:19
T & operator[](const MFIter &a_mfi) noexcept
Definition: AMReX_LayoutData.H:84
const T & operator[](const MFIter &a_mfi) const noexcept
Definition: AMReX_LayoutData.H:93
Definition: AMReX_MFIter.H:57
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition: AMReX_Vector.H:27
Definition: AMReX_Amr.cpp:49