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

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