compiles on openSUSE 15.4 part 2
[engrid-github.git] / src / libengrid / dolfynwriter.cpp
blob480d17a0186c293cd77e8161340a8876189f9ad3
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 "dolfynwriter.h"
23 #include "engrid.h"
24 #include "guimainwindow.h"
26 DolfynWriter::DolfynWriter()
28 setFormat("Dolfyn mesh files(*.vrt)");
31 void DolfynWriter::writeVertices()
33 QTextStream f(m_VrtFile);
34 QString str;
35 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
36 vec3_t x;
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]);
39 f << str;
43 void DolfynWriter::writeElements()
45 int elid = 1;
46 QTextStream f(m_CelFile);
47 QString str;
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",
53 elid,
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,
56 1, 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",
59 elid,
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,
62 1, 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",
65 elid,
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,
68 1, 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",
72 elid,
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,
75 1, 1); */
76 str.sprintf("%8d %8d %8d %8d %8d %8d %8d %8d %8d %4d %4d\n",
77 elid,
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,
80 1, 1);
81 } else {
82 //f << "Skipped!\n"
83 continue;
85 f << str;
86 elid++;
90 void DolfynWriter::writeBoundaries()
92 int bndid = 1, bcid = 1;
93 QTextStream f(m_BndFile);
94 QString str;
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",
112 bndid,
113 pts[0] + 1, pts[1] + 1, pts[2] + 1, pts[2] + 1,
114 bcid, 0);
115 } else if (m_Grid->GetCellType(id_cell) == VTK_QUAD) {
116 str.sprintf("%8d %8d %8d %8d %9d %4d %4d",
117 bndid,
118 pts[0] + 1, pts[1] + 1, pts[2] + 1, pts[3] + 1,
119 bcid, 0);
120 } else {
121 //f << "Skipped!\n";
122 continue;
124 f << str << bc_name.left(10) << "\n";
125 bndid++;
127 bcid++;
131 void DolfynWriter::operate()
133 try {
134 QFileInfo file_info(GuiMainWindow::pointer()->getFilename());
135 readOutputFileName(file_info.completeBaseName() + ".vrt");
136 if (isValid()) {
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);
145 writeVertices();
146 writeElements();
147 writeBoundaries();
149 delete m_VrtFile;
150 delete m_CelFile;
151 delete m_BndFile;
153 } catch (Error err) {
154 err.display();