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 "guimainwindow.h"
25 #include "updatedesiredmeshdensity.h"
26 #include <vtkXMLUnstructuredGridWriter.h>
28 CreateVolumeMesh::CreateVolumeMesh()
33 void CreateVolumeMesh::setTraceCells(const QVector
<vtkIdType
> &cells
)
35 m_TraceCells
.resize(cells
.size());
36 qCopy(cells
.begin(), cells
.end(), m_TraceCells
.begin());
39 void CreateVolumeMesh::getTraceCells(QVector
<vtkIdType
> &cells
)
41 cells
.resize(m_TraceCells
.size());
42 qCopy(m_TraceCells
.begin(), m_TraceCells
.end(), cells
.begin());
45 void CreateVolumeMesh::computeMeshDensity()
48 QString buffer = GuiMainWindow::pointer()->getXmlSection("engrid/surface/settings").replace("\n", " ");
49 if (!buffer.isEmpty()) {
50 QTextStream in(&buffer, QIODevice::ReadOnly);
51 in >> m_MaxEdgeLength;
52 in >> m_MinEdgeLength;
55 m_MaxEdgeLength = 1000.0;
56 m_MinEdgeLength = 0.0;
60 QVector<double> H(m_Grid->GetNumberOfPoints(), m_MaxEdgeLength);
62 QVector<bool> fixed(m_Grid->GetNumberOfPoints(), false);
64 vtkIdType id_min = -1;
65 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
66 bool volume_only = true;
67 for (int i = 0; i < m_Part.n2cGSize(id_node); ++i) {
68 if (isSurface(m_Part.n2cGG(id_node, i), m_Grid)) {
72 fixed[id_node] = true;
76 m_Grid->GetPoint(id_node, xi.data());
77 for (int j = 0; j < m_Part.n2nGSize(id_node); ++j) {
78 if (m_Part.n2nGG(id_node, j)) {
80 m_Grid->GetPoint(m_Part.n2nGG(id_node, j), xj.data());
81 H[id_node] += (xi-xj).abs();
92 if (H[id_node] < H_min) {
103 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
105 m_Grid->GetPoint(id_node, x.data());
106 double cl_src = m_ELSManager.minEdgeLength(x);
108 if (cl_src < H[id_node]) {
114 QVector<bool> marked(m_Grid->GetNumberOfPoints(), false);
115 marked[id_min] = true;
119 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
120 if (marked[id_node] && H[id_node] <= H_min) {
122 m_Grid->GetPoint(id_node, x1.data());
123 for (int i = 0; i < m_Part.n2nGSize(id_node); ++i) {
124 vtkIdType id_neigh = m_Part.n2nGG(id_node,i);
125 if (!marked[id_neigh]) {
127 m_Grid->GetPoint(id_neigh, x2.data());
128 double dist = (x1 - x2).abs();
129 double h = H[id_node] + (m_GrowthFactor - 1)*dist;
133 H[id_neigh] = min(H[id_neigh], h);
134 marked[id_neigh] = true;
135 //H[id_neigh] += 1.0*H[id_node];
141 H_min *= m_GrowthFactor;
144 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
146 m_Grid->GetPoint(id_node, x.data());
147 double cl_src = m_ELSManager.minEdgeLength(x);
149 if (cl_src < H[id_node]) {
155 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
157 m_Grid->GetPoint(id_node, x1.data());
159 for (int j = 0; j < m_Part.n2nGSize(id_node); ++j) {
161 m_Grid->GetPoint(m_Part.n2nGG(id_node, j), xj.data());
162 for (int k = 0; k < 3; ++k) {
163 x1[k] = min(xj[k], x1[k]);
164 x2[k] = max(xj[k], x2[k]);
168 // Do something here!!
176 void CreateVolumeMesh::operate()
179 double a
= m_MaximalEdgeLength
;
180 double V
= a
*a
*a
/(6*sqrt(2.0));
183 flags
= QString("pq1.4a") + flags
;
184 cout
<< qPrintable(flags
) << endl
;