Chombo + EB + MF  3.2
LayoutDataI.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _LAYOUTDATAI_H_
12 #define _LAYOUTDATAI_H_
13 
14 #include "MayDay.H"
15 #include "DataIterator.H"
16 #include "SPMD.H"
17 #include "CH_Timer.H"
18 #include "NamespaceHeader.H"
19 
20 // template < > void LayoutData<Real>::allocate();
21 
22 // template < > void LayoutData<int>::allocate();
23 
24 template<class T>
25 inline const T& LayoutData<T>::operator [] (const DataIndex& a_index) const
26 {
27  CH_assert(m_boxLayout.check(a_index));
28 
29  // using a DataIndex for data on another processor -
30  // if you are reading this error in a debugger, then you haven't used
31  // addBox(Box, int) correctly, or you are using a LayoutIterator to
32  // access a data holder.
33  // CH_assert(m_boxLayout.procID(a_index) == procID());
34 
35  return *(m_vector[a_index.datInd()]);
36 }
37 
38 template<class T>
39 inline const T& LayoutData<T>::operator [] (const DataIterator& a_index) const
40 {
41  return (*this)[a_index()];
42 }
43 
44 template<class T>
45 inline T& LayoutData<T>::operator [] (const DataIndex& a_index)
46 {
47  CH_assert(m_boxLayout.check(a_index));
48 
49  // using a DataIndex for data on another processor -
50  // if you are reading this error in a debugger, then you haven't used
51  // addBox(Box, int) correctly, or you are using a LayoutIterator to
52  // access a data holder.
53  //CH_assert(m_boxLayout.procID(a_index) == procID());
54 
55  return *(m_vector[a_index.datInd()]);
56 }
57 
58 template<class T>
59 inline T& LayoutData<T>::operator [] (const DataIterator& a_index)
60 {
61 
62  return (*this)[a_index()];
63 }
64 
65 template<class T>
66 inline Box LayoutData<T>::box(const DataIndex& a_index) const
67 {
68  return m_boxLayout.get(a_index);
69 }
70 
71 template<class T>
72 inline Box LayoutData<T>::box(const DataIterator& a_index) const
73 {
74  return m_boxLayout.get(a_index());
75 }
76 
77 template<class T>
79 {
80  return m_boxLayout.dataIterator();
81 }
82 
83 template<class T>
85 {
86  return m_boxLayout.timedDataIterator();
87 }
88 
89 template<class T>
91 {
92  m_boxLayout.close();
93  m_callDelete = true;
94 }
95 
96 template<class T>
98  :
99  m_boxLayout(a_dp)
100 {
101  CH_assert(a_dp.isClosed());
102  m_callDelete = true;
103  allocate();
104 }
105 
106 template<class T>
107 inline void LayoutData<T>::define(const BoxLayout& a_dp)
108 {
109  CH_assert(a_dp.isClosed());
110  m_boxLayout = a_dp;
111  allocate();
112 }
113 
114 template<class T>
116 {
117  CH_TIME("~LayoutData");
118  if (m_callDelete == true)
119  {
121  for (; it.ok(); ++it)
122  {
123  delete m_vector[it().datInd()];
124  }
125  }
126 }
127 
128 template<class T>
130 {
131  m_callDelete = true;
132 
133  for (unsigned int i = 0; i < m_vector.size(); ++i)
134  {
135  delete m_vector[i];
136  m_vector[i] = NULL;
137  }
138 
140  m_vector.resize(it.size(), NULL);
141 
142  for (; it.ok(); ++it)
143  {
144  unsigned int index = it().datInd();
145  if (m_vector[index] == NULL)
146  {
147  m_vector[index] = new T;
148  if (m_vector[index] == NULL)
149  {
150  MayDay::Error("OutOfMemory in LayoutData::allocate");
151  }
152  }
153  }
154 }
155 
156 #include "NamespaceFooter.H"
157 #endif
virtual ~LayoutData()
Definition: LayoutDataI.H:115
int datInd() const
Definition: DataIndex.H:64
bool m_callDelete
Definition: LayoutData.H:131
LayoutData()
Definition: LayoutDataI.H:90
#define CH_assert(cond)
Definition: CHArray.H:37
Vector< T * > m_vector
Definition: LayoutData.H:124
A not-necessarily-disjoint collective of boxes.
Definition: BoxLayout.H:145
DataIterator dataIterator() const
Definition: LayoutDataI.H:78
Box box(const DataIndex &a_index) const
Definition: LayoutDataI.H:66
virtual bool ok() const
return true if this iterator is still in its Layout
Definition: LayoutIterator.H:117
Definition: DataIterator.H:190
BoxLayout m_boxLayout
Definition: LayoutData.H:118
void resize(unsigned int isize)
Definition: Vector.H:346
unsigned int index(const LayoutIndex &index) const
Definition: BoxLayout.H:724
int size() const
Definition: DataIterator.H:218
#define CH_TIME(name)
Definition: CH_Timer.H:82
void allocate()
Definition: LayoutDataI.H:129
TimedDataIterator timedDataIterator() const
Definition: LayoutDataI.H:84
size_t size() const
Definition: Vector.H:192
virtual void define(const BoxLayout &a_dp)
Definition: LayoutDataI.H:107
static void Error(const char *const a_msg=m_nullString, int m_exitCode=CH_DEFAULT_ERROR_CODE)
Print out message to cerr and exit with the specified exit code.
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
Definition: DataIndex.H:114
const T & operator[](const DataIndex &a_index) const
const accessor function
Definition: LayoutDataI.H:25
bool isClosed() const
Definition: BoxLayout.H:730
Definition: TimedDataIterator.H:23