1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
32 #include "objectRegistry.H"
34 #include "fluentFvMesh.H"
35 #include "primitiveMesh.H"
36 #include "wallFvPatch.H"
37 #include "symmetryFvPatch.H"
38 #include "cellModeller.H"
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 Foam::fluentFvMesh::fluentFvMesh(const IOobject& io)
48 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
50 void Foam::fluentFvMesh::writeFluentMesh() const
52 // make a directory called proInterface in the case
53 mkDir(time().rootPath()/time().caseName()/"fluentInterface");
55 // open a file for the mesh
56 ofstream fluentMeshFile
62 time().caseName() + ".msh"
66 Info << "Writing Header" << endl;
69 << "(0 \"FOAM to Fluent Mesh File\")" << std::endl << std::endl
70 << "(0 \"Dimension:\")" << std::endl
71 << "(2 3)" << std::endl << std::endl
72 << "(0 \"Grid dimensions:\")" << std::endl;
74 // Writing number of points
79 fluentMeshFile.setf(ios::hex, ios::basefield);
82 << nPoints() << " 0 3))" << std::endl;
84 // Writing number of cells
87 << nCells() << " 0 0))" << std::endl;
89 // Writing number of faces
90 label nFcs = nFaces();
97 << nFcs << " 0 0))" << std::endl << std::endl;
100 fluentMeshFile.setf(ios::dec, ios::basefield);
106 fluentMeshFile.setf(ios::hex, ios::basefield);
108 << nPoints() << " 1 3)"
109 << std::endl << "(" << std::endl;
111 fluentMeshFile.precision(10);
112 fluentMeshFile.setf(ios::scientific);
114 const pointField& p = points();
120 << p[pointI].x() << " "
122 << " " << p[pointI].z() << std::endl;
126 << "))" << std::endl << std::endl;
128 const unallocLabelList& own = owner();
129 const unallocLabelList& nei = neighbour();
131 const faceList& fcs = faces();
133 // Writing (mixed) internal faces
136 << own.size() << " 2 0)" << std::endl << "(" << std::endl;
140 const labelList& l = fcs[faceI];
142 fluentMeshFile << " ";
144 fluentMeshFile << l.size() << " ";
148 fluentMeshFile << l[lI] + 1 << " ";
151 fluentMeshFile << nei[faceI] + 1 << " ";
152 fluentMeshFile << own[faceI] + 1 << std::endl;
155 fluentMeshFile << "))" << std::endl;
157 label nWrittenFaces = own.size();
159 // Writing boundary faces
160 forAll (boundary(), patchI)
162 const unallocFaceList& patchFaces = boundaryMesh()[patchI];
164 const labelList& patchFaceCells =
165 boundaryMesh()[patchI].faceCells();
167 // The face group will be offset by 10 from the patch label
171 << "(13 (" << patchI + 10 << " " << nWrittenFaces + 1
172 << " " << nWrittenFaces + patchFaces.size() << " ";
174 nWrittenFaces += patchFaces.size();
177 if (isA<wallFvPatch>(boundary()[patchI]))
181 else if (isA<symmetryFvPatch>(boundary()[patchI]))
191 <<" 0)" << std::endl << "(" << std::endl;
193 forAll (patchFaces, faceI)
195 const labelList& l = patchFaces[faceI];
197 fluentMeshFile << " ";
199 fluentMeshFile << l.size() << " ";
201 // Note: In Fluent, all boundary faces point inwards, which is
202 // opposite from the FOAM convention. Turn them round 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;
228 forAll (cells, cellI)
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 // ************************************************************************* //