-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExaMesh.h
More file actions
315 lines (268 loc) · 8.39 KB
/
ExaMesh.h
File metadata and controls
315 lines (268 loc) · 8.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
// Copyright 2019 by Carl Ollivier-Gooch. The University of British
// Columbia disclaims all copyright interest in the software ExaMesh.//
//
// This file is part of ExaMesh.
//
// ExaMesh is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// ExaMesh is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with ExaMesh. If not, see <https://www.gnu.org/licenses/>.
/*
* examesh.h
*
* Created on: May 17, 2019
* Author: cfog
*/
#ifndef SRC_EXAMESH_H_
#define SRC_EXAMESH_H_
#include <limits.h>
#include <assert.h>
#include <memory>
#include "Mapping.h"
#include "exa-defs.h"
#include "FaceVerts.h"
#include <set>
class UMesh;
class CubicMesh;
using vecSharePtrUmesh = std::vector<std::shared_ptr<UMesh>>;
using vecSharePtrCubicMesh = std::vector<std::shared_ptr<CubicMesh>>;
struct MeshSize {
ssize_t nBdryVerts, nVerts, nBdryTris, nBdryQuads, nTets, nPyrs, nPrisms,
nHexes;
};
class ExaMesh {
protected:
double *m_lenScale;
exa_set<QuadFaceVerts> m_partQuads;
exa_set<TriFaceVerts> m_partTris;
exa_set<TriFaceVerts> m_refinedPartTris;
exa_set<QuadFaceVerts> m_refinedPartQuads;
std::vector<std::vector<emInt>> vcell2cell;
std::vector<emInt> vcellID2type;
std::vector<std::pair<emInt,emInt>> cellID2cellTypeLocalID;
std::map < std::pair<emInt,emInt>, std::set<std::set<emInt>>> cell2faces;
void setupLengthScales();
public:
ExaMesh() :
m_lenScale(nullptr) {
}
virtual ~ExaMesh() {
if (m_lenScale) delete[] m_lenScale;
}
static std::unique_ptr<ExaMesh> readMeshFromFile(const std::string fileName,
const std::string fileSuffix, const std::string fileInfix = "");
virtual std::unique_ptr<UMesh>
subdivideMesh(const emInt nDivs, const emInt partID = 0) const = 0;
virtual double getX(const emInt vert) const = 0;
virtual double getY(const emInt vert) const = 0;
virtual double getZ(const emInt vert) const =0;
virtual void getCoords(const emInt vert, double coords[3]) const = 0;
virtual emInt numVerts() const = 0;
virtual emInt numVertsAllocated() const = 0;
virtual emInt numBdryVerts() const = 0;
virtual emInt numBdryTris() const = 0;
virtual emInt numBdryQuads() const = 0;
virtual emInt numTets() const = 0;
virtual emInt numPyramids() const = 0;
virtual emInt numPrisms() const = 0;
virtual emInt numHexes() const = 0;
virtual emInt numCells() const = 0 ;
emInt numVolCells() const {
return numCells() - numBdryTris() - numBdryQuads();
}
virtual emInt numVertsToCopy() const {
return numVerts();
}
virtual emInt addVert(const double newCoords[3]) = 0;
virtual emInt addBdryTri(const emInt verts[]) = 0;
virtual emInt addBdryQuad(const emInt verts[]) = 0;
virtual emInt addTet(const emInt verts[]) = 0;
virtual emInt addPyramid(const emInt verts[]) = 0;
virtual emInt addPrism(const emInt verts[]) = 0;
virtual emInt addHex(const emInt verts[]) = 0;
const virtual emInt* getBdryTriConn(const emInt bdryTri) const=0;
const virtual emInt* getBdryQuadConn(const emInt bdryQuad) const=0;
const virtual emInt* getTetConn(const emInt tet) const=0;
const virtual emInt* getPyrConn(const emInt pyr) const=0;
const virtual emInt* getPrismConn(const emInt prism) const=0;
const virtual emInt* getHexConn(const emInt hex) const=0;
virtual Mapping::MappingType getDefaultMappingType() const = 0;
std::size_t getCellConnSize (const emInt cellID)
const
{
return vcell2cell[cellID].size();
}
emInt getCellConn (const emInt cellID, const emInt neighID)
const
{
return vcell2cell[cellID][neighID];
}
emInt getCellType (const emInt cellID)
const
{
return vcellID2type[cellID];
}
emInt FastpartFaceMatching(const emInt nParts, const std::vector<std::vector<emInt>> &part2cells,
const std::vector<emInt> &cell2part,
vecVecTri &tris, vecVecQuad &quads) const;
std::vector<std::pair<emInt,emInt>> getCellID2CellType2LocalID() const
{
return cellID2cellTypeLocalID;
}
void getFaceLists (const emInt ind, const emInt type,
const emInt partID, const emInt numDivs,
std::vector<TriFaceVerts> &tris,
std::vector<QuadFaceVerts> &quads) const;
void printMeshSizeStats();
double getLengthScale(const emInt vert) const {
assert(vert < numVertsAllocated());
// TODO Would be better to always associate a length scale with the mesh.
if (m_lenScale) {
return m_lenScale[vert];
}
else {
return 1;
}
}
const double* getAllLengthScale() const
{
return m_lenScale;
}
void setLengthScale(const emInt vert, const double len) const {
assert(vert < numVertsAllocated());
assert(len > 0);
// TODO Would be better to always associate a length scale with the mesh.
if (m_lenScale) {
m_lenScale[vert] = len;
}
}
MeshSize computeFineMeshSize(const int nDivs) const;
void buildCellToCellConnectivity();
void buildFaceCellConnectivity();
void buildCell2CellConnFromFace2Cell(multimpFace2Cell& face2cell, const emInt nCells);
std::vector<std::pair<emInt,emInt>> getCellID2CellType () const
{
return cellID2cellTypeLocalID;
}
void setCellId2CellTypeLocal (const std::vector<std::pair<emInt,emInt>>& cellIDs )
{
cellID2cellTypeLocalID=cellIDs;
}
virtual emInt getTriType() const = 0;
virtual emInt getQuadType() const = 0;
virtual emInt getTetType() const = 0;
virtual emInt getPyrType() const = 0;
virtual emInt getPrismType() const = 0;
virtual emInt getHexType() const = 0;
virtual std::unique_ptr<ExaMesh>
extractCoarseMeshMPI(const emInt partID, const std::vector<emInt> &partcells , const int numDivs,
const std::unordered_set<TriFaceVerts>& tris,
const std::unordered_set<QuadFaceVerts>& quads) const = 0;
void prettyPrintCellCount(size_t cells, const char* prefix) const;
void addPartTritoSet(const TriFaceVerts &obj){
auto iter = m_partTris.find(obj);
if (iter != m_partTris.end()) {
m_partTris.erase(iter);
}
else {
m_partTris.insert(obj);
}
}
void addPartQuadtoSet(const QuadFaceVerts &obj){
auto iter = m_partQuads.find(obj);
if (iter != m_partQuads.end()) {
m_partQuads.erase(iter);
}
else {
m_partQuads.insert(obj);
}
}
void addRefinedPartTritoSet(const TriFaceVerts &obj){
auto iter = m_refinedPartTris.find(obj);
if (iter != m_refinedPartTris.end()) {
m_refinedPartTris.erase(iter);
}
else {
m_refinedPartTris.insert(obj);
}
}
void addRefinedPartQuadtoSet(const QuadFaceVerts &obj){
auto iter = m_refinedPartQuads.find(obj);
if (iter != m_refinedPartQuads.end()) {
m_refinedPartQuads.erase(iter);
}
else {
m_refinedPartQuads.insert(obj);
}
}
size_t getSizePartTris()const
{
return m_partTris.size();
}
size_t getSizePartQuads()const
{
return m_partQuads.size();
}
const exa_set<QuadFaceVerts>& getTempQuadPart () const
{
return m_partQuads;
}
const exa_set<TriFaceVerts>& getTempTriPart () const
{
return m_partTris;
}
const exa_set<TriFaceVerts>& getRefinedPartTris () const
{
return m_refinedPartTris;
}
const exa_set<QuadFaceVerts>& getRefinedPartQuads() const
{
return m_refinedPartQuads;
}
private:
void findCentroidOfVerts(const emInt* verts, emInt nPts, double& x, double& y,
double& z) const;
};
template<typename T>
void addUniquely(exa_set<T>& mySet, T& val) {
typename exa_set<T>::iterator vertIter, VIend = mySet.end();
auto inserResult = mySet.insert(val);
if(!inserResult.second)
{
mySet.erase(inserResult.first);
}
// auto iter = mySet.find(val);
// if (iter != mySet.end()) {
// mySet.erase(iter);
// }
// else {
// mySet.insert(val);
// }
}
template<typename T>
void addUniquely(std::set<T> &mySet, T& val) {
auto iter = mySet.find(val);
if (iter != mySet.end()) {
mySet.erase(iter);
}
else {
mySet.insert(val);
}
}
bool computeMeshSize(const struct MeshSize& MSIn, const emInt nDivs,
struct MeshSize& MSOut);
// Defined elsewhere.
emInt subdividePartMesh(const ExaMesh * const pVM_input,
UMesh * const pVM_output,
const int nDivs, const emInt partID=-1);
void sortVerts3(const emInt input[3], emInt output[3]);
void sortVerts4(const emInt input[4], emInt output[4]);
#endif /* SRC_EXAMESH_H_ */