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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "tauwriter.h"
24 #include "guimainwindow.h"
25 #include <netcdfcpp.h>
28 TauWriter::TauWriter()
30 setFormat("Tau files(*.grid)");
31 m_MenuText
= "export to Tau format";
34 void TauWriter::operate()
37 QFileInfo
file_info(GuiMainWindow::pointer()->getFilename());
38 readOutputFileName(file_info
.completeBaseName() + ".grid");
40 QString file_name
= getFileName();
41 NcFile
*nc_file
= new NcFile(file_name
.toAscii(), NcFile::Replace
);
42 if (!nc_file
->is_valid()) {
43 EG_ERR_RETURN("unable to open NetCFD file for writing");
47 size_t Np
= m_Grid
->GetNumberOfPoints();
48 vector
<double> x(Np
),y(Np
),z(Np
);
49 for (vtkIdType id_node
= 0; id_node
< m_Grid
->GetNumberOfPoints(); ++id_node
) {
51 m_Grid
->GetPoint(id_node
, xv
.data());
56 NcDim
*no_of_points
= nc_file
->add_dim("no_of_points", Np
);
57 NcVar
*points_xc
= nc_file
->add_var("points_xc", ncDouble
, no_of_points
);
58 NcVar
*points_yc
= nc_file
->add_var("points_yc", ncDouble
, no_of_points
);
59 NcVar
*points_zc
= nc_file
->add_var("points_zc", ncDouble
, no_of_points
);
60 points_xc
->put(&x
[0],Np
);
61 points_yc
->put(&y
[0],Np
);
62 points_zc
->put(&z
[0],Np
);
68 for (vtkIdType id_cell
= 0; id_cell
< m_Grid
->GetNumberOfCells(); ++id_cell
) {
69 if (isSurface(id_cell
, m_Grid
)) {
71 if (m_Grid
->GetCellType(id_cell
) == VTK_TRIANGLE
) {
73 } else if (m_Grid
->GetCellType(id_cell
) == VTK_QUAD
) {
76 EG_ERR_RETURN("unsupported boundary element type encountered");
80 NcDim
*no_of_surfaceelements
= nc_file
->add_dim("no_of_surfaceelements", Nbe
);
81 NcVar
*boundarymarker_of_surfaces
= nc_file
->add_var("boundarymarker_of_surfaces", ncInt
, no_of_surfaceelements
);
82 vector
<int> bm(Nbe
,0), tri(3*Ntri
), quad(4*Nquad
);
84 QSet
<int> bc_set
= getAllBoundaryCodes(m_Grid
);
85 QVector
<int> bcs(bc_set
.size());
86 qCopy(bc_set
.begin(), bc_set
.end(), bcs
.begin());
87 EG_VTKDCC(vtkIntArray
, cell_code
, m_Grid
, "cell_code");
89 NcDim
*no_of_surfacetriangles
= nc_file
->add_dim("no_of_surfacetriangles", Ntri
);
90 NcDim
*points_per_surfacetriangle
= nc_file
->add_dim("points_per_surfacetriangle", 3);
91 NcVar
*points_of_surfacetriangles
= nc_file
->add_var("points_of_surfacetriangles", ncInt
, no_of_surfacetriangles
, points_per_surfacetriangle
);
93 for (vtkIdType id_cell
= 0; id_cell
< m_Grid
->GetNumberOfCells(); ++id_cell
) {
94 if (isSurface(id_cell
, m_Grid
)) {
95 if (m_Grid
->GetCellType(id_cell
) == VTK_TRIANGLE
) {
96 for (int i_bc
= 0; i_bc
< bcs
.size(); ++i_bc
) {
97 if (bcs
[i_bc
] == cell_code
->GetValue(id_cell
)) {
102 vtkIdType N_pts
, *pts
;
103 m_Grid
->GetCellPoints(id_cell
, N_pts
, pts
);
104 tri
[i_tri
+ 0] = pts
[0];
105 tri
[i_tri
+ 1] = pts
[1];
106 tri
[i_tri
+ 2] = pts
[2];
112 points_of_surfacetriangles
->put(&tri
[0],Ntri
,3);
115 NcDim
*no_of_surfacequadrilaterals
= nc_file
->add_dim("no_of_surfacequadrilaterals",Nquad
);
116 NcDim
*points_per_surfacequadrilateral
= nc_file
->add_dim("points_per_surfacequadrilateral",4);
117 NcVar
*points_of_surfacequadrilaterals
= nc_file
->add_var("points_of_surfacequadrilaterals",ncInt
, no_of_surfacequadrilaterals
, points_per_surfacequadrilateral
);
119 for (vtkIdType id_cell
= 0; id_cell
< m_Grid
->GetNumberOfCells(); ++id_cell
) {
120 if (isSurface(id_cell
, m_Grid
)) {
121 if (m_Grid
->GetCellType(id_cell
) == VTK_QUAD
) {
122 for (int i_bc
= 0; i_bc
< bcs
.size(); ++i_bc
) {
123 if (bcs
[i_bc
] == cell_code
->GetValue(id_cell
)) {
128 vtkIdType N_pts
, *pts
;
129 m_Grid
->GetCellPoints(id_cell
, N_pts
, pts
);
130 quad
[i_quad
+ 0] = pts
[0];
131 quad
[i_quad
+ 1] = pts
[1];
132 quad
[i_quad
+ 2] = pts
[2];
133 quad
[i_quad
+ 3] = pts
[3];
139 points_of_surfacequadrilaterals
->put(&quad
[0],Nquad
,4);
141 boundarymarker_of_surfaces
->put(&bm
[0],Nbe
);
142 NcDim
*no_of_markers
= nc_file
->add_dim("no_of_markers", bcs
.size());
149 for (vtkIdType id_cell
= 0; id_cell
< m_Grid
->GetNumberOfCells(); ++id_cell
) {
150 if (m_Grid
->GetCellType(id_cell
) == VTK_TETRA
) ++Ntet
;
151 if (m_Grid
->GetCellType(id_cell
) == VTK_PYRAMID
) ++Npyr
;
152 if (m_Grid
->GetCellType(id_cell
) == VTK_WEDGE
) ++Npri
;
153 if (m_Grid
->GetCellType(id_cell
) == VTK_HEXAHEDRON
) ++Nhex
;
156 vector
<int> tet(Ntet
*4),pyr(Npyr
*5),pri(Npri
*6),hex(Nhex
*8);
162 NcDim
*no_of_tetraeders
= nc_file
->add_dim("no_of_tetraeders",Ntet
);
163 NcDim
*points_per_tetraeder
= nc_file
->add_dim("points_per_tetraeder",4);
164 NcVar
*points_of_tetraeders
= nc_file
->add_var("points_of_tetraeders",ncInt
, no_of_tetraeders
, points_per_tetraeder
);
165 for (vtkIdType id_cell
= 0; id_cell
< m_Grid
->GetNumberOfCells(); ++id_cell
) {
166 if (m_Grid
->GetCellType(id_cell
) == VTK_TETRA
) {
167 vtkIdType
*pts
, N_pts
;
168 m_Grid
->GetCellPoints(id_cell
, N_pts
, pts
);
169 tet
[i_tet
+ 0] = pts
[0];
170 tet
[i_tet
+ 1] = pts
[1];
171 tet
[i_tet
+ 2] = pts
[2];
172 tet
[i_tet
+ 3] = pts
[3];
176 points_of_tetraeders
->put(&tet
[0],Ntet
,4);
179 NcDim
*no_of_pyramids
= nc_file
->add_dim("no_of_pyramids",Npyr
);
180 NcDim
*points_per_pyramid
= nc_file
->add_dim("points_per_pyramid",5);
181 NcVar
*points_of_pyramids
= nc_file
->add_var("points_of_pyramids",ncInt
, no_of_pyramids
, points_per_pyramid
);
182 for (vtkIdType id_cell
= 0; id_cell
< m_Grid
->GetNumberOfCells(); ++id_cell
) {
183 if (m_Grid
->GetCellType(id_cell
) == VTK_PYRAMID
) {
184 vtkIdType
*pts
, N_pts
;
185 m_Grid
->GetCellPoints(id_cell
, N_pts
, pts
);
186 pyr
[i_pyr
+ 0] = pts
[0];
187 pyr
[i_pyr
+ 1] = pts
[1];
188 pyr
[i_pyr
+ 2] = pts
[2];
189 pyr
[i_pyr
+ 3] = pts
[3];
190 pyr
[i_pyr
+ 4] = pts
[4];
194 points_of_pyramids
->put(&pyr
[0],Npyr
,5);
197 NcDim
*no_of_prisms
= nc_file
->add_dim("no_of_prisms",Npri
);
198 NcDim
*points_per_prism
= nc_file
->add_dim("points_per_prism",6);
199 NcVar
*points_of_prisms
= nc_file
->add_var("points_of_prisms",ncInt
, no_of_prisms
, points_per_prism
);
200 for (vtkIdType id_cell
= 0; id_cell
< m_Grid
->GetNumberOfCells(); ++id_cell
) {
201 if (m_Grid
->GetCellType(id_cell
) == VTK_WEDGE
) {
202 vtkIdType
*pts
, N_pts
;
203 m_Grid
->GetCellPoints(id_cell
, N_pts
, pts
);
204 pri
[i_pri
+ 0] = pts
[0];
205 pri
[i_pri
+ 1] = pts
[2];
206 pri
[i_pri
+ 2] = pts
[1];
207 pri
[i_pri
+ 3] = pts
[3];
208 pri
[i_pri
+ 4] = pts
[5];
209 pri
[i_pri
+ 5] = pts
[4];
213 points_of_prisms
->put(&pri
[0],Npri
,6);
216 NcDim
*no_of_hexaeders
= nc_file
->add_dim("no_of_hexaeders",Nhex
);
217 NcDim
*points_per_hexaeder
= nc_file
->add_dim("points_per_hexaeder",8);
218 NcVar
*points_of_hexaeders
= nc_file
->add_var("points_of_hexaeders",ncInt
, no_of_hexaeders
, points_per_hexaeder
);
219 for (vtkIdType id_cell
= 0; id_cell
< m_Grid
->GetNumberOfCells(); ++id_cell
) {
220 if (m_Grid
->GetCellType(id_cell
) == VTK_HEXAHEDRON
) {
221 vtkIdType
*pts
, N_pts
;
222 m_Grid
->GetCellPoints(id_cell
, N_pts
, pts
);
223 hex
[i_hex
+ 0] = pts
[4];
224 hex
[i_hex
+ 1] = pts
[7];
225 hex
[i_hex
+ 2] = pts
[6];
226 hex
[i_hex
+ 3] = pts
[5];
227 hex
[i_hex
+ 4] = pts
[0];
228 hex
[i_hex
+ 5] = pts
[3];
229 hex
[i_hex
+ 6] = pts
[2];
230 hex
[i_hex
+ 7] = pts
[1];
234 points_of_hexaeders
->put(&hex
[0],Nhex
,8);
239 } catch (Error err
) {
244 #endif // TAU_SUPPORT