Nektar++
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <boost/config.hpp>
45 #include <boost/graph/adjacency_list.hpp>
46 #include <boost/graph/bandwidth.hpp>
47 #include <boost/graph/cuthill_mckee_ordering.hpp>
48 #include <boost/graph/properties.hpp>
49 #include <set>
50 #include <vector>
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> SubGraphSharedPtr;
64 typedef std::shared_ptr<MultiLevelBisectedGraph>
66 typedef std::shared_ptr<PatchMap> PatchMapSharedPtr;
67 
68 class PatchMap
69 {
70 public:
72  MULTI_REGIONS_EXPORT PatchMap(const int vals);
74  MULTI_REGIONS_EXPORT void SetPatchMap(const int n, const int patchId,
75  const int dofId,
76  const unsigned int bndPatch,
77  const NekDouble sign);
78 
79  void SetNewLevelMap(
80  Array<OneD, const unsigned int> numLocalBndCondPerPatch,
81  Array<OneD, const unsigned int> numLocalIntCondPerPatch);
82 
84  {
85  return m_patchId;
86  }
87 
89  {
90  return m_dofId;
91  }
92 
94  {
95  return m_newLevelMap;
96  }
97 
99  {
100  return m_bndPatch;
101  }
102 
104  {
105  return m_sign;
106  }
107 
108 protected:
114 };
115 
116 class SubGraph
117 {
118 public:
119  MULTI_REGIONS_EXPORT SubGraph(const int nVerts, const int idOffset = 0)
120  : m_nVerts(nVerts), m_idOffset(idOffset)
121  {
122  }
123 
125  {
126  }
127 
128  inline int GetNverts(void) const
129  {
130  return m_nVerts;
131  }
132 
133  inline void SetNverts(const int i)
134  {
135  m_nVerts = i;
136  }
137 
138  inline int GetIdOffset(void) const
139  {
140  return m_idOffset;
141  }
142 
143  inline void SetIdOffset(const int i)
144  {
145  m_idOffset = i;
146  }
147 
148 protected:
149  int m_nVerts;
151 };
152 
154 
156 {
157 public:
159  MultiLevelBisectedGraphSharedPtr oldLevel, const int nPartition);
160  MULTI_REGIONS_EXPORT MultiLevelBisectedGraph(const int nBndDofs);
162 
163  MULTI_REGIONS_EXPORT int GetTotDofs() const;
165  MULTI_REGIONS_EXPORT void DumpNBndDofs(void) const;
167  std::vector<SubGraphSharedPtr> &leaves) const;
171  {
172  return m_daughterGraphs.size();
173  }
174 
175  inline const SubGraphSharedPtr GetBndDofsGraph() const
176  {
177  return m_BndDofs;
178  }
179 
180  inline std::vector<MultiLevelBisectedGraphSharedPtr> &GetDaughterGraphs()
181  {
182  return m_daughterGraphs;
183  }
184 
185 protected:
187  std::vector<MultiLevelBisectedGraphSharedPtr> m_daughterGraphs;
188 };
189 
191 {
192 public:
194  MultiLevelBisectedGraphSharedPtr graph, int nPartition = 0,
195  bool globaloffset = false);
198 
199  MULTI_REGIONS_EXPORT int GetTotDofs() const;
200 
202  Array<OneD, int> &perm, Array<OneD, int> &iperm) const;
203 
205  const Array<OneD, const int> &wgts);
206 
208  const int leveltomask, Array<OneD, NekDouble> &maskarray) const;
209 
211  const int whichlevel) const;
212 
214  const int whichlevel, Array<OneD, unsigned int> &outarray) const;
215 
216  MULTI_REGIONS_EXPORT int GetInteriorOffset(const int whichlevel,
217  const int patch = 0) const;
218 
219  MULTI_REGIONS_EXPORT std::vector<SubGraphSharedPtr> GetInteriorBlocks(
220  const int whichlevel) const;
221 
222  MULTI_REGIONS_EXPORT int GetNumGlobalDofs(const int whichlevel) const;
223 
224  MULTI_REGIONS_EXPORT int GetNlevels() const;
225 
226  MULTI_REGIONS_EXPORT void Dump() const;
227 
228 protected:
229  std::vector<SubGraphSharedPtr> m_IntBlocks;
231 
232 private:
233  void SetBottomUpReordering(Array<OneD, int> &iperm) const;
234 
236  {
237  return m_daughterGraph;
238  }
239  inline std::vector<SubGraphSharedPtr> GetInteriorBlocks() const
240  {
241  return m_IntBlocks;
242  }
243 };
244 
245 namespace
246 {
247 typedef boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS>
248  BoostGraph;
249 }
250 
251 MULTI_REGIONS_EXPORT void CuthillMckeeReordering(const BoostGraph &graph,
252  Array<OneD, int> &perm,
253  Array<OneD, int> &iperm);
254 
256  const BoostGraph &graph, Array<OneD, int> &perm, Array<OneD, int> &iperm,
257  BottomUpSubStructuredGraphSharedPtr &substructgraph,
258  std::set<int> partVerts = std::set<int>(), int mdswitch = 1);
259 
260 // The parameter MDSWITCH.
261 //
262 // This parameters defines the maximal size of the smallest patches. If
263 // at a certain level, a patch bundles less than MDSWITCH
264 // graph-vertices, metis is not going to partition this subgraph any
265 // further. Some quick and basis test have shown that 30 seems to be
266 // good value. However, this optimal value will probably depend on the
267 // polynomial order of the expansion and there is still room for
268 // optimisation here.
269 
270 MULTI_REGIONS_EXPORT void NoReordering(const BoostGraph &graph,
271  Array<OneD, int> &perm,
272  Array<OneD, int> &iperm);
273 } // namespace MultiRegions
274 } // namespace Nektar
275 
276 #endif // MULTIREGIONS_SUBSTRUCTUREDGRAPH_H
#define MULTI_REGIONS_EXPORT
#define sign(a, b)
return the sign(b)*a
Definition: Polylib.cpp:49
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:2
double NekDouble