writeFaceSet.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-2018 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 "writeFaceSet.H"
27 #include "OFstream.H"
28 #include "writeFuns.H"
29 
30 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
31 
33 (
34  const bool binary,
35  const vtkMesh& vMesh,
36  const faceSet& set,
37  const fileName& fileName
38 )
39 {
40  const faceList& faces = vMesh.mesh().faces();
41 
42  std::ofstream ostr(fileName.c_str());
43 
44  writeFuns::writeHeader
45  (
46  ostr,
47  binary,
48  set.name()
49  );
50 
51  ostr<< "DATASET POLYDATA" << std::endl;
52 
53  //------------------------------------------------------------------
54  //
55  // Write topology
56  //
57  //------------------------------------------------------------------
58 
59 
60  // Construct primitivePatch of faces in faceSet.
61 
62  faceList setFaces(set.size());
63  labelList setFaceLabels(set.size());
64  label setFacei = 0;
65 
66  forAllConstIter(faceSet, set, iter)
67  {
68  setFaceLabels[setFacei] = iter.key();
69  setFaces[setFacei] = faces[iter.key()];
70  setFacei++;
71  }
72  primitiveFacePatch fp(setFaces, vMesh.mesh().points());
73 
74 
75  // Write points and faces as polygons
76 
77  ostr<< "POINTS " << fp.nPoints() << " float" << std::endl;
78 
79  DynamicList<floatScalar> ptField(3*fp.nPoints());
80 
81  writeFuns::insert(fp.localPoints(), ptField);
82 
83  writeFuns::write(ostr, binary, ptField);
84 
85 
86  label nFaceVerts = 0;
87 
88  forAll(fp.localFaces(), facei)
89  {
90  nFaceVerts += fp.localFaces()[facei].size() + 1;
91  }
92  ostr<< "POLYGONS " << fp.size() << ' ' << nFaceVerts << std::endl;
93 
94 
95  DynamicList<label> vertLabels(nFaceVerts);
96 
97  forAll(fp.localFaces(), facei)
98  {
99  const face& f = fp.localFaces()[facei];
100 
101  vertLabels.append(f.size());
102 
103  writeFuns::insert(f, vertLabels);
104  }
105  writeFuns::write(ostr, binary, vertLabels);
106 
107 
108  //-----------------------------------------------------------------
109  //
110  // Write data
111  //
112  //-----------------------------------------------------------------
113 
114  // Write faceID
115 
116  ostr
117  << "CELL_DATA " << fp.size() << std::endl
118  << "FIELD attributes 1" << std::endl;
119 
120  // Cell ids first
121  ostr<< "faceID 1 " << fp.size() << " int" << std::endl;
122 
123  writeFuns::write(ostr, binary, setFaceLabels);
124 }
125 
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
List< face > faceList
Definition: faceListFwd.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
void write(Ostream &, const label, const dictionary &)
Write with dictionary lookup.
Write faceSet to vtk polydata file. Only one data which is original faceID.
timeIndices insert(timeIndex, timeDirs[timeI].value())
void writeFaceSet(const bool binary, const vtkMesh &vMesh, const faceSet &set, const fileName &fileName)
List< label > labelList
A List of labels.
Definition: labelList.H:56
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
PrimitivePatch< face, List, const pointField & > primitiveFacePatch
Foam::primitiveFacePatch.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47