slider for smoothing
[engrid-github.git] / src / libengrid / createvolumemesh.cpp
blob6969cdc9dec77b7c522ba75ccda0550aa751923e
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 "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()
33 EG_TYPENAME;
34 m_CreateBoundaryLayer = false;
35 m_BackgroundGrid = vtkSmartPointer<vtkUnstructuredGrid>::New();
36 m_FirstCall = true;
37 m_Debug = false;
40 int CreateVolumeMesh::numVolumeCells()
42 int N = 0;
43 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
44 if (isVolume(id_cell, m_Grid)) {
45 ++N;
48 return N;
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));
55 int N1 = 0;
56 int N2 = numVolumeCells();
57 int pass = 1;
58 QString V_txt;
59 V_txt.setNum(V);
60 bool done = false;
61 while (!done) {
62 N1 = N2;
63 QString flags;
64 QString q_txt = "1.2/0";
65 if (pass > 1) {
66 q_txt = "1.2/0";
68 flags = QString("pq") + q_txt + "a" + V_txt;
69 if (!m_FirstCall) {
70 flags += "m";
72 if (preserve_surface) {
73 flags += "Y";
75 cout << "TetGen pass " << pass << " flags=" << qPrintable(flags) << endl;
76 if (m_FirstCall) {
77 m_FirstCall = false;
78 tetgen(flags);
79 } else {
80 makeCopy(m_Grid, m_BackgroundGrid);
81 tetgen(flags, m_BackgroundGrid);
84 N2 = numVolumeCells();
85 cout << N2 << endl;
86 ++pass;
87 if (fabs(double(N2-N1)/N1) < 0.05 || pass > max_num_passes) {
88 done = true;
93 void CreateVolumeMesh::setBoundaryLayerOn()
95 m_CreateBoundaryLayer = true;
98 void CreateVolumeMesh::operate()
100 readSettings();
101 m_Part.trackGrid(m_Grid);
103 if (m_CreateBoundaryLayer) {
104 CreateBoundaryLayerShell blayer;
105 blayer.setGrid(m_Grid);
106 blayer.setAllCells();
107 blayer();
108 if (!m_Debug) {
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);
118 delete_cells();
119 m_Part.addPartition(prismatic_part);
120 } else {
121 cout << "An error ocuured while creating the prismatic layers!" << endl;
124 } else {
125 createTetMesh(2, true);