Nektar++
SubStructuredGraph.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File SubStructuredGraph.h
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: a collection of classes that facilitates the implementation
32 // of the multi-level static condensation routines
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef MULTIREGIONS_SUBSTRUCTUREDGRAPH_H
37 #define MULTIREGIONS_SUBSTRUCTUREDGRAPH_H
38 
40 
43 
44 #include <vector>
45 #include <set>
46 #include <boost/config.hpp>
47 #include <boost/graph/adjacency_list.hpp>
48 #include <boost/graph/cuthill_mckee_ordering.hpp>
49 #include <boost/graph/properties.hpp>
50 #include <boost/graph/bandwidth.hpp>
51 
52 namespace Nektar
53 {
54  namespace MultiRegions
55  {
56  class BottomUpSubStructuredGraph;
57  class SubGraph;
58  class MultiLevelBisectedGraph;
59  class PatchMap;
60 
61  typedef std::shared_ptr<BottomUpSubStructuredGraph>
63  typedef std::shared_ptr<SubGraph>
65  typedef std::shared_ptr<MultiLevelBisectedGraph>
67  typedef std::shared_ptr<PatchMap>
69 
70  class PatchMap
71  {
72  public:
74  MULTI_REGIONS_EXPORT PatchMap(const int vals);
77  const int n,
78  const int patchId,
79  const int dofId,
80  const unsigned int bndPatch,
81  const NekDouble sign);
82 
83  void SetNewLevelMap(Array<OneD, const unsigned int> numLocalBndCondPerPatch,
84  Array<OneD, const unsigned int> numLocalIntCondPerPatch);
85 
86 
88  {
89  return m_patchId;
90  }
91 
93  {
94  return m_dofId;
95  }
96 
98  {
99  return m_newLevelMap;
100  }
101 
103  {
104  return m_bndPatch;
105  }
106 
108  {
109  return m_sign;
110  }
111 
112  protected:
118  };
119 
120  class SubGraph
121  {
122  public:
123 
125  const int nVerts, const int idOffset = 0) :
126  m_nVerts(nVerts),
127  m_idOffset(idOffset)
128  {
129  }
130 
132  {
133  }
134 
135  inline int GetNverts(void) const
136  {
137  return m_nVerts;
138  }
139 
140  inline void SetNverts(const int i)
141  {
142  m_nVerts = i;
143  }
144 
145  inline int GetIdOffset(void) const
146  {
147  return m_idOffset;
148  }
149 
150  inline void SetIdOffset(const int i)
151  {
152  m_idOffset = i;
153  }
154 
155  protected:
156  int m_nVerts;
158  };
159 
161 
163  {
164  public:
167  const int nPartition);
169  const int nBndDofs);
171 
172  MULTI_REGIONS_EXPORT int GetTotDofs() const;
174  MULTI_REGIONS_EXPORT void DumpNBndDofs(void) const;
176  std::vector<SubGraphSharedPtr>& leaves) const;
180  {
181  return m_daughterGraphs.size();
182  }
183 
184  inline const SubGraphSharedPtr GetBndDofsGraph() const
185  {
186  return m_BndDofs;
187  }
188 
189  inline
190  std::vector<MultiLevelBisectedGraphSharedPtr> &GetDaughterGraphs()
191  {
192  return m_daughterGraphs;
193  }
194 
195  protected:
197  std::vector<MultiLevelBisectedGraphSharedPtr> m_daughterGraphs;
198  };
199 
200 
202  {
203  public:
206  int nPartition = 0,
207  bool globaloffset = false);
209  const int nVerts);
211 
212  MULTI_REGIONS_EXPORT int GetTotDofs() const;
213 
215  Array<OneD, int>& perm,
216  Array<OneD, int>& iperm) const;
217 
219  const Array<OneD, const int>& wgts);
220 
222  const int leveltomask,
223  Array<OneD, NekDouble>& maskarray) const;
224 
226  const int whichlevel) const;
227 
229  const int whichlevel,
230  Array<OneD, unsigned int> &outarray) const;
231 
233  const int whichlevel,
234  const int patch = 0) const;
235 
236  MULTI_REGIONS_EXPORT std::vector<SubGraphSharedPtr>
237  GetInteriorBlocks(const int whichlevel) const;
238 
240  const int whichlevel) const;
241 
242  MULTI_REGIONS_EXPORT int GetNlevels() const;
243 
244  MULTI_REGIONS_EXPORT void Dump() const;
245 
246  protected:
247  std::vector<SubGraphSharedPtr> m_IntBlocks;
249 
250  private:
251  void SetBottomUpReordering(Array<OneD, int>& iperm) const;
252 
254  {
255  return m_daughterGraph;
256  }
257  inline std::vector<SubGraphSharedPtr> GetInteriorBlocks() const
258  {
259  return m_IntBlocks;
260  }
261  };
262 
263  namespace
264  {
265  typedef boost::adjacency_list<
266  boost::setS, boost::vecS, boost::undirectedS> BoostGraph;
267  }
268 
270  const BoostGraph& graph,
271  Array<OneD, int>& perm,
272  Array<OneD, int>& iperm);
273 
275  const BoostGraph &graph,
276  Array<OneD, int> &perm,
277  Array<OneD, int> &iperm,
278  BottomUpSubStructuredGraphSharedPtr &substructgraph,
279  std::set<int> partVerts = std::set<int>(),
280  int mdswitch = 1);
281 
282  // The parameter MDSWITCH.
283  //
284  // This parameters defines the maximal size of the smallest patches. If
285  // at a certain level, a patch bundles less than MDSWITCH
286  // graph-vertices, metis is not going to partition this subgraph any
287  // further. Some quick and basis test have shown that 30 seems to be
288  // good value. However, this optimal value will probably depend on the
289  // polynomial order of the expansion and there is still room for
290  // optimisation here.
291 
292  MULTI_REGIONS_EXPORT void NoReordering(const BoostGraph& graph,
293  Array<OneD, int>& perm,
294  Array<OneD, int>& iperm);
295  } // end of namespace
296 } // end of namespace
297 
298 #endif // MULTIREGIONS_SUBSTRUCTUREDGRAPH_H
#define MULTI_REGIONS_EXPORT
#define sign(a, b)
return the sign(b)*a
Definition: Polylib.cpp:15
void GetNintDofsPerPatch(const int whichlevel, Array< OneD, unsigned int > &outarray) const
void ExpandGraphWithVertexWeights(const Array< OneD, const int > &wgts)
std::vector< SubGraphSharedPtr > GetInteriorBlocks() const
BottomUpSubStructuredGraphSharedPtr GetDaughterGraph() const
void SetBottomUpReordering(Array< OneD, int > &iperm) const
int GetInteriorOffset(const int whichlevel, const int patch=0) const
BottomUpSubStructuredGraph(MultiLevelBisectedGraphSharedPtr graph, int nPartition=0, bool globaloffset=false)
void UpdateBottomUpReordering(Array< OneD, int > &perm, Array< OneD, int > &iperm) const
BottomUpSubStructuredGraphSharedPtr m_daughterGraph
void MaskPatches(const int leveltomask, Array< OneD, NekDouble > &maskarray) const
int GetNpatchesWithInterior(const int whichlevel) const
MultiLevelBisectedGraph(MultiLevelBisectedGraphSharedPtr oldLevel, const int nPartition)
void CollectLeaves(std::vector< SubGraphSharedPtr > &leaves) const
std::vector< MultiLevelBisectedGraphSharedPtr > & GetDaughterGraphs()
const SubGraphSharedPtr GetBndDofsGraph() const
std::vector< MultiLevelBisectedGraphSharedPtr > m_daughterGraphs
Array< OneD, unsigned int > m_bndPatch
void SetPatchMap(const int n, const int patchId, const int dofId, const unsigned int bndPatch, const NekDouble sign)
Array< OneD, const int > GetDofId() const
void SetNewLevelMap(Array< OneD, const unsigned int > numLocalBndCondPerPatch, Array< OneD, const unsigned int > numLocalIntCondPerPatch)
Array< OneD, NekDouble > m_sign
Array< OneD, const int > GetPatchId() const
Array< OneD, const NekDouble > GetSign() const
Array< OneD, const int > GetNewLevelMap() const
Array< OneD, const unsigned int > IsBndDof() const
SubGraph(const int nVerts, const int idOffset=0)
void NoReordering(const BoostGraph &graph, Array< OneD, int > &perm, Array< OneD, int > &iperm)
void CuthillMckeeReordering(const BoostGraph &graph, Array< OneD, int > &perm, Array< OneD, int > &iperm)
void MultiLevelBisectionReordering(const BoostGraph &graph, Array< OneD, int > &perm, Array< OneD, int > &iperm, BottomUpSubStructuredGraphSharedPtr &substructgraph, std::set< int > partVerts, int mdswitch)
std::shared_ptr< BottomUpSubStructuredGraph > BottomUpSubStructuredGraphSharedPtr
bool SubGraphWithoutVerts(const SubGraphSharedPtr g)
std::shared_ptr< MultiLevelBisectedGraph > MultiLevelBisectedGraphSharedPtr
std::shared_ptr< SubGraph > SubGraphSharedPtr
std::shared_ptr< PatchMap > PatchMapSharedPtr
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
double NekDouble