fluentFvMesh.C
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
00027 #include <fstream>
00028 #include <iostream>
00029
00030 using std::ofstream;
00031 using std::ios;
00032
00033 #include "Time.H"
00034 #include "fluentFvMesh.H"
00035 #include "primitiveMesh.H"
00036 #include "wallFvPatch.H"
00037 #include "symmetryFvPatch.H"
00038 #include "cellModeller.H"
00039
00040
00041
00042 Foam::fluentFvMesh::fluentFvMesh(const IOobject& io)
00043 :
00044 fvMesh(io)
00045 {}
00046
00047
00048
00049
00050 void Foam::fluentFvMesh::writeFluentMesh() const
00051 {
00052
00053 mkDir(time().rootPath()/time().caseName()/"fluentInterface");
00054
00055
00056 ofstream fluentMeshFile
00057 (
00058 (
00059 time().rootPath()/
00060 time().caseName()/
00061 "fluentInterface"/
00062 time().caseName() + ".msh"
00063 ).c_str()
00064 );
00065
00066 Info << "Writing Header" << endl;
00067
00068 fluentMeshFile
00069 << "(0 \"FOAM to Fluent Mesh File\")" << std::endl << std::endl
00070 << "(0 \"Dimension:\")" << std::endl
00071 << "(2 3)" << std::endl << std::endl
00072 << "(0 \"Grid dimensions:\")" << std::endl;
00073
00074
00075 fluentMeshFile
00076 << "(10 (0 1 ";
00077
00078
00079 fluentMeshFile.setf(ios::hex, ios::basefield);
00080
00081 fluentMeshFile
00082 << nPoints() << " 0 3))" << std::endl;
00083
00084
00085 fluentMeshFile
00086 << "(12 (0 1 "
00087 << nCells() << " 0 0))" << std::endl;
00088
00089
00090 label nFcs = nFaces();
00091
00092 fluentMeshFile
00093 << "(13 (0 1 ";
00094
00095
00096 fluentMeshFile
00097 << nFcs << " 0 0))" << std::endl << std::endl;
00098
00099
00100 fluentMeshFile.setf(ios::dec, ios::basefield);
00101
00102
00103 fluentMeshFile
00104 << "(10 (1 1 ";
00105
00106 fluentMeshFile.setf(ios::hex, ios::basefield);
00107 fluentMeshFile
00108 << nPoints() << " 1 3)"
00109 << std::endl << "(" << std::endl;
00110
00111 fluentMeshFile.precision(10);
00112 fluentMeshFile.setf(ios::scientific);
00113
00114 const pointField& p = points();
00115
00116 forAll (p, pointI)
00117 {
00118 fluentMeshFile
00119 << " "
00120 << p[pointI].x() << " "
00121 << p[pointI].y()
00122 << " " << p[pointI].z() << std::endl;
00123 }
00124
00125 fluentMeshFile
00126 << "))" << std::endl << std::endl;
00127
00128 const unallocLabelList& own = owner();
00129 const unallocLabelList& nei = neighbour();
00130
00131 const faceList& fcs = faces();
00132
00133
00134 fluentMeshFile
00135 << "(13 (2 1 "
00136 << own.size() << " 2 0)" << std::endl << "(" << std::endl;
00137
00138 forAll (own, faceI)
00139 {
00140 const labelList& l = fcs[faceI];
00141
00142 fluentMeshFile << " ";
00143
00144 fluentMeshFile << l.size() << " ";
00145
00146 forAll (l, lI)
00147 {
00148 fluentMeshFile << l[lI] + 1 << " ";
00149 }
00150
00151 fluentMeshFile << nei[faceI] + 1 << " ";
00152 fluentMeshFile << own[faceI] + 1 << std::endl;
00153 }
00154
00155 fluentMeshFile << "))" << std::endl;
00156
00157 label nWrittenFaces = own.size();
00158
00159
00160 forAll (boundary(), patchI)
00161 {
00162 const unallocFaceList& patchFaces = boundaryMesh()[patchI];
00163
00164 const labelList& patchFaceCells =
00165 boundaryMesh()[patchI].faceCells();
00166
00167
00168
00169
00170 fluentMeshFile
00171 << "(13 (" << patchI + 10 << " " << nWrittenFaces + 1
00172 << " " << nWrittenFaces + patchFaces.size() << " ";
00173
00174 nWrittenFaces += patchFaces.size();
00175
00176
00177 if
00178 (
00179 typeid(boundary()[patchI]) == typeid(wallFvPatch)
00180 )
00181 {
00182 fluentMeshFile << 3;
00183 }
00184 else if
00185 (
00186 typeid(boundary()[patchI]) == typeid(symmetryFvPatch)
00187 )
00188 {
00189 fluentMeshFile << 7;
00190 }
00191 else
00192 {
00193 fluentMeshFile << 4;
00194 }
00195
00196 fluentMeshFile
00197 <<" 0)" << std::endl << "(" << std::endl;
00198
00199 forAll (patchFaces, faceI)
00200 {
00201 const labelList& l = patchFaces[faceI];
00202
00203 fluentMeshFile << " ";
00204
00205 fluentMeshFile << l.size() << " ";
00206
00207
00208
00209 forAllReverse (l, lI)
00210 {
00211 fluentMeshFile << l[lI] + 1 << " ";
00212 }
00213
00214 fluentMeshFile << patchFaceCells[faceI] + 1 << " 0" << std::endl;
00215 }
00216
00217 fluentMeshFile << "))" << std::endl;
00218 }
00219
00220
00221 fluentMeshFile
00222 << "(12 (1 1 "
00223 << nCells() << " 1 0)(" << std::endl;
00224
00225 const cellModel& hex = *(cellModeller::lookup("hex"));
00226 const cellModel& prism = *(cellModeller::lookup("prism"));
00227 const cellModel& pyr = *(cellModeller::lookup("pyr"));
00228 const cellModel& tet = *(cellModeller::lookup("tet"));
00229
00230 const cellShapeList& cells = cellShapes();
00231
00232 bool hasWarned = false;
00233
00234 forAll (cells, cellI)
00235 {
00236 if (cells[cellI].model() == tet)
00237 {
00238 fluentMeshFile << " " << 2;
00239 }
00240 else if (cells[cellI].model() == hex)
00241 {
00242 fluentMeshFile << " " << 4;
00243 }
00244 else if (cells[cellI].model() == pyr)
00245 {
00246 fluentMeshFile << " " << 5;
00247 }
00248 else if (cells[cellI].model() == prism)
00249 {
00250 fluentMeshFile << " " << 6;
00251 }
00252 else
00253 {
00254 if (!hasWarned)
00255 {
00256 hasWarned = true;
00257
00258 WarningIn("void fluentFvMesh::writeFluentMesh() const")
00259 << "foamMeshToFluent: cell shape for cell "
00260 << cellI << " only supported by Fluent polyhedral meshes."
00261 << nl
00262 << " Suppressing any further messages for polyhedral"
00263 << " cells." << endl;
00264 }
00265 fluentMeshFile << " " << 7;
00266 }
00267 }
00268
00269 fluentMeshFile << ")())" << std::endl;
00270
00271
00272 fluentMeshFile.setf(ios::dec, ios::basefield);
00273
00274
00275 fluentMeshFile << "(39 (1 fluid fluid-1)())" << std::endl;
00276 fluentMeshFile << "(39 (2 interior interior-1)())" << std::endl;
00277
00278
00279 forAll (boundary(), patchI)
00280 {
00281 fluentMeshFile
00282 << "(39 (" << patchI + 10 << " ";
00283
00284
00285 if
00286 (
00287 typeid(boundary()[patchI]) == typeid(wallFvPatch)
00288 )
00289 {
00290 fluentMeshFile << "wall ";
00291 }
00292 else if
00293 (
00294 typeid(boundary()[patchI]) == typeid(symmetryFvPatch)
00295 )
00296 {
00297 fluentMeshFile << "symmetry ";
00298 }
00299 else
00300 {
00301 fluentMeshFile << "pressure-outlet ";
00302 }
00303
00304 fluentMeshFile
00305 << boundary()[patchI].name() << ")())" << std::endl;
00306 }
00307 }
00308
00309
00310
Copyright © 2000-2009 OpenCFD Ltd