Proto  3.2
Proto_MBProblemDomain.H
Go to the documentation of this file.
1 #pragma once
2 #ifndef _PROTO_MB_PROBLEM_DOMAIN_
3 #define _PROTO_MB_PROBLEM_DOMAIN_
4 
5 #include "Proto.H"
6 #include "Proto_MBGraph.H"
7 
8 namespace Proto
9 {
10  struct MBPoint
11  {
14 
15  inline MBPoint(PatchID a_patch, BlockIndex a_block) : point(a_patch), block(a_block) {}
16  inline MBPoint(const MBPoint& a_rhs) : point(a_rhs.point), block(a_rhs.block) {}
17  MBPoint& operator=(const MBPoint& a_rhs) = default;
18  inline bool operator<(const MBPoint& a_rhs) const
19  {
20  if (block == a_rhs.block)
21  {
22  return (point < a_rhs.point);
23  } else {
24  return (block < a_rhs.block);
25  }
26  }
27  inline bool operator==(const MBPoint a_rhs) const{
28  return point == a_rhs.point && block == a_rhs.block;
29  }
30  struct Hash
31  {
32  std::size_t operator()(const MBPoint &key) const
33  {
34  std::size_t seed = 0;
35 
36  // Hash combine function
37  auto hash_combine = [](std::size_t& seed, std::size_t value) {
38  seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2);
39  };
40 
41  // Hash the vector elements
42  for (int dd = 0; dd < DIM; dd++) {
43  hash_combine(seed, std::hash<int>{}(key.point[dd]));
44  }
45 
46  // Hash the unsigned int
47  hash_combine(seed, std::hash<int>{}(key.block));
48 
49  return seed;
50  }
51  };
52 
53  };
54 
55  inline MBPoint operator+(const MBPoint& mbpoint, const Point& p)
56  {
57  return MBPoint(mbpoint.point + p, mbpoint.block);
58  }
59  inline MBPoint operator+(const Point& p, const MBPoint& mbpoint)
60  {
61  return mbpoint + p;
62  }
63  inline MBPoint operator+(const MBPoint& p1, const MBPoint& p2)
64  {
65  PROTO_ASSERT(p1.block == p2.block,
66  "MBPoint::operator+ | Error: MBPoint objects are in different blocks (%i and %i)",
67  p1.block, p2.block);
68  return MBPoint(p1.point + p2.point, p1.block);
69  }
70  /// Mapped Multi-Block Problem Domain
71  /**
72  The ProblemDomain equivalent for a MMB domain. Contains all of the
73  normal ProblemDomain objects for each individual block as well
74  as the connectivity information between blocks.
75  */
77  {
78  public:
79 
80  inline MBProblemDomain();
81 
82  inline MBProblemDomain(unsigned int a_numBlocks);
83 
84  inline MBProblemDomain(std::shared_ptr<MBGraph> a_graph);
85 
86  // Set Size of Specified Block
87  inline void defineDomain(BlockIndex a_blockID, Point a_domainSize);
88 
89  // Add a Codimension-1 Boundary to the Graph
90  inline void defineBoundary(
91  BlockIndex a_srcBlock,
92  BlockIndex a_dstBlock,
93  unsigned int a_dir,
94  Side::LoHiSide a_side,
95  CoordPermutation& a_rotation);
96 
97  // Add a Codimension-1 Boundary to the Graph
98  inline void defineBoundary(
99  BlockIndex a_srcBlock,
100  BlockIndex a_dstBlock,
101  Point a_dir,
102  CoordPermutation& a_rotation);
103 
104  // Number of Blocks
105  inline unsigned int size() const { return m_graph->numBlocks(); }
106 
107  // Number of Blocks
108  inline unsigned int numBlocks() const { return size(); }
109 
110  // Get Graph Reference
111  inline MBGraph& graph() const { return *m_graph; }
112 
113  // Get Graph Reference
114  inline std::shared_ptr<MBGraph> graphPtr() const { return m_graph; }
115 
116  // Get Local Problem Domain
117  inline const ProblemDomain& getBlock(BlockIndex a_blockID) const;
118 
119  // Get Size of Block
120  inline Point blockSize(BlockIndex a_blockID) const;
121 
122  // Get Differential Volume
123  inline double dv(BlockIndex a_blockID) const;
124 
125 
126  inline std::vector<MBGraphArc> boundaries(
127  BlockIndex a_srcBlock,
128  Point a_dir) const;
129 
130  // Convert a Point Between Block Coordinate Systems
131  inline Point convertNode(
132  Point a_point,
133  BlockIndex a_srcBlock,
134  BlockIndex a_dstBlock) const;
135 
136  // Convert a Point Between Block Coordinate Systems
137  inline Point convertPoint(
138  Point a_point,
139  BlockIndex a_srcBlock,
140  BlockIndex a_dstBlock,
141  Centering a_ctr) const;
142 
143  // Convert a Box Between Block Coordinate Systems
144  inline Box convertBox(
145  Box a_box,
146  BlockIndex a_srcBlock,
147  BlockIndex a_dstBlock,
148  Centering a_ctr = PR_CELL) const;
150  inline MBProblemDomain coarsen(Point a_refRatio) const;
151  inline MBProblemDomain coarsen(const std::vector<Point>& a_refRatios) const;
152  inline MBProblemDomain refine(Point a_refRatio) const;
153  inline MBProblemDomain refine(const std::vector<Point>& a_refRatios) const;
154 
155  inline bool coarsenable(Point a_refRatio) const;
156  inline bool coarsenable(BlockIndex a_block, Point a_refRatio) const;
157  inline bool defined() const;
158  inline bool operator==(const MBProblemDomain& a_rhs) const;
159  inline void close() const;
160 
161  inline std::vector<MBPoint> patches(int a_boxSize) const;
162  inline std::vector<MBPoint> patches(Point a_boxSize) const;
163  inline std::vector<MBPoint> patches(const std::vector<Point>& a_boxSizes) const;
164 
165  inline bool isPointInTriplePoint(Point a_point, BlockIndex a_block) const;
166  inline bool isPointInTriplePoint(Point a_point, BlockIndex a_block, Point a_dir) const;
167 
168  inline bool isPointInBlockBoundary(Point a_point, BlockIndex a_block) const;
169  inline bool isPointInBlockBoundary(Point a_point, BlockIndex a_block, Point a_dir) const;
170 
171  inline bool isPointInDomainBoundary(Point a_point, BlockIndex a_block) const;
172  inline bool isPointInDomainBoundary(Point a_point, BlockIndex a_block, Point a_dir) const;
173 
174  inline bool isPointInInterior(Point a_point, BlockIndex a_block) const;
175 
176  inline bool isPointOnBlockBoundary(Point a_point, BlockIndex a_block) const;
177  inline bool isPointOnBlockBoundary(Point a_point, BlockIndex a_block, Point a_dir) const;
178 
179  inline bool isPointOnDomainBoundary(Point a_point, BlockIndex a_block) const;
180  inline bool isPointOnDomainBoundary(Point a_point, BlockIndex a_block, Point a_dir) const;
181 
182  private:
183 
184  mutable bool m_closed;
185 
186  std::vector<ProblemDomain> m_domains;
187  std::shared_ptr<MBGraph> m_graph;
188 
189  std::vector<bool> m_domainsDefined;
190 
191  }; // end class MBProblemDomain
192 #include "implem/Proto_MBProblemDomainImplem.H"
193 }
194 
195 #endif // end include guard
std::size_t operator()(const MBPoint &key) const
Definition: Proto_MBProblemDomain.H:32
std::shared_ptr< MBGraph > graphPtr() const
Definition: Proto_MBProblemDomain.H:114
LoHiSide
Side Enum.
Definition: Proto_Face.H:23
Graph of a mapped multiblock domain. Nodes represent blocks and arcs represent boundaries between blo...
Definition: Proto_MBGraph.H:105
bool operator==(const MBPoint a_rhs) const
Definition: Proto_MBProblemDomain.H:27
std::vector< bool > m_domainsDefined
Definition: Proto_MBProblemDomain.H:189
Definition: Proto_MBProblemDomain.H:10
int BlockIndex
Defines what type is used for indexing block entities.
Definition: Proto_MBGraph.H:9
MBGraph & graph() const
Definition: Proto_MBProblemDomain.H:111
Defines discrete rotations in logically rectangular coordinate systems.
Definition: Proto_CoordPermutation.H:13
bool m_closed
Definition: Proto_MBProblemDomain.H:184
An interval in DIM dimensional space.
Definition: Proto_Box.H:29
std::vector< ProblemDomain > m_domains
Definition: Proto_MBProblemDomain.H:186
Mapped Multi-Block Problem Domain.
Definition: Proto_MBProblemDomain.H:76
PatchID point
Definition: Proto_MBProblemDomain.H:12
MBPoint & operator=(const MBPoint &a_rhs)=default
BlockIndex block
Definition: Proto_MBProblemDomain.H:13
std::shared_ptr< MBGraph > m_graph
Definition: Proto_MBProblemDomain.H:187
MBPoint operator+(const MBPoint &mbpoint, const Point &p)
Definition: Proto_MBProblemDomain.H:55
MBPoint(const MBPoint &a_rhs)
Definition: Proto_MBProblemDomain.H:16
#define PROTO_ASSERT(stmt, args...)
Definition: Proto_PAssert.H:48
Definition: Proto_Array.H:17
unsigned int numBlocks() const
Definition: Proto_MBProblemDomain.H:108
Integer Valued Vector.
Definition: Proto_Point.H:24
std::map< Point, MBPatchBoundInfo > boundaries
Definition: Proto_MBBoxPartition.H:88
unsigned int size() const
Definition: Proto_MBProblemDomain.H:105
Definition: Proto_Centering.H:9
MBPoint(PatchID a_patch, BlockIndex a_block)
Definition: Proto_MBProblemDomain.H:15
Represents a rectangular domain over which a problem can be defined, including periodic images...
Definition: Proto_ProblemDomain.H:22
bool operator<(const MBPoint &a_rhs) const
Definition: Proto_MBProblemDomain.H:18
Centering
Definition: Proto_Centering.H:7