Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / postProcessing / dataConversion / foamToVTK / patchWriter.C
blob572d1270edbe57cb95a3d6228f0106ac118e2b63
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "patchWriter.H"
27 #include "writeFuns.H"
29 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
31 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
33 // Construct from components
34 Foam::patchWriter::patchWriter
36     const vtkMesh& vMesh,
37     const bool binary,
38     const bool nearCellValue,
39     const fileName& fName,
40     const labelList& patchIDs
43     vMesh_(vMesh),
44     binary_(binary),
45     nearCellValue_(nearCellValue),
46     fName_(fName),
47     patchIDs_(patchIDs),
48     os_(fName.c_str())
50     const fvMesh& mesh = vMesh_.mesh();
51     const polyBoundaryMesh& patches = mesh.boundaryMesh();
53     // Write header
54     if (patchIDs_.size() == 1)
55     {
56         writeFuns::writeHeader(os_, binary_, patches[patchIDs_[0]].name());
57     }
58     else
59     {
60         writeFuns::writeHeader(os_, binary_, "patches");
61     }
62     os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
64     // Write topology
65     nPoints_ = 0;
66     nFaces_ = 0;
67     label nFaceVerts = 0;
69     forAll(patchIDs_, i)
70     {
71         const polyPatch& pp = patches[patchIDs_[i]];
73         nPoints_ += pp.nPoints();
74         nFaces_ += pp.size();
76         forAll(pp, faceI)
77         {
78             nFaceVerts += pp[faceI].size() + 1;
79         }
80     }
82     os_ << "POINTS " << nPoints_ << " float" << std::endl;
84     DynamicList<floatScalar> ptField(3*nPoints_);
86     forAll(patchIDs_, i)
87     {
88         const polyPatch& pp = patches[patchIDs_[i]];
90         writeFuns::insert(pp.localPoints(), ptField);
91     }
92     writeFuns::write(os_, binary_, ptField);
94     os_ << "CELLS " << nFaces_ << ' ' << nFaceVerts
95         << std::endl;
97     DynamicList<label> vertLabels(nFaceVerts);
98     DynamicList<label> faceTypes(nFaceVerts);
100     label offset = 0;
102     forAll(patchIDs_, i)
103     {
104         const polyPatch& pp = patches[patchIDs_[i]];
106         forAll(pp, faceI)
107         {
108             const face& f = pp.localFaces()[faceI];
110             const label fSize = f.size();
111             vertLabels.append(fSize);
113             writeFuns::insert(f + offset, vertLabels);
115             if (fSize == 3)
116             {
117                 faceTypes.append(vtkTopo::VTK_TRIANGLE);
118             }
119             else if (fSize == 4)
120             {
121                 faceTypes.append(vtkTopo::VTK_QUAD);
122             }
123             else
124             {
125                 faceTypes.append(vtkTopo::VTK_POLYGON);
126             }
127         }
128         offset += pp.nPoints();
129     }
130     writeFuns::write(os_, binary_, vertLabels);
132     os_ << "CELL_TYPES " << nFaces_ << std::endl;
134     writeFuns::write(os_, binary_, faceTypes);
138 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
140 void Foam::patchWriter::writePatchIDs()
142     const fvMesh& mesh = vMesh_.mesh();
144     DynamicList<floatScalar> fField(nFaces_);
146     os_ << "patchID 1 " << nFaces_ << " float" << std::endl;
148     forAll(patchIDs_, i)
149     {
150         label patchI = patchIDs_[i];
152         const polyPatch& pp = mesh.boundaryMesh()[patchI];
154         if (!isA<emptyPolyPatch>(pp))
155         {
156             writeFuns::insert(scalarField(pp.size(), patchI), fField);
157         }
158     }
159     writeFuns::write(os_, binary_, fField);
163 // ************************************************************************* //