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

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