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"
23 #include "guimainwindow.h"
25 DolfynWriter::DolfynWriter()
27 setFormat("Dolfyn mesh files(*.vrt)");
30 void DolfynWriter::writeVertices()
32 QTextStream
f(m_VrtFile
);
34 for (vtkIdType id_node
= 0; id_node
< m_Grid
->GetNumberOfPoints(); ++id_node
) {
36 m_Grid
->GetPoint(id_node
, x
.data());
37 str
.sprintf("%9d %16.9E%16.9E%16.9E\n", id_node
+ 1, x
[0], x
[1], x
[2]);
42 void DolfynWriter::writeElements()
45 QTextStream
f(m_CelFile
);
47 EG_VTKDCC(vtkIntArray
, cell_code
, m_Grid
, "cell_code");
48 for (vtkIdType cellId
= 0; cellId
< m_Grid
->GetNumberOfCells(); ++cellId
) {
51 m_Grid
->GetCellPoints(cellId
, Npts
, pts
);
52 if (m_Grid
->GetCellType(cellId
) == VTK_HEXAHEDRON
) {
53 str
.sprintf("%8d %8d %8d %8d %8d %8d %8d %8d %8d %4d %4d\n",
55 pts
[0] + 1, pts
[1] + 1, pts
[2] + 1, pts
[3] + 1,
56 pts
[4] + 1, pts
[5] + 1, pts
[6] + 1, pts
[7] + 1,
58 } else if (m_Grid
->GetCellType(cellId
) == VTK_TETRA
) {
59 str
.sprintf("%8d %8d %8d %8d %8d %8d %8d %8d %8d %4d %4d\n",
61 pts
[0] + 1, pts
[1] + 1, pts
[2] + 1, pts
[2] + 1,
62 pts
[3] + 1, pts
[3] + 1, pts
[3] + 1, pts
[3] + 1,
64 } else if (m_Grid
->GetCellType(cellId
) == VTK_PYRAMID
) {
65 str
.sprintf("%8d %8d %8d %8d %8d %8d %8d %8d %8d %4d %4d\n",
67 pts
[0] + 1, pts
[1] + 1, pts
[2] + 1, pts
[3] + 1,
68 pts
[4] + 1, pts
[4] + 1, pts
[4] + 1, pts
[4] + 1,
70 } else if (m_Grid
->GetCellType(cellId
) == VTK_WEDGE
) {
72 str.sprintf("%9d %9d%9d%9d%9d%9d%9d%9d%9d %5d%5d\n",
74 pts[0] + 1, pts[1] + 1, pts[2] + 1, pts[2] + 1,
75 pts[3] + 1, pts[4] + 1, pts[5] + 1, pts[5] + 1,
77 str
.sprintf("%8d %8d %8d %8d %8d %8d %8d %8d %8d %4d %4d\n",
79 pts
[3] + 1, pts
[4] + 1, pts
[5] + 1, pts
[5] + 1,
80 pts
[0] + 1, pts
[1] + 1, pts
[2] + 1, pts
[2] + 1,
91 void DolfynWriter::writeBoundaries()
93 int bndid
= 1, bcid
= 1;
94 QTextStream
f(m_BndFile
);
96 QSet
<int> bcs
= GuiMainWindow::pointer()->getAllBoundaryCodes();
97 EG_VTKDCC(vtkIntArray
, cell_code
, m_Grid
, "cell_code");
98 foreach (int bc
, bcs
) {
99 BoundaryCondition BC
= GuiMainWindow::pointer()->getBC(bc
);
100 QString bc_name
= BC
.getName();
101 QList
<vtkIdType
> faces
;
102 for (vtkIdType id_cell
= 0; id_cell
< m_Grid
->GetNumberOfCells(); ++id_cell
) {
103 if (isSurface(id_cell
, m_Grid
)) {
104 if (cell_code
->GetValue(id_cell
) == bc
) {
105 faces
.append(id_cell
);
109 foreach (vtkIdType id_cell
, faces
) {
110 vtkIdType N_pts
, *pts
;
111 m_Grid
->GetCellPoints(id_cell
, N_pts
, pts
);
112 if (m_Grid
->GetCellType(id_cell
) == VTK_TRIANGLE
) {
113 str
.sprintf("%8d %8d %8d %8d %9d %4d %4d",
115 pts
[0] + 1, pts
[1] + 1, pts
[2] + 1, pts
[2] + 1,
117 } else if (m_Grid
->GetCellType(id_cell
) == VTK_QUAD
) {
118 str
.sprintf("%8d %8d %8d %8d %9d %4d %4d",
120 pts
[0] + 1, pts
[1] + 1, pts
[2] + 1, pts
[3] + 1,
126 f
<< str
<< bc_name
.left(10) << "\n";
133 void DolfynWriter::operate()
136 QFileInfo
file_info(GuiMainWindow::pointer()->getFilename());
137 readOutputFileName(file_info
.completeBaseName() + ".vrt");
139 QFileInfo
filename(getFileName());
140 m_VrtFile
= new QFile(getFileName());
141 m_VrtFile
->open(QIODevice::WriteOnly
| QIODevice::Text
);
142 m_CelFile
= new QFile(filename
.dir().filePath(filename
.completeBaseName() + ".cel"));
143 m_CelFile
->open(QIODevice::WriteOnly
| QIODevice::Text
);
144 m_BndFile
= new QFile(filename
.dir().filePath(filename
.completeBaseName() + ".bnd"));
145 m_BndFile
->open(QIODevice::WriteOnly
| QIODevice::Text
);
155 } catch (Error err
) {