writePatch.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "writePatch.H"
27 #include "OFstream.H"
28 #include "writeFuns.H"
29 #include "primitiveFacePatch.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
37 
38 void writePatch
39 (
40  const bool binary,
41  const word& setName,
42  const primitiveFacePatch& fp,
43  const word& fieldName,
44  labelList& fieldValues,
45  const fileName& fileName
46 )
47 {
48  std::ofstream pStream(fileName.c_str());
49 
50  pStream
51  << "# vtk DataFile Version 2.0" << std::endl
52  << setName << std::endl;
53  if (binary)
54  {
55  pStream << "BINARY" << std::endl;
56  }
57  else
58  {
59  pStream << "ASCII" << std::endl;
60  }
61  pStream << "DATASET POLYDATA" << std::endl;
62 
63 
64  //------------------------------------------------------------------
65  //
66  // Write topology
67  //
68  //------------------------------------------------------------------
69 
70 
71  // Write points and faces as polygons
72 
73  pStream << "POINTS " << fp.nPoints() << " float" << std::endl;
74 
75  DynamicList<floatScalar> ptField(3*fp.nPoints());
76 
77  writeFuns::insert(fp.localPoints(), ptField);
78 
79  writeFuns::write(pStream, binary, ptField);
80 
81 
82  label nFaceVerts = 0;
83 
84  forAll(fp.localFaces(), facei)
85  {
86  nFaceVerts += fp.localFaces()[facei].size() + 1;
87  }
88  pStream << "POLYGONS " << fp.size() << ' ' << nFaceVerts
89  << std::endl;
90 
91 
92  DynamicList<label> vertLabels(nFaceVerts);
93 
94  forAll(fp.localFaces(), facei)
95  {
96  const face& f = fp.localFaces()[facei];
97 
98  vertLabels.append(f.size());
99 
100  writeFuns::insert(f, vertLabels);
101  }
102  writeFuns::write(pStream, binary, vertLabels);
103 
104 
105  //-----------------------------------------------------------------
106  //
107  // Write data
108  //
109  //-----------------------------------------------------------------
110 
111  // Write faceID
112 
113  pStream
114  << "CELL_DATA " << fp.size() << std::endl
115  << "FIELD attributes 1" << std::endl;
116 
117  // Cell ids first
118  pStream << fieldName << " 1 " << fp.size() << " int" << std::endl;
119 
120  writeFuns::write(pStream, binary, fieldValues);
121 }
122 
123 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
124 
125 } // End namespace Foam
126 
127 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
static void insert(const point &, DynamicList< floatScalar > &dest)
Append point to given DynamicList.
Write faceSet to vtk polydata file. Only one data which is original faceID.
List< label > labelList
A List of labels.
Definition: labelList.H:56
static void write(std::ostream &, const bool, DynamicList< floatScalar > &)
Write floats ascii or binary.
PrimitivePatch< face, List, const pointField & > primitiveFacePatch
Foam::primitiveFacePatch.
void writePatch(const bool binary, const word &setName, const primitiveFacePatch &fp, const word &fieldName, labelList &fieldValues, const fileName &fileName)
Namespace for OpenFOAM.