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>
43 
44 class TiXmlElement;
45 
46 namespace Nektar
47 {
48  namespace LibUtilities
49  {
50  class MeshPartition;
52  typedef boost::shared_ptr<SessionReader> SessionReaderSharedPtr;
53  typedef std::map<int, std::vector<unsigned int> > CompositeOrdering;
54  typedef std::map<int, std::vector<unsigned int> > BndRegionOrdering;
55 
56  /// Datatype of the NekFactory used to instantiate classes derived from
57  /// the EquationSystem class.
59 
60  LIB_UTILITIES_EXPORT MeshPartitionFactory& GetMeshPartitionFactory();
61 
63  {
64 
65  public:
66  LIB_UTILITIES_EXPORT MeshPartition(const SessionReaderSharedPtr& pSession);
68 
69  LIB_UTILITIES_EXPORT void PartitionMesh(int nParts, bool shared = false, bool overlapping = false);
71  SessionReaderSharedPtr& pSession);
73  SessionReaderSharedPtr& pSession);
74 
75  LIB_UTILITIES_EXPORT void PrintPartInfo(std::ostream &out);
77  CompositeOrdering &composites);
79  BndRegionOrdering &composites);
80 
81  LIB_UTILITIES_EXPORT void GetElementIDs(const int procid,
82  std::vector<unsigned int> &tmp);
83 
84  private:
85  struct MeshEntity
86  {
87  int id;
88  char type;
89  std::vector<unsigned int> list;
90  };
91 
92  struct MeshFace
93  {
94  int id;
95  std::vector<int> edgeList;
96  };
97 
98  struct MeshElement
99  {
100  int id;
101  char type;
102  std::vector<int> list;
103  };
104 
105  struct MeshCurved
106  {
107  int id;
108  std::string entitytype;
109  int entityid;
110  std::string type;
111  int npoints;
112  std::string data;
113  int ptid;
114  int ptoffset;
115  };
116 
118  {
119  int id;
120  char type;
121  std::vector<int> list;
122  };
123 
124  bool m_isCompressed; // Idenfity if input is compressed and if so set output to be compressed
125  typedef std::pair<std::string, int> MeshCurvedKey;
126  typedef std::vector<unsigned int> MultiWeight;
127 
128  // Element in a mesh
130  {
131  int id; ///< Universal ID of the vertex
132  int partition; ///< Index of the partition to which it belongs
133  MultiWeight weight; ///< Weightings to this graph vertex
134  };
135 
136  // Face/Edge/Vertex between two adjacent elements
138  {
139  int id;
140  std::vector<MeshVertex> vertices;
141  std::vector<MeshEdge> edges;
142  };
143 
144  // Basic graph definition
145  typedef boost::adjacency_list<
146  boost::setS,
147  boost::vecS,
148  boost::undirectedS,
150  boost::property<
151  boost::edge_index_t,
152  unsigned int,
154  >
156 
157  // Use induced subgraphs to manage the partitions
158  typedef boost::subgraph< BoostGraph > BoostSubGraph;
159 
160  typedef boost::graph_traits<
161  BoostGraph
162  >::vertex_descriptor BoostVertex;
163  typedef boost::graph_traits<
164  BoostGraph
165  >::edge_descriptor BoostEdge;
166  typedef boost::graph_traits<
167  BoostGraph
168  >::edge_iterator BoostEdgeIterator;
169  typedef boost::graph_traits<
170  BoostGraph
171  >::vertex_iterator BoostVertexIterator;
172  typedef boost::graph_traits<
173  BoostGraph
174  >::adjacency_iterator BoostAdjacencyIterator;
175 
176  typedef std::vector<unsigned int> NumModes;
177  typedef std::map<std::string, NumModes> NummodesPerField;
178 
179  int m_dim;
181 
182  std::map<int, MeshVertex> m_meshVertices;
183  std::map<int, MeshEntity> m_meshEdges;
184  std::map<int, MeshEntity> m_meshFaces;
185  std::map<int, MeshEntity> m_meshElements;
186  std::map<MeshCurvedKey, MeshCurved> m_meshCurved;
187  std::map<int, MeshCurvedPts> m_meshCurvedPts;
188  std::map<int, MeshEntity> m_meshComposites;
189  std::vector<unsigned int> m_domain;
190  std::map<std::string, std::string> m_vertexAttributes;
191 
192  // hierarchial mapping: composite id -> field name -> integer list
193  // of directional nummodes described by expansion type clause.
194  std::map<int, NummodesPerField> m_expansions;
195 
196  std::map<std::string, int> m_fieldNameToId;
197  std::map<int, MultiWeight> m_vertWeights;
198 
199  BndRegionOrdering m_bndRegOrder;
200 
201  BoostSubGraph m_mesh;
202  std::vector<BoostSubGraph> m_localPartition;
203 
205 
207  bool m_shared;
208 
209  void ReadExpansions(const SessionReaderSharedPtr& pSession);
210  void ReadGeometry(const SessionReaderSharedPtr& pSession);
211  void ReadConditions(const SessionReaderSharedPtr& pSession);
212  void WeightElements();
213  void CreateGraph(BoostSubGraph& pGraph);
214  void PartitionGraph(BoostSubGraph& pGraph,
215  int nParts,
216  std::vector<BoostSubGraph>& pLocalPartition,
217  bool overlapping = false);
218 
219  virtual void PartitionGraphImpl(
220  int& nVerts,
221  int& nVertConds,
226  int& nparts,
227  int& volume,
229 
230  void OutputPartition(SessionReaderSharedPtr& pSession, BoostSubGraph& pGraph, TiXmlElement* pGeometry);
231  void CheckPartitions(int nParts, Array<OneD, int> &pPart);
232  int CalculateElementWeight(char elmtType, bool bndWeight, int na, int nb, int nc);
233  };
234 
235  typedef boost::shared_ptr<MeshPartition> MeshPartitionSharedPtr;
236  }
237 }
238 
239 #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:54
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
boost::graph_traits< BoostGraph >::vertex_descriptor BoostVertex
std::map< int, MultiWeight > m_vertWeights
std::map< int, std::vector< unsigned int > > CompositeOrdering
Definition: MeshPartition.h:53
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
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:58
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
void ReadGeometry(const SessionReaderSharedPtr &pSession)
std::pair< std::string, int > MeshCurvedKey
boost::graph_traits< BoostGraph >::adjacency_iterator BoostAdjacencyIterator
std::map< int, MeshEntity > m_meshEdges
Reads and parses information from a Nektar++ XML session file.
boost::graph_traits< BoostGraph >::edge_iterator BoostEdgeIterator
void PartitionMesh(int nParts, bool shared=false, bool overlapping=false)
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)
void PartitionGraph(BoostSubGraph &pGraph, int nParts, std::vector< BoostSubGraph > &pLocalPartition, bool overlapping=false)
Partition the graph.
MeshPartition(const SessionReaderSharedPtr &pSession)
std::map< int, MeshCurvedPts > m_meshCurvedPts
MeshPartitionFactory & GetMeshPartitionFactory()
Provides a generic Factory class.
Definition: NekFactory.hpp:116
boost::subgraph< BoostGraph > BoostSubGraph