2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008,2009 Oliver Gloth +
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 "foamwriter.h"
27 FoamWriter::FoamWriter()
29 setFormat("Foam boundary files(boundary)");
33 void FoamWriter::writePoints(const PolyMesh
&poly
)
35 QString filename
= QFileInfo(getFileName()).absolutePath() + "/constant/polyMesh/points";
37 file
.open(QIODevice::WriteOnly
);
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";
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";
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";
62 f
<< "// ************************************************************************* //\n\n\n";
65 void FoamWriter::writeFaces(const PolyMesh
&poly
)
67 QString filename
= QFileInfo(getFileName()).absolutePath() + "/constant/polyMesh/faces";
69 file
.open(QIODevice::WriteOnly
);
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";
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";
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) {
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";
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";
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";
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";
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";
154 f
<< "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
156 for (int i
= 0; i
< poly
.numFaces(); ++i
) {
157 if (poly
.boundaryCode(i
) != 0) break;
161 for (int i
= 0; i
< N
; ++i
) {
162 f
<< poly
.neighbour(i
) << "\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";
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";
189 f
<< "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
190 f
<< poly
.numCells() << "\n(\n";
191 for (int i
= 0; i
< poly
.numCells(); ++i
) {
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";
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";
219 f
<< "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
220 f
<< poly
.numFaces() << "\n(\n";
221 for (int i
= 0; i
< poly
.numFaces(); ++i
) {
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";
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";
249 f
<< "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
251 for (int i
= 0; i
< poly
.numFaces(); ++i
) {
252 if (poly
.boundaryCode(i
) != 0) break;
255 f
<< poly
.numBCs() << "\n(\n";
257 while (i
< poly
.numFaces()) {
258 int bc
= poly
.boundaryCode(i
);
261 bool loop
= (poly
.boundaryCode(i
) == bc
);
265 loop
= (i
< poly
.numFaces());
266 if (loop
) loop
= (poly
.boundaryCode(i
) == bc
);
268 f
<< " BC" << bc
<< "\n";
270 f
<< " type patch;\n";
271 f
<< " nFaces " << nFaces
<< ";\n";
272 f
<< " startFace " << startFace
<< ";\n";
276 f
<< "// ************************************************************************* //\n\n\n";
279 void FoamWriter::operate()
282 readOutputDirectory();
288 writeNeighbour(poly
);
290 writeAllCellsSet(poly
);
291 writeAllFacesSet(poly
);
293 } catch (Error err
) {