Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MeshPartition.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: MeshPartition.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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description:
33 //
34 //
35 ////////////////////////////////////////////////////////////////////////////////
36 #ifndef NEKTAR_LIBUTILITIES_BASICUTILS_MESHPARTITION_H
37 #define NEKTAR_LIBUTILITIES_BASICUTILS_MESHPARTITION_H
38 
39 #include <boost/graph/subgraph.hpp>
40 #include <boost/graph/adjacency_list.hpp>
42 
43 class TiXmlElement;
44 
45 namespace Nektar
46 {
47  namespace LibUtilities
48  {
49  class MeshPartition;
51  typedef boost::shared_ptr<SessionReader> SessionReaderSharedPtr;
52  typedef std::map<int, std::vector<unsigned int> > CompositeOrdering;
53  typedef std::map<int, std::vector<unsigned int> > BndRegionOrdering;
54 
55  /// Datatype of the NekFactory used to instantiate classes derived from
56  /// the EquationSystem class.
58 
60 
62  {
63 
64  public:
67 
68  LIB_UTILITIES_EXPORT void PartitionMesh(int nParts, bool shared = false);
70  SessionReaderSharedPtr& pSession);
72  SessionReaderSharedPtr& pSession);
73 
74  LIB_UTILITIES_EXPORT void PrintPartInfo(std::ostream &out);
76  CompositeOrdering &composites);
78  BndRegionOrdering &composites);
79 
80  LIB_UTILITIES_EXPORT void GetElementIDs(const int procid,
81  std::vector<unsigned int> &tmp);
82 
83  private:
84  struct MeshEntity
85  {
86  int id;
87  char type;
88  std::vector<unsigned int> list;
89  };
90 
91  struct MeshVertex
92  {
93  int id;
97  };
98 
99  struct MeshEdge
100  {
101  int id;
102  int v0;
103  int v1;
104  };
105 
106  struct MeshFace
107  {
108  int id;
109  std::vector<int> edgeList;
110  };
111 
112  struct MeshElement
113  {
114  int id;
115  char type;
116  std::vector<int> list;
117  };
118 
119  struct MeshCurved
120  {
121  int id;
122  std::string entitytype;
123  int entityid;
124  std::string type;
125  int npoints;
126  std::string data;
127  };
128  typedef std::pair<std::string, int> MeshCurvedKey;
129 
131  {
132  int id;
133  char type;
134  std::vector<int> list;
135  };
136 
137  typedef std::vector<unsigned int> MultiWeight;
138 
139  // Element in a mesh
141  {
142  int id; ///< Universal ID of the vertex
143  int partition; ///< Index of the partition to which it belongs
144  int partid; ///< Global ID of the vertex in the partition
145  MultiWeight weight; ///< Weightings to this graph vertex
146  };
147 
148  // Face/Edge/Vertex between two adjacent elements
150  {
151  int id;
152  std::vector<MeshVertex> vertices;
153  std::vector<MeshEdge> edges;
154  };
155 
156  // Basic graph definition
157  typedef boost::adjacency_list<
158  boost::setS,
159  boost::vecS,
160  boost::undirectedS,
162  boost::property<
163  boost::edge_index_t,
164  unsigned int,
166  >
168 
169  // Use induced subgraphs to manage the partitions
170  typedef boost::subgraph< BoostGraph > BoostSubGraph;
171 
172  typedef boost::graph_traits<
173  BoostGraph
174  >::vertex_descriptor BoostVertex;
175  typedef boost::graph_traits<
176  BoostGraph
177  >::edge_descriptor BoostEdge;
178  typedef boost::graph_traits<
179  BoostGraph
180  >::edge_iterator BoostEdgeIterator;
181  typedef boost::graph_traits<
182  BoostGraph
183  >::vertex_iterator BoostVertexIterator;
184  typedef boost::graph_traits<
185  BoostGraph
186  >::adjacency_iterator BoostAdjacencyIterator;
187 
188  typedef std::vector<unsigned int> NumModes;
189  typedef std::map<std::string, NumModes> NummodesPerField;
190 
191  int m_dim;
193 
194  std::map<int, MeshVertex> m_meshVertices;
195  std::map<int, MeshEntity> m_meshEdges;
196  std::map<int, MeshEntity> m_meshFaces;
197  std::map<int, MeshEntity> m_meshElements;
198  std::map<MeshCurvedKey, MeshCurved> m_meshCurved;
199  std::map<int, MeshEntity> m_meshComposites;
200  std::vector<unsigned int> m_domain;
201  std::map<std::string, std::string> m_vertexAttributes;
202 
203  // hierarchial mapping: composite id -> field name -> integer list
204  // of directional nummodes described by expansion type clause.
205  std::map<int, NummodesPerField> m_expansions;
206 
207  std::map<std::string, int> m_fieldNameToId;
208  std::vector<MultiWeight> m_vertWeights;
209 
211 
213  std::vector<BoostSubGraph> m_localPartition;
214 
216 
218  bool m_shared;
219 
220  void ReadExpansions(const SessionReaderSharedPtr& pSession);
221  void ReadGeometry(const SessionReaderSharedPtr& pSession);
222  void ReadConditions(const SessionReaderSharedPtr& pSession);
223  void WeightElements();
224  void CreateGraph(BoostSubGraph& pGraph);
225  void PartitionGraph(BoostSubGraph& pGraph,
226  int nParts,
227  std::vector<BoostSubGraph>& pLocalPartition);
228 
229  virtual void PartitionGraphImpl(
230  int& nVerts,
231  int& nVertConds,
232  Nektar::Array<Nektar::OneD, int>& xadj,
233  Nektar::Array<Nektar::OneD, int>& adjcy,
234  Nektar::Array<Nektar::OneD, int>& vertWgt,
235  Nektar::Array<Nektar::OneD, int>& vertSize,
236  int& nparts,
237  int& volume,
238  Nektar::Array<Nektar::OneD, int>& part) = 0;
239 
240  void OutputPartition(SessionReaderSharedPtr& pSession, BoostSubGraph& pGraph, TiXmlElement* pGeometry);
241  void CheckPartitions(int nParts, Array<OneD, int> &pPart);
242  int CalculateElementWeight(char elmtType, bool bndWeight, int na, int nb, int nc);
243  };
244 
245  typedef boost::shared_ptr<MeshPartition> MeshPartitionSharedPtr;
246  }
247 }
248 
249 #endif