Proto
Proto_DisjointBoxLayout.H
1 #ifndef _PROTO_DisjointBoxLayout_H_
2 #define _PROTO_DisjointBoxLayout_H_
3 
4 #include "Proto_Point.H"
5 #include "Proto_Box.H"
6 #include "implem/Proto_Stack.H"
7 #include "Proto_ProblemDomain.H"
8 #include "Proto_DBLInternals.H"
9 #include "Proto_DataIndex.H"
10 #include "Proto_Morton.H"
11 #include "Proto_SPMD.H"
12 #include <cstdlib> //for size_t
13 #include <iostream>
14 #include <stack>
15 #include <memory>
16 #include <array>
17 #include <unordered_map>
18 
19 //using namespace std;
20 //using std::shared_ptr;
21 //using std::array;
22 //using std::vector;
23 //using std::stack;
24 //using namespace Proto;
25 
26 namespace Proto
27 {
28  // Forward Declarations
29  class DataIterator;
30 
32 
38  {
39  friend class DataIndex;
40 
41  private:
42  ProblemDomain m_problemDomain;
43  Point m_boxSize;
44  DataIndex m_end;
45  shared_ptr<DBLInternals> m_internals;
46  /*
47  The use of shared_ptr<DBLInternals> makes the proliferation of copies not be a
48  performance barrier, as well as making the data pointed at by m_internals reusable
49  under coarsening or refinement.If making m_problemDomain and m_boxSize objects
50  becomes a performance issue, can wrap them in a shared pointer as well.
51  */
52 
53  public:
54 
56  inline DisjointBoxLayout();
57 
59 
65  inline DisjointBoxLayout(const ProblemDomain & a_problemDomain,
66  const Point & a_boxSize);
67 
69 
86  inline DisjointBoxLayout(const ProblemDomain & a_problemDomain,
87  const vector<Point> & a_coarsenedPatches,
88  const Point & a_boxSize);
89 
91 
94  inline DisjointBoxLayout(const DisjointBoxLayout& a_input)
95  {
96  m_internals = a_input.m_internals;
97  m_problemDomain = a_input.m_problemDomain;
98  m_boxSize = a_input.m_boxSize;
99  };
100 
102 
105  inline void define(const ProblemDomain & a_problemDomain,
106  const Point & a_boxSize);
107 
109 
112  inline void
113  define(const ProblemDomain & a_problemDomain,
114  const vector<Point> & a_coarsenedPatches,
115  const Point & a_boxSize);
116 
118 
122  {
123  m_internals = a_input.m_internals;
124  m_problemDomain = a_input.m_problemDomain;
125  m_boxSize = a_input.m_boxSize;
126  return *this;
127  };
128 
130  inline bool operator==(const DisjointBoxLayout& a_input) const
131  {
132  return ((a_input.m_internals == m_internals)&&
133  (a_input.m_problemDomain == m_problemDomain)&&
134  (a_input.m_boxSize == m_boxSize));
135  };
136 
144  inline const shared_ptr<DBLInternals> dblInternals() const{return m_internals;};
147 
150  inline Box operator[](const DataIndex& a_index) const;
151  //inline Point operator[](const DataIndex& a_index) const;
152 
154 
157  inline Box box(const DataIndex& a_index) const;
158 
160 
163  inline Point point(const DataIndex& a_index) const;
164 
166  inline int procID(const DataIndex& a_index) const; //consistent syntax
167  inline int procid(const DataIndex& a_index) const;
168 
170 
173  inline unsigned int offset(int a_proc) const;
174  inline unsigned int offset() const { return offset(Proto::procID()); }
175 
177 
184  inline DataIndex index(Point& a_coarsenedPt) const;
185 
190  inline unsigned int size() const;
191 
193 
196  inline unsigned int localSize() const;
197  inline unsigned int mySize() const;
198 
200 
205  inline DataIndex index(unsigned int a_indexInt) const;
206 
208 
213  inline DataIndex localIndex(unsigned int a_myIndexInt) const;
214  inline DataIndex myIndex(unsigned int a_myIndexInt) const;
215 
217 
223  inline int localIntIndex(const DataIndex& a_di) const;
224  inline int myIntIndex(const DataIndex& a_di) const;
225 
227 
230  inline Point boxSize() const{return m_boxSize;};
231 
233  inline ProblemDomain domain() const {return m_problemDomain;};
234  inline ProblemDomain problemDomain() const{return m_problemDomain;};
235 
237 
242  inline DataIndex find(const Point& a_pt) const;
245  inline const DataIndex& end() const
246  {
247  return m_end;
248  };
249 
251  inline DataIterator begin() const;
252 
254 
259  inline bool coarsenable(const Point& a_refrat) const;
260 
262 
272  inline DisjointBoxLayout coarsen(const Point& a_refrat) const;
273 
275 
285  inline DisjointBoxLayout refine(const Point& a_refrat) const;
286 
287  template <MemType MEMTYPE>
288  static StackAlloc<MEMTYPE>& getStackAllocator()
289  {
290  static StackAlloc<MEMTYPE> s_allocator;
291  return s_allocator;
292  }
293 
294 #ifdef PROTO_CUDA
295  //Returns the single stream
296  static protoStream_t getCurrentStream()
297  {
298  static protoStream_t currStream;
299  static bool init=false;
300  if(!init)
301  {
302  protoStreamCreate(&currStream);
303  init=true;
304  }
305  return currStream;
306  }
307 #endif
308 };
310 inline std::ostream& operator<< (std::ostream& os, const DisjointBoxLayout& a_dbl)
311 {
312  os << "DisjointBoxLayout: \n" ;
313  os << a_dbl.problemDomain() << "\n";
314  auto internals = a_dbl.dblInternals();
315  os << "coarsened Domain = " << internals->coarsenedDomain << "\n" ;
316  os << "Points and ranks: \n";
317  for (int k = 0; k < internals->allBoxes.size();k++)
318  {
319  os << internals->allBoxes[k].first
320  << " , " << internals->allBoxes[k].second << "\n";
321  }
322  os << "StartProc vector: \n";
323  for (int k = 0; k < internals->startProc.size() ; k++)
324  {
325  os << "Starting patch number for processor " << k
326  << " = " << internals->startProc[k] << "\n";
327  }
328  return os;
329 }
330 #include "implem/Proto_DisjointBoxLayoutImplem.H"
331 } //end namespace Proto
332 
333 #endif
DisjointBoxLayout coarsen(const Point &a_refrat) const
Coarsen.
Definition: Proto_DisjointBoxLayout.H:194
unsigned int size() const
Size.
Definition: Proto_DisjointBoxLayout.H:82
DataIterator begin() const
Get Iterator.
Definition: Proto_LevelIterators.H:159
Definition: Proto_LevelIterators.H:19
void define(const ProblemDomain &a_problemDomain, const Point &a_boxSize)
Define (Full Domain)
Definition: Proto_DisjointBoxLayout.H:16
std::ostream & operator<<(std::ostream &a_os, const Box &a_box)
OStream Operator.
Definition: Proto_Box.H:850
Disjoint Box Layout.
Definition: Proto_DisjointBoxLayout.H:37
bool operator==(const DisjointBoxLayout &a_input) const
Equality Operator.
Definition: Proto_DisjointBoxLayout.H:130
DataIndex localIndex(unsigned int a_myIndexInt) const
Local Indexing.
Definition: Proto_DisjointBoxLayout.H:145
bool coarsenable(const Point &a_refrat) const
Coarsenable Query.
Definition: Proto_DisjointBoxLayout.H:187
unsigned int localSize() const
Local Size.
Definition: Proto_DisjointBoxLayout.H:88
An interval in DIM dimensional space.
Definition: Proto_Box.H:26
DisjointBoxLayout(const DisjointBoxLayout &a_input)
Copy Constructor.
Definition: Proto_DisjointBoxLayout.H:94
const shared_ptr< DBLInternals > dblInternals() const
Get Internals.
Definition: Proto_DisjointBoxLayout.H:144
DataIndex find(const Point &a_pt) const
Find Index.
Definition: Proto_DisjointBoxLayout.H:172
int procID()
local process ID
Definition: Proto_SPMD.H:52
const DataIndex & end() const
Definition: Proto_DisjointBoxLayout.H:245
DataIndex index(Point &a_coarsenedPt) const
Get Index From Point.
Definition: Proto_DisjointBoxLayout.H:133
ProblemDomain domain() const
Get Problem Domain.
Definition: Proto_DisjointBoxLayout.H:233
Box operator[](const DataIndex &a_index) const
Index Access.
Definition: Proto_DisjointBoxLayout.H:100
DisjointBoxLayout & operator=(const DisjointBoxLayout &a_input)
Assignment.
Definition: Proto_DisjointBoxLayout.H:121
Definition: Proto_Box.H:11
Point boxSize() const
Get Box Size.
Definition: Proto_DisjointBoxLayout.H:230
Integer Valued Vector.
Definition: Proto_Point.H:21
int localIntIndex(const DataIndex &a_di) const
Local Indexing (Inverse)
Definition: Proto_DisjointBoxLayout.H:157
Definition: Proto_DataIndex.H:17
Point point(const DataIndex &a_index) const
Point Indexing.
Definition: Proto_DisjointBoxLayout.H:107
unsigned int offset(int a_proc) const
Patch Offset.
Definition: Proto_DisjointBoxLayout.H:74
Box box(const DataIndex &a_index) const
Box Indexing.
Definition: Proto_DisjointBoxLayout.H:113
DisjointBoxLayout refine(const Point &a_refrat) const
Refine.
Definition: Proto_DisjointBoxLayout.H:205
int procID(const DataIndex &a_index) const
Get Process ID.
Definition: Proto_DisjointBoxLayout.H:121
Represents a rectangular domain over which a problem can be defined, including periodic images...
Definition: Proto_ProblemDomain.H:22