writePatch.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 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 "vtkWriteOps.H"
29 #include "primitiveFacePatch.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
34 (
35  const bool binary,
36  const word& setName,
37  const primitiveFacePatch& fp,
38  const word& fieldName,
39  labelList& fieldValues,
40  const fileName& fileName
41 )
42 {
43  std::ofstream pStream(fileName.c_str());
44 
45  pStream
46  << "# vtk DataFile Version 2.0" << std::endl
47  << setName << std::endl;
48  if (binary)
49  {
50  pStream << "BINARY" << std::endl;
51  }
52  else
53  {
54  pStream << "ASCII" << std::endl;
55  }
56  pStream << "DATASET POLYDATA" << std::endl;
57 
58 
59  //------------------------------------------------------------------
60  //
61  // Write topology
62  //
63  //------------------------------------------------------------------
64 
65 
66  // Write points and faces as polygons
67 
68  pStream << "POINTS " << fp.nPoints() << " float" << std::endl;
69 
70  DynamicList<floatScalar> ptField(3*fp.nPoints());
71 
72  vtkWriteOps::insert(fp.localPoints(), ptField);
73 
74  vtkWriteOps::write(pStream, binary, ptField);
75 
76 
77  label nFaceVerts = 0;
78 
79  forAll(fp.localFaces(), facei)
80  {
81  nFaceVerts += fp.localFaces()[facei].size() + 1;
82  }
83  pStream << "POLYGONS " << fp.size() << ' ' << nFaceVerts
84  << std::endl;
85 
86 
87  DynamicList<label> vertLabels(nFaceVerts);
88 
89  forAll(fp.localFaces(), facei)
90  {
91  const face& f = fp.localFaces()[facei];
92 
93  vertLabels.append(f.size());
94 
95  vtkWriteOps::insert(f, vertLabels);
96  }
97  vtkWriteOps::write(pStream, binary, vertLabels);
98 
99 
100  //-----------------------------------------------------------------
101  //
102  // Write data
103  //
104  //-----------------------------------------------------------------
105 
106  // Write faceID
107 
108  pStream
109  << "CELL_DATA " << fp.size() << std::endl
110  << "FIELD attributes 1" << std::endl;
111 
112  // Cell ids first
113  pStream << fieldName << " 1 " << fp.size() << " int" << std::endl;
114 
115  vtkWriteOps::write(pStream, binary, fieldValues);
116 }
117 
118 
119 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
void writePatch(const bool binary, const word &setName, const primitiveFacePatch &fp, const word &fieldName, labelList &fieldValues, const fileName &fileName)
Write patch.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
void insert(const scalar, DynamicList< floatScalar > &)
Append scalar to given DynamicList.
Write faceSet to vtk polydata file. Only one data which is original faceID.
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
List< label > labelList
A List of labels.
Definition: labelList.H:56
PrimitivePatch< List< face >, const pointField & > primitiveFacePatch
Foam::primitiveFacePatch.