DeleteSetOfPoints function working
[engrid.git] / foamwriter.cpp
blob1438ba8ce83fbd84f0971d5b9964addf9da3d9ba
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008,2009 Oliver Gloth +
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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "foamwriter.h"
25 #include <QFileInfo>
27 FoamWriter::FoamWriter()
29 setFormat("Foam boundary files(boundary)");
30 setExtension("");
33 void FoamWriter::writePoints(const PolyMesh &poly)
35 QString filename = QFileInfo(getFileName()).absolutePath() + "/constant/polyMesh/points";
36 QFile file(filename);
37 file.open(QIODevice::WriteOnly);
38 QTextStream f(&file);
39 f << "/*--------------------------------*- C++ -*----------------------------------*\\\n";
40 f << "| ========= | |\n";
41 f << "| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |\n";
42 f << "| \\ / O peration | Version: 1.5 |\n";
43 f << "| \\ / A nd | Web: http://www.OpenFOAM.org |\n";
44 f << "| \\/ M anipulation | |\n";
45 f << "\\*---------------------------------------------------------------------------*/\n\n";
46 f << "FoamFile\n";
47 f << "{\n";
48 f << " version 2.0;\n";
49 f << " format ascii;\n";
50 f << " class vectorField;\n";
51 f << " location \"constant/polyMesh\";\n";
52 f << " object points;\n";
53 f << "}\n\n";
54 f << "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
55 f << poly.totalNumNodes() << "\n(\n";
56 for (int i = 0; i < poly.totalNumNodes(); ++i) {
57 vec3_t x = poly.nodeVector(i);
58 f.setRealNumberPrecision(16);
59 f << "(" << x[0] << " " << x[1] << " " << x[2] << ")\n";
61 f << ")\n\n";
62 f << "// ************************************************************************* //\n\n\n";
65 void FoamWriter::writeFaces(const PolyMesh &poly)
67 QString filename = QFileInfo(getFileName()).absolutePath() + "/constant/polyMesh/faces";
68 QFile file(filename);
69 file.open(QIODevice::WriteOnly);
70 QTextStream f(&file);
71 f << "/*--------------------------------*- C++ -*----------------------------------*\\\n";
72 f << "| ========= | |\n";
73 f << "| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |\n";
74 f << "| \\ / O peration | Version: 1.5 |\n";
75 f << "| \\ / A nd | Web: http://www.OpenFOAM.org |\n";
76 f << "| \\/ M anipulation | |\n";
77 f << "\\*---------------------------------------------------------------------------*/\n\n";
78 f << "FoamFile\n";
79 f << "{\n";
80 f << " version 2.0;\n";
81 f << " format ascii;\n";
82 f << " class faceList;\n";
83 f << " location \"constant/polyMesh\";\n";
84 f << " object faces;\n";
85 f << "}\n\n";
86 f << "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
87 f << poly.numFaces() << "\n(\n";
88 for (int i = 0; i < poly.numFaces(); ++i) {
89 f << poly.numNodes(i) << "(";
90 for (int j = 0; j < poly.numNodes(i); ++j) {
91 f << poly.nodeIndex(i,j);
92 if (j == poly.numNodes(i) - 1) {
93 f << ")\n";
94 } else {
95 f << " ";
99 f << ")\n\n";
100 f << "// ************************************************************************* //\n\n\n";
103 void FoamWriter::writeOwner(const PolyMesh &poly)
105 QString filename = QFileInfo(getFileName()).absolutePath() + "/constant/polyMesh/owner";
106 QFile file(filename);
107 file.open(QIODevice::WriteOnly);
108 QTextStream f(&file);
109 f << "/*--------------------------------*- C++ -*----------------------------------*\\\n";
110 f << "| ========= | |\n";
111 f << "| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |\n";
112 f << "| \\ / O peration | Version: 1.5 |\n";
113 f << "| \\ / A nd | Web: http://www.OpenFOAM.org |\n";
114 f << "| \\/ M anipulation | |\n";
115 f << "\\*---------------------------------------------------------------------------*/\n\n";
116 f << "FoamFile\n";
117 f << "{\n";
118 f << " version 2.0;\n";
119 f << " format ascii;\n";
120 f << " class labelList;\n";
121 f << " location \"constant/polyMesh\";\n";
122 f << " object owner;\n";
123 f << "}\n\n";
124 f << "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
125 f << poly.numFaces() << "\n(\n";
126 for (int i = 0; i < poly.numFaces(); ++i) {
127 f << poly.owner(i) << "\n";
129 f << ")\n\n";
130 f << "// ************************************************************************* //\n\n\n";
133 void FoamWriter::writeNeighbour(const PolyMesh &poly)
135 QString filename = QFileInfo(getFileName()).absolutePath() + "/constant/polyMesh/neighbour";
136 QFile file(filename);
137 file.open(QIODevice::WriteOnly);
138 QTextStream f(&file);
139 f << "/*--------------------------------*- C++ -*----------------------------------*\\\n";
140 f << "| ========= | |\n";
141 f << "| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |\n";
142 f << "| \\ / O peration | Version: 1.5 |\n";
143 f << "| \\ / A nd | Web: http://www.OpenFOAM.org |\n";
144 f << "| \\/ M anipulation | |\n";
145 f << "\\*---------------------------------------------------------------------------*/\n\n";
146 f << "FoamFile\n";
147 f << "{\n";
148 f << " version 2.0;\n";
149 f << " format ascii;\n";
150 f << " class labelList;\n";
151 f << " location \"constant/polyMesh\";\n";
152 f << " object neighbour;\n";
153 f << "}\n\n";
154 f << "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
155 int N = 0;
156 for (int i = 0; i < poly.numFaces(); ++i) {
157 if (poly.boundaryCode(i) != 0) break;
158 ++N;
160 f << N << "\n(\n";
161 for (int i = 0; i < N; ++i) {
162 f << poly.neighbour(i) << "\n";
164 f << ")\n\n";
165 f << "// ************************************************************************* //\n\n\n";
168 void FoamWriter::writeAllCellsSet(const PolyMesh &poly)
170 QString filename = QFileInfo(getFileName()).absolutePath() + "/constant/polyMesh/sets/allCells";
171 QFile file(filename);
172 file.open(QIODevice::WriteOnly);
173 QTextStream f(&file);
174 f << "/*--------------------------------*- C++ -*----------------------------------*\\\n";
175 f << "| ========= | |\n";
176 f << "| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |\n";
177 f << "| \\ / O peration | Version: 1.5 |\n";
178 f << "| \\ / A nd | Web: http://www.OpenFOAM.org |\n";
179 f << "| \\/ M anipulation | |\n";
180 f << "\\*---------------------------------------------------------------------------*/\n\n";
181 f << "FoamFile\n";
182 f << "{\n";
183 f << " version 2.0;\n";
184 f << " format ascii;\n";
185 f << " class cellSet;\n";
186 f << " location \"constant/polyMesh/sets\";\n";
187 f << " object allCells;\n";
188 f << "}\n\n";
189 f << "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
190 f << poly.numCells() << "\n(\n";
191 for (int i = 0; i < poly.numCells(); ++i) {
192 f << i << "\n";
194 f << ")\n\n";
195 f << "// ************************************************************************* //\n\n\n";
198 void FoamWriter::writeAllFacesSet(const PolyMesh &poly)
200 QString filename = QFileInfo(getFileName()).absolutePath() + "/constant/polyMesh/sets/allFaces";
201 QFile file(filename);
202 file.open(QIODevice::WriteOnly);
203 QTextStream f(&file);
204 f << "/*--------------------------------*- C++ -*----------------------------------*\\\n";
205 f << "| ========= | |\n";
206 f << "| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |\n";
207 f << "| \\ / O peration | Version: 1.5 |\n";
208 f << "| \\ / A nd | Web: http://www.OpenFOAM.org |\n";
209 f << "| \\/ M anipulation | |\n";
210 f << "\\*---------------------------------------------------------------------------*/\n\n";
211 f << "FoamFile\n";
212 f << "{\n";
213 f << " version 2.0;\n";
214 f << " format ascii;\n";
215 f << " class faceSet;\n";
216 f << " location \"constant/polyMesh/sets\";\n";
217 f << " object allFaces;\n";
218 f << "}\n\n";
219 f << "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
220 f << poly.numFaces() << "\n(\n";
221 for (int i = 0; i < poly.numFaces(); ++i) {
222 f << i << "\n";
224 f << ")\n\n";
225 f << "// ************************************************************************* //\n\n\n";
228 void FoamWriter::writeBoundary(const PolyMesh &poly)
230 QString filename = QFileInfo(getFileName()).absolutePath() + "/constant/polyMesh/boundary";
231 QFile file(filename);
232 file.open(QIODevice::WriteOnly);
233 QTextStream f(&file);
234 f << "/*--------------------------------*- C++ -*----------------------------------*\\\n";
235 f << "| ========= | |\n";
236 f << "| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |\n";
237 f << "| \\ / O peration | Version: 1.5 |\n";
238 f << "| \\ / A nd | Web: http://www.OpenFOAM.org |\n";
239 f << "| \\/ M anipulation | |\n";
240 f << "\\*---------------------------------------------------------------------------*/\n\n";
241 f << "FoamFile\n";
242 f << "{\n";
243 f << " version 2.0;\n";
244 f << " format ascii;\n";
245 f << " class polyBoundaryMesh;\n";
246 f << " location \"constant/polyMesh\";\n";
247 f << " object boundary;\n";
248 f << "}\n\n";
249 f << "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
250 int N = 0;
251 for (int i = 0; i < poly.numFaces(); ++i) {
252 if (poly.boundaryCode(i) != 0) break;
253 ++N;
255 f << poly.numBCs() << "\n(\n";
256 int i = N;
257 while (i < poly.numFaces()) {
258 int bc = poly.boundaryCode(i);
259 int nFaces = 0;
260 int startFace = i;
261 bool loop = (poly.boundaryCode(i) == bc);
262 while (loop) {
263 ++nFaces;
264 ++i;
265 loop = (i < poly.numFaces());
266 if (loop) loop = (poly.boundaryCode(i) == bc);
268 f << " BC" << bc << "\n";
269 f << " {\n";
270 f << " type patch;\n";
271 f << " nFaces " << nFaces << ";\n";
272 f << " startFace " << startFace << ";\n";
273 f << " }\n";
275 f << ")\n\n";
276 f << "// ************************************************************************* //\n\n\n";
279 void FoamWriter::operate()
281 try {
282 readOutputDirectory();
283 if (isValid()) {
284 PolyMesh poly(grid);
285 writePoints(poly);
286 writeFaces(poly);
287 writeOwner(poly);
288 writeNeighbour(poly);
289 writeBoundary(poly);
290 writeAllCellsSet(poly);
291 writeAllFacesSet(poly);
293 } catch (Error err) {
294 err.display();