FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

fluentFvMesh.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <fstream>
00027 #include <iostream>
00028 
00029 using std::ofstream;
00030 using std::ios;
00031 
00032 #include <OpenFOAM/Time.H>
00033 #include "fluentFvMesh.H"
00034 #include <OpenFOAM/primitiveMesh.H>
00035 #include <finiteVolume/wallFvPatch.H>
00036 #include <finiteVolume/symmetryFvPatch.H>
00037 #include <OpenFOAM/cellModeller.H>
00038 
00039 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00040 
00041 Foam::fluentFvMesh::fluentFvMesh(const IOobject& io)
00042 :
00043     fvMesh(io)
00044 {}
00045 
00046 
00047 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00048 
00049 void Foam::fluentFvMesh::writeFluentMesh() const
00050 {
00051     // make a directory called proInterface in the case
00052     mkDir(time().rootPath()/time().caseName()/"fluentInterface");
00053 
00054     // open a file for the mesh
00055     ofstream fluentMeshFile
00056     (
00057         (
00058             time().rootPath()/
00059             time().caseName()/
00060             "fluentInterface"/
00061             time().caseName() + ".msh"
00062         ).c_str()
00063     );
00064 
00065     Info << "Writing Header" << endl;
00066 
00067     fluentMeshFile
00068         << "(0 \"FOAM to Fluent Mesh File\")" << std::endl << std::endl
00069         << "(0 \"Dimension:\")" << std::endl
00070         << "(2 3)" << std::endl << std::endl
00071         << "(0 \"Grid dimensions:\")" << std::endl;
00072 
00073     // Writing number of points
00074     fluentMeshFile
00075             << "(10 (0 1 ";
00076 
00077     // Writing hex
00078     fluentMeshFile.setf(ios::hex, ios::basefield);
00079 
00080     fluentMeshFile
00081         << nPoints() << " 0 3))" << std::endl;
00082 
00083     // Writing number of cells
00084     fluentMeshFile
00085         << "(12 (0 1 "
00086         << nCells() << " 0 0))" << std::endl;
00087 
00088     // Writing number of faces
00089     label nFcs = nFaces();
00090 
00091     fluentMeshFile
00092             << "(13 (0 1 ";
00093 
00094     // Still writing hex
00095     fluentMeshFile
00096         << nFcs << " 0 0))" << std::endl << std::endl;
00097 
00098     // Return to dec
00099     fluentMeshFile.setf(ios::dec, ios::basefield);
00100 
00101     // Writing points
00102     fluentMeshFile
00103             << "(10 (1 1 ";
00104 
00105     fluentMeshFile.setf(ios::hex, ios::basefield);
00106     fluentMeshFile
00107         << nPoints() << " 1 3)"
00108         << std::endl << "(" << std::endl;
00109 
00110     fluentMeshFile.precision(10);
00111     fluentMeshFile.setf(ios::scientific);
00112 
00113     const pointField& p = points();
00114 
00115     forAll (p, pointI)
00116     {
00117         fluentMeshFile
00118             << "    "
00119             << p[pointI].x() << " "
00120             << p[pointI].y()
00121             << " " << p[pointI].z() << std::endl;
00122     }
00123 
00124     fluentMeshFile
00125         << "))" << std::endl << std::endl;
00126 
00127     const unallocLabelList& own = owner();
00128     const unallocLabelList& nei = neighbour();
00129 
00130     const faceList& fcs = faces();
00131 
00132     // Writing (mixed) internal faces
00133     fluentMeshFile
00134         << "(13 (2 1 "
00135         << own.size() << " 2 0)" << std::endl << "(" << std::endl;
00136 
00137     forAll (own, faceI)
00138     {
00139         const labelList& l = fcs[faceI];
00140 
00141         fluentMeshFile << "    ";
00142 
00143         fluentMeshFile << l.size() << " ";
00144 
00145         forAll (l, lI)
00146         {
00147             fluentMeshFile << l[lI] + 1 << " ";
00148         }
00149 
00150         fluentMeshFile << nei[faceI] + 1 << " ";
00151         fluentMeshFile << own[faceI] + 1 << std::endl;
00152     }
00153 
00154     fluentMeshFile << "))" << std::endl;
00155 
00156     label nWrittenFaces = own.size();
00157 
00158     // Writing boundary faces
00159     forAll (boundary(), patchI)
00160     {
00161         const unallocFaceList& patchFaces = boundaryMesh()[patchI];
00162 
00163         const labelList& patchFaceCells =
00164             boundaryMesh()[patchI].faceCells();
00165 
00166         // The face group will be offset by 10 from the patch label
00167 
00168         // Write header
00169         fluentMeshFile
00170             << "(13 (" << patchI + 10 << " " << nWrittenFaces + 1
00171             << " " << nWrittenFaces + patchFaces.size() << " ";
00172 
00173         nWrittenFaces += patchFaces.size();
00174 
00175         // Write patch type
00176         if (isA<wallFvPatch>(boundary()[patchI]))
00177         {
00178             fluentMeshFile << 3;
00179         }
00180         else if (isA<symmetryFvPatch>(boundary()[patchI]))
00181         {
00182             fluentMeshFile << 7;
00183         }
00184         else
00185         {
00186             fluentMeshFile << 4;
00187         }
00188 
00189         fluentMeshFile
00190             <<" 0)" << std::endl << "(" << std::endl;
00191 
00192         forAll (patchFaces, faceI)
00193         {
00194             const labelList& l = patchFaces[faceI];
00195 
00196             fluentMeshFile << "    ";
00197 
00198             fluentMeshFile << l.size() << " ";
00199 
00200             // Note: In Fluent, all boundary faces point inwards, which is
00201             // opposite from the FOAM convention. Turn them round on printout
00202             forAllReverse (l, lI)
00203             {
00204                 fluentMeshFile << l[lI] + 1 << " ";
00205             }
00206 
00207             fluentMeshFile << patchFaceCells[faceI] + 1 << " 0" << std::endl;
00208         }
00209 
00210         fluentMeshFile << "))" << std::endl;
00211     }
00212 
00213     // Writing cells
00214     fluentMeshFile
00215         << "(12 (1 1 "
00216         << nCells() << " 1 0)(" << std::endl;
00217 
00218     const cellModel& hex = *(cellModeller::lookup("hex"));
00219     const cellModel& prism = *(cellModeller::lookup("prism"));
00220     const cellModel& pyr = *(cellModeller::lookup("pyr"));
00221     const cellModel& tet = *(cellModeller::lookup("tet"));
00222 
00223     const cellShapeList& cells = cellShapes();
00224 
00225     bool hasWarned = false;
00226 
00227     forAll (cells, cellI)
00228     {
00229         if (cells[cellI].model() == tet)
00230         {
00231             fluentMeshFile << " " << 2;
00232         }
00233         else if (cells[cellI].model() == hex)
00234         {
00235             fluentMeshFile << " " << 4;
00236         }
00237         else if (cells[cellI].model() == pyr)
00238         {
00239             fluentMeshFile << " " << 5;
00240         }
00241         else if (cells[cellI].model() == prism)
00242         {
00243             fluentMeshFile << " " << 6;
00244         }
00245         else
00246         {
00247             if (!hasWarned)
00248             {
00249                 hasWarned = true;
00250 
00251                 WarningIn("void fluentFvMesh::writeFluentMesh() const")
00252                     << "foamMeshToFluent: cell shape for cell "
00253                     << cellI << " only supported by Fluent polyhedral meshes."
00254                     << nl
00255                     << "    Suppressing any further messages for polyhedral"
00256                     << " cells." << endl;
00257             }
00258             fluentMeshFile << " " << 7;
00259         }
00260     }
00261 
00262     fluentMeshFile << ")())" << std::endl;
00263 
00264     // Return to dec
00265     fluentMeshFile.setf(ios::dec, ios::basefield);
00266 
00267     // Writing patch types
00268     fluentMeshFile << "(39 (1 fluid fluid-1)())" << std::endl;
00269     fluentMeshFile << "(39 (2 interior interior-1)())" << std::endl;
00270 
00271     // Writing boundary patch types
00272     forAll (boundary(), patchI)
00273     {
00274         fluentMeshFile
00275             << "(39 (" << patchI + 10 << " ";
00276 
00277         // Write patch type
00278         if (isA<wallFvPatch>(boundary()[patchI]))
00279         {
00280             fluentMeshFile << "wall ";
00281         }
00282         else if (isA<symmetryFvPatch>(boundary()[patchI]))
00283         {
00284             fluentMeshFile << "symmetry ";
00285         }
00286         else
00287         {
00288             fluentMeshFile << "pressure-outlet ";
00289         }
00290 
00291         fluentMeshFile
00292             << boundary()[patchI].name() << ")())" << std::endl;
00293     }
00294 }
00295 
00296 
00297 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines