1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
33 #include "fluentFvMesh.H"
34 #include "primitiveMesh.H"
35 #include "wallFvPatch.H"
36 #include "symmetryFvPatch.H"
37 #include "cellModeller.H"
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 Foam::fluentFvMesh::fluentFvMesh(const IOobject& io)
47 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
49 void Foam::fluentFvMesh::writeFluentMesh() const
51 // make a directory called proInterface in the case
52 mkDir(time().rootPath()/time().caseName()/"fluentInterface");
54 // open a file for the mesh
55 ofstream fluentMeshFile
61 time().caseName() + ".msh"
65 Info<< "Writing Header" << endl;
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;
73 // Writing number of points
78 fluentMeshFile.setf(ios::hex, ios::basefield);
81 << nPoints() << " 0 3))" << std::endl;
83 // Writing number of cells
86 << nCells() << " 0 0))" << std::endl;
88 // Writing number of faces
89 label nFcs = nFaces();
96 << nFcs << " 0 0))" << std::endl << std::endl;
99 fluentMeshFile.setf(ios::dec, ios::basefield);
105 fluentMeshFile.setf(ios::hex, ios::basefield);
107 << nPoints() << " 1 3)"
108 << std::endl << "(" << std::endl;
110 fluentMeshFile.precision(10);
111 fluentMeshFile.setf(ios::scientific);
113 const pointField& p = points();
119 << p[pointI].x() << " "
121 << " " << p[pointI].z() << std::endl;
125 << "))" << std::endl << std::endl;
127 const labelUList& own = owner();
128 const labelUList& nei = neighbour();
130 const faceList& fcs = faces();
132 // Writing (mixed) internal faces
135 << own.size() << " 2 0)" << std::endl << "(" << std::endl;
139 const labelList& l = fcs[faceI];
141 fluentMeshFile << " ";
143 fluentMeshFile << l.size() << " ";
147 fluentMeshFile << l[lI] + 1 << " ";
150 fluentMeshFile << nei[faceI] + 1 << " ";
151 fluentMeshFile << own[faceI] + 1 << std::endl;
154 fluentMeshFile << "))" << std::endl;
156 label nWrittenFaces = own.size();
158 // Writing boundary faces
159 forAll(boundary(), patchI)
161 const faceUList& patchFaces = boundaryMesh()[patchI];
163 const labelList& patchFaceCells =
164 boundaryMesh()[patchI].faceCells();
166 // The face group will be offset by 10 from the patch label
170 << "(13 (" << patchI + 10 << " " << nWrittenFaces + 1
171 << " " << nWrittenFaces + patchFaces.size() << " ";
173 nWrittenFaces += patchFaces.size();
176 if (isA<wallFvPatch>(boundary()[patchI]))
180 else if (isA<symmetryFvPatch>(boundary()[patchI]))
190 <<" 0)" << std::endl << "(" << std::endl;
192 forAll(patchFaces, faceI)
194 const labelList& l = patchFaces[faceI];
196 fluentMeshFile << " ";
198 fluentMeshFile << l.size() << " ";
200 // Note: In Fluent, all boundary faces point inwards, which is
201 // opposite from the OpenFOAM convention.
202 // Turn them around on printout
203 forAllReverse (l, lI)
205 fluentMeshFile << l[lI] + 1 << " ";
208 fluentMeshFile << patchFaceCells[faceI] + 1 << " 0" << std::endl;
211 fluentMeshFile << "))" << std::endl;
217 << nCells() << " 1 0)(" << std::endl;
219 const cellModel& hex = *(cellModeller::lookup("hex"));
220 const cellModel& prism = *(cellModeller::lookup("prism"));
221 const cellModel& pyr = *(cellModeller::lookup("pyr"));
222 const cellModel& tet = *(cellModeller::lookup("tet"));
224 const cellShapeList& cells = cellShapes();
226 bool hasWarned = false;
230 if (cells[cellI].model() == tet)
232 fluentMeshFile << " " << 2;
234 else if (cells[cellI].model() == hex)
236 fluentMeshFile << " " << 4;
238 else if (cells[cellI].model() == pyr)
240 fluentMeshFile << " " << 5;
242 else if (cells[cellI].model() == prism)
244 fluentMeshFile << " " << 6;
252 WarningIn("void fluentFvMesh::writeFluentMesh() const")
253 << "foamMeshToFluent: cell shape for cell "
254 << cellI << " only supported by Fluent polyhedral meshes."
256 << " Suppressing any further messages for polyhedral"
257 << " cells." << endl;
259 fluentMeshFile << " " << 7;
263 fluentMeshFile << ")())" << std::endl;
266 fluentMeshFile.setf(ios::dec, ios::basefield);
268 // Writing patch types
269 fluentMeshFile << "(39 (1 fluid fluid-1)())" << std::endl;
270 fluentMeshFile << "(39 (2 interior interior-1)())" << std::endl;
272 // Writing boundary patch types
273 forAll(boundary(), patchI)
276 << "(39 (" << patchI + 10 << " ";
279 if (isA<wallFvPatch>(boundary()[patchI]))
281 fluentMeshFile << "wall ";
283 else if (isA<symmetryFvPatch>(boundary()[patchI]))
285 fluentMeshFile << "symmetry ";
289 fluentMeshFile << "pressure-outlet ";
293 << boundary()[patchI].name() << ")())" << std::endl;
298 // ************************************************************************* //