Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
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 
00040 
00041 Foam::fluentFvMesh::fluentFvMesh(const IOobject& io)
00042 :
00043     fvMesh(io)
00044 {}
00045 
00046 
00047 
00048 
00049 void Foam::fluentFvMesh::writeFluentMesh() const
00050 {
00051     
00052     mkDir(time().rootPath()/time().caseName()/"fluentInterface");
00053 
00054     
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     
00074     fluentMeshFile
00075             << "(10 (0 1 ";
00076 
00077     
00078     fluentMeshFile.setf(ios::hex, ios::basefield);
00079 
00080     fluentMeshFile
00081         << nPoints() << " 0 3))" << std::endl;
00082 
00083     
00084     fluentMeshFile
00085         << "(12 (0 1 "
00086         << nCells() << " 0 0))" << std::endl;
00087 
00088     
00089     label nFcs = nFaces();
00090 
00091     fluentMeshFile
00092             << "(13 (0 1 ";
00093 
00094     
00095     fluentMeshFile
00096         << nFcs << " 0 0))" << std::endl << std::endl;
00097 
00098     
00099     fluentMeshFile.setf(ios::dec, ios::basefield);
00100 
00101     
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     
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     
00159     forAll (boundary(), patchI)
00160     {
00161         const unallocFaceList& patchFaces = boundaryMesh()[patchI];
00162 
00163         const labelList& patchFaceCells =
00164             boundaryMesh()[patchI].faceCells();
00165 
00166         
00167 
00168         
00169         fluentMeshFile
00170             << "(13 (" << patchI + 10 << " " << nWrittenFaces + 1
00171             << " " << nWrittenFaces + patchFaces.size() << " ";
00172 
00173         nWrittenFaces += patchFaces.size();
00174 
00175         
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             
00201             
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     
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     
00265     fluentMeshFile.setf(ios::dec, ios::basefield);
00266 
00267     
00268     fluentMeshFile << "(39 (1 fluid fluid-1)())" << std::endl;
00269     fluentMeshFile << "(39 (2 interior interior-1)())" << std::endl;
00270 
00271     
00272     forAll (boundary(), patchI)
00273     {
00274         fluentMeshFile
00275             << "(39 (" << patchI + 10 << " ";
00276 
00277         
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