limited volume meshing to boundary layer only
[engrid-github.git] / src / libengrid / checkforoverlap.cpp
blobbd6b0ea677e3a558f67941c004e6eab79c2b5ffa
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
11 // + +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
16 // + +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 #include "checkforoverlap.h"
23 #include "guimainwindow.h"
24 #include "timer.h"
25 #include "facefinder.h"
27 CheckForOverlap::CheckForOverlap()
29 EG_TYPENAME;
32 void CheckForOverlap::operate()
34 cout << "testing mesh for overlapping faces ..." << endl;
35 Timer timer;
36 m_BoundaryCodes = GuiMainWindow::pointer()->getAllBoundaryCodes();
37 QVector<bool> is_overlap(m_Grid->GetNumberOfCells(), false);
38 QVector<vtkIdType> faces;
39 getAllSurfaceCells(faces, m_Grid);
40 setAllSurfaceCells();
41 int bc_max = 0;
42 EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
44 FaceFinder find;
45 find.setMaxNumFaces(100);
46 find.setGrid(m_Grid);
48 int N_searches = 0;
49 int N_buckets = 0;
50 int N_faces = 0;
51 for (int i_faces = 0; i_faces < faces.size(); ++i_faces) {
52 vtkIdType id_face1 = faces[i_faces];
53 bc_max = max(bc_max, cell_code->GetValue(id_face1));
54 QVector<vec3_t> x1;
55 vec3_t xc(0,0,0);
56 QSet<vtkIdType> neighbours;
58 EG_GET_CELL(id_face1, m_Grid);
59 x1.resize(num_pts + 1);
60 for (int i = 0; i < num_pts; ++i) {
61 m_Grid->GetPoint(pts[i], x1[i].data());
62 xc += x1[i];
63 for (int j = 0; j < m_Part.n2cGSize(pts[i]); ++j) {
64 neighbours.insert(m_Part.n2cGG(pts[i], j));
67 xc *= 1.0 / num_pts;
68 x1[num_pts] = x1[0];
70 QVector<vtkIdType> close_faces;
71 find.getCloseFaces(xc, close_faces);
72 if (close_faces.size() == 0) {
73 EG_BUG;
75 ++N_buckets;
76 N_faces += close_faces.size();
77 foreach (vtkIdType id_face2, close_faces) {
78 if (!neighbours.contains(id_face2)) {
79 ++N_searches;
80 EG_GET_CELL(id_face2, m_Grid);
81 QVector<vec3_t> x2(num_pts);
82 for (int i = 0; i < num_pts; ++i) {
83 m_Grid->GetPoint(pts[i], x2[i].data());
85 for (int i = 0; i < x1.size() - 1; ++i) {
86 vec3_t x, r;
87 if (intersectEdgeAndTriangle(x2[0], x2[1], x2[2], x1[i], x1[i+1], x, r, 1e-6)) {
88 is_overlap[id_face1] = true;
89 is_overlap[id_face2] = true;
94 if (timer()) {
95 cout << " " << i_faces + 1 << " of " << faces.size() << " " << N_searches << " searches" << endl;
96 cout << N_faces/N_buckets << " faces/bucket" << endl;
97 N_searches = 0;
100 int N = 0;
101 foreach (vtkIdType id_face, faces) {
102 if (is_overlap[id_face]) {
103 cell_code->SetValue(id_face, bc_max + 1);
104 ++N;
107 if (N > 0) {
108 GuiMainWindow::pointer()->setBC(bc_max + 1, BoundaryCondition("overlapping_faces", "patch", bc_max + 1));
109 GuiMainWindow::pointer()->updateBoundaryCodes(true);
111 cout << N << " overlapping or close faces found" << endl;
112 cout << N_faces/N_buckets << " faces/bucket" << endl;