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 "createvolumemesh.h"
23 #include "deletetetras.h"
24 #include "deletecells.h"
25 #include "guimainwindow.h"
26 #include "updatedesiredmeshdensity.h"
27 #include "createboundarylayershell.h"
29 #include <vtkXMLUnstructuredGridWriter.h>
31 CreateVolumeMesh::CreateVolumeMesh()
34 m_CreateBoundaryLayer
= false;
35 m_BackgroundGrid
= vtkSmartPointer
<vtkUnstructuredGrid
>::New();
40 int CreateVolumeMesh::numVolumeCells()
43 for (vtkIdType id_cell
= 0; id_cell
< m_Grid
->GetNumberOfCells(); ++id_cell
) {
44 if (isVolume(id_cell
, m_Grid
)) {
51 void CreateVolumeMesh::createTetMesh(int max_num_passes
, bool preserve_surface
)
53 double a
= m_MaximalEdgeLength
;
54 double V
= a
*a
*a
/(6*sqrt(2.0));
56 int N2
= numVolumeCells();
64 QString q_txt
= "1.2/0";
68 flags
= QString("pq") + q_txt
+ "a" + V_txt
;
72 if (preserve_surface
) {
75 cout
<< "TetGen pass " << pass
<< " flags=" << qPrintable(flags
) << endl
;
80 makeCopy(m_Grid
, m_BackgroundGrid
);
81 tetgen(flags
, m_BackgroundGrid
);
84 N2
= numVolumeCells();
87 if (fabs(double(N2
-N1
)/N1
) < 0.05 || pass
> max_num_passes
) {
93 void CreateVolumeMesh::setBoundaryLayerOn()
95 m_CreateBoundaryLayer
= true;
98 void CreateVolumeMesh::operate()
101 m_Part
.trackGrid(m_Grid
);
103 if (m_CreateBoundaryLayer
) {
104 CreateBoundaryLayerShell blayer
;
105 blayer
.setGrid(m_Grid
);
106 blayer
.setAllCells();
109 if (blayer
.success()) {
110 createTetMesh(2, true);
111 vtkUnstructuredGrid
*prismatic_grid
= blayer
.getPrismaticGrid();
112 MeshPartition
prismatic_part(prismatic_grid
, true);
113 QVector
<vtkIdType
> shell_cells
;
114 getSurfaceCells(blayer
.getBoundaryLayerCodes(), shell_cells
, m_Grid
);
115 DeleteCells delete_cells
;
116 delete_cells
.setGrid(m_Grid
);
117 delete_cells
.setCellsToDelete(shell_cells
);
119 m_Part
.addPartition(prismatic_part
);
121 cout
<< "An error ocuured while creating the prismatic layers!" << endl
;
125 createTetMesh(2, true);