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 
84  {
85  return m_patchId;
86  }
87 
89  {
90  return m_dofId;
91  }
92 
94  {
95  return m_bndPatch;
96  }
97 
99  {
100  return m_sign;
101  }
102 
103  protected:
108  };
109 
110  class SubGraph
111  {
112  public:
113 
115  const int nVerts, const int idOffset = 0) :
116  m_nVerts(nVerts),
117  m_idOffset(idOffset)
118  {
119  }
120 
122  {
123  }
124 
125  inline int GetNverts(void) const
126  {
127  return m_nVerts;
128  }
129 
130  inline void SetNverts(const int i)
131  {
132  m_nVerts = i;
133  }
134 
135  inline int GetIdOffset(void) const
136  {
137  return m_idOffset;
138  }
139 
140  inline void SetIdOffset(const int i)
141  {
142  m_idOffset = i;
143  }
144 
145  protected:
146  int m_nVerts;
148  };
149 
151 
153  {
154  public:
157  const int nPartition);
158  MULTI_REGIONS_EXPORT MultiLevelBisectedGraph(
159  const int nBndDofs);
160  MULTI_REGIONS_EXPORT ~MultiLevelBisectedGraph(void);
161 
162  MULTI_REGIONS_EXPORT int GetTotDofs() const;
163  MULTI_REGIONS_EXPORT void SetGlobalNumberingOffset();
164  MULTI_REGIONS_EXPORT void DumpNBndDofs(void) const;
165  MULTI_REGIONS_EXPORT void CollectLeaves(
166  std::vector<SubGraphSharedPtr>& leaves) const;
167  MULTI_REGIONS_EXPORT int CutLeaves();
168  MULTI_REGIONS_EXPORT int CutEmptyLeaves();
170  {
171  return m_daughterGraphs.size();
172  }
173 
174  inline const SubGraphSharedPtr GetBndDofsGraph() const
175  {
176  return m_BndDofs;
177  }
178 
179  inline
180  std::vector<MultiLevelBisectedGraphSharedPtr> &GetDaughterGraphs()
181  {
182  return m_daughterGraphs;
183  }
184 
185  protected:
187  std::vector<MultiLevelBisectedGraphSharedPtr> m_daughterGraphs;
188  };
189 
190 
192  {
193  public:
196  int nPartition = 0,
197  bool globaloffset = false);
198  MULTI_REGIONS_EXPORT BottomUpSubStructuredGraph(
199  const int nVerts);
200  MULTI_REGIONS_EXPORT ~BottomUpSubStructuredGraph(void);
201 
202  MULTI_REGIONS_EXPORT int GetTotDofs() const;
203 
204  MULTI_REGIONS_EXPORT void UpdateBottomUpReordering(
205  Array<OneD, int>& perm,
206  Array<OneD, int>& iperm) const;
207 
208  MULTI_REGIONS_EXPORT void ExpandGraphWithVertexWeights(
209  const Array<OneD, const int>& wgts);
210 
211  MULTI_REGIONS_EXPORT void MaskPatches(
212  const int leveltomask,
213  Array<OneD, NekDouble>& maskarray) const;
214 
215  MULTI_REGIONS_EXPORT int GetNpatchesWithInterior(
216  const int whichlevel) const;
217 
218  MULTI_REGIONS_EXPORT void GetNintDofsPerPatch(
219  const int whichlevel,
220  Array<OneD, unsigned int> &outarray) const;
221 
222  MULTI_REGIONS_EXPORT int GetInteriorOffset(
223  const int whichlevel,
224  const int patch = 0) const;
225 
226  MULTI_REGIONS_EXPORT std::vector<SubGraphSharedPtr>
227  GetInteriorBlocks(const int whichlevel) const;
228 
229  MULTI_REGIONS_EXPORT int GetNumGlobalDofs(
230  const int whichlevel) const;
231 
232  MULTI_REGIONS_EXPORT int GetNlevels() const;
233 
234  MULTI_REGIONS_EXPORT void Dump() const;
235 
236  protected:
237  std::vector<SubGraphSharedPtr> m_IntBlocks;
238  BottomUpSubStructuredGraphSharedPtr m_daughterGraph;
239 
240  private:
241  void SetBottomUpReordering(Array<OneD, int>& iperm) const;
242 
243  inline BottomUpSubStructuredGraphSharedPtr GetDaughterGraph() const
244  {
245  return m_daughterGraph;
246  }
247  inline std::vector<SubGraphSharedPtr> GetInteriorBlocks() const
248  {
249  return m_IntBlocks;
250  }
251  };
252 
253  namespace
254  {
255  typedef boost::adjacency_list<
256  boost::setS, boost::vecS, boost::undirectedS> BoostGraph;
257  }
258 
260  const BoostGraph& graph,
261  Array<OneD, int>& perm,
262  Array<OneD, int>& iperm);
263 
265  const BoostGraph &graph,
266  Array<OneD, int> &perm,
267  Array<OneD, int> &iperm,
268  BottomUpSubStructuredGraphSharedPtr &substructgraph,
269  std::set<int> partVerts = std::set<int>(),
270  int mdswitch = 1);
271 
272  // The parameter MDSWITCH.
273  //
274  // This parameters defines the maximal size of the smallest patches. If
275  // at a certain level, a patch bundles less than MDSWITCH
276  // graph-vertices, metis is not going to partition this subgraph any
277  // further. Some quick and basis test have shown that 30 seems to be
278  // good value. However, this optimal value will probably depend on the
279  // polynomial order of the expansion and there is still room for
280  // optimisation here.
281 
282  MULTI_REGIONS_EXPORT void NoReordering(const BoostGraph& graph,
283  Array<OneD, int>& perm,
284  Array<OneD, int>& iperm);
285  } // end of namespace
286 } // end of namespace
287 
288 #endif // MULTIREGIONS_SUBSTRUCTUREDGRAPH_H
Array< OneD, NekDouble > m_sign
void MultiLevelBisectionReordering(const BoostGraph &graph, Array< OneD, int > &perm, Array< OneD, int > &iperm, BottomUpSubStructuredGraphSharedPtr &substructgraph, std::set< int > partVerts, int mdswitch)
#define sign(a, b)
return the sign(b)*a
Definition: Polylib.cpp:16
std::vector< MultiLevelBisectedGraphSharedPtr > m_daughterGraphs
std::vector< SubGraphSharedPtr > GetInteriorBlocks() const
BottomUpSubStructuredGraphSharedPtr GetDaughterGraph() const
Array< OneD, const unsigned int > IsBndDof() const
const SubGraphSharedPtr GetBndDofsGraph() const
std::vector< MultiLevelBisectedGraphSharedPtr > & GetDaughterGraphs()
#define MULTI_REGIONS_EXPORT
void CuthillMckeeReordering(const BoostGraph &graph, Array< OneD, int > &perm, Array< OneD, int > &iperm)
Array< OneD, const int > GetDofId() const
Array< OneD, const int > GetPatchId() const
Array< OneD, unsigned int > m_bndPatch
std::shared_ptr< PatchMap > PatchMapSharedPtr
std::shared_ptr< SubGraph > SubGraphSharedPtr
double NekDouble
BottomUpSubStructuredGraphSharedPtr m_daughterGraph
Array< OneD, const NekDouble > GetSign() const
std::shared_ptr< MultiLevelBisectedGraph > MultiLevelBisectedGraphSharedPtr
bool SubGraphWithoutVerts(const SubGraphSharedPtr g)
SubGraph(const int nVerts, const int idOffset=0)
void SetPatchMap(const int n, const int patchId, const int dofId, const unsigned int bndPatch, const NekDouble sign)
std::shared_ptr< BottomUpSubStructuredGraph > BottomUpSubStructuredGraphSharedPtr
void NoReordering(const BoostGraph &graph, Array< OneD, int > &perm, Array< OneD, int > &iperm)