compiles on openSUSE 15.4 part 2
[engrid-github.git] / src / libengrid / su2writer.cpp
blob10ebbc328303704bd7151bf3e6143f7bdfa9a3e3
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 "su2writer.h"
23 #include "engrid.h"
24 #include "guimainwindow.h"
26 Su2Writer::Su2Writer()
28 setFormat("SU2 mesh files(*.su2)");
31 void Su2Writer::writeHeader()
33 QTextStream f(m_File);
34 f << "%\n";
35 f << "% Problem dimension\n";
36 f << "%\n";
37 f << "NDIME= 3\n";
40 void Su2Writer::writeElements()
42 QTextStream f(m_File);
43 f << "%\n";
44 f << "% Inner element connectivity\n";
45 f << "%\n";
46 int N = 0;
47 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
48 if (isVolume(id_cell, m_Grid)) {
49 ++N;
52 f << "NELEM= " << N << "\n";
53 int i = 0;
54 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
55 if (isVolume(id_cell, m_Grid)) {
56 f << m_Grid->GetCellType(id_cell);
57 EG_GET_CELL(id_cell, m_Grid);
58 for (int j = 0; j < num_pts; ++j) {
59 f << " " << pts[j];
61 f << " " << i << "\n";
62 ++i;
67 void Su2Writer::writeNodes()
69 QTextStream f(m_File);
70 f << "%\n";
71 f << "% Node coordinates\n";
72 f << "%\n";
73 f << "NPOIN= " << m_Grid->GetNumberOfPoints() << "\n";
74 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
75 vec3_t x;
76 m_Grid->GetPoint(id_node, x.data());
77 f.setRealNumberPrecision(16);
78 f << x[0] << " " << x[1] << " " << x[2] << " " << id_node << "\n";
82 void Su2Writer::writeBoundaries()
84 QTextStream f(m_File);
85 f << "%\n";
86 f << "% Boundary elements\n";
87 f << "%\n";
88 QSet<int> bcs = GuiMainWindow::pointer()->getAllBoundaryCodes();
89 f << "NMARK= " << bcs.size() << "\n";
90 EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
91 foreach (int bc, bcs) {
92 BoundaryCondition BC = GuiMainWindow::pointer()->getBC(bc);
93 f << "MARKER_TAG= " << BC.getName() << "\n";
94 QList<vtkIdType> faces;
95 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
96 if (isSurface(id_cell, m_Grid)) {
97 if (cell_code->GetValue(id_cell) == bc) {
98 faces.append(id_cell);
102 f << "MARKER_ELEMS= " << faces.size() << "\n";
103 foreach (vtkIdType id_cell, faces) {
104 f << m_Grid->GetCellType(id_cell);
105 EG_GET_CELL(id_cell, m_Grid);
106 for (int j = 0; j < num_pts; ++j) {
107 f << " " << pts[j];
109 f << "\n";
114 void Su2Writer::operate()
116 try {
117 QFileInfo file_info(GuiMainWindow::pointer()->getFilename());
118 readOutputFileName(file_info.completeBaseName() + ".su2");
119 if (isValid()) {
120 m_File = new QFile(getFileName());
121 m_File->open(QIODevice::WriteOnly | QIODevice::Text);
122 writeHeader();
123 writeElements();
124 writeNodes();
125 writeBoundaries();
126 delete m_File;
128 } catch (Error err) {
129 err.display();