1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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
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
39 const bool nearCellValue,
40 const fileName& fName,
41 const labelList& patchIDs
46 nearCellValue_(nearCellValue),
51 const fvMesh& mesh = vMesh_.mesh();
52 const polyBoundaryMesh& patches = mesh.boundaryMesh();
55 if (patchIDs_.size() == 1)
57 writeFuns::writeHeader(os_, binary_, patches[patchIDs_[0]].name());
61 writeFuns::writeHeader(os_, binary_, "patches");
63 os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
72 const polyPatch& pp = patches[patchIDs_[i]];
74 nPoints_ += pp.nPoints();
79 nFaceVerts += pp[faceI].size() + 1;
83 os_ << "POINTS " << nPoints_ << " float" << std::endl;
85 DynamicList<floatScalar> ptField(3*nPoints_);
89 const polyPatch& pp = patches[patchIDs_[i]];
91 writeFuns::insert(pp.localPoints(), ptField);
93 writeFuns::write(os_, binary_, ptField);
95 os_ << "CELLS " << nFaces_ << ' ' << nFaceVerts
98 DynamicList<label> vertLabels(nFaceVerts);
99 DynamicList<label> faceTypes(nFaceVerts);
105 const polyPatch& pp = patches[patchIDs_[i]];
109 const face& f = pp.localFaces()[faceI];
111 const label fSize = f.size();
112 vertLabels.append(fSize);
114 writeFuns::insert(f + offset, vertLabels);
118 faceTypes.append(vtkTopo::VTK_TRIANGLE);
122 faceTypes.append(vtkTopo::VTK_QUAD);
126 faceTypes.append(vtkTopo::VTK_POLYGON);
129 offset += pp.nPoints();
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;
151 label patchI = patchIDs_[i];
153 const polyPatch& pp = mesh.boundaryMesh()[patchI];
155 if (!isA<emptyPolyPatch>(pp))
157 writeFuns::insert(scalarField(pp.size(), patchI), fField);
160 writeFuns::write(os_, binary_, fField);
164 // ************************************************************************* //