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,
60  int, std::map<int, MeshEntity>,
61  CompositeDescriptor>
63 
65 
66 class MeshPartition
67 {
68 
69 public:
70  MeshPartition(const LibUtilities::SessionReaderSharedPtr session,
71  int meshDim,
72  std::map<int, MeshEntity> element,
73  CompositeDescriptor compMap);
74  virtual ~MeshPartition();
75 
77  int nParts,
78  bool shared = false,
79  bool overlapping = false,
80  int nLocal = 0);
81 
82  SPATIAL_DOMAINS_EXPORT void PrintPartInfo(std::ostream &out);
83 
85  const int procid,
86  std::vector<unsigned int> &tmp);
87 
88 protected:
89  typedef std::vector<unsigned int> MultiWeight;
90 
91  // Element in a mesh
93  {
94  int id = 0; ///< Universal ID of the vertex
95  int partition = 0; ///< Index of the partition to which it belongs
96  MultiWeight weight; ///< Weightings to this graph vertex
97  MultiWeight bndWeight;
98  MultiWeight edgeWeight;
99  };
100 
101  // Face/Edge/Vertex between two adjacent elements
103  {
104  int id = 0;
105  std::vector<MeshVertex> vertices;
106  std::vector<MeshEdge> edges;
107  };
108 
109  // Basic graph definition
110  typedef boost::adjacency_list<
111  boost::setS, boost::vecS, boost::undirectedS, GraphVertexProperties,
112  boost::property<boost::edge_index_t, unsigned int, GraphEdgeProperties>>
114 
115  typedef boost::graph_traits<BoostGraph>::vertex_descriptor BoostVertex;
116  typedef boost::graph_traits<BoostGraph>::edge_descriptor BoostEdge;
117  typedef boost::graph_traits<BoostGraph>::edge_iterator BoostEdgeIterator;
118  typedef boost::graph_traits<BoostGraph>::vertex_iterator
120  typedef boost::graph_traits<BoostGraph>::adjacency_iterator
122 
123  typedef std::vector<unsigned int> NumModes;
124  typedef std::map<std::string, NumModes> NummodesPerField;
125 
126  LibUtilities::SessionReaderSharedPtr m_session;
127 
128  int m_dim;
130 
131  std::map<int, MeshEntity> m_elements;
132  std::map<int, MeshEntity> m_ghostElmts;
133  CompositeDescriptor m_compMap;
134 
135  // hierarchial mapping: elmt id -> field name -> integer list
136  // of directional nummodes described by expansion type clause.
137  std::map<int, NummodesPerField> m_expansions;
138 
139  // map of each elements shape
140  std::map<int, LibUtilities::ShapeType> m_shape;
141 
142  std::map<std::string, int> m_fieldNameToId;
143  std::map<int, MultiWeight> m_vertWeights;
144  std::map<int, MultiWeight> m_vertBndWeights;
145  std::map<int, MultiWeight> m_edgeWeights;
146 
148  std::vector<std::vector<unsigned int>> m_localPartition;
149 
151 
155  bool m_shared;
157 
158  void ReadExpansions();
159  void ReadConditions();
160  void WeightElements();
161  void CreateGraph();
162  void PartitionGraph(int nParts, bool overlapping = false);
163 
164  virtual void PartitionGraphImpl(int &nVerts, int &nVertConds,
170  int &nparts, int &volume,
172 
173  void CheckPartitions(int nParts, Array<OneD, int> &pPart);
175  int na, int nb, int nc);
177  int na, int nb, int nc);
178 };
179 
180 typedef std::shared_ptr<MeshPartition> MeshPartitionSharedPtr;
181 }
182 }
183 
184 #endif
void PrintPartInfo(std::ostream &out)
LibUtilities::CommSharedPtr m_comm
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
std::shared_ptr< MeshPartition > MeshPartitionSharedPtr
boost::graph_traits< BoostGraph >::adjacency_iterator BoostAdjacencyIterator
std::map< int, MultiWeight > m_vertWeights
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:53
int CalculateEdgeWeight(LibUtilities::ShapeType elmtType, int na, int nb, int nc)
std::map< int, MeshEntity > m_ghostElmts
LibUtilities::NekFactory< std::string, MeshPartition, const LibUtilities::SessionReaderSharedPtr, int, std::map< int, MeshEntity >, CompositeDescriptor > MeshPartitionFactory
Datatype of the NekFactory used to instantiate classes derived from the EquationSystem class...
Definition: MeshPartition.h:62
LibUtilities::SessionReaderSharedPtr m_session
void CheckPartitions(int nParts, Array< OneD, int > &pPart)
void GetElementIDs(const int procid, std::vector< unsigned int > &tmp)
std::map< int, MultiWeight > m_vertBndWeights
MeshPartition(const LibUtilities::SessionReaderSharedPtr session, int meshDim, std::map< int, MeshEntity > element, CompositeDescriptor compMap)
boost::adjacency_list< boost::setS, boost::vecS, boost::undirectedS, GraphVertexProperties, boost::property< boost::edge_index_t, unsigned int, GraphEdgeProperties > > BoostGraph
boost::graph_traits< BoostGraph >::vertex_descriptor BoostVertex
std::map< int, MultiWeight > m_edgeWeights
boost::graph_traits< BoostGraph >::vertex_iterator BoostVertexIterator
std::map< int, NummodesPerField > m_expansions
void PartitionGraph(int nParts, bool overlapping=false)
Partition the graph.
std::map< int, LibUtilities::ShapeType > m_shape
std::vector< unsigned int > NumModes
std::map< int, std::pair< LibUtilities::ShapeType, std::vector< int > > > CompositeDescriptor
Definition: MeshGraph.h:62
std::vector< unsigned int > MultiWeight
Definition: MeshPartition.h:89
std::map< int, MeshEntity > m_elements
std::map< std::string, int > m_fieldNameToId
std::map< std::string, NumModes > NummodesPerField
void PartitionMesh(int nParts, bool shared=false, bool overlapping=false, int nLocal=0)
int CalculateElementWeight(LibUtilities::ShapeType elmtType, bool bndWeight, int na, int nb, int nc)
MeshPartitionFactory & GetMeshPartitionFactory()
MultiWeight weight
Weightings to this graph vertex.
Definition: MeshPartition.h:96
int partition
Index of the partition to which it belongs.
Definition: MeshPartition.h:95
boost::graph_traits< BoostGraph >::edge_descriptor BoostEdge
std::shared_ptr< SessionReader > SessionReaderSharedPtr
#define SPATIAL_DOMAINS_EXPORT
boost::graph_traits< BoostGraph >::edge_iterator BoostEdgeIterator
Provides a generic Factory class.
Definition: NekFactory.hpp:103
std::vector< std::vector< unsigned int > > m_localPartition