Proto  3.2
Proto_MBBoxPartition.H
Go to the documentation of this file.
1 #pragma once
2 #ifndef _PROTO_MB_BOX_PARTITION_
3 #define _PROTO_MB_BOX_PARTITION_
4 
6 #include <unordered_map>
7 #include <unordered_set>
8 
9 namespace Proto
10 {
11  namespace
12  {
13  struct PatchBound
14  {
15  uint64_t index;
16  Point dir;
17 
18  bool operator==(const PatchBound &a_rhs) const
19  {
20  if (index != a_rhs.index)
21  {
22  return false;
23  }
24  if (dir != a_rhs.dir)
25  {
26  return false;
27  }
28  return true;
29  }
30 
31  struct Hash
32  {
33  std::size_t operator()(const PatchBound &key) const
34  {
35 
36  std::size_t hash = std::hash<uint64_t>{}(key.index);
37  for (int ii = 0; ii < DIM; ++ii)
38  {
39  hash ^= std::hash<int>{}(key.dir[ii]) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
40  }
41  return hash;
42  }
43  };
44  };
45 
47  {
48  PR_DOMAIN_BOUNDARY,
49  PR_BLOCK_BOUNDARY,
50  PR_INTERIOR_BOUNDARY
51  };
52 
53  struct MBPatchBoundInfo {
54  MBPatchBoundInfo()
55  {
56  adjacentPatches.clear();
57  boundaryType = PR_INTERIOR_BOUNDARY;
58  isRefinementBoundary = false;
59  }
60  std::set<MBPoint> adjacentPatches;
61  BoundaryType boundaryType;
63  std::string typeString()
64  {
65  switch(boundaryType)
66  {
67  case PR_BLOCK_BOUNDARY: return "BLOCK_BOUNDARY";
68  case PR_DOMAIN_BOUNDARY: return "DOMAIN_BOUNDARY";
69  case PR_INTERIOR_BOUNDARY: return "INTERIOR_BOUNDARY";
70  default: return "UNKNOWN_BOUNDARY";
71  }
72  }
73  };
74  struct MBPatchInfo {
75  MBPatchInfo() : patch(Point::Zeros(), 0) {}
76  MBPatchInfo(const MBPoint& _patch, bool _exists)
77  : patch(_patch), exists(_exists)
78  {
79  boundaries.clear();
80  for (auto dir : Point::Directions())
81  {
82  boundaries[dir] = MBPatchBoundInfo();
83  }
84  }
85 
86  MBPoint patch;
87  bool exists;
88  std::map<Point, MBPatchBoundInfo> boundaries;
89  };
90 
91  }
93  {
94  public:
95 
96  inline MBBoxPartition(
97  const MBProblemDomain& a_domain);
98  inline MBBoxPartition(
99  const MBProblemDomain& a_domain,
100  const std::vector<MBPoint>& a_patches);
101  inline void define(
102  const MBProblemDomain& a_domain,
103  const std::vector<MBPoint>& a_patches);
104  inline void define(
105  const std::vector<MBPoint>& a_patches);
106  inline void loadBalance();
107  inline bool compatible(const MBBoxPartition& a_rhs);
108  const MBProblemDomain& domain() const {return m_patchDomain; }
109  inline unsigned int numProcs() const;
110  inline unsigned int numBoxes() const;
111  inline unsigned int numBoxes(unsigned int a_proc);
112  inline BlockIndex numBlocks() const;
113  inline uint64_t procStartIndex(unsigned int a_proc) const;
114  inline uint64_t procEndIndex(unsigned int a_proc) const;
115  inline uint64_t localIndex(uint64_t a_globalIndex, unsigned int a_proc) const;
116  inline uint64_t globalIndex(uint64_t a_localIndex, unsigned int a_proc) const;
117  inline uint64_t find(Point a_patch, BlockIndex a_block) const;
118  inline bool contains(Point a_patch, BlockIndex a_block) const;
119 
120  inline void validatePatch(const MBPoint& patch, std::string methodName) const;
121  inline void validateIndex(uint64_t index, std::string methodName) const;
122  inline Point connectivity(const MBPoint& src, const MBPoint& dst) const;
123  unsigned int getProc(uint64_t globalIndex) const;
124  inline MBPoint getPatch(uint64_t globalIndex) const;
125  inline BlockIndex getBlock(uint64_t globalIndex) const;
126  inline Point getPoint(uint64_t globalIndex) const;
127  inline std::set<MBPoint> adjacentPatches(const MBPoint& patch) const;
128  inline bool isBlockBoundary(
129  MBPoint patch,
130  Point dir) const;
131  inline bool isBlockBoundary(
132  MBPoint patch,
133  Point dir,
134  BlockIndex adjBlock) const;
135  inline bool isDomainBoundary(
136  MBPoint patch,
137  Point dir) const;
138  inline bool isInteriorBoundary(
139  MBPoint patch,
140  Point dir) const;
141  inline bool isRefinementBoundary(
142  MBPoint patch,
143  Point dir) const;
144  inline const MBPatchInfo& patchInfo(MBPoint patchID) const { return m_patchAdjacencies[patchID]; }
145  inline const std::vector<std::pair<MBPoint, unsigned int>>& partition() const
146  { return m_partition; }
147  inline std::shared_ptr<BoxPartition> blockPartition(BlockIndex a_block) const;
148  inline void print();
149 
150  private:
151 
152  inline void assign(
153  std::vector<Point>& a_patches,
154  unsigned int a_globalIndex,
155  int a_proc,
156  unsigned int a_num);
157 
158  inline void buildLocalMaps();
159  inline void buildGlobalMaps();
160  inline void findAdjacencies();
161  inline void getBoundaryInfo(MBPatchInfo& patchInfo);
162  inline void updateRefinementBoundaries();
163 
165  mutable std::map<MBPoint, uint64_t> m_indexMap; ///< Maps local to global
166  mutable std::unordered_map<unsigned int, std::pair<uint64_t, uint64_t>> m_procMap; ///< Maps proc to global indices
167  std::vector<std::shared_ptr<BoxPartition>> m_blockPartitions;
168  std::vector<std::pair<MBPoint, unsigned int>> m_partition;
169  mutable std::unordered_map<MBPoint, MBPatchInfo, MBPoint::Hash> m_patchAdjacencies;
170 
171  };
172 #include "implem/Proto_MBBoxPartitionImplem.H"
173 } // end namespace Proto
174 
175 #endif //end include guard
Definition: Proto_MBBoxPartition.H:92
Definition: Proto_MBProblemDomain.H:10
std::unordered_map< unsigned int, std::pair< uint64_t, uint64_t > > m_procMap
Maps proc to global indices.
Definition: Proto_MBBoxPartition.H:166
int BlockIndex
Defines what type is used for indexing block entities.
Definition: Proto_MBGraph.H:9
std::set< MBPoint > adjacentPatches
Definition: Proto_MBBoxPartition.H:60
std::map< MBPoint, uint64_t > m_indexMap
Maps local to global.
Definition: Proto_MBBoxPartition.H:165
MBProblemDomain m_patchDomain
Definition: Proto_MBBoxPartition.H:164
bool exists
Definition: Proto_MBBoxPartition.H:87
const std::vector< std::pair< MBPoint, unsigned int > > & partition() const
Definition: Proto_MBBoxPartition.H:145
const MBProblemDomain & domain() const
Definition: Proto_MBBoxPartition.H:108
Mapped Multi-Block Problem Domain.
Definition: Proto_MBProblemDomain.H:76
std::unordered_map< MBPoint, MBPatchInfo, MBPoint::Hash > m_patchAdjacencies
Definition: Proto_MBBoxPartition.H:169
static std::set< Point > Directions()
static ACCEL_DECORATION Point Zeros()
Get Zeros.
Definition: Proto_Array.H:17
std::vector< std::shared_ptr< BoxPartition > > m_blockPartitions
Definition: Proto_MBBoxPartition.H:167
uint64_t index
Definition: Proto_MBBoxPartition.H:15
BoundaryType
Definition: Proto_MBBoxPartition.H:46
std::vector< std::pair< MBPoint, unsigned int > > m_partition
Definition: Proto_MBBoxPartition.H:168
Integer Valued Vector.
Definition: Proto_Point.H:24
std::map< Point, MBPatchBoundInfo > boundaries
Definition: Proto_MBBoxPartition.H:88
bool isRefinementBoundary
Definition: Proto_MBBoxPartition.H:62
const MBPatchInfo & patchInfo(MBPoint patchID) const
Definition: Proto_MBBoxPartition.H:144
MBPoint patch
Definition: Proto_MBBoxPartition.H:86
Point dir
Definition: Proto_MBBoxPartition.H:16
BoundaryType boundaryType
Definition: Proto_MBBoxPartition.H:61