ensightFacesIO.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) 2020-2023 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 "ensightFaces.H"
29 #include "ensightOutput.H"
30 #include "InfoProxy.H"
31 #include "polyMesh.H"
32 #include "globalIndex.H"
33 #include "globalMeshData.H"
34 #include "indirectPrimitivePatch.H"
35 
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37 
39 (
41  const polyMesh& mesh,
42  bool parallel
43 ) const
44 {
45  const ensightFaces& part = *this;
46 
47  parallel = parallel && Pstream::parRun();
48 
49  // Renumber the patch points/faces into unique points
50  label nPoints = 0; // Total number of points
51  labelList pointToGlobal; // local point to unique global index
52  labelList uniqueMeshPointLabels; // unique global points
53 
54 
55  const pointField& points = mesh.points();
56  const faceList& faces = mesh.faces();
57 
58 
59  // Use the properly sorted faceIds (ensightFaces) and do NOT use
60  // the faceZone or anything else directly, otherwise the
61  // point-maps will not correspond.
62  // - perform face-flipping later
63 
65  (
66  UIndirectList<face>(faces, part.faceIds()),
67  points
68  );
69 
70  if (parallel)
71  {
72  autoPtr<globalIndex> globalPointsPtr =
73  mesh.globalData().mergePoints
74  (
75  pp.meshPoints(),
76  pp.meshPointMap(),
77  pointToGlobal,
78  uniqueMeshPointLabels
79  );
80 
81  nPoints = globalPointsPtr().totalSize(); // nPoints (global)
82  }
83  else
84  {
85  // Non-parallel
86  // - all information already available from PrimitivePatch
87 
88  nPoints = pp.meshPoints().size();
89  uniqueMeshPointLabels = pp.meshPoints();
90 
91  pointToGlobal.resize_nocopy(nPoints);
92  Foam::identity(pointToGlobal);
93  }
94 
96  (
97  os,
98  part.index(),
99  part.name(),
100  nPoints, // nPoints (global)
101  UIndirectList<point>(points, uniqueMeshPointLabels),
102  parallel
103  );
104 
105 
106  // Renumber the faces belonging to the faceZone,
107  // from local numbering to unique global index.
108 
109  faceList patchFaces(pp.localFaces());
110  ListListOps::inplaceRenumber(pointToGlobal, patchFaces);
111 
112  // Also a good place to perform face flipping
113  if (part.usesFlipMap())
114  {
115  const boolList& flip = part.flipMap();
116 
117  forAll(patchFaces, facei)
118  {
119  face& f = patchFaces[facei];
120 
121  if (flip[facei])
122  {
123  f.flip();
124  }
125  }
126  }
127 
129  (
130  os,
131  part,
132  patchFaces,
133  parallel
134  );
135 }
136 
137 
138 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
139 
140 template<>
141 Foam::Ostream& Foam::operator<<
142 (
143  Ostream& os,
144  const InfoProxy<ensightFaces>& iproxy
145 )
146 {
147  const auto& part = *iproxy;
148 
149  os << part.name().c_str();
150 
151  for (label typei=0; typei < ensightFaces::nTypes; ++typei)
152  {
153  const auto etype = ensightFaces::elemType(typei);
154 
155  os << ' ' << ensightFaces::elemNames[etype]
156  << ':' << part.total(etype);
157  }
158  os << nl;
159 
160  return os;
161 }
162 
163 
164 // ************************************************************************* //
static const char * elemNames[nTypes]
The ensight &#39;Face&#39; element type names.
Definition: ensightFaces.H:94
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:68
virtual const fileName & name() const override
Read/write access to the name of the stream.
Definition: OSstream.H:128
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Specialized Ensight output with extra geometry file header.
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1049
Sorting/classification of faces (2D) into corresponding ensight types.
Definition: ensightFaces.H:66
void writeFaceConnectivityPresorted(ensightGeoFile &os, const ensightFaces &part, const faceUList &faces, bool parallel)
Write the presorted face connectivity for the part.
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
Definition: ListI.H:175
bool usesFlipMap() const
True for non-zero flip-map that spans the addresses.
Definition: ensightFacesI.H:91
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
void inplaceRenumber(const labelUList &oldToNew, IntListType &lists)
Inplace renumber the values (not the indices) of a list of lists.
Definition: ensightOutput.H:92
A list of faces which address into the list of points.
const string & name() const noexcept
The part name or description.
Definition: ensightPart.H:201
dynamicFvMesh & mesh
const pointField & points
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
Definition: labelLists.C:44
label nPoints
virtual void write(ensightGeoFile &os, const polyMesh &mesh, bool parallel) const
Write geometry, using a mesh reference.
const boolList & flipMap() const
Processor-local flip-map of all elements.
Definition: ensightFacesI.H:85
const labelList & faceIds() const noexcept
Processor-local face ids of all elements.
Definition: ensightFacesI.H:72
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
static constexpr int nTypes
Number of &#39;Face&#39; element types (3)
Definition: ensightFaces.H:89
labelList f(nPoints)
label index() const noexcept
The index in a list (0-based)
Definition: ensightPart.H:153
elemType
Supported ensight &#39;Face&#39; element types.
Definition: ensightFaces.H:79
A helper class for outputting values to Ostream.
Definition: ensightCells.H:43
A List with indirect addressing. Like IndirectList but does not store addressing. ...
Definition: faMatrix.H:56
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
bool writeCoordinates(ensightGeoFile &os, const label partId, const word &partName, const label nPoints, const FieldContainer< Foam::point > &fld, bool parallel)
Write coordinates (component-wise) for the given part.