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

patchWriter.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 "patchWriter.H"
00027 #include "writeFuns.H"
00028 
00029 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00030 
00031 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00032 
00033 // Construct from components
00034 Foam::patchWriter::patchWriter
00035 (
00036     const vtkMesh& vMesh,
00037     const bool binary,
00038     const bool nearCellValue,
00039     const fileName& fName,
00040     const labelList& patchIDs
00041 )
00042 :
00043     vMesh_(vMesh),
00044     binary_(binary),
00045     nearCellValue_(nearCellValue),
00046     fName_(fName),
00047     patchIDs_(patchIDs),
00048     os_(fName.c_str())
00049 {
00050     const fvMesh& mesh = vMesh_.mesh();
00051     const polyBoundaryMesh& patches = mesh.boundaryMesh();
00052 
00053     // Write header
00054     if (patchIDs_.size() == 1)
00055     {
00056         writeFuns::writeHeader(os_, binary_, patches[patchIDs_[0]].name());
00057     }
00058     else
00059     {
00060         writeFuns::writeHeader(os_, binary_, "patches");
00061     }
00062     os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
00063 
00064     // Write topology
00065     nPoints_ = 0;
00066     nFaces_ = 0;
00067     label nFaceVerts = 0;
00068 
00069     forAll(patchIDs_, i)
00070     {
00071         const polyPatch& pp = patches[patchIDs_[i]];
00072 
00073         nPoints_ += pp.nPoints();
00074         nFaces_ += pp.size();
00075 
00076         forAll(pp, faceI)
00077         {
00078             nFaceVerts += pp[faceI].size() + 1;
00079         }
00080     }
00081 
00082     os_ << "POINTS " << nPoints_ << " float" << std::endl;
00083 
00084     DynamicList<floatScalar> ptField(3*nPoints_);
00085 
00086     forAll(patchIDs_, i)
00087     {
00088         const polyPatch& pp = patches[patchIDs_[i]];
00089 
00090         writeFuns::insert(pp.localPoints(), ptField);
00091     }
00092     writeFuns::write(os_, binary_, ptField);
00093 
00094     os_ << "CELLS " << nFaces_ << ' ' << nFaceVerts
00095         << std::endl;
00096 
00097     DynamicList<label> vertLabels(nFaceVerts);
00098     DynamicList<label> faceTypes(nFaceVerts);
00099 
00100     label offset = 0;
00101 
00102     forAll(patchIDs_, i)
00103     {
00104         const polyPatch& pp = patches[patchIDs_[i]];
00105 
00106         forAll(pp, faceI)
00107         {
00108             const face& f = pp.localFaces()[faceI];
00109 
00110             const label fSize = f.size();
00111             vertLabels.append(fSize);
00112 
00113             writeFuns::insert(f + offset, vertLabels);
00114 
00115             if (fSize == 3)
00116             {
00117                 faceTypes.append(vtkTopo::VTK_TRIANGLE);
00118             }
00119             else if (fSize == 4)
00120             {
00121                 faceTypes.append(vtkTopo::VTK_QUAD);
00122             }
00123             else
00124             {
00125                 faceTypes.append(vtkTopo::VTK_POLYGON);
00126             }
00127         }
00128         offset += pp.nPoints();
00129     }
00130     writeFuns::write(os_, binary_, vertLabels);
00131 
00132     os_ << "CELL_TYPES " << nFaces_ << std::endl;
00133 
00134     writeFuns::write(os_, binary_, faceTypes);
00135 }
00136 
00137 
00138 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00139 
00140 void Foam::patchWriter::writePatchIDs()
00141 {
00142     const fvMesh& mesh = vMesh_.mesh();
00143 
00144     DynamicList<floatScalar> fField(nFaces_);
00145 
00146     os_ << "patchID 1 " << nFaces_ << " float" << std::endl;
00147 
00148     forAll(patchIDs_, i)
00149     {
00150         label patchI = patchIDs_[i];
00151 
00152         const polyPatch& pp = mesh.boundaryMesh()[patchI];
00153 
00154         if (!isA<emptyPolyPatch>(pp))
00155         {
00156             writeFuns::insert(scalarField(pp.size(), patchI), fField);
00157         }
00158     }
00159     writeFuns::write(os_, binary_, fField);
00160 }
00161 
00162 
00163 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines