Loading...
Searching...
No Matches
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-2023 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 (3 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 labelUList& patchFaceCells = boundaryMesh()[patchi].faceCells();
165
166 // The face group will be offset by 10 from the patch label
167
168 // Write header
169 fluentMeshFile
170 << "(13 (" << patchi + 10 << " " << nWrittenFaces + 1
171 << " " << nWrittenFaces + patchFaces.size() << " ";
172
173 nWrittenFaces += patchFaces.size();
174
175 // Write patch type
176 if (isA<wallFvPatch>(boundary()[patchi]))
177 {
178 fluentMeshFile << 3;
179 }
180 else if
181 (
183 || isA<symmetryFvPatch>(boundary()[patchi])
184 )
185 {
186 fluentMeshFile << 7;
187 }
188 else
189 {
190 fluentMeshFile << 4;
191 }
192
193 fluentMeshFile
194 <<" 0)" << std::endl << "(" << std::endl;
195
196 forAll(patchFaces, facei)
197 {
198 const labelList& l = patchFaces[facei];
199
200 fluentMeshFile << " ";
201
202 fluentMeshFile << l.size() << " ";
203
204 // Note: In Fluent, all boundary faces point inwards, which is
205 // opposite from the OpenFOAM convention.
206 // Turn them around on printout
207 forAllReverse(l, lI)
208 {
209 fluentMeshFile << l[lI] + 1 << " ";
210 }
211
212 fluentMeshFile << patchFaceCells[facei] + 1 << " 0" << std::endl;
213 }
214
215 fluentMeshFile << "))" << std::endl;
216 }
217
218 // Writing cells
219 fluentMeshFile
220 << "(12 (1 1 " << nCells() << " 1 0)" << nl
221 << '(';
222
223 const cellModel& hex = cellModel::ref(cellModel::HEX);
224 const cellModel& prism = cellModel::ref(cellModel::PRISM);
225 const cellModel& pyr = cellModel::ref(cellModel::PYR);
226 const cellModel& tet = cellModel::ref(cellModel::TET);
227
228 const cellShapeList& cells = cellShapes();
229
230 label nPolys = 0;
231
232 int nElemPerLine = 25; // Start with linebreak and indent
233
234 forAll(cells, celli)
235 {
236 if (nElemPerLine == 25)
237 {
238 // 25 elements per line with initial indent (readability)
239 fluentMeshFile << "\n ";
240 nElemPerLine = 0;
241 }
242 else if (!(nElemPerLine % 5))
243 {
244 // Format in blocks of 5 (readability)
245 fluentMeshFile << token::SPACE;
246 }
247 fluentMeshFile << token::SPACE;
248 ++nElemPerLine;
249
250
251 if (cells[celli].model() == tet)
252 {
253 fluentMeshFile << 2;
254 }
255 else if (cells[celli].model() == hex)
256 {
257 fluentMeshFile << 4;
258 }
259 else if (cells[celli].model() == pyr)
260 {
261 fluentMeshFile << 5;
262 }
263 else if (cells[celli].model() == prism)
264 {
265 fluentMeshFile << 6;
266 }
267 else
268 {
269 fluentMeshFile << 7;
270 ++nPolys;
271 }
272 }
273
274 fluentMeshFile
275 << nl << "))" << nl;
276
277
278 if (nPolys)
279 {
280 Info<< "Mesh had " << nPolys << " polyhedrals." << endl;
281 }
282
283
284 // Return to dec
285 fluentMeshFile.setf(ios::dec, ios::basefield);
286
287 // Writing patch types
288 fluentMeshFile << "(39 (1 fluid fluid-1)())" << std::endl;
289 fluentMeshFile << "(39 (2 interior interior-1)())" << std::endl;
290
291 // Writing boundary patch types
292 forAll(boundary(), patchi)
293 {
294 fluentMeshFile
295 << "(39 (" << patchi + 10 << " ";
296
297 // Write patch type
298 if (isA<wallFvPatch>(boundary()[patchi]))
299 {
300 fluentMeshFile << "wall ";
301 }
302 else if
303 (
305 || isA<symmetryFvPatch>(boundary()[patchi])
306 )
307 {
308 fluentMeshFile << "symmetry ";
309 }
310 else
311 {
312 fluentMeshFile << "pressure-outlet ";
313 }
314
315 fluentMeshFile
316 << boundary()[patchi].name() << ")())" << std::endl;
317 }
318}
319
320
321// ************************************************************************* //
const fileName & rootPath() const noexcept
Return the Time::rootPath().
Definition IOobject.C:462
const fileName & caseName() const noexcept
Return the Time::caseName().
Definition IOobject.C:468
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
static const cellModel & ref(const modelType model)
Look up reference to cellModel by enumeration. Fatal on failure.
Definition cellModels.C:150
fluentFvMesh(const IOobject &io)
Construct from IOobject.
void writeFluentMesh() const
Write Fluent mesh.
const Time & time() const
Return the top-level database.
Definition fvMesh.H:360
const labelUList & owner() const
Internal face owner. Note bypassing virtual mechanism so.
Definition fvMesh.H:572
const labelUList & neighbour() const
Internal face neighbour.
Definition fvMesh.H:580
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
Definition fvMesh.H:395
UPtrList< const labelUList > faceCells() const
Return a list of faceCells for each patch.
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition polyMesh.H:609
virtual const faceList & faces() const
Return raw faces.
Definition polyMesh.C:1088
virtual const pointField & points() const
Return raw points.
Definition polyMesh.C:1063
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:144
volScalarField & p
const auto & io
List< label > labelList
A List of labels.
Definition List.H:62
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Definition POSIX.C:616
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< face > faceList
List of faces.
Definition faceListFwd.H:41
IOstream & hex(IOstream &io)
Definition IOstream.H:579
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
Definition typeInfo.H:87
vectorField pointField
pointField is a vectorField.
UList< label > labelUList
A UList of labels.
Definition UList.H:75
List< cellShape > cellShapeList
List of cellShape.
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
UList< face > faceUList
UList of faces.
Definition faceListFwd.H:43
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition stdFoam.H:315