Mesh.hpp 8.11 KB
Newer Older
1
2
3
#ifndef _MESH_H_
#define _MESH_H_

4
#include "ProcSet.hpp"
5
6
#include "Identify.hpp"

7
8
#include "DataSet.hpp"
#include "DataRule.hpp"
9
10
#include "Meshfile.hpp"
#include "MeshPart.hpp"
11
12
13
14
15
16
17

#include <memory>
#include <list>


class MapGeometry {
public:
18
    virtual Point operator()(const Point &) const = 0;
19

20
    virtual const char *MeshName() const = 0;
21
22
23
24
};

class MapIdentity : public MapGeometry {
public:
25
    Point operator()(const Point &p) const override { return p; }
26

27
    const char *MeshName() const override { return "Meshname not known"; }
28
29
30
};


31
class Mesh {
32
33
    int verbose = 1;

34
    int level;
35
36
37
38
39

    int plevel;

    int commSplit;

40
    int dimension;
41

42
    double scaling;
43
44
45

    bool identifyBnd = false;

46
47
48
49
50
51
    std::string meshName;

    std::string distName;

    std::string olapName;

52
protected:
53
    Cells meshCells{};
54

55
    Edges meshEdges{};
56

57
    Faces meshFaces{};
58

59
    Vertices meshVertices{};
60

61
    Cells meshOverlapCells{};
62

63
    BoundaryFaces meshBndFaces{};
64

65
    void InsertVertex(const Point &p);
66

67
    bool RemoveVertex(const Point &p);
68

69
    void InsertEdge(const Point &left, const Point &right);
70

71
    bool RemoveEdge(const Point &edgeCenter);
72

73
    bool RefineEdge(const procset &p, Mesh &N);
74

75
    void RemoveFace(const Point &F, const face &f, const Point &C);
76

77
    void RemoveFace(const cell &c, const Point &F);
78

79
    void RefineFace(const procset &p, Mesh &N);
80

81
    std::map<CELLTYPE, int> occurringCellTypes; // todo set dimension with this
82
public:
83
    ProcSets procSets{};
84
    IdentifySets identifySets{};
85
86
87
    bool Parallel; // todo make private and set with information about level and plevel

    Mesh(double scaling = 1.0, int commSplit = 0) : identifyBnd(false), scaling(scaling),
88
                                                    commSplit(commSplit) {
89
        procSets.SetCommSplit(commSplit);
90
    }
91
92

    Mesh(const std::string &meshName, const std::string &distName,
93
         const std::string &olapName, int plevel, int level,
94
95
         int commSplit, double scaling)
        : meshName(meshName), distName(distName), olapName(olapName),
96
          plevel(plevel), level(level), commSplit(commSplit), scaling(scaling) {
97
        config.get("MeshVerbose", verbose);
98
        procSets.SetCommSplit(commSplit);
99
    }
100

101
    Mesh(const Mesh &mesh, const MapGeometry &);
102

103
104
    std::string Name() const { return meshName; }

105
    void Fill(const CoarseGeometry &geometry, const MapGeometry &Map);
106

107
    void Fill(const string &geoName, const MapGeometry &Map);
108

109
    void Fill(const CoarseGeometry &geometry);
110

111
    virtual void Fill(const string &geoName);
112

113
    void Fill(const Mesh &originMesh);
114

115
    virtual std::unique_ptr<Mesh> Refine();
116

117
    cell InsertCell(CELLTYPE tp, int flag, const vector<Point> &x);
118

119
    void InsertOverlapCell(cell c);
120

121
    void InsertOverlapCell(Cell *C);
122

123
    void RemoveOverlapCell(const Point &center);
124

125
    void InsertFace(const Point &faceCenter, const Point &cellCenter);
126

127
    void InsertFace(const Point &faceCenter, const Face &faceValue);
128

129
130
131
    void RemoveFace(const Point &faceCenter);

    virtual void RemoveCell(cell c);
132

133
    vertex vertices() const;
134

135
    vertex vertices_end() const;
136

137
    vertex find_vertex(const Point &point) const;
138

139
    edge edges() const;
140

141
    edge edges_end() const;
142

143
    edge find_edge(const Point &center) const;
144

145
    face faces() const;
146

147
    face faces_end() const;
148

149
    face find_face(const Point &center) const;
150

151
    bnd_face bnd_faces() const;
152

153
    bnd_face bnd_faces_end() const;
154

155
    bnd_face find_bnd_face(const Point &z) const;
156

157
    cell cells() const;
158

159
    cell cells_end() const;
160

161
    cell find_cell(const Point &center) const;
162

163
    cell find_cell_considering_overlap(const face &f, const Point &z) const;
164

165
    cell find_neighbour_cell(const cell &c, int f) const;
166

167
168
169
170
171
172
    cell overlap() const;

    cell overlap_end() const;

    cell find_overlap_cell(const Point &center) const;

173
174
175
176
177
178
    procset procsets() const;

    procset procsets_end() const;

    procset find_procset(const Point &z) const;

179
    // Todo remove, only call via midPoint
180
181
182
    template<class C>
    procset find_procset(const C &c) const;

183
184
185
186
187
188
    identifyset identifysets() const;

    identifyset identifysets_end() const;

    identifyset find_identifyset(const Point &z) const;

189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
    int VertexCount() const;

    int VertexCountGeometry() const;

    int EdgeCount() const;

    int EdgeCountGeometry() const;

    int FaceCount() const;

    int FaceCountGeometry() const;

    int CellCount() const;

    int CellCountGeometry() const;

205
    int find_neighbour_face_id(const Point &f_c, const cell &cf) const;
206

207
    bool onBndDG(const cell &c, int f) const;
208

209
210
    int ProcSetsCount() const;

211
212
    int ProcSetsCountWithoutInfty() const;

213
214
215
216
    int ProcSetsCountGeometry() const;

    int ProcSetsCountGeometryWithoutInfty() const;

217
    int OverlapCount() const;
218

219
    int OverlapCountGeometry() const;
220

221
    int BoundaryFaceCount() const { return meshBndFaces.size(); }
222

223
    void InsertBoundaryFace(const Point &z, int part);
224

225
    void InsertBoundaryFace(const Point &z, const BoundaryFace &B);
226

227
    void RemoveBoundaryFace(const Point &x);
228

229
    auto &bnd_ref() { return meshBndFaces.ref(); }
230

231
    int BoundaryFacePart(const Point &bndFaceCenter) const;
232

233
    void FinishParallel();
234

235
    void Finish();
236

237
    int dim() const { return dimension; }
238

239
240
    int CommSplit() const { return commSplit; }

241
    void SetDim(int dim) { dimension = dim; }
242

243
    bool identify() const { return identifyBnd; }
244

245
    bool parallel() const { return Parallel; }
246

247
    bool onBnd(const Point &x) const;
248

249
    double Scaling() const { return scaling; }
250

251
252
    string MeshWidthStr() const;

253
254
    void PrintInfo() const;

255
256
257
258
    Point Neighbor(const Cell &c, int cFace) const {
        face f = find_face(c.Face(cFace));
        return f.Right();
    }
259

260
    std::pair<double, double> MeshWidth() const;
261

262
    const std::map<CELLTYPE, int> &GetOccurringCellTypes() const {
263
        return occurringCellTypes;
264
    }
265

266
267
268
    // === Data Mesh Stuff === //
    /// Dummy method for DataMeshes. See DataMesh.hpp for documentation.
    virtual bool StoresData() const { return false; }
269

270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
    /// Dummy method for DataMeshes. See DataMesh.hpp for documentation.
    virtual int GetChamber() const { return -1; }

    /// Dummy method for DataMeshes. See DataMesh.hpp for documentation.
    virtual DataContainer &DataAt(const Point &z) const { return dummyContainer; }

    /// Dummy method for DataMeshes. See DataMesh.h for documentation.
    virtual vector<struct DataContainer> DataIn(const cell &c) const {
        vector<DataContainer> data(c.Corners());
        for (int i = 0; i < c.Corners(); i++)
            data[i] = dummyContainer;
        return data;
    }

    /// Dummy method for DataMeshes. See DataMesh.hpp for documentation.
    virtual DataContainer &DataAverage(const cell &c) const { return dummyContainer; }

    /// Dummy method for DataMeshes. See DataMesh.hpp for documentation.
    virtual cell
289
290
291
292
    InsertCell(CELLTYPE tp,
               int flag,
               const vector<Point> &x,
               vector<DataContainer> &data) {
293
294
        return InsertCell(tp, flag, x);
    };
295

296
297
    virtual void InsertData(Point p, DataContainer &data) {
    }
298

299
    virtual ~Mesh();
300

301
    friend Logging &operator<<(Logging &s, const Mesh &M);
302
303
304
};

class BFParts {
305
306
307
    int bnd[6];
    int n;
    bool onbnd;
308
public:
309
    BFParts(const Mesh &M, const cell &c);
310

311
    int operator[](int i) const { return bnd[i]; }
312

313
314
315
316
    const int *operator()() const {
        if (onbnd) return bnd;
        return 0;
    }
317

318
    bool onBnd() const { return onbnd; }
319

320
    int size() const { return n; }
321

322
    friend Logging &operator<<(Logging &s, const BFParts &BF);
323
324
325
326
327
328
329
330
331
};

void CoarseMeshBoundary(Mesh &M, const CoarseGeometry &CG,
                        std::map<string, std::list<int>> &bc_nodes,
                        std::map<string, int> &key_to_bc,
                        std::map<string, std::list<Point>> &surf,
                        std::map<string, int> &surf_to_bc);

static Point project(const Point &P) {
332
333
334
335
    Point D = P - Point(10, 0, P[2]);
    double d = norm(D);
    Point T = D / d + Point(10, 0, P[2]);
    return T;
336
337
338
}

static Point project2D(const Point &P) {
339
340
341
342
    Point D = P - Point(10, 0);
    double d = norm(D);
    Point T = D / d + Point(10, 0);
    return T;
343
344
345
}

#endif // of #ifndef _MESH_H_