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

internalWriter.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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "internalWriter.H"
00028 #include "writeFuns.H"
00029 
00030 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00031 
00032 // Construct from components
00033 Foam::internalWriter::internalWriter
00034 (
00035     const vtkMesh& vMesh,
00036     const bool binary,
00037     const fileName& fName
00038 )
00039 :
00040     vMesh_(vMesh),
00041     binary_(binary),
00042     fName_(fName),
00043     os_(fName.c_str())
00044 {
00045     const fvMesh& mesh = vMesh_.mesh();
00046     const vtkTopo& topo = vMesh_.topo();
00047 
00048     // Write header
00049     writeFuns::writeHeader(os_, binary_, mesh.time().caseName());
00050     os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
00051 
00052 
00053     //------------------------------------------------------------------
00054     //
00055     // Write topology
00056     // 
00057     //------------------------------------------------------------------
00058 
00059     const labelList& addPointCellLabels = topo.addPointCellLabels();
00060     const label nTotPoints = mesh.nPoints() + addPointCellLabels.size();
00061 
00062     os_ << "POINTS " << nTotPoints
00063         << " float" << std::endl;
00064 
00065     DynamicList<floatScalar> ptField(3*nTotPoints);
00066 
00067     writeFuns::insert(mesh.points(), ptField);
00068 
00069     const pointField& ctrs = mesh.cellCentres();
00070     forAll(addPointCellLabels, api)
00071     {
00072         writeFuns::insert(ctrs[addPointCellLabels[api]], ptField);
00073     }
00074     writeFuns::write(os_, binary_, ptField);
00075 
00076 
00077     //
00078     // Write cells
00079     //
00080 
00081     const labelListList& vtkVertLabels = topo.vertLabels();
00082 
00083     // Count total number of vertices referenced.
00084     label nFaceVerts = 0;
00085 
00086     forAll(vtkVertLabels, cellI)
00087     {
00088         nFaceVerts += vtkVertLabels[cellI].size() + 1;
00089     }
00090 
00091     os_ << "CELLS " << vtkVertLabels.size() << ' ' << nFaceVerts
00092         << std::endl;
00093 
00094 
00095     DynamicList<label> vertLabels(nFaceVerts);
00096 
00097     forAll(vtkVertLabels, cellI)
00098     {
00099         const labelList& vtkVerts = vtkVertLabels[cellI];
00100 
00101         vertLabels.append(vtkVerts.size());
00102 
00103         writeFuns::insert(vtkVerts, vertLabels);
00104     }
00105     writeFuns::write(os_, binary_, vertLabels);
00106 
00107 
00108 
00109     const labelList& vtkCellTypes = topo.cellTypes();
00110 
00111     os_ << "CELL_TYPES " << vtkCellTypes.size() << std::endl;
00112 
00113     // Make copy since writing might swap stuff.
00114     DynamicList<label> cellTypes(vtkCellTypes.size());
00115 
00116     writeFuns::insert(vtkCellTypes, cellTypes);
00117 
00118     writeFuns::write(os_, binary_, cellTypes);
00119 }
00120 
00121 
00122 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00123 
00124 void Foam::internalWriter::writeCellIDs()
00125 {
00126     const fvMesh& mesh = vMesh_.mesh();
00127     const vtkTopo& topo = vMesh_.topo();
00128     const labelList& vtkCellTypes = topo.cellTypes();
00129     const labelList& superCells = topo.superCells();
00130 
00131     // Cell ids first
00132     os_ << "cellID 1 " << vtkCellTypes.size() << " int"
00133         << std::endl;
00134 
00135     labelList cellId(vtkCellTypes.size());
00136     label labelI = 0;
00137 
00138 
00139     if (vMesh_.useSubMesh())
00140     {
00141         const labelList& cMap = vMesh_.subsetter().cellMap();
00142 
00143         forAll(mesh.cells(), cellI)
00144         {
00145             cellId[labelI++] = cMap[cellI];
00146         }
00147         forAll(superCells, superCellI)
00148         {
00149             label origCellI = cMap[superCells[superCellI]];
00150 
00151             cellId[labelI++] = origCellI;
00152         }
00153     }
00154     else
00155     {
00156         forAll(mesh.cells(), cellI)
00157         {
00158             cellId[labelI++] = cellI;
00159         }
00160         forAll(superCells, superCellI)
00161         {
00162             label origCellI = superCells[superCellI];
00163 
00164             cellId[labelI++] = origCellI;
00165         }
00166     }
00167 
00168     writeFuns::write(os_, binary_, cellId);
00169 }
00170 
00171 
00172 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd