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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include <fstream>
29 #include <iostream>
30 
31 using std::ios;
32 
33 #include "Time.H"
34 #include "fluentFvMesh.H"
35 #include "primitiveMesh.H"
36 #include "wallFvPatch.H"
37 #include "symmetryPlaneFvPatch.H"
38 #include "symmetryFvPatch.H"
39 #include "cellModel.H"
40 
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 
43 Foam::fluentFvMesh::fluentFvMesh(const IOobject& io)
44 :
45  fvMesh(io)
46 {}
47 
48 
49 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
50 
52 {
53  // Make a directory called fluentInterface in the case
54  mkDir(time().rootPath()/time().caseName()/"fluentInterface");
55 
56  // Open a file for the mesh
57  std::ofstream fluentMeshFile
58  (
59  time().rootPath()
60  / time().caseName()
61  / "fluentInterface"
62  / time().caseName() + ".msh"
63  );
64 
65  Info<< "Writing Header" << endl;
66 
67  fluentMeshFile
68  << "(0 \"FOAM to Fluent Mesh File\")" << std::endl << std::endl
69  << "(0 \"Dimension:\")" << std::endl
70  << "(2 3)" << std::endl << std::endl
71  << "(0 \"Grid dimensions:\")" << std::endl;
72 
73  // Writing number of points
74  fluentMeshFile
75  << "(10 (0 1 ";
76 
77  // Writing hex
78  fluentMeshFile.setf(ios::hex, ios::basefield);
79 
80  fluentMeshFile
81  << nPoints() << " 0 3))" << std::endl;
82 
83  // Writing number of cells
84  fluentMeshFile
85  << "(12 (0 1 "
86  << nCells() << " 0 0))" << std::endl;
87 
88  // Writing number of faces
89  label nFcs = nFaces();
90 
91  fluentMeshFile
92  << "(13 (0 1 ";
93 
94  // Still writing hex
95  fluentMeshFile
96  << nFcs << " 0 0))" << std::endl << std::endl;
97 
98  // Return to dec
99  fluentMeshFile.setf(ios::dec, ios::basefield);
100 
101  // Writing points
102  fluentMeshFile
103  << "(10 (1 1 ";
104 
105  fluentMeshFile.setf(ios::hex, ios::basefield);
106  fluentMeshFile
107  << nPoints() << " 1 3)"
108  << std::endl << "(" << std::endl;
109 
110  fluentMeshFile.precision(10);
111  fluentMeshFile.setf(ios::scientific);
112 
113  const pointField& p = points();
114 
115  forAll(p, pointi)
116  {
117  fluentMeshFile
118  << " "
119  << p[pointi].x() << " "
120  << p[pointi].y()
121  << " " << p[pointi].z() << std::endl;
122  }
123 
124  fluentMeshFile
125  << "))" << std::endl << std::endl;
126 
127  const labelUList& own = owner();
128  const labelUList& nei = neighbour();
129 
130  const faceList& fcs = faces();
131 
132  // Writing (mixed) internal faces
133  fluentMeshFile
134  << "(13 (2 1 "
135  << own.size() << " 2 0)" << std::endl << "(" << std::endl;
136 
137  forAll(own, facei)
138  {
139  const labelList& l = fcs[facei];
140 
141  fluentMeshFile << " ";
142 
143  fluentMeshFile << l.size() << " ";
144 
145  forAll(l, lI)
146  {
147  fluentMeshFile << l[lI] + 1 << " ";
148  }
149 
150  fluentMeshFile << nei[facei] + 1 << " ";
151  fluentMeshFile << own[facei] + 1 << std::endl;
152  }
153 
154  fluentMeshFile << "))" << std::endl;
155 
156  label nWrittenFaces = own.size();
157 
158  // Writing boundary faces
159  forAll(boundary(), patchi)
160  {
161  const faceUList& patchFaces = boundaryMesh()[patchi];
162 
163  const labelList& patchFaceCells =
164  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  (
182  isA<symmetryPlaneFvPatch>(boundary()[patchi])
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 "
221  << nCells() << " 1 0)(" << std::endl;
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  bool hasWarned = false;
231 
232  forAll(cells, celli)
233  {
234  if (cells[celli].model() == tet)
235  {
236  fluentMeshFile << " " << 2;
237  }
238  else if (cells[celli].model() == hex)
239  {
240  fluentMeshFile << " " << 4;
241  }
242  else if (cells[celli].model() == pyr)
243  {
244  fluentMeshFile << " " << 5;
245  }
246  else if (cells[celli].model() == prism)
247  {
248  fluentMeshFile << " " << 6;
249  }
250  else
251  {
252  if (!hasWarned)
253  {
254  hasWarned = true;
255 
257  << "foamMeshToFluent: cell shape for cell "
258  << celli << " only supported by Fluent polyhedral meshes."
259  << nl
260  << " Suppressing any further messages for polyhedral"
261  << " cells." << endl;
262  }
263  fluentMeshFile << " " << 7;
264  }
265  }
266 
267  fluentMeshFile << ")())" << std::endl;
268 
269  // Return to dec
270  fluentMeshFile.setf(ios::dec, ios::basefield);
271 
272  // Writing patch types
273  fluentMeshFile << "(39 (1 fluid fluid-1)())" << std::endl;
274  fluentMeshFile << "(39 (2 interior interior-1)())" << std::endl;
275 
276  // Writing boundary patch types
277  forAll(boundary(), patchi)
278  {
279  fluentMeshFile
280  << "(39 (" << patchi + 10 << " ";
281 
282  // Write patch type
283  if (isA<wallFvPatch>(boundary()[patchi]))
284  {
285  fluentMeshFile << "wall ";
286  }
287  else if
288  (
289  isA<symmetryPlaneFvPatch>(boundary()[patchi])
290  || isA<symmetryFvPatch>(boundary()[patchi])
291  )
292  {
293  fluentMeshFile << "symmetry ";
294  }
295  else
296  {
297  fluentMeshFile << "pressure-outlet ";
298  }
299 
300  fluentMeshFile
301  << boundary()[patchi].name() << ")())" << std::endl;
302  }
303 }
304 
305 
306 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
hex
const cellModel & hex
Definition: createBlockMesh.H:1
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
fluentFvMesh.H
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::cellModel::HEX
hex
Definition: cellModel.H:81
Foam::cellShapeList
List< cellShape > cellShapeList
List of cellShapes and PtrList of List of cellShape.
Definition: cellShapeList.H:45
wallFvPatch.H
primitiveMesh.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::fluentFvMesh::fluentFvMesh
fluentFvMesh(const IOobject &io)
Construct from IOobject.
symmetryPlaneFvPatch.H
Foam::cellModel::TET
tet
Definition: cellModel.H:85
Foam::Ostream::precision
virtual int precision() const =0
Get precision of output field.
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
cellModel.H
Foam::dec
IOstream & dec(IOstream &io)
Definition: IOstream.H:431
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::cellModel::PRISM
prism
Definition: cellModel.H:83
Foam::cellModel::ref
static const cellModel & ref(const modelType model)
Look up reference to cellModel by enumeration. Fatal on failure.
Definition: cellModels.C:157
symmetryFvPatch.H
Foam::scientific
IOstream & scientific(IOstream &io)
Definition: IOstream.H:455
Foam::hex
IOstream & hex(IOstream &io)
Definition: IOstream.H:437
Foam::IOstream::setf
ios_base::fmtflags setf(const ios_base::fmtflags f)
Set flags of stream.
Definition: IOstream.H:369
Time.H
Foam::cellModel::PYR
pyr
Definition: cellModel.H:84
Foam::faceUList
UList< face > faceUList
A UList of faces.
Definition: faceListFwd.H:44
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::faceList
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
points
const pointField & points
Definition: gmvOutputHeader.H:1
forAllReverse
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: stdFoam.H:309
cellShapes
cellShapeList cellShapes
Definition: createBlockMesh.H:3
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:80
Foam::mkDir
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:507
Foam::fluentFvMesh::writeFluentMesh
void writeFluentMesh() const
Write Fluent mesh.
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:298
boundary
faceListList boundary
Definition: createBlockMesh.H:4