writeFaceSet.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 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  // Use binary mode in case we write binary.
43  // Causes windows reading to fail if we don't
44  std::ofstream ostr(fileName.c_str(),
45  ios_base::out|ios_base::binary);
46 
47  writeFuns::writeHeader
48  (
49  ostr,
50  binary,
51  set.name()
52  );
53 
54  ostr<< "DATASET POLYDATA" << std::endl;
55 
56  //------------------------------------------------------------------
57  //
58  // Write topology
59  //
60  //------------------------------------------------------------------
61 
62 
63  // Construct primitivePatch of faces in faceSet.
64 
65  faceList setFaces(set.size());
66  labelList setFaceLabels(set.size());
67  label setFaceI = 0;
68 
69  forAllConstIter(faceSet, set, iter)
70  {
71  setFaceLabels[setFaceI] = iter.key();
72  setFaces[setFaceI] = faces[iter.key()];
73  setFaceI++;
74  }
75  primitiveFacePatch fp(setFaces, vMesh.mesh().points());
76 
77 
78  // Write points and faces as polygons
79 
80  ostr<< "POINTS " << fp.nPoints() << " double" << std::endl;
81 
82  DynamicList<doubleScalar> ptField(3*fp.nPoints());
83 
84  writeFuns::insert(fp.localPoints(), ptField);
85 
86  writeFuns::write(ostr, binary, ptField);
87 
88 
89  label nFaceVerts = 0;
90 
91  forAll(fp.localFaces(), faceI)
92  {
93  nFaceVerts += fp.localFaces()[faceI].size() + 1;
94  }
95  ostr<< "POLYGONS " << fp.size() << ' ' << nFaceVerts << std::endl;
96 
97 
98  DynamicList<label> vertLabels(nFaceVerts);
99 
100  forAll(fp.localFaces(), faceI)
101  {
102  const face& f = fp.localFaces()[faceI];
103 
104  vertLabels.append(f.size());
105 
106  writeFuns::insert(f, vertLabels);
107  }
108  writeFuns::write(ostr, binary, vertLabels);
109 
110 
111  //-----------------------------------------------------------------
112  //
113  // Write data
114  //
115  //-----------------------------------------------------------------
116 
117  // Write faceID
118 
119  ostr
120  << "CELL_DATA " << fp.size() << std::endl
121  << "FIELD attributes 1" << std::endl;
122 
123  // Cell ids first
124  ostr<< "faceID 1 " << fp.size() << " int" << std::endl;
125 
126  writeFuns::write(ostr, binary, setFaceLabels);
127 }
128 
129 
130 // ************************************************************************* //
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
writeFuns.H
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:56
Foam::PrimitivePatch::localPoints
const Field< PointType > & localPoints() const
Return pointField of points in patch.
Definition: PrimitivePatchTemplate.C:432
Foam::faceSet
A list of face labels.
Definition: faceSet.H:48
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::vtkMesh
Encapsulation of VTK mesh data. Holds mesh or meshsubset and polyhedral-cell decomposition on it.
Definition: vtkMesh.H:52
writeFaceSet.H
Write faceSet to vtk polydata file. Only one data which is original faceID.
Foam::writeFaceSet
void writeFaceSet(const bool binary, const vtkMesh &vMesh, const faceSet &set, const fileName &fileName)
Definition: writeFaceSet.C:33
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
OFstream.H
Foam::label
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
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobject.H:273
Foam::PrimitivePatch::nPoints
label nPoints() const
Return number of points supporting patch faces.
Definition: PrimitivePatchTemplate.H:293
Foam::HashTable::size
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::vtkMesh::mesh
const fvMesh & mesh() const
Access either mesh or submesh.
Definition: vtkMesh.H:119
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1004
f
labelList f(nPoints)
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::PrimitivePatch::localFaces
const List< Face > & localFaces() const
Return patch faces addressing into local point list.
Definition: PrimitivePatchTemplate.C:372
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
write
Tcoeff write()
insert
timeIndices insert(timeIndex, timeDirs[timeI].value())
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88