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 vtkIdType N_pts
, *pts
;
59 m_Grid
->GetCellPoints(id_face1
, N_pts
, pts
);
61 for (int i
= 0; i
< N_pts
; ++i
) {
62 m_Grid
->GetPoint(pts
[i
], x1
[i
].data());
64 for (int j
= 0; j
< m_Part
.n2cGSize(pts
[i
]); ++j
) {
65 neighbours
.insert(m_Part
.n2cGG(pts
[i
], j
));
71 QVector
<vtkIdType
> close_faces
;
72 find
.getCloseFaces(xc
, close_faces
);
73 if (close_faces
.size() == 0) {
77 N_faces
+= close_faces
.size();
78 foreach (vtkIdType id_face2
, close_faces
) {
79 if (!neighbours
.contains(id_face2
)) {
81 vtkIdType N_pts
, *pts
;
82 m_Grid
->GetCellPoints(id_face2
, N_pts
, pts
);
83 QVector
<vec3_t
> x2(N_pts
);
84 for (int i
= 0; i
< N_pts
; ++i
) {
85 m_Grid
->GetPoint(pts
[i
], x2
[i
].data());
87 for (int i
= 0; i
< x1
.size() - 1; ++i
) {
89 if (intersectEdgeAndTriangle(x2
[0], x2
[1], x2
[2], x1
[i
], x1
[i
+1], x
, r
, 1e-6)) {
90 is_overlap
[id_face1
] = true;
91 is_overlap
[id_face2
] = true;
97 cout
<< " " << i_faces
+ 1 << " of " << faces
.size() << " " << N_searches
<< " searches" << endl
;
98 cout
<< N_faces
/N_buckets
<< " faces/bucket" << endl
;
103 foreach (vtkIdType id_face
, faces
) {
104 if (is_overlap
[id_face
]) {
105 cell_code
->SetValue(id_face
, bc_max
+ 1);
110 GuiMainWindow::pointer()->addBC(bc_max
+ 1, BoundaryCondition("overlapping_faces", "patch"));
111 GuiMainWindow::pointer()->updateBoundaryCodes(true);
113 cout
<< N
<< " overlapping or close faces found" << endl
;
114 cout
<< N_faces
/N_buckets
<< " faces/bucket" << endl
;