added icon for OpenFOAM export
[engrid.git] / polymesh.h
blobcea09c894858c1fb6db6bb3e04432e4d48a7b6b7
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008,2009 Oliver Gloth +
7 // + +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
12 // + +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
17 // + +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #ifndef polymesh_H
24 #define polymesh_H
26 class PolyMesh;
28 #include "egvtkobject.h"
30 class PolyMesh : public EgVtkObject
33 protected: // data types
35 enum idx_t { node, edge, face, cell };
37 struct node_t {
38 PolyMesh *poly; // 4
39 idx_t type; // 4
40 vtkIdType idx; // 4
41 int subidx; // 4
42 //double w; // 8
43 //vec3_t x; // 24
44 //vec3_t n; // 24
45 float x,y,z;
46 node_t(PolyMesh *p, idx_t t, int i, int si) { poly = p; type = t; idx = i; subidx = si; };
47 node_t() { poly = NULL, type = node, idx = 0; subidx = 0; };
48 bool operator==(const node_t N) const;
51 friend uint qHash(node_t N);
52 friend ostream& operator<<(ostream& s, node_t N);
54 struct face_t {
55 QVector<node_t> node;
56 int owner, neighbour, bc;
57 node_t operator[](int i) { while(i<0) i+=node.size(); while(i>=node.size()) i-=node.size(); return node[i]; };
58 void checkOrientation();
59 bool operator<(const face_t &F) const;
60 vec3_t normal();
63 friend ostream& operator<<(ostream& s, face_t F);
65 protected: // attributes
67 bool dbg;
68 vtkUnstructuredGrid *grid;
69 QList<face_t> face_list;
70 QVector<face_t> faces;
71 QVector<int> cell2pc;
72 QVector<int> node2pc;
73 int id_newpc;
74 QVector<vtkIdType> cells;
75 QVector<vec3_t> nodes;
76 QVector<QVector<int> > c2c;
77 QList<int> bcs;
78 QVector<double> weight;
79 bool dual;
81 protected: // methods
83 int pcIdxNode(vtkIdType id_node);
84 int pcIdxCell(vtkIdType id_node);
85 void pass1Tetras();
86 void pass1Prisms();
87 void pass1Hexas();
88 void pass1();
89 void computeNodes();
90 void createNodes();
91 void sortFaces();
92 face_t combineFaces(QList<face_t> faces);
93 double faceW(double w) { if (w > 1.01) return 0.5*w; else return w; };
95 void pass2();
96 void pass3();
98 public: // methods
100 PolyMesh(vtkUnstructuredGrid *a_grid, bool dual_mesh = true);
101 int totalNumNodes() const { return nodes.size(); };
102 vec3_t nodeVector(int i) const { return nodes[i]; };
103 int numNodes(int i) const { return faces[i].node.size(); };
104 int nodeIndex(int i, int j) const { return faces[i].node[j].idx; };
105 int numFaces() const { return faces.size(); };
106 int numCells() const { return id_newpc; };
107 int owner(int i) const { return faces[i].owner; };
108 int neighbour(int i) const { return faces[i].neighbour; };
109 int boundaryCode(int i) const { return faces[i].bc; };
110 int numBCs() const { return bcs.size()-1; };
111 void getFace(vtkIdType idx, int subidx, QList<vtkIdType> &nodes);
112 void getEdge(vtkIdType idx, int subidx, QList<vtkIdType> &nodes);
117 uint qHash(PolyMesh::node_t N);
119 #endif