OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

writePatch.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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "writePatch.H"
00030 #include "OFstream.H"
00031 #include "writeFuns.H"
00032 #include "primitiveFacePatch.H"
00033 
00034 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00035 
00036 namespace Foam
00037 {
00038 
00039 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
00040 
00041 void writePatch
00042 (
00043     const bool binary,
00044     const word& setName,
00045     const primitiveFacePatch& fp,
00046     const word& fieldName,
00047     labelList& fieldValues,
00048     const fileName& fileName
00049 )
00050 {
00051     std::ofstream pStream(fileName.c_str());
00052 
00053     pStream
00054         << "# vtk DataFile Version 2.0" << std::endl
00055         << setName << std::endl;
00056     if (binary)
00057     {
00058         pStream << "BINARY" << std::endl;
00059     }
00060     else
00061     {
00062         pStream << "ASCII" << std::endl;
00063     }
00064     pStream << "DATASET POLYDATA" << std::endl;
00065 
00066 
00067     //------------------------------------------------------------------
00068     //
00069     // Write topology
00070     // 
00071     //------------------------------------------------------------------
00072 
00073 
00074     // Write points and faces as polygons
00075 
00076     pStream << "POINTS " << fp.nPoints() << " float" << std::endl;
00077 
00078     DynamicList<floatScalar> ptField(3*fp.nPoints());
00079 
00080     writeFuns::insert(fp.localPoints(), ptField);
00081 
00082     writeFuns::write(pStream, binary, ptField);
00083 
00084 
00085     label nFaceVerts = 0;
00086 
00087     forAll(fp.localFaces(), faceI)
00088     {
00089         nFaceVerts += fp.localFaces()[faceI].size() + 1;
00090     }
00091     pStream << "POLYGONS " << fp.size() << ' ' << nFaceVerts
00092         << std::endl;
00093 
00094 
00095     DynamicList<label> vertLabels(nFaceVerts);
00096 
00097     forAll(fp.localFaces(), faceI)
00098     {
00099         const face& f = fp.localFaces()[faceI];
00100 
00101         vertLabels.append(f.size());
00102 
00103         writeFuns::insert(f, vertLabels);
00104     }
00105     writeFuns::write(pStream, binary, vertLabels);
00106 
00107 
00108     //-----------------------------------------------------------------
00109     //
00110     // Write data
00111     // 
00112     //-----------------------------------------------------------------
00113 
00114     // Write faceID
00115 
00116     pStream
00117         << "CELL_DATA " << fp.size() << std::endl
00118         << "FIELD attributes 1" << std::endl;
00119 
00120     // Cell ids first
00121     pStream << fieldName << " 1 " << fp.size() << " int" << std::endl;
00122 
00123     writeFuns::write(pStream, binary, fieldValues);
00124 }
00125 
00126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00127 
00128 } // End namespace Foam
00129 
00130 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd