1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
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. +
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. +
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/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 #include "checkforoverlap.h"
23 #include "guimainwindow.h"
25 #include "facefinder.h"
27 CheckForOverlap::CheckForOverlap()
32 void CheckForOverlap::operate()
34 cout
<< "testing mesh for overlapping faces ..." << endl
;
36 m_BoundaryCodes
= GuiMainWindow::pointer()->getAllBoundaryCodes();
37 QVector
<bool> is_overlap(m_Grid
->GetNumberOfCells(), false);
38 QVector
<vtkIdType
> faces
;
39 getAllSurfaceCells(faces
, m_Grid
);
42 EG_VTKDCC(vtkIntArray
, cell_code
, m_Grid
, "cell_code");
45 find
.setMaxNumFaces(100);
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
));
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());
63 for (int j
= 0; j
< m_Part
.n2cGSize(pts
[i
]); ++j
) {
64 neighbours
.insert(m_Part
.n2cGG(pts
[i
], j
));
70 QVector
<vtkIdType
> close_faces
;
71 find
.getCloseFaces(xc
, close_faces
);
72 if (close_faces
.size() == 0) {
76 N_faces
+= close_faces
.size();
77 foreach (vtkIdType id_face2
, close_faces
) {
78 if (!neighbours
.contains(id_face2
)) {
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
) {
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;
95 cout
<< " " << i_faces
+ 1 << " of " << faces
.size() << " " << N_searches
<< " searches" << endl
;
96 cout
<< N_faces
/N_buckets
<< " faces/bucket" << endl
;
101 foreach (vtkIdType id_face
, faces
) {
102 if (is_overlap
[id_face
]) {
103 cell_code
->SetValue(id_face
, bc_max
+ 1);
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
;