Proto  3.2
Proto_CoarseFineBoundary.H
Go to the documentation of this file.
1 #pragma once
2 #ifndef _PROTO_COARSE_FINE_BOUNDARY_
3 #define _PROTO_COARSE_FINE_BOUNDARY_
4 
5 #include "Proto.H"
6 
7 namespace Proto
8 {
9 
10  template < typename P>
12  {
13  public:
14  CoarseFineBoundary(std::shared_ptr<P> coarsePartition, std::shared_ptr<P> finePartition);
15 
16  bool onCoarseBoundary(DataIndex<P> coarseIndex) const;
17  bool onFineBoundary(DataIndex<P> fineIndex) const;
18  std::vector<DataIndex<P>> getCoarseFromFine(DataIndex<P> fineIndex) const;
19  std::vector<DataIndex<P>> getFineFromCoarse(DataIndex<P> coarseIndex) const;
20  private:
21  std::shared_ptr<P> m_coarsePartition;
22  std::shared_ptr<P> m_finePartition;
23  std::map<DataIndex<P>, std::vector<DataIndex<P>>> m_coarseMap;
24  std::map<DataIndex<P>, std::vector<DataIndex<P>>> m_fineMap;
25 
26  };
27 
28  template <typename P>
30  std::shared_ptr<P> coarsePartition,
31  std::shared_ptr<P> finePartition)
32  {
33  m_coarsePartition = coarsePartition;
34  m_finePartition = finePartition;
35 
36  DataIterator<P> coarseIter(coarsePartition);
37  DataIterator<P> fineIter(finePartition);
38 
39  for (auto iter = fineIter.begin(); iter != fineIter.end(); ++fineIter)
40  {
41  DataIndex<P> fineIndex = *iter;
42  DataIndex<P> coarseIndex = finePartition->getCoarseIndexFromFine(fineIndex, coarsePartition);
43  PROTO_ASSERT(coarseIndex != *coarseIter.end(),
44  "CoarseFineBoundary::constructor | Error: Proper Nesting Violation");
45 
47  {
48  if (finePartition->isInteriorBoundary(fineIndex, dir))
49  {
50  DataIndex<P> adjFineIndex = finePartition->getAdjacentIndex(fineIndex);
51  if (adjFineIndex == *fineIter.end())
52  {
53  DataIndex<P> adjCoarseIndex = finePartition->getCoarseIndexFromFine(fineIndex, coarsePartition, dir);
54  PROTO_ASSERT(adjCoarseIndex != *coarseIter.end(),
55  "CoarseFineBoundary::constructor | Error: Proper Nesting Violation");
56  m_fineMap[fineIndex].push_back(adjCoarseIndex);
57  m_coarseMap[adjCoarseIndex].push_back(fineIndex);
58  }
59  }
60  }
61 
62  }
63  }
64 
65  template<typename P>
67  {
69  "CoarseFineBoundary::onCoarseBoundary | Error: Incompatible Index");
70  bool exists = (m_coarseMap.find(coarseIndex) != m_coarseMap.end());
71  return exists;
72  }
73 
74  template<typename P>
76  {
78  "CoarseFineBoundary::onFineBoundary | Error: Incompatible Index");
79  bool exists = (m_fineMap.find(fineIndex) != m_fineMap.end());
80  return exists;
81  }
82 
83  template<typename P>
84  std::vector<DataIndex<P>> CoarseFineBoundary<P>::getCoarseFromFine(DataIndex<P> fineIndex) const
85  {
86  if (onFineBoundary(fineIndex))
87  {
88  return m_fineMap[fineIndex];
89  }
90  return std::vector<DataIndex<P>>();
91  }
92 
93  template<typename P>
94  std::vector<DataIndex<P>> CoarseFineBoundary<P>::getFineFromCoarse(DataIndex<P> coarseIndex) const
95  {
96  if (onCoarseBoundary(coarseIndex))
97  {
98  return m_coarseMap[coarseIndex];
99  }
100  return std::vector<DataIndex<P>>();
101  }
102 }
103 #endif
std::vector< DataIndex< P > > getCoarseFromFine(DataIndex< P > fineIndex) const
Definition: Proto_CoarseFineBoundary.H:84
DataIterator< P > & end()
Set To End.
Definition: Proto_DataIterator.H:22
Definition: Proto_CoarseFineBoundary.H:11
Distributed Data Iterator.
Definition: Proto_DataIndex.H:10
bool compatible(const DataIndex< P > &a_index) const
Compatibility Query.
Definition: Proto_DataIndex.H:103
std::map< DataIndex< P >, std::vector< DataIndex< P > > > m_fineMap
Definition: Proto_CoarseFineBoundary.H:24
static std::set< Point > DirectionsOfCodim(int a_codim)
std::vector< DataIndex< P > > getFineFromCoarse(DataIndex< P > coarseIndex) const
Definition: Proto_CoarseFineBoundary.H:94
bool exists
Definition: Proto_MBBoxPartition.H:87
std::shared_ptr< P > m_coarsePartition
Definition: Proto_CoarseFineBoundary.H:21
bool onFineBoundary(DataIndex< P > fineIndex) const
Definition: Proto_CoarseFineBoundary.H:75
DataIterator< P > & begin()
Set To Start.
Definition: Proto_DataIterator.H:13
CoarseFineBoundary(std::shared_ptr< P > coarsePartition, std::shared_ptr< P > finePartition)
Definition: Proto_CoarseFineBoundary.H:29
bool onCoarseBoundary(DataIndex< P > coarseIndex) const
Definition: Proto_CoarseFineBoundary.H:66
std::shared_ptr< P > m_finePartition
Definition: Proto_CoarseFineBoundary.H:22
#define PROTO_ASSERT(stmt, args...)
Definition: Proto_PAssert.H:48
Definition: Proto_Array.H:17
std::map< DataIndex< P >, std::vector< DataIndex< P > > > m_coarseMap
Definition: Proto_CoarseFineBoundary.H:23
Integer Valued Vector.
Definition: Proto_Point.H:24
Data Index.
Definition: Proto_DataIndex.H:20
Point dir
Definition: Proto_MBBoxPartition.H:16