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
45class TiXmlElement;
46
48{
49class MeshPartition;
50
51typedef std::map<int, std::pair<LibUtilities::ShapeType, std::vector<int>>>
53
54/// Datatype of the NekFactory used to instantiate classes derived from
55/// the EquationSystem class.
56typedef LibUtilities::NekFactory<std::string, MeshPartition,
59 std::map<int, MeshEntity>, CompositeDescriptor>
61
63
65{
66
67public:
69 LibUtilities::CommSharedPtr comm, int meshDim,
70 std::map<int, MeshEntity> element,
71 CompositeDescriptor compMap);
72 virtual ~MeshPartition();
73
74 SPATIAL_DOMAINS_EXPORT void PartitionMesh(int nParts, bool shared = false,
75 bool overlapping = false,
76 int nLocal = 0);
77
78 SPATIAL_DOMAINS_EXPORT void PrintPartInfo(std::ostream &out);
79
80 SPATIAL_DOMAINS_EXPORT void GetElementIDs(const int procid,
81 std::vector<unsigned int> &tmp);
82
83protected:
84 typedef std::vector<unsigned int> MultiWeight;
85
86 // Element in a mesh
88 {
89 int id = 0; ///< Universal ID of the vertex
90 int partition = 0; ///< Index of the partition to which it belongs
91 MultiWeight weight; ///< Weightings to this graph vertex
94 };
95
96 // Face/Edge/Vertex between two adjacent elements
98 {
99 int id = 0;
100 std::vector<MeshVertex> vertices;
101 std::vector<MeshEdge> edges;
102 };
103
104 // Basic graph definition
105 typedef boost::adjacency_list<
106 boost::setS, boost::vecS, boost::undirectedS, GraphVertexProperties,
107 boost::property<boost::edge_index_t, unsigned int, GraphEdgeProperties>>
109
110 typedef boost::graph_traits<BoostGraph>::vertex_descriptor BoostVertex;
111 typedef boost::graph_traits<BoostGraph>::edge_descriptor BoostEdge;
112 typedef boost::graph_traits<BoostGraph>::edge_iterator BoostEdgeIterator;
113 typedef boost::graph_traits<BoostGraph>::vertex_iterator
115 typedef boost::graph_traits<BoostGraph>::adjacency_iterator
117
118 typedef std::vector<unsigned int> NumModes;
119 typedef std::map<std::string, NumModes> NummodesPerField;
120
123
124 int m_dim;
126
127 std::map<int, MeshEntity> m_elements;
128 std::map<int, MeshEntity> m_ghostElmts;
130
131 // hierarchial mapping: elmt id -> field name -> integer list
132 // of directional nummodes described by expansion type clause.
133 std::map<int, NummodesPerField> m_expansions;
134
135 // map of each elements shape
136 std::map<int, LibUtilities::ShapeType> m_shape;
137
138 std::map<std::string, int> m_fieldNameToId;
139 std::map<int, MultiWeight> m_vertWeights;
140 std::map<int, MultiWeight> m_vertBndWeights;
141 std::map<int, MultiWeight> m_edgeWeights;
142
144 std::map<int, std::vector<unsigned int>> m_localPartition;
145
151
152 void ReadExpansions();
153 void ReadConditions();
154 void WeightElements();
155 void CreateGraph();
156 void PartitionGraph(int nParts, bool overlapping = false);
157
158 void CheckPartitions(int nParts, Array<OneD, int> &pPart);
159 int CalculateElementWeight(LibUtilities::ShapeType elmtType, bool bndWeight,
160 int na, int nb, int nc);
161 int CalculateEdgeWeight(LibUtilities::ShapeType elmtType, int na, int nb,
162 int nc);
163
165 int &nVerts, int &nVertConds, Nektar::Array<Nektar::OneD, int> &xadj,
169 Nektar::Array<Nektar::OneD, int> &edgeWgt, int &nparts, int &volume,
171};
172
173typedef std::shared_ptr<MeshPartition> MeshPartitionSharedPtr;
174
175} // namespace Nektar::SpatialDomains
176
177#endif
#define SPATIAL_DOMAINS_EXPORT
Provides a generic Factory class.
Definition: NekFactory.hpp:104
boost::graph_traits< BoostGraph >::vertex_iterator BoostVertexIterator
virtual void v_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:84
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:55
std::map< int, std::pair< LibUtilities::ShapeType, std::vector< int > > > CompositeDescriptor
Definition: MeshGraph.h:61
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:60
std::shared_ptr< MeshPartition > MeshPartitionSharedPtr
MultiWeight weight
Weightings to this graph vertex.
Definition: MeshPartition.h:91
int partition
Index of the partition to which it belongs.
Definition: MeshPartition.h:90