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"
28 FoamWriter::FoamWriter()
31 setFormat("Foam boundary files(boundary)");
35 void FoamWriter::writePoints(const PolyMesh
&poly
)
37 QString filename
= path
+ "points";
39 file
.open(QIODevice::WriteOnly
);
41 f
<< "/*--------------------------------*- C++ -*----------------------------------*\\\n";
42 f
<< "| ========= | |\n";
43 f
<< "| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |\n";
44 f
<< "| \\ / O peration | Version: 1.5 |\n";
45 f
<< "| \\ / A nd | Web: http://www.OpenFOAM.org |\n";
46 f
<< "| \\/ M anipulation | |\n";
47 f
<< "\\*---------------------------------------------------------------------------*/\n\n";
50 f
<< " version 2.0;\n";
51 f
<< " format ascii;\n";
52 f
<< " class vectorField;\n";
53 f
<< " location \"constant/polyMesh\";\n";
54 f
<< " object points;\n";
56 f
<< "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
57 f
<< poly
.totalNumNodes() << "\n(\n";
58 for (int i
= 0; i
< poly
.totalNumNodes(); ++i
) {
59 vec3_t x
= poly
.nodeVector(i
);
60 f
.setRealNumberPrecision(16);
61 f
<< "(" << x
[0] << " " << x
[1] << " " << x
[2] << ")\n";
64 f
<< "// ************************************************************************* //\n\n\n";
67 void FoamWriter::writeFaces(const PolyMesh
&poly
)
69 QString filename
= path
+ "faces";
71 file
.open(QIODevice::WriteOnly
);
73 f
<< "/*--------------------------------*- C++ -*----------------------------------*\\\n";
74 f
<< "| ========= | |\n";
75 f
<< "| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |\n";
76 f
<< "| \\ / O peration | Version: 1.5 |\n";
77 f
<< "| \\ / A nd | Web: http://www.OpenFOAM.org |\n";
78 f
<< "| \\/ M anipulation | |\n";
79 f
<< "\\*---------------------------------------------------------------------------*/\n\n";
82 f
<< " version 2.0;\n";
83 f
<< " format ascii;\n";
84 f
<< " class faceList;\n";
85 f
<< " location \"constant/polyMesh\";\n";
86 f
<< " object faces;\n";
88 f
<< "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
89 f
<< poly
.numFaces() << "\n(\n";
90 for (int i
= 0; i
< poly
.numFaces(); ++i
) {
91 f
<< poly
.numNodes(i
) << "(";
92 for (int j
= 0; j
< poly
.numNodes(i
); ++j
) {
93 f
<< poly
.nodeIndex(i
,j
);
94 if (j
== poly
.numNodes(i
) - 1) {
102 f
<< "// ************************************************************************* //\n\n\n";
105 void FoamWriter::writeOwner(const PolyMesh
&poly
)
107 QString filename
= path
+ "owner";
108 QFile
file(filename
);
109 file
.open(QIODevice::WriteOnly
);
110 QTextStream
f(&file
);
111 f
<< "/*--------------------------------*- C++ -*----------------------------------*\\\n";
112 f
<< "| ========= | |\n";
113 f
<< "| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |\n";
114 f
<< "| \\ / O peration | Version: 1.5 |\n";
115 f
<< "| \\ / A nd | Web: http://www.OpenFOAM.org |\n";
116 f
<< "| \\/ M anipulation | |\n";
117 f
<< "\\*---------------------------------------------------------------------------*/\n\n";
120 f
<< " version 2.0;\n";
121 f
<< " format ascii;\n";
122 f
<< " class labelList;\n";
123 f
<< " location \"constant/polyMesh\";\n";
124 f
<< " object owner;\n";
126 f
<< "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
127 f
<< poly
.numFaces() << "\n(\n";
128 for (int i
= 0; i
< poly
.numFaces(); ++i
) {
129 f
<< poly
.owner(i
) << "\n";
132 f
<< "// ************************************************************************* //\n\n\n";
135 void FoamWriter::writeNeighbour(const PolyMesh
&poly
)
137 QString filename
= path
+ "neighbour";
138 QFile
file(filename
);
139 file
.open(QIODevice::WriteOnly
);
140 QTextStream
f(&file
);
141 f
<< "/*--------------------------------*- C++ -*----------------------------------*\\\n";
142 f
<< "| ========= | |\n";
143 f
<< "| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |\n";
144 f
<< "| \\ / O peration | Version: 1.5 |\n";
145 f
<< "| \\ / A nd | Web: http://www.OpenFOAM.org |\n";
146 f
<< "| \\/ M anipulation | |\n";
147 f
<< "\\*---------------------------------------------------------------------------*/\n\n";
150 f
<< " version 2.0;\n";
151 f
<< " format ascii;\n";
152 f
<< " class labelList;\n";
153 f
<< " location \"constant/polyMesh\";\n";
154 f
<< " object neighbour;\n";
156 f
<< "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
158 for (int i
= 0; i
< poly
.numFaces(); ++i
) {
159 if (poly
.boundaryCode(i
) != 0) break;
163 for (int i
= 0; i
< N
; ++i
) {
164 f
<< poly
.neighbour(i
) << "\n";
167 f
<< "// ************************************************************************* //\n\n\n";
170 void FoamWriter::writeBoundary(const PolyMesh
&poly
)
172 QString filename
= path
+ "boundary";
173 QFile
file(filename
);
174 file
.open(QIODevice::WriteOnly
);
175 QTextStream
f(&file
);
176 f
<< "/*--------------------------------*- C++ -*----------------------------------*\\\n";
177 f
<< "| ========= | |\n";
178 f
<< "| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |\n";
179 f
<< "| \\ / O peration | Version: 1.5 |\n";
180 f
<< "| \\ / A nd | Web: http://www.OpenFOAM.org |\n";
181 f
<< "| \\/ M anipulation | |\n";
182 f
<< "\\*---------------------------------------------------------------------------*/\n\n";
185 f
<< " version 2.0;\n";
186 f
<< " format ascii;\n";
187 f
<< " class polyBoundaryMesh;\n";
188 f
<< " location \"constant/polyMesh\";\n";
189 f
<< " object boundary;\n";
191 f
<< "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
193 for (int i
= 0; i
< poly
.numFaces(); ++i
) {
194 if (poly
.boundaryCode(i
) != 0) break;
197 f
<< poly
.numBCs() << "\n(\n";
199 while (i
< poly
.numFaces()) {
200 int bc
= poly
.boundaryCode(i
);
201 BoundaryCondition BC
= getBC(bc
);
204 bool loop
= (poly
.boundaryCode(i
) == bc
);
208 loop
= (i
< poly
.numFaces());
209 if (loop
) loop
= (poly
.boundaryCode(i
) == bc
);
211 f
<< " " << BC
.getName() << "\n";
213 f
<< " type " << BC
.getType() << ";\n";
214 f
<< " nFaces " << nFaces
<< ";\n";
215 f
<< " startFace " << startFace
<< ";\n";
219 f
<< "// ************************************************************************* //\n\n\n";
222 void FoamWriter::operate()
225 readOutputDirectory();
227 QString p1
= getFileName();
228 QString p2
= p1
+ "/constant";
235 d1
.mkdir("constant");
240 p2
= p1
+ "/polyMesh";
243 d1
.mkdir("polyMesh");
245 path
= getFileName() + "/constant/polyMesh/";
246 if (!QDir(path
).exists()) {
253 writeNeighbour(poly
);
256 } catch (Error err
) {