2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008-2013 enGits GmbH +
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. +
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. +
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/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "foamreader.h"
24 #include "guimainwindow.h"
26 FoamReader::FoamReader()
31 void FoamReader::operate()
34 readInputDirectory("Select OpenFOAM case directory");
35 setCaseDir(getFileName());
38 EG_VTKSP(vtkUnstructuredGrid
, ug
);
42 readFile("constant/polyMesh/faces");
43 QTextStream
f(getBuffer());
48 int num_triangles
= 0;
50 readFile("constant/polyMesh/faces");
51 QTextStream
f(getBuffer());
53 for (int i
= 0; i
< num_faces
; ++i
) {
56 QVector
<vtkIdType
> pts(N_pts
);
57 for (int j
= 0; j
< N_pts
; ++j
) {
60 if (i
>= getFirstBoundaryFace()) {
64 num_triangles
+= (N_pts
- 2);
69 allocateGrid(ug
, num_triangles
, numSurfNodes());
70 EG_VTKDCC(vtkIntArray
, bc
, ug
, "cell_code");
71 EG_VTKDCC(vtkIntArray
, orgdir
, ug
, "cell_orgdir");
72 EG_VTKDCC(vtkIntArray
, voldir
, ug
, "cell_voldir");
73 EG_VTKDCC(vtkIntArray
, curdir
, ug
, "cell_curdir");
74 QVector
<vtkIdType
> face2id(num_faces
, -1);
75 QVector
<int> num_tris(num_faces
, 0);
79 readFile("constant/polyMesh/points");
80 QTextStream
f(getBuffer());
83 for (int i
= 0; i
< num_nodes
; ++i
) {
85 f
>> x
[0] >> x
[1] >> x
[2];
86 if (volToSurf(i
) != -1) {
87 ug
->GetPoints()->SetPoint(volToSurf(i
), x
.data());
92 qWarning() << ug
->GetNumberOfPoints() << " nodes";
93 qWarning() << num_faces
- getFirstBoundaryFace() << " faces";
94 qWarning() << num_triangles
<< " triangles";
95 qWarning() << num_tris
.size();
99 readFile("constant/polyMesh/faces");
100 QTextStream
f(getBuffer());
102 for (int i
= 0; i
< num_faces
; ++i
) {
105 QVector
<vtkIdType
> pts(N_pts
+2);
106 for (int j
= 0; j
< N_pts
; ++j
) {
109 if (i
>= getFirstBoundaryFace()) {
110 for (int j
= 0; j
< N_pts
; ++j
) {
111 pts
[j
] = volToSurf(pts
[j
]);
114 pts
[N_pts
+1] = pts
[1];
115 QVector
<vec3_t
> x(N_pts
+2);
117 for (int j
= 0; j
< N_pts
; ++j
) {
118 ug
->GetPoint(pts
[j
], x
[j
].data());
125 for (int j
= 0; j
< N_pts
; ++j
) {
126 vec3_t u
= x
[j
] - xc
;
127 vec3_t v
= x
[j
+1] - xc
;
133 for (int j
= 1; j
<= N_pts
; ++j
) {
134 vec3_t u
= x
[j
] - x
[j
-1];
135 vec3_t v
= x
[j
+1] - x
[j
];
138 vec3_t nj
= u
.cross(v
);
146 for (int j
= 0; j
< j0
- 1; ++j
) {
150 for (int j
= j0
+ 1; j
< N_pts
; ++j
) {
154 for (int j
= j0
+ 1; j
< N_pts
- 1; ++j
) {
158 foreach (int j
, jn
) {
163 vtkIdType id_cell
= ug
->InsertNextCell(VTK_TRIANGLE
, 3, p
);
164 bc
->SetValue(id_cell
, 999);
165 orgdir
->SetValue(id_cell
, 0);
166 curdir
->SetValue(id_cell
, 0);
167 voldir
->SetValue(id_cell
, 0);
168 if (num_tris
[i
] == 0) {
169 face2id
[i
] = id_cell
;
176 GuiMainWindow::pointer()->clearBCs();
180 readFile("constant/polyMesh/boundary");
181 QTextStream
f(getBuffer());
184 for (int i
= 1; i
<= num_patches
; ++i
) {
185 QString name
, dummy
, type
;
186 f
>> name
>> dummy
>> type
;
187 BoundaryCondition
BC(name
, type
);
188 GuiMainWindow::pointer()->addBC(i
, BC
);
189 vtkIdType num_faces
, start_face
;
190 f
>> dummy
>> num_faces
;
191 f
>> dummy
>> start_face
;
192 for (vtkIdType i_face
= start_face
; i_face
< start_face
+ num_faces
; ++i_face
) {
193 if (face2id
[i_face
] < 0) {
197 N2
+= num_tris
[i_face
];
198 for (int j
= 0; j
< num_tris
[i_face
]; ++j
) {
199 vtkIdType id_cell
= face2id
[i_face
] + j
;
200 bc
->SetValue(id_cell
, i
);
203 qWarning() << i
<< ',' << N1
<< ',' << N2
;
206 makeCopy(ug
, m_Grid
);
207 createBasicFields(m_Grid
, m_Grid
->GetNumberOfCells(), m_Grid
->GetNumberOfPoints());
208 UpdateCellIndex(m_Grid
);
210 } catch (Error err
) {