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 // 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:
32 //
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 #ifndef NEKTAR_SPATIALDOMAINS_MESHPARTITION_H
36 #define NEKTAR_SPATIALDOMAINS_MESHPARTITION_H
37 
43 #include <boost/graph/adjacency_list.hpp>
44 
45 class TiXmlElement;
46 
47 namespace Nektar
48 {
49 namespace SpatialDomains
50 {
51 class MeshPartition;
52 
53 typedef std::map<int, std::pair<LibUtilities::ShapeType, std::vector<int>>>
55 
56 /// Datatype of the NekFactory used to instantiate classes derived from
57 /// the EquationSystem class.
58 typedef LibUtilities::NekFactory<std::string, MeshPartition,
61  int, std::map<int, MeshEntity>,
64 
66 
68 {
69 
70 public:
73  int meshDim,
74  std::map<int, MeshEntity> element,
75  CompositeDescriptor compMap);
76  virtual ~MeshPartition();
77 
79  int nParts,
80  bool shared = false,
81  bool overlapping = false,
82  int nLocal = 0);
83 
84  SPATIAL_DOMAINS_EXPORT void PrintPartInfo(std::ostream &out);
85 
87  const int procid,
88  std::vector<unsigned int> &tmp);
89 
90 protected:
91  typedef std::vector<unsigned int> MultiWeight;
92 
93  // Element in a mesh
95  {
96  int id = 0; ///< Universal ID of the vertex
97  int partition = 0; ///< Index of the partition to which it belongs
98  MultiWeight weight; ///< Weightings to this graph vertex
101  };
102 
103  // Face/Edge/Vertex between two adjacent elements
105  {
106  int id = 0;
107  std::vector<MeshVertex> vertices;
108  std::vector<MeshEdge> edges;
109  };
110 
111  // Basic graph definition
112  typedef boost::adjacency_list<
113  boost::setS, boost::vecS, boost::undirectedS, GraphVertexProperties,
114  boost::property<boost::edge_index_t, unsigned int, GraphEdgeProperties>>
116 
117  typedef boost::graph_traits<BoostGraph>::vertex_descriptor BoostVertex;
118  typedef boost::graph_traits<BoostGraph>::edge_descriptor BoostEdge;
119  typedef boost::graph_traits<BoostGraph>::edge_iterator BoostEdgeIterator;
120  typedef boost::graph_traits<BoostGraph>::vertex_iterator
122  typedef boost::graph_traits<BoostGraph>::adjacency_iterator
124 
125  typedef std::vector<unsigned int> NumModes;
126  typedef std::map<std::string, NumModes> NummodesPerField;
127 
130 
131  int m_dim;
133 
134  std::map<int, MeshEntity> m_elements;
135  std::map<int, MeshEntity> m_ghostElmts;
137 
138  // hierarchial mapping: elmt id -> field name -> integer list
139  // of directional nummodes described by expansion type clause.
140  std::map<int, NummodesPerField> m_expansions;
141 
142  // map of each elements shape
143  std::map<int, LibUtilities::ShapeType> m_shape;
144 
145  std::map<std::string, int> m_fieldNameToId;
146  std::map<int, MultiWeight> m_vertWeights;
147  std::map<int, MultiWeight> m_vertBndWeights;
148  std::map<int, MultiWeight> m_edgeWeights;
149 
151  std::map<int, std::vector<unsigned int>> m_localPartition;
152 
156  bool m_shared;
158 
159  void ReadExpansions();
160  void ReadConditions();
161  void WeightElements();
162  void CreateGraph();
163  void PartitionGraph(int nParts, bool overlapping = false);
164 
165  virtual void PartitionGraphImpl(int &nVerts, int &nVertConds,
171  int &nparts, int &volume,
173 
174  void CheckPartitions(int nParts, Array<OneD, int> &pPart);
175  int CalculateElementWeight(LibUtilities::ShapeType elmtType, bool bndWeight,
176  int na, int nb, int nc);
178  int na, int nb, int nc);
179 };
180 
181 typedef std::shared_ptr<MeshPartition> MeshPartitionSharedPtr;
182 }
183 }
184 
185 #endif
#define SPATIAL_DOMAINS_EXPORT
Provides a generic Factory class.
Definition: NekFactory.hpp:105
boost::graph_traits< BoostGraph >::vertex_iterator BoostVertexIterator
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, Nektar::Array< Nektar::OneD, int > &edgeWgt, int &nparts, int &volume, Nektar::Array< Nektar::OneD, int > &part)=0
void PartitionGraph(int nParts, bool overlapping=false)
Partition the graph.
std::map< int, NummodesPerField > m_expansions
boost::graph_traits< BoostGraph >::vertex_descriptor BoostVertex
boost::graph_traits< BoostGraph >::adjacency_iterator BoostAdjacencyIterator
std::map< int, MultiWeight > m_edgeWeights
std::map< std::string, int > m_fieldNameToId
std::map< int, MeshEntity > m_ghostElmts
LibUtilities::SessionReaderSharedPtr m_session
std::map< int, MultiWeight > m_vertBndWeights
boost::adjacency_list< boost::setS, boost::vecS, boost::undirectedS, GraphVertexProperties, boost::property< boost::edge_index_t, unsigned int, GraphEdgeProperties > > BoostGraph
std::map< int, MultiWeight > m_vertWeights
void PrintPartInfo(std::ostream &out)
void GetElementIDs(const int procid, std::vector< unsigned int > &tmp)
boost::graph_traits< BoostGraph >::edge_descriptor BoostEdge
std::vector< unsigned int > NumModes
std::map< int, std::vector< unsigned int > > m_localPartition
int CalculateElementWeight(LibUtilities::ShapeType elmtType, bool bndWeight, int na, int nb, int nc)
std::vector< unsigned int > MultiWeight
Definition: MeshPartition.h:91
std::map< std::string, NumModes > NummodesPerField
boost::graph_traits< BoostGraph >::edge_iterator BoostEdgeIterator
int CalculateEdgeWeight(LibUtilities::ShapeType elmtType, int na, int nb, int nc)
void PartitionMesh(int nParts, bool shared=false, bool overlapping=false, int nLocal=0)
std::map< int, MeshEntity > m_elements
MeshPartition(const LibUtilities::SessionReaderSharedPtr session, LibUtilities::CommSharedPtr comm, int meshDim, std::map< int, MeshEntity > element, CompositeDescriptor compMap)
LibUtilities::CommSharedPtr m_comm
void CheckPartitions(int nParts, Array< OneD, int > &pPart)
std::map< int, LibUtilities::ShapeType > m_shape
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:54
std::map< int, std::pair< LibUtilities::ShapeType, std::vector< int > > > CompositeDescriptor
Definition: MeshGraph.h:63
MeshPartitionFactory & GetMeshPartitionFactory()
LibUtilities::NekFactory< std::string, MeshPartition, const LibUtilities::SessionReaderSharedPtr, LibUtilities::CommSharedPtr, int, std::map< int, MeshEntity >, CompositeDescriptor > MeshPartitionFactory
Datatype of the NekFactory used to instantiate classes derived from the EquationSystem class.
Definition: MeshPartition.h:63
std::shared_ptr< MeshPartition > MeshPartitionSharedPtr
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
MultiWeight weight
Weightings to this graph vertex.
Definition: MeshPartition.h:98
int partition
Index of the partition to which it belongs.
Definition: MeshPartition.h:97