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 
93  indirectPatchWriter writer(pp, opts);
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 // ************************************************************************* //
Foam::vtk::outputOptions
Encapsulated combinations of output format options. This is primarily useful when defining the output...
Definition: foamVtkOutputOptions.H:59
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::vtk::GenericPatchWriter
Write concrete PrimitivePatch faces/points (optionally with fields) as a vtp file or a legacy vtk fil...
Definition: foamVtkGenericPatchWriter.H:65
foamVtkIndPatchWriter.H
globalIndex.H
Foam::vtk::writeCellSetFaces
bool writeCellSetFaces(const polyMesh &mesh, const cellSet &set, const vtk::outputOptions opts, const fileName &file, bool parallel=Pstream::parRun())
Write perimeter faces of cellset to vtk polydata file.
Definition: foamVtkWriteCellSetFaces.C:37
Foam::writer::write
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > * > &, Ostream &) const =0
General entry point for writing.
Foam::Map< label >
polyMesh.H
Foam::HashSet< label, Hash< label > >
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::IndirectList
A List with indirect addressing.
Definition: IndirectList.H:56
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::writer
Base class for graphics format writing. Entry points are.
Definition: writer.H:81
Foam::cellSet
A collection of cell labels.
Definition: cellSet.H:51
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
Foam::List< label >
foamVtkWriteTopoSet.H
Write topoSet in VTK format.
cellSet.H
writer
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:54
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:79