fluentFvMesh.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include <fstream>
30#include <iostream>
31
32using std::ios;
33
34#include "Time.H"
35#include "fluentFvMesh.H"
36#include "primitiveMesh.H"
37#include "wallFvPatch.H"
39#include "symmetryFvPatch.H"
40#include "cellModel.H"
41
42// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43
45:
46 fvMesh(io)
47{}
48
49
50// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
51
53{
54 // Make a directory called fluentInterface in the case
55 mkDir(time().rootPath()/time().caseName()/"fluentInterface");
56
57 // Open a file for the mesh
58 std::ofstream fluentMeshFile
59 (
60 time().rootPath()
61 / time().caseName()
62 / "fluentInterface"
63 / time().caseName() + ".msh"
64 );
65
66 Info<< "Writing Fluent Mesh" << endl;
67
68 fluentMeshFile
69 << "(0 \"OpenFOAM to Fluent Mesh File\")" << nl << nl
70 << "(0 \"Dimension:\")" << nl
71 << "(2 3)" << nl << nl
72 << "(0 \"Grid dimensions:\")" << nl;
73
74 // Writing number of points
75 fluentMeshFile
76 << "(10 (0 1 ";
77
78 // Writing hex
79 fluentMeshFile.setf(ios::hex, ios::basefield);
80
81 fluentMeshFile
82 << nPoints() << " 0 3))" << std::endl;
83
84 // Writing number of cells
85 fluentMeshFile
86 << "(12 (0 1 "
87 << nCells() << " 0 0))" << std::endl;
88
89 // Writing number of faces
90 label nFcs = nFaces();
91
92 fluentMeshFile
93 << "(13 (0 1 ";
94
95 // Still writing hex
96 fluentMeshFile
97 << nFcs << " 0 0))" << std::endl << std::endl;
98
99 // Return to dec
100 fluentMeshFile.setf(ios::dec, ios::basefield);
101
102 // Writing points
103 fluentMeshFile
104 << "(10 (1 1 ";
105
106 fluentMeshFile.setf(ios::hex, ios::basefield);
107 fluentMeshFile
108 << nPoints() << " 1 3)"
109 << std::endl << "(" << std::endl;
110
111 fluentMeshFile.precision(10);
112 fluentMeshFile.setf(ios::scientific);
113
114 const pointField& p = points();
115
116 forAll(p, pointi)
117 {
118 fluentMeshFile
119 << " "
120 << p[pointi].x() << " "
121 << p[pointi].y()
122 << " " << p[pointi].z() << std::endl;
123 }
124
125 fluentMeshFile
126 << "))" << std::endl << std::endl;
127
128 const labelUList& own = owner();
129 const labelUList& nei = neighbour();
130
131 const faceList& fcs = faces();
132
133 // Writing (mixed) internal faces
134 fluentMeshFile
135 << "(13 (2 1 "
136 << own.size() << " 2 0)" << std::endl << "(" << std::endl;
137
138 forAll(own, facei)
139 {
140 const labelList& l = fcs[facei];
141
142 fluentMeshFile << " ";
143
144 fluentMeshFile << l.size() << " ";
145
146 forAll(l, lI)
147 {
148 fluentMeshFile << l[lI] + 1 << " ";
149 }
150
151 fluentMeshFile << nei[facei] + 1 << " ";
152 fluentMeshFile << own[facei] + 1 << std::endl;
153 }
154
155 fluentMeshFile << "))" << std::endl;
156
157 label nWrittenFaces = own.size();
158
159 // Writing boundary faces
160 forAll(boundary(), patchi)
161 {
162 const faceUList& patchFaces = boundaryMesh()[patchi];
163
164 const labelList& patchFaceCells =
165 boundaryMesh()[patchi].faceCells();
166
167 // The face group will be offset by 10 from the patch label
168
169 // Write header
170 fluentMeshFile
171 << "(13 (" << patchi + 10 << " " << nWrittenFaces + 1
172 << " " << nWrittenFaces + patchFaces.size() << " ";
173
174 nWrittenFaces += patchFaces.size();
175
176 // Write patch type
177 if (isA<wallFvPatch>(boundary()[patchi]))
178 {
179 fluentMeshFile << 3;
180 }
181 else if
182 (
183 isA<symmetryPlaneFvPatch>(boundary()[patchi])
184 || isA<symmetryFvPatch>(boundary()[patchi])
185 )
186 {
187 fluentMeshFile << 7;
188 }
189 else
190 {
191 fluentMeshFile << 4;
192 }
193
194 fluentMeshFile
195 <<" 0)" << std::endl << "(" << std::endl;
196
197 forAll(patchFaces, facei)
198 {
199 const labelList& l = patchFaces[facei];
200
201 fluentMeshFile << " ";
202
203 fluentMeshFile << l.size() << " ";
204
205 // Note: In Fluent, all boundary faces point inwards, which is
206 // opposite from the OpenFOAM convention.
207 // Turn them around on printout
208 forAllReverse(l, lI)
209 {
210 fluentMeshFile << l[lI] + 1 << " ";
211 }
212
213 fluentMeshFile << patchFaceCells[facei] + 1 << " 0" << std::endl;
214 }
215
216 fluentMeshFile << "))" << std::endl;
217 }
218
219 // Writing cells
220 fluentMeshFile
221 << "(12 (1 1 " << nCells() << " 1 0)" << nl
222 << '(';
223
224 const cellModel& hex = cellModel::ref(cellModel::HEX);
225 const cellModel& prism = cellModel::ref(cellModel::PRISM);
226 const cellModel& pyr = cellModel::ref(cellModel::PYR);
227 const cellModel& tet = cellModel::ref(cellModel::TET);
228
229 const cellShapeList& cells = cellShapes();
230
231 label nPolys = 0;
232
233 int nElemPerLine = 25; // Start with linebreak and indent
234
235 forAll(cells, celli)
236 {
237 if (nElemPerLine == 25)
238 {
239 // 25 elements per line with initial indent (readability)
240 fluentMeshFile << "\n ";
241 nElemPerLine = 0;
242 }
243 else if (!(nElemPerLine % 5))
244 {
245 // Format in blocks of 5 (readability)
246 fluentMeshFile << token::SPACE;
247 }
248 fluentMeshFile << token::SPACE;
249 ++nElemPerLine;
250
251
252 if (cells[celli].model() == tet)
253 {
254 fluentMeshFile << 2;
255 }
256 else if (cells[celli].model() == hex)
257 {
258 fluentMeshFile << 4;
259 }
260 else if (cells[celli].model() == pyr)
261 {
262 fluentMeshFile << 5;
263 }
264 else if (cells[celli].model() == prism)
265 {
266 fluentMeshFile << 6;
267 }
268 else
269 {
270 fluentMeshFile << 7;
271 ++nPolys;
272 }
273 }
274
275 fluentMeshFile
276 << nl << "))" << nl;
277
278
279 if (nPolys)
280 {
281 Info<< "Mesh had " << nPolys << " polyhedrals." << endl;
282 }
283
284
285 // Return to dec
286 fluentMeshFile.setf(ios::dec, ios::basefield);
287
288 // Writing patch types
289 fluentMeshFile << "(39 (1 fluid fluid-1)())" << std::endl;
290 fluentMeshFile << "(39 (2 interior interior-1)())" << std::endl;
291
292 // Writing boundary patch types
293 forAll(boundary(), patchi)
294 {
295 fluentMeshFile
296 << "(39 (" << patchi + 10 << " ";
297
298 // Write patch type
299 if (isA<wallFvPatch>(boundary()[patchi]))
300 {
301 fluentMeshFile << "wall ";
302 }
303 else if
304 (
305 isA<symmetryPlaneFvPatch>(boundary()[patchi])
306 || isA<symmetryFvPatch>(boundary()[patchi])
307 )
308 {
309 fluentMeshFile << "symmetry ";
310 }
311 else
312 {
313 fluentMeshFile << "pressure-outlet ";
314 }
315
316 fluentMeshFile
317 << boundary()[patchi].name() << ")())" << std::endl;
318 }
319}
320
321
322// ************************************************************************* //
const fileName & caseName() const
Return the Time::caseName()
Definition: IOobject.C:518
const fileName & rootPath() const
Return the Time::rootPath()
Definition: IOobject.C:512
ios_base::fmtflags setf(const ios_base::fmtflags f)
Set flags of stream.
Definition: IOstream.H:378
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
@ PRISM
prism
Definition: cellModel.H:83
reference ref() const
A reference to the entry (Error if not found)
Definition: dictionary.H:225
void writeFluentMesh() const
Write Fluent mesh.
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:712
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:290
const labelUList & owner() const
Internal face owner. Note bypassing virtual mechanism so.
Definition: fvMesh.H:417
const labelUList & neighbour() const
Internal face neighbour.
Definition: fvMesh.H:423
UPtrList< const labelUList > faceCells() const
Return a list of faceCells for each patch.
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1108
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:456
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1083
const cellShapeList & cellShapes() const
Return cell shapes.
label nPoints() const noexcept
Number of mesh points.
label nCells() const noexcept
Number of mesh cells.
label nFaces() const noexcept
Number of mesh faces.
const cellList & cells() const
@ SPACE
Space [isspace].
Definition: token.H:125
volScalarField & p
const cellModel & hex
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
List< cellShape > cellShapeList
List of cellShapes and PtrList of List of cellShape.
Definition: cellShapeList.H:45
List< label > labelList
A List of labels.
Definition: List.H:66
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Definition: MSwindows.C:515
messageStream Info
Information stream (stdout output on master, null elsewhere)
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
UList< face > faceUList
A UList of faces.
Definition: faceListFwd.H:46
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
UList< label > labelUList
A UList of labels.
Definition: UList.H:85
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: stdFoam.H:346