foamVtkWriteCellSetFaces.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2017-2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "foamVtkWriteTopoSet.H"
29 #include "foamVtkIndPatchWriter.H"
30 #include "polyMesh.H"
31 #include "cellSet.H"
32 #include "globalIndex.H"
33 
34 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
35 
37 (
38  const polyMesh& mesh,
39  const cellSet& set,
40  const vtk::outputOptions opts,
41  const fileName& file,
42  bool parallel
43 )
44 {
45  typedef IndirectList<face> FaceListType;
46 
48  (
49  FaceListType(mesh.faces(), labelList()),
50  mesh.points()
51  );
52  FaceListType& faces = pp;
53 
54 
55  //-------------------------------------------------------------------------
56 
57  // External faces of cellset with OpenFOAM cellID as value
58 
59  Map<label> cellFaces(2*set.size());
60 
61  for (const label celli : static_cast<const labelHashSet&>(set))
62  {
63  const cell& cFaces = mesh.cells()[celli];
64 
65  for (const label facei : cFaces)
66  {
67  if (mesh.isInternalFace(facei))
68  {
69  label otherCelli = mesh.faceOwner()[facei];
70 
71  if (otherCelli == celli)
72  {
73  otherCelli = mesh.faceNeighbour()[facei];
74  }
75 
76  if (!set.found(otherCelli))
77  {
78  cellFaces.insert(facei, celli);
79  }
80  }
81  else
82  {
83  cellFaces.insert(facei, celli);
84  }
85  }
86  }
87 
88  // Use these faces
89  faces.addressing() = cellFaces.sortedToc();
90 
91  //-------------------------------------------------------------------------
92 
94 
95  writer.open(file, parallel);
96 
97  writer.beginFile(set.name());
98  writer.writeGeometry();
99 
100  //-------------------------------------------------------------------------
101 
102  // CellData - faceID only
103 
104  writer.beginCellData(1);
105  {
106  // For each face, the corresponding cellID
107 
108  labelList faceValues(faces.size());
109 
110  const labelList& faceIds = faces.addressing();
111 
112  // processor-local cellID offset
113  const label cellIdOffset =
114  (
115  writer.parallel() ? globalIndex(mesh.nCells()).localStart() : 0
116  );
117 
118  forAll(faceValues, facei)
119  {
120  faceValues[facei] = cellFaces[faceIds[facei]] + cellIdOffset;
121  }
122 
123  writer.write("faceID", faceValues);
124  }
125 
126  // End CellData/PointData is implicit
127 
128  writer.close();
129 
130  return true;
131 }
132 
133 
134 // ************************************************************************* //
Write concrete PrimitivePatch faces/points (optionally with fields) as a vtp file or a legacy vtk fil...
A class for handling file names.
Definition: fileName.H:72
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/"finiteArea-edgesCentres"))
bool writeCellSetFaces(const polyMesh &mesh, const cellSet &set, const vtk::outputOptions opts, const fileName &file, bool parallel=UPstream::parRun())
Write perimeter faces of cellset to vtk polydata file.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Encapsulated combinations of output format options. This is primarily useful when defining the output...
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:152
A list of faces which address into the list of points.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:61
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
Write topoSet in VTK format.
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:53
A collection of cell labels.
Definition: cellSet.H:47
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:139
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< label > labelList
A List of labels.
Definition: List.H:62
A List with indirect addressing.
Definition: IndirectList.H:60
bool found
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())