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-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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"
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 =
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(nPoints);
92 ListOps::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
140template<>
141Foam::Ostream& Foam::operator<<
142(
143 Ostream& os,
145)
146{
147 const ensightFaces& part = ip.t_;
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// ************************************************************************* //
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:52
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of faces which address into the list of points.
const Map< label > & meshPointMap() const
Mesh point map.
const labelList & meshPoints() const
Return labelList of mesh points in patch.
const List< face_type > & localFaces() const
Return patch faces addressing into local point list.
A List with indirect addressing. Like IndirectList but does not store addressing.
Definition: IndirectList.H:79
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Sorting/classification of faces (2D) into corresponding ensight types.
Definition: ensightFaces.H:75
bool usesFlipMap() const
True for non-zero flip-map that spans the addresses.
Definition: ensightFacesI.H:98
const labelList & faceIds() const noexcept
Processor-local face ids of all elements.
Definition: ensightFacesI.H:79
static constexpr int nTypes
Number of 'Face' element types (3)
Definition: ensightFaces.H:90
static const char * elemNames[nTypes]
The ensight 'Face' element type names.
Definition: ensightFaces.H:93
elemType
Supported ensight 'Face' element types.
Definition: ensightFaces.H:83
label total() const
The global size of all element types.
Definition: ensightFaces.C:136
const boolList & flipMap() const
Processor-local flip-map of all elements.
Definition: ensightFacesI.H:92
Specialized Ensight output with extra geometry file header.
label index() const noexcept
The index in a list (0-based)
Definition: ensightPart.H:124
const string & name() const noexcept
The part name or description.
Definition: ensightPart.H:160
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
virtual bool write()
Write the output fields.
autoPtr< globalIndex > mergePoints(labelList &pointToGlobal, labelList &uniquePoints) const
Helper for merging (collocated!) mesh point data.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1108
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1310
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1083
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
const pointField & points
label nPoints
void inplaceRenumber(const labelUList &oldToNew, IntListType &lists)
Inplace renumber the values (not the indices) of a list of lists.
Definition: ensightOutput.H:90
void identity(labelUList &map, label start=0)
Set identity map with (map[i] == i)
Definition: ListOps.C:203
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.
void writeFaceConnectivityPresorted(ensightGeoFile &os, const ensightFaces &part, const faceUList &faces, bool parallel)
Write the presorted face connectivity for the part.
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
labelList f(nPoints)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333