BUGFIX: Illegal use of uninitialised value (backport)
[foam-extend-3.2.git] / applications / utilities / postProcessing / dataConversion / foamToVTK / patchWriter.C
blobb33cc81354c1115871f31fb911361bebaffb93a6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "patchWriter.H"
28 #include "writeFuns.H"
30 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
32 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
34 // Construct from components
35 Foam::patchWriter::patchWriter
37     const vtkMesh& vMesh,
38     const bool binary,
39     const bool nearCellValue,
40     const fileName& fName,
41     const labelList& patchIDs
44     vMesh_(vMesh),
45     binary_(binary),
46     nearCellValue_(nearCellValue),
47     fName_(fName),
48     patchIDs_(patchIDs),
49     os_(fName.c_str())
51     const fvMesh& mesh = vMesh_.mesh();
52     const polyBoundaryMesh& patches = mesh.boundaryMesh();
54     // Write header
55     if (patchIDs_.size() == 1)
56     {
57         writeFuns::writeHeader(os_, binary_, patches[patchIDs_[0]].name());
58     }
59     else
60     {
61         writeFuns::writeHeader(os_, binary_, "patches");
62     }
63     os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
65     // Write topology
66     nPoints_ = 0;
67     nFaces_ = 0;
68     label nFaceVerts = 0;
70     forAll(patchIDs_, i)
71     {
72         const polyPatch& pp = patches[patchIDs_[i]];
74         nPoints_ += pp.nPoints();
75         nFaces_ += pp.size();
77         forAll(pp, faceI)
78         {
79             nFaceVerts += pp[faceI].size() + 1;
80         }
81     }
83     os_ << "POINTS " << nPoints_ << " float" << std::endl;
85     DynamicList<floatScalar> ptField(3*nPoints_);
87     forAll(patchIDs_, i)
88     {
89         const polyPatch& pp = patches[patchIDs_[i]];
91         writeFuns::insert(pp.localPoints(), ptField);
92     }
93     writeFuns::write(os_, binary_, ptField);
95     os_ << "CELLS " << nFaces_ << ' ' << nFaceVerts
96         << std::endl;
98     DynamicList<label> vertLabels(nFaceVerts);
99     DynamicList<label> faceTypes(nFaceVerts);
101     label offset = 0;
103     forAll(patchIDs_, i)
104     {
105         const polyPatch& pp = patches[patchIDs_[i]];
107         forAll(pp, faceI)
108         {
109             const face& f = pp.localFaces()[faceI];
111             const label fSize = f.size();
112             vertLabels.append(fSize);
114             writeFuns::insert(f + offset, vertLabels);
116             if (fSize == 3)
117             {
118                 faceTypes.append(vtkTopo::VTK_TRIANGLE);
119             }
120             else if (fSize == 4)
121             {
122                 faceTypes.append(vtkTopo::VTK_QUAD);
123             }
124             else
125             {
126                 faceTypes.append(vtkTopo::VTK_POLYGON);
127             }
128         }
129         offset += pp.nPoints();
130     }
131     writeFuns::write(os_, binary_, vertLabels);
133     os_ << "CELL_TYPES " << nFaces_ << std::endl;
135     writeFuns::write(os_, binary_, faceTypes);
139 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
141 void Foam::patchWriter::writePatchIDs()
143     const fvMesh& mesh = vMesh_.mesh();
145     DynamicList<floatScalar> fField(nFaces_);
147     os_ << "patchID 1 " << nFaces_ << " float" << std::endl;
149     forAll(patchIDs_, i)
150     {
151         label patchI = patchIDs_[i];
153         const polyPatch& pp = mesh.boundaryMesh()[patchI];
155         if (!isA<emptyPolyPatch>(pp))
156         {
157             writeFuns::insert(scalarField(pp.size(), patchI), fField);
158         }
159     }
160     writeFuns::write(os_, binary_, fField);
164 // ************************************************************************* //