NEMoSys  0.63.0
A modular, extensible resource with robust automated mesh generation, mesh quality analysis, adaptive mesh refinement, and data transfer between arbitrary meshes.
meshPartitioner.H
Go to the documentation of this file.
1 /*******************************************************************************
2 * Promesh *
3 * Copyright (C) 2022, IllinoisRocstar LLC. All rights reserved. *
4 * *
5 * Promesh is the property of IllinoisRocstar LLC. *
6 * *
7 * IllinoisRocstar LLC *
8 * Champaign, IL *
9 * www.illinoisrocstar.com *
10 * promesh@illinoisrocstar.com *
11 *******************************************************************************/
12 /*******************************************************************************
13 * This file is part of Promesh *
14 * *
15 * This version of Promesh is free software: you can redistribute it and/or *
16 * modify it under the terms of the GNU Lesser General Public License as *
17 * published by the Free Software Foundation, either version 3 of the License, *
18 * or (at your option) any later version. *
19 * *
20 * Promesh is distributed in the hope that it will be useful, but WITHOUT ANY *
21 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more *
23 * details. *
24 * *
25 * You should have received a copy of the GNU Lesser General Public License *
26 * along with this program. If not, see <https://www.gnu.org/licenses/>. *
27 * *
28 *******************************************************************************/
29 #ifndef NEMOSYS_MESHPARTITIONER_H_
30 #define NEMOSYS_MESHPARTITIONER_H_
31 
32 #include "nemosys_export.h"
33 #include "Mesh/meshBase.H"
34 
35 #include <iostream>
36 #include <vector>
37 #include <fstream>
38 #include <map>
39 
40 // other
41 #ifdef HAVE_METIS
42  #include <metis.h>
43 #endif
44 #ifdef HAVE_GMSH
45 #include <MAdLib.h>
46 #endif
47 
48 // forward declare cgnsAnalyzer to prevent gmsh name conflicts w/ simmetrix
49 class cgnsAnalyzer;
50 
51 enum class MeshType_t {
52  MESH_TRI_3,
55  MESH_HEX_8,
57 };
58 
59 /* Defines class(es) for mesh partitioning */
60 class NEMOSYS_EXPORT meshPartition
61 {
62  public:
63  meshPartition(int pidx,
64  const std::vector<int> &glbElmPartedIdx,
65  const std::vector<int> &glbElmConn,
66  MeshType_t inMshType);
67 
68  ~meshPartition() = default;
69 
70  std::vector<double> getCrds(const std::vector<double> &crds) const;
71  std::vector<int> getConns() const { return partElmConn; }
72  std::vector<double> getElmSlns(const std::vector<double> &slns) const;
73  std::vector<double> getElmSlnsVec(const std::vector<double> &slns, int nComp) const;
74 
75  std::map<int, int> getPartToGlobNodeMap() const { return ndeIdxPartToGlob; }
76  std::map<int, int> getPartToGlobElmMap() const { return elmIdxPartToGlob; }
77 
78  public:
79  int nNde;
80  int nElm;
81 
82  private:
83  int pIdx;
84  int nNdeElm;
85  std::vector<int> globNdeIdx;
86  std::vector<int> globElmIdx;
87  std::vector<int> partElmConn;
88  std::map<int, int> ndeIdxGlobToPart;
89  std::map<int, int> ndeIdxPartToGlob;
90  std::map<int, int> elmIdxGlobToPart;
91  std::map<int, int> elmIdxPartToGlob;
93 };
94 
95 
96 class NEMOSYS_EXPORT meshPartitioner
97 {
98  public:
99  // constructors
100  // from scratch
101  meshPartitioner(int nNde, int nElm,
102  const std::vector<int> &elemConn,
103  MeshType_t meshType) :
104  nNde(nNde), nElm(nElm), nPart(0), meshType(meshType)
105  {
106  elmConn.insert(elmConn.begin(), elemConn.begin(), elemConn.end());
107  }
108 
109  /* disable -- AEG
110  // from CGNS object
111  explicit meshPartitioner(cgnsAnalyzer *inCg);
112  */
113 #ifdef HAVE_GMSH
114  // from MAdMesh object
115  explicit meshPartitioner(MAd::pMesh inMesh);
116 #endif
117  // from meshBase object
118  explicit meshPartitioner(const meshBase *inMB);
119 
120  // destructor
122  {
123  if (!meshParts.empty())
124  for (int iPart = 0; iPart < nPart; iPart++)
125  delete meshParts[iPart];
126  };
127 
128  // mesh information
129  void setNPartition(int nPartition) { nPart = nPartition; }
130  int getNPartition() const { return nPart; }
131  int partition(int nPartition);
132  int partition();
133 
134  std::vector<double> getPartedNde() const;
135  std::vector<double> getPartedElm() const;
136 
137  void setPartedElm(const std::vector<double> &prtElm);
138 
139  std::vector<double> getCrds(int iPart,
140  const std::vector<double> &crds) const
141  { return meshParts[iPart]->getCrds(crds); }
142  std::vector<int> getConns(int iPart) const
143  { return meshParts[iPart]->getConns(); }
144  int getNNdePart(int iPart) const { return meshParts[iPart]->nNde; }
145  int getNElmPart(int iPart) const { return meshParts[iPart]->nElm; }
146 
147  std::map<int, int> getPartToGlobNodeMap(int iPart) const;
148  std::map<int, int> getPartToGlobElmMap(int iPart) const;
149  // solution data
150 
151  // for scalar nodal values the same operator acting on
152  // coordinates can be used to find solution values for
153  // the partition
154  std::vector<double> getNdeSlnScalar(int iPart,
155  const std::vector<double> &slns) const
156  { return getCrds(iPart, slns); }
157 
158  std::vector<double> getElmSlnScalar(int iPart,
159  const std::vector<double> &slns) const
160  { return meshParts[iPart]->getElmSlns(slns); }
161  std::vector<double> getElmSlnVec(int iPart,
162  const std::vector<double> &slns,
163  int nComp) const
164  { return meshParts[iPart]->getElmSlnsVec(slns, nComp); }
165 
166  private:
167  void buildPartitions();
168 
169  private:
170  int nNde;
171  int nElm;
172  int nPart;
173  std::vector<int> elmConnVec;
174  std::vector<int> elmConn;
176 #ifdef HAVE_METIS
177  // metis datastructures
178  idx_t options[METIS_NOPTIONS];
179 #endif
180  std::vector<int> epart;
181  std::vector<int> npart;
182  // partition data
183  std::vector<meshPartition *> meshParts;
184 };
185 
186 #endif // NEMOSYS_MESHPARTITIONER_H_
int getNElmPart(int iPart) const
std::vector< int > epart
meshPartitioner(int nNde, int nElm, const std::vector< int > &elemConn, MeshType_t meshType)
A brief description of meshBase.
Definition: meshBase.H:64
MeshType_t meshType
std::vector< meshPartition * > meshParts
std::vector< int > npart
std::vector< int > globNdeIdx
std::map< int, int > ndeIdxPartToGlob
MeshType_t
int getNNdePart(int iPart) const
std::vector< double > getElmSlnVec(int iPart, const std::vector< double > &slns, int nComp) const
std::map< int, int > getPartToGlobNodeMap() const
std::vector< double > getNdeSlnScalar(int iPart, const std::vector< double > &slns) const
std::vector< int > elmConn
std::vector< int > elmConnVec
void setNPartition(int nPartition)
MeshType_t mshType
std::map< int, int > ndeIdxGlobToPart
std::vector< double > getCrds(int iPart, const std::vector< double > &crds) const
std::vector< double > getElmSlnScalar(int iPart, const std::vector< double > &slns) const
std::map< int, int > getPartToGlobElmMap() const
std::vector< int > getConns(int iPart) const
std::vector< int > globElmIdx
std::map< int, int > elmIdxGlobToPart
int getNPartition() const
std::vector< int > partElmConn
std::vector< int > getConns() const
std::map< int, int > elmIdxPartToGlob