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 "dolfynwriter.h"
24 #include "guimainwindow.h"
26 DolfynWriter::DolfynWriter()
28 setFormat("Dolfyn mesh files(*.vrt)");
31 void DolfynWriter::writeVertices()
33 QTextStream
f(m_VrtFile
);
35 for (vtkIdType id_node
= 0; id_node
< m_Grid
->GetNumberOfPoints(); ++id_node
) {
37 m_Grid
->GetPoint(id_node
, x
.data());
38 str
.sprintf("%9d %16.9E%16.9E%16.9E\n", id_node
+ 1, x
[0], x
[1], x
[2]);
43 void DolfynWriter::writeElements()
46 QTextStream
f(m_CelFile
);
48 EG_VTKDCC(vtkIntArray
, cell_code
, m_Grid
, "cell_code");
49 for (vtkIdType cellId
= 0; cellId
< m_Grid
->GetNumberOfCells(); ++cellId
) {
50 EG_GET_CELL(cellId
, m_Grid
);
51 if (m_Grid
->GetCellType(cellId
) == VTK_HEXAHEDRON
) {
52 str
.sprintf("%8d %8d %8d %8d %8d %8d %8d %8d %8d %4d %4d\n",
54 pts
[0] + 1, pts
[1] + 1, pts
[2] + 1, pts
[3] + 1,
55 pts
[4] + 1, pts
[5] + 1, pts
[6] + 1, pts
[7] + 1,
57 } else if (m_Grid
->GetCellType(cellId
) == VTK_TETRA
) {
58 str
.sprintf("%8d %8d %8d %8d %8d %8d %8d %8d %8d %4d %4d\n",
60 pts
[0] + 1, pts
[1] + 1, pts
[2] + 1, pts
[2] + 1,
61 pts
[3] + 1, pts
[3] + 1, pts
[3] + 1, pts
[3] + 1,
63 } else if (m_Grid
->GetCellType(cellId
) == VTK_PYRAMID
) {
64 str
.sprintf("%8d %8d %8d %8d %8d %8d %8d %8d %8d %4d %4d\n",
66 pts
[0] + 1, pts
[1] + 1, pts
[2] + 1, pts
[3] + 1,
67 pts
[4] + 1, pts
[4] + 1, pts
[4] + 1, pts
[4] + 1,
69 } else if (m_Grid
->GetCellType(cellId
) == VTK_WEDGE
) {
71 str.sprintf("%9d %9d%9d%9d%9d%9d%9d%9d%9d %5d%5d\n",
73 pts[0] + 1, pts[1] + 1, pts[2] + 1, pts[2] + 1,
74 pts[3] + 1, pts[4] + 1, pts[5] + 1, pts[5] + 1,
76 str
.sprintf("%8d %8d %8d %8d %8d %8d %8d %8d %8d %4d %4d\n",
78 pts
[3] + 1, pts
[4] + 1, pts
[5] + 1, pts
[5] + 1,
79 pts
[0] + 1, pts
[1] + 1, pts
[2] + 1, pts
[2] + 1,
90 void DolfynWriter::writeBoundaries()
92 int bndid
= 1, bcid
= 1;
93 QTextStream
f(m_BndFile
);
95 QSet
<int> bcs
= GuiMainWindow::pointer()->getAllBoundaryCodes();
96 EG_VTKDCC(vtkIntArray
, cell_code
, m_Grid
, "cell_code");
97 foreach (int bc
, bcs
) {
98 BoundaryCondition BC
= GuiMainWindow::pointer()->getBC(bc
);
99 QString bc_name
= BC
.getName();
100 QList
<vtkIdType
> faces
;
101 for (vtkIdType id_cell
= 0; id_cell
< m_Grid
->GetNumberOfCells(); ++id_cell
) {
102 if (isSurface(id_cell
, m_Grid
)) {
103 if (cell_code
->GetValue(id_cell
) == bc
) {
104 faces
.append(id_cell
);
108 foreach (vtkIdType id_cell
, faces
) {
109 EG_GET_CELL(id_cell
, m_Grid
);
110 if (m_Grid
->GetCellType(id_cell
) == VTK_TRIANGLE
) {
111 str
.sprintf("%8d %8d %8d %8d %9d %4d %4d",
113 pts
[0] + 1, pts
[1] + 1, pts
[2] + 1, pts
[2] + 1,
115 } else if (m_Grid
->GetCellType(id_cell
) == VTK_QUAD
) {
116 str
.sprintf("%8d %8d %8d %8d %9d %4d %4d",
118 pts
[0] + 1, pts
[1] + 1, pts
[2] + 1, pts
[3] + 1,
124 f
<< str
<< bc_name
.left(10) << "\n";
131 void DolfynWriter::operate()
134 QFileInfo
file_info(GuiMainWindow::pointer()->getFilename());
135 readOutputFileName(file_info
.completeBaseName() + ".vrt");
137 QFileInfo
filename(getFileName());
138 m_VrtFile
= new QFile(getFileName());
139 m_VrtFile
->open(QIODevice::WriteOnly
| QIODevice::Text
);
140 m_CelFile
= new QFile(filename
.dir().filePath(filename
.completeBaseName() + ".cel"));
141 m_CelFile
->open(QIODevice::WriteOnly
| QIODevice::Text
);
142 m_BndFile
= new QFile(filename
.dir().filePath(filename
.completeBaseName() + ".bnd"));
143 m_BndFile
->open(QIODevice::WriteOnly
| QIODevice::Text
);
153 } catch (Error err
) {