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
47namespace Nektar
48{
49namespace SpatialDomains
50{
51class MeshPartition;
52
53typedef 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.
58typedef LibUtilities::NekFactory<std::string, MeshPartition,
61 std::map<int, MeshEntity>, CompositeDescriptor>
63
65
67{
68
69public:
71 LibUtilities::CommSharedPtr comm, int meshDim,
72 std::map<int, MeshEntity> element,
73 CompositeDescriptor compMap);
74 virtual ~MeshPartition();
75
76 SPATIAL_DOMAINS_EXPORT void PartitionMesh(int nParts, bool shared = false,
77 bool overlapping = false,
78 int nLocal = 0);
79
80 SPATIAL_DOMAINS_EXPORT void PrintPartInfo(std::ostream &out);
81
82 SPATIAL_DOMAINS_EXPORT void GetElementIDs(const int procid,
83 std::vector<unsigned int> &tmp);
84
85protected:
86 typedef std::vector<unsigned int> MultiWeight;
87
88 // Element in a mesh
90 {
91 int id = 0; ///< Universal ID of the vertex
92 int partition = 0; ///< Index of the partition to which it belongs
93 MultiWeight weight; ///< Weightings to this graph vertex
96 };
97
98 // Face/Edge/Vertex between two adjacent elements
100 {
101 int id = 0;
102 std::vector<MeshVertex> vertices;
103 std::vector<MeshEdge> edges;
104 };
105
106 // Basic graph definition
107 typedef boost::adjacency_list<
108 boost::setS, boost::vecS, boost::undirectedS, GraphVertexProperties,
109 boost::property<boost::edge_index_t, unsigned int, GraphEdgeProperties>>
111
112 typedef boost::graph_traits<BoostGraph>::vertex_descriptor BoostVertex;
113 typedef boost::graph_traits<BoostGraph>::edge_descriptor BoostEdge;
114 typedef boost::graph_traits<BoostGraph>::edge_iterator BoostEdgeIterator;
115 typedef boost::graph_traits<BoostGraph>::vertex_iterator
117 typedef boost::graph_traits<BoostGraph>::adjacency_iterator
119
120 typedef std::vector<unsigned int> NumModes;
121 typedef std::map<std::string, NumModes> NummodesPerField;
122
125
126 int m_dim;
128
129 std::map<int, MeshEntity> m_elements;
130 std::map<int, MeshEntity> m_ghostElmts;
132
133 // hierarchial mapping: elmt id -> field name -> integer list
134 // of directional nummodes described by expansion type clause.
135 std::map<int, NummodesPerField> m_expansions;
136
137 // map of each elements shape
138 std::map<int, LibUtilities::ShapeType> m_shape;
139
140 std::map<std::string, int> m_fieldNameToId;
141 std::map<int, MultiWeight> m_vertWeights;
142 std::map<int, MultiWeight> m_vertBndWeights;
143 std::map<int, MultiWeight> m_edgeWeights;
144
146 std::map<int, std::vector<unsigned int>> m_localPartition;
147
153
154 void ReadExpansions();
155 void ReadConditions();
156 void WeightElements();
157 void CreateGraph();
158 void PartitionGraph(int nParts, bool overlapping = false);
159
160 void CheckPartitions(int nParts, Array<OneD, int> &pPart);
161 int CalculateElementWeight(LibUtilities::ShapeType elmtType, bool bndWeight,
162 int na, int nb, int nc);
163 int CalculateEdgeWeight(LibUtilities::ShapeType elmtType, int na, int nb,
164 int nc);
165
167 int &nVerts, int &nVertConds, Nektar::Array<Nektar::OneD, int> &xadj,
171 Nektar::Array<Nektar::OneD, int> &edgeWgt, int &nparts, int &volume,
173};
174
175typedef std::shared_ptr<MeshPartition> MeshPartitionSharedPtr;
176
177} // namespace SpatialDomains
178} // namespace Nektar
179
180#endif
#define SPATIAL_DOMAINS_EXPORT
Provides a generic Factory class.
Definition: NekFactory.hpp:105
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:86
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:57
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:62
std::shared_ptr< MeshPartition > MeshPartitionSharedPtr
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
MultiWeight weight
Weightings to this graph vertex.
Definition: MeshPartition.h:93
int partition
Index of the partition to which it belongs.
Definition: MeshPartition.h:92