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 "su2writer.h"
23 #include "guimainwindow.h"
25 Su2Writer::Su2Writer()
27 setFormat("SU2 mesh files(*.su2)");
30 void Su2Writer::writeHeader()
32 QTextStream
f(m_File
);
34 f
<< "% Problem dimension\n";
39 void Su2Writer::writeElements()
41 QTextStream
f(m_File
);
43 f
<< "% Inner element connectivity\n";
46 for (vtkIdType id_cell
= 0; id_cell
< m_Grid
->GetNumberOfCells(); ++id_cell
) {
47 if (isVolume(id_cell
, m_Grid
)) {
51 f
<< "NELEM= " << N
<< "\n";
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
) {
61 f
<< " " << i
<< "\n";
67 void Su2Writer::writeNodes()
69 QTextStream
f(m_File
);
71 f
<< "% Node coordinates\n";
73 f
<< "NPOIN= " << m_Grid
->GetNumberOfPoints() << "\n";
74 for (vtkIdType id_node
= 0; id_node
< m_Grid
->GetNumberOfPoints(); ++id_node
) {
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
);
86 f
<< "% Boundary elements\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
) {
115 void Su2Writer::operate()
118 QFileInfo
file_info(GuiMainWindow::pointer()->getFilename());
119 readOutputFileName(file_info
.completeBaseName() + ".su2");
121 m_File
= new QFile(getFileName());
122 m_File
->open(QIODevice::WriteOnly
| QIODevice::Text
);
129 } catch (Error err
) {