fixed edge display for volume cells
[engrid-github.git] / src / libengrid / su2writer.cpp
blobe796c403619c6ba252ef42727db02ba352893067
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 "guimainwindow.h"
25 Su2Writer::Su2Writer()
27 setFormat("SU2 mesh files(*.su2)");
30 void Su2Writer::writeHeader()
32 QTextStream f(m_File);
33 f << "%\n";
34 f << "% Problem dimension\n";
35 f << "%\n";
36 f << "NDIME= 3\n";
39 void Su2Writer::writeElements()
41 QTextStream f(m_File);
42 f << "%\n";
43 f << "% Inner element connectivity\n";
44 f << "%\n";
45 int N = 0;
46 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
47 if (isVolume(id_cell, m_Grid)) {
48 ++N;
51 f << "NELEM= " << N << "\n";
52 int i = 0;
53 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
54 if (isVolume(id_cell, m_Grid)) {
55 f << m_Grid->GetCellType(id_cell);
56 vtkIdType N_pts, *pts;
57 m_Grid->GetCellPoints(id_cell, N_pts, pts);
58 for (int j = 0; j < N_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 vtkIdType N_pts, *pts;
106 m_Grid->GetCellPoints(id_cell, N_pts, pts);
107 for (int j = 0; j < N_pts; ++j) {
108 f << " " << pts[j];
110 f << "\n";
115 void Su2Writer::operate()
117 try {
118 QFileInfo file_info(GuiMainWindow::pointer()->getFilename());
119 readOutputFileName(file_info.completeBaseName() + ".su2");
120 if (isValid()) {
121 m_File = new QFile(getFileName());
122 m_File->open(QIODevice::WriteOnly | QIODevice::Text);
123 writeHeader();
124 writeElements();
125 writeNodes();
126 writeBoundaries();
127 delete m_File;
129 } catch (Error err) {
130 err.display();