2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008-2012 enGits GmbH +
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. +
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. +
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/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24 #include "checkforoverlap.h"
25 #include "guimainwindow.h"
27 #include "facefinder.h"
29 CheckForOverlap::CheckForOverlap()
34 void CheckForOverlap::operate()
36 cout
<< "testing mesh for overlapping faces ..." << endl
;
38 m_BoundaryCodes
= GuiMainWindow::pointer()->getAllBoundaryCodes();
39 QVector
<bool> is_overlap(m_Grid
->GetNumberOfCells(), false);
40 QVector
<vtkIdType
> faces
;
41 getAllSurfaceCells(faces
, m_Grid
);
44 EG_VTKDCC(vtkIntArray
, cell_code
, m_Grid
, "cell_code");
47 find
.setMaxNumFaces(100);
53 for (int i_faces
= 0; i_faces
< faces
.size(); ++i_faces
) {
54 vtkIdType id_face1
= faces
[i_faces
];
55 bc_max
= max(bc_max
, cell_code
->GetValue(id_face1
));
58 QSet
<vtkIdType
> neighbours
;
60 vtkIdType N_pts
, *pts
;
61 m_Grid
->GetCellPoints(id_face1
, N_pts
, pts
);
63 for (int i
= 0; i
< N_pts
; ++i
) {
64 m_Grid
->GetPoint(pts
[i
], x1
[i
].data());
66 for (int j
= 0; j
< m_Part
.n2cGSize(pts
[i
]); ++j
) {
67 neighbours
.insert(m_Part
.n2cGG(pts
[i
], j
));
73 QVector
<vtkIdType
> close_faces
;
74 find
.getCloseFaces(xc
, close_faces
);
75 if (close_faces
.size() == 0) {
79 N_faces
+= close_faces
.size();
80 foreach (vtkIdType id_face2
, close_faces
) {
81 if (!neighbours
.contains(id_face2
)) {
83 vtkIdType N_pts
, *pts
;
84 m_Grid
->GetCellPoints(id_face2
, N_pts
, pts
);
85 QVector
<vec3_t
> x2(N_pts
);
86 for (int i
= 0; i
< N_pts
; ++i
) {
87 m_Grid
->GetPoint(pts
[i
], x2
[i
].data());
89 for (int i
= 0; i
< x1
.size() - 1; ++i
) {
91 if (intersectEdgeAndTriangle(x2
[0], x2
[1], x2
[2], x1
[i
], x1
[i
+1], x
, r
, 1e-6)) {
92 is_overlap
[id_face1
] = true;
93 is_overlap
[id_face2
] = true;
99 cout
<< " " << i_faces
+ 1 << " of " << faces
.size() << " " << N_searches
<< " searches" << endl
;
100 cout
<< N_faces
/N_buckets
<< " faces/bucket" << endl
;
105 foreach (vtkIdType id_face
, faces
) {
106 if (is_overlap
[id_face
]) {
107 cell_code
->SetValue(id_face
, bc_max
+ 1);
112 GuiMainWindow::pointer()->addBC(bc_max
+ 1, BoundaryCondition("overlapping_faces", "patch"));
113 GuiMainWindow::pointer()->updateBoundaryCodes(true);
115 cout
<< N
<< " overlapping or close faces found" << endl
;
116 cout
<< N_faces
/N_buckets
<< " faces/bucket" << endl
;