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

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