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

writeFaceSet.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 "writeFaceSet.H"
00030 #include "OFstream.H"
00031 #include "writeFuns.H"
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037 
00038 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
00039 
00040 void writeFaceSet
00041 (
00042     const bool binary,
00043     const vtkMesh& vMesh,
00044     const faceSet& set,
00045     const fileName& fileName
00046 )
00047 {
00048     const faceList& faces = vMesh.mesh().faces();
00049 
00050     std::ofstream pStream(fileName.c_str());
00051 
00052     pStream
00053         << "# vtk DataFile Version 2.0" << std::endl
00054         << set.name() << std::endl;
00055     if (binary)
00056     {
00057         pStream << "BINARY" << std::endl;
00058     }
00059     else
00060     {
00061         pStream << "ASCII" << std::endl;
00062     }
00063     pStream << "DATASET POLYDATA" << std::endl;
00064 
00065 
00066     //------------------------------------------------------------------
00067     //
00068     // Write topology
00069     // 
00070     //------------------------------------------------------------------
00071 
00072 
00073     // Construct primitivePatch of faces in faceSet.
00074 
00075     faceList setFaces(set.size());
00076     labelList setFaceLabels(set.size());
00077     label setFaceI = 0;
00078 
00079     for
00080     (
00081         faceSet::const_iterator iter = set.begin();
00082         iter != set.end();
00083         ++iter
00084     )
00085     {
00086         setFaceLabels[setFaceI] = iter.key();
00087         setFaces[setFaceI] = faces[iter.key()];
00088         setFaceI++;
00089     }
00090     primitiveFacePatch fp(setFaces, vMesh.mesh().points());
00091 
00092 
00093     // Write points and faces as polygons
00094 
00095     pStream << "POINTS " << fp.nPoints() << " float" << std::endl;
00096 
00097     DynamicList<floatScalar> ptField(3*fp.nPoints());
00098 
00099     writeFuns::insert(fp.localPoints(), ptField);
00100 
00101     writeFuns::write(pStream, binary, ptField);
00102 
00103 
00104     label nFaceVerts = 0;
00105 
00106     forAll(fp.localFaces(), faceI)
00107     {
00108         nFaceVerts += fp.localFaces()[faceI].size() + 1;
00109     }
00110     pStream << "POLYGONS " << fp.size() << ' ' << nFaceVerts
00111         << std::endl;
00112 
00113 
00114     DynamicList<label> vertLabels(nFaceVerts);
00115 
00116     forAll(fp.localFaces(), faceI)
00117     {
00118         const face& f = fp.localFaces()[faceI];
00119 
00120         vertLabels.append(f.size());
00121 
00122         writeFuns::insert(f, vertLabels);
00123     }
00124     writeFuns::write(pStream, binary, vertLabels);
00125 
00126 
00127     //-----------------------------------------------------------------
00128     //
00129     // Write data
00130     // 
00131     //-----------------------------------------------------------------
00132 
00133     // Write faceID
00134 
00135     pStream
00136         << "CELL_DATA " << fp.size() << std::endl
00137         << "FIELD attributes 1" << std::endl;
00138 
00139     // Cell ids first
00140     pStream << "faceID 1 " << fp.size() << " int" << std::endl;
00141 
00142     writeFuns::write(pStream, binary, setFaceLabels);
00143 }
00144 
00145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00146 
00147 } // End namespace Foam
00148 
00149 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd