Nektar++
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 
59  LIB_UTILITIES_EXPORT MeshPartitionFactory& GetMeshPartitionFactory();
60 
62  {
63 
64  public:
65  LIB_UTILITIES_EXPORT MeshPartition(const SessionReaderSharedPtr& pSession);
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  MultiWeight weight; ///< Weightings to this graph vertex
145  };
146 
147  // Face/Edge/Vertex between two adjacent elements
149  {
150  int id;
151  std::vector<MeshVertex> vertices;
152  std::vector<MeshEdge> edges;
153  };
154 
155  // Basic graph definition
156  typedef boost::adjacency_list<
157  boost::setS,
158  boost::vecS,
159  boost::undirectedS,
161  boost::property<
162  boost::edge_index_t,
163  unsigned int,
165  >
167 
168  // Use induced subgraphs to manage the partitions
169  typedef boost::subgraph< BoostGraph > BoostSubGraph;
170 
171  typedef boost::graph_traits<
172  BoostGraph
173  >::vertex_descriptor BoostVertex;
174  typedef boost::graph_traits<
175  BoostGraph
176  >::edge_descriptor BoostEdge;
177  typedef boost::graph_traits<
178  BoostGraph
179  >::edge_iterator BoostEdgeIterator;
180  typedef boost::graph_traits<
181  BoostGraph
182  >::vertex_iterator BoostVertexIterator;
183  typedef boost::graph_traits<
184  BoostGraph
185  >::adjacency_iterator BoostAdjacencyIterator;
186 
187  typedef std::vector<unsigned int> NumModes;
188  typedef std::map<std::string, NumModes> NummodesPerField;
189 
190  int m_dim;
192 
193  std::map<int, MeshVertex> m_meshVertices;
194  std::map<int, MeshEntity> m_meshEdges;
195  std::map<int, MeshEntity> m_meshFaces;
196  std::map<int, MeshEntity> m_meshElements;
197  std::map<MeshCurvedKey, MeshCurved> m_meshCurved;
198  std::map<int, MeshEntity> m_meshComposites;
199  std::vector<unsigned int> m_domain;
200  std::map<std::string, std::string> m_vertexAttributes;
201 
202  // hierarchial mapping: composite id -> field name -> integer list
203  // of directional nummodes described by expansion type clause.
204  std::map<int, NummodesPerField> m_expansions;
205 
206  std::map<std::string, int> m_fieldNameToId;
207  std::map<int, MultiWeight> m_vertWeights;
208 
209  BndRegionOrdering m_bndRegOrder;
210 
211  BoostSubGraph m_mesh;
212  std::vector<BoostSubGraph> m_localPartition;
213 
215 
217  bool m_shared;
218 
219  void ReadExpansions(const SessionReaderSharedPtr& pSession);
220  void ReadGeometry(const SessionReaderSharedPtr& pSession);
221  void ReadConditions(const SessionReaderSharedPtr& pSession);
222  void WeightElements();
223  void CreateGraph(BoostSubGraph& pGraph);
224  void PartitionGraph(BoostSubGraph& pGraph,
225  int nParts,
226  std::vector<BoostSubGraph>& pLocalPartition);
227 
228  virtual void PartitionGraphImpl(
229  int& nVerts,
230  int& nVertConds,
235  int& nparts,
236  int& volume,
238 
239  void OutputPartition(SessionReaderSharedPtr& pSession, BoostSubGraph& pGraph, TiXmlElement* pGeometry);
240  void CheckPartitions(int nParts, Array<OneD, int> &pPart);
241  int CalculateElementWeight(char elmtType, bool bndWeight, int na, int nb, int nc);
242  };
243 
244  typedef boost::shared_ptr<MeshPartition> MeshPartitionSharedPtr;
245  }
246 }
247 
248 #endif
void GetCompositeOrdering(CompositeOrdering &composites)
int CalculateElementWeight(char elmtType, bool bndWeight, int na, int nb, int nc)
std::map< std::string, std::string > m_vertexAttributes
int partition
Index of the partition to which it belongs.
std::map< int, MeshEntity > m_meshComposites
void WriteLocalPartition(SessionReaderSharedPtr &pSession)
std::map< int, MeshVertex > m_meshVertices
boost::shared_ptr< MeshPartition > MeshPartitionSharedPtr
void CheckPartitions(int nParts, Array< OneD, int > &pPart)
void ReadConditions(const SessionReaderSharedPtr &pSession)
std::vector< unsigned int > NumModes
std::map< MeshCurvedKey, MeshCurved > m_meshCurved
std::map< int, std::vector< unsigned int > > BndRegionOrdering
Definition: MeshPartition.h:53
virtual void PartitionGraphImpl(int &nVerts, int &nVertConds, Nektar::Array< Nektar::OneD, int > &xadj, Nektar::Array< Nektar::OneD, int > &adjcy, Nektar::Array< Nektar::OneD, int > &vertWgt, Nektar::Array< Nektar::OneD, int > &vertSize, int &nparts, int &volume, Nektar::Array< Nektar::OneD, int > &part)=0
void PartitionMesh(int nParts, bool shared=false)
boost::graph_traits< BoostGraph >::vertex_descriptor BoostVertex
std::map< int, MultiWeight > m_vertWeights
std::map< int, std::vector< unsigned int > > CompositeOrdering
Definition: MeshPartition.h:52
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:50
std::map< std::string, NumModes > NummodesPerField
std::map< std::string, int > m_fieldNameToId
std::vector< unsigned int > MultiWeight
void ReadExpansions(const SessionReaderSharedPtr &pSession)
std::map< int, NummodesPerField > m_expansions
std::map< int, MeshEntity > m_meshElements
boost::adjacency_list< boost::setS, boost::vecS, boost::undirectedS, GraphVertexProperties, boost::property< boost::edge_index_t, unsigned int, GraphEdgeProperties > > BoostGraph
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:53
LibUtilities::NekFactory< std::string, MeshPartition, const SessionReaderSharedPtr & > MeshPartitionFactory
Datatype of the NekFactory used to instantiate classes derived from the EquationSystem class...
Definition: MeshPartition.h:57
MultiWeight weight
Weightings to this graph vertex.
void CreateGraph(BoostSubGraph &pGraph)
#define LIB_UTILITIES_EXPORT
void GetBndRegionOrdering(BndRegionOrdering &composites)
void GetElementIDs(const int procid, std::vector< unsigned int > &tmp)
std::vector< unsigned int > m_domain
std::vector< BoostSubGraph > m_localPartition
double NekDouble
void ReadGeometry(const SessionReaderSharedPtr &pSession)
std::pair< std::string, int > MeshCurvedKey
boost::graph_traits< BoostGraph >::adjacency_iterator BoostAdjacencyIterator
std::map< int, MeshEntity > m_meshEdges
void PartitionGraph(BoostSubGraph &pGraph, int nParts, std::vector< BoostSubGraph > &pLocalPartition)
Reads and parses information from a Nektar++ XML session file.
boost::graph_traits< BoostGraph >::edge_iterator BoostEdgeIterator
boost::graph_traits< BoostGraph >::edge_descriptor BoostEdge
void PrintPartInfo(std::ostream &out)
std::map< int, MeshEntity > m_meshFaces
void WriteAllPartitions(SessionReaderSharedPtr &pSession)
boost::graph_traits< BoostGraph >::vertex_iterator BoostVertexIterator
void OutputPartition(SessionReaderSharedPtr &pSession, BoostSubGraph &pGraph, TiXmlElement *pGeometry)
MeshPartition(const SessionReaderSharedPtr &pSession)
MeshPartitionFactory & GetMeshPartitionFactory()
Provides a generic Factory class.
Definition: NekFactory.hpp:116
boost::subgraph< BoostGraph > BoostSubGraph