feature magic defaults to 1 now
[engrid.git] / src / libengrid / su2writer.cpp
bloba408187edcc7e585fcc69377f87b9616556d8c84
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008-2013 enGits GmbH +
7 // + +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
12 // + +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
17 // + +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 //
24 #include "su2writer.h"
25 #include "guimainwindow.h"
27 Su2Writer::Su2Writer()
29 setFormat("SU2 mesh files(*.su2)");
32 void Su2Writer::writeHeader()
34 QTextStream f(m_File);
35 f << "%\n";
36 f << "% Problem dimension\n";
37 f << "%\n";
38 f << "NDIME= 3\n";
41 void Su2Writer::writeElements()
43 QTextStream f(m_File);
44 f << "%\n";
45 f << "% Inner element connectivity\n";
46 f << "%\n";
47 int N = 0;
48 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
49 if (isVolume(id_cell, m_Grid)) {
50 ++N;
53 f << "NELEM= " << N << "\n";
54 int i = 0;
55 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
56 if (isVolume(id_cell, m_Grid)) {
57 f << m_Grid->GetCellType(id_cell);
58 vtkIdType N_pts, *pts;
59 m_Grid->GetCellPoints(id_cell, N_pts, pts);
60 for (int j = 0; j < N_pts; ++j) {
61 f << " " << pts[j];
63 f << " " << i << "\n";
64 ++i;
69 void Su2Writer::writeNodes()
71 QTextStream f(m_File);
72 f << "%\n";
73 f << "% Node coordinates\n";
74 f << "%\n";
75 f << "NPOIN= " << m_Grid->GetNumberOfPoints() << "\n";
76 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
77 vec3_t x;
78 m_Grid->GetPoint(id_node, x.data());
79 f.setRealNumberPrecision(16);
80 f << x[0] << " " << x[1] << " " << x[2] << " " << id_node << "\n";
84 void Su2Writer::writeBoundaries()
86 QTextStream f(m_File);
87 f << "%\n";
88 f << "% Boundary elements\n";
89 f << "%\n";
90 QSet<int> bcs = GuiMainWindow::pointer()->getAllBoundaryCodes();
91 f << "NMARK= " << bcs.size() << "\n";
92 EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
93 foreach (int bc, bcs) {
94 BoundaryCondition BC = GuiMainWindow::pointer()->getBC(bc);
95 f << "MARKER_TAG= " << BC.getName() << "\n";
96 QList<vtkIdType> faces;
97 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
98 if (isSurface(id_cell, m_Grid)) {
99 if (cell_code->GetValue(id_cell) == bc) {
100 faces.append(id_cell);
104 f << "MARKER_ELEMS= " << faces.size() << "\n";
105 foreach (vtkIdType id_cell, faces) {
106 f << m_Grid->GetCellType(id_cell);
107 vtkIdType N_pts, *pts;
108 m_Grid->GetCellPoints(id_cell, N_pts, pts);
109 for (int j = 0; j < N_pts; ++j) {
110 f << " " << pts[j];
112 f << "\n";
117 void Su2Writer::operate()
119 try {
120 QFileInfo file_info(GuiMainWindow::pointer()->getFilename());
121 readOutputFileName(file_info.completeBaseName() + ".su2");
122 if (isValid()) {
123 m_File = new QFile(getFileName());
124 m_File->open(QIODevice::WriteOnly | QIODevice::Text);
125 writeHeader();
126 writeElements();
127 writeNodes();
128 writeBoundaries();
129 delete m_File;
131 } catch (Error err) {
132 err.display();