ensightCellsAddr.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 "ensightCells.H"
29#include "polyMesh.H"
30#include "globalIndex.H"
31#include "globalMeshData.H"
32#include "ListOps.H"
34
35// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36
39{
41 const cellList& meshCells = manifoldCellsMeshObject::New(mesh).cells();
42 const faceList& meshFaces = mesh.faces();
43
44 Map<label> pointMap(8*this->size());
45
46 // Pass 1: markup used points from cells
47
48 for (const label celli : this->cellIds())
49 {
50 for (const label facei : meshCells[celli])
51 {
52 for (const label pointi : meshFaces[facei])
53 {
54 pointMap.insert(pointi, 0);
55 }
56 }
57 }
58
59 // Compact point numbering, preserves the original order
60 label nPoints = 0;
61 for (const label pointi : pointMap.sortedToc())
62 {
63 pointMap(pointi) = nPoints++;
64 }
65
66 return pointMap;
67}
68
69
70Foam::label Foam::ensightCells::meshPointMapppings
71(
72 const polyMesh& mesh,
73 labelList& pointToGlobalRequest,
74 labelList& uniqueMeshPointLabels,
75 bool parallel
76) const
77{
79 const cellList& meshCells = manifoldCellsMeshObject::New(mesh).cells();
80
81 labelList pointToGlobal;
82
83 const bool rewritePointMap = notNull(pointToGlobalRequest);
84
85 if (notNull(pointToGlobalRequest))
86 {
87 pointToGlobal.transfer(pointToGlobalRequest);
88 }
89
90
91 const ensightCells& part = *this;
92
93 parallel = parallel && Pstream::parRun();
94
95 // Renumber the points/faces into unique points
96 label nPoints = 0; // Total number of points
97
98 bool allCells = (part.size() == mesh.nCells());
99
100 if (parallel)
101 {
102 Foam::reduce(allCells, andOp<bool>());
103
104 if (allCells)
105 {
106 // All cells used, and thus all points
107
108 autoPtr<globalIndex> globalPointsPtr =
110 (
111 pointToGlobal,
112 uniqueMeshPointLabels
113 );
114
115 nPoints = globalPointsPtr().totalSize(); // nPoints (global)
116 }
117 else
118 {
119 // Map mesh point index to local (compact) point index
120
121 Map<label> meshPointMap(part.meshPointMap(mesh));
122
123 labelList meshPoints(meshPointMap.sortedToc());
124
125 autoPtr<globalIndex> globalPointsPtr =
127 (
128 meshPoints,
129 meshPointMap,
130 pointToGlobal,
131 uniqueMeshPointLabels
132 );
133
134 nPoints = globalPointsPtr().totalSize(); // nPoints (global)
135
136 meshPointMap.clear();
137
138 // The mergePoints returns pointToGlobal under the
139 // assumption of local addressing
140 // (eg, patch localFaces).
141 // Recast as original mesh points to new global points
142
143 if (rewritePointMap)
144 {
145 labelList oldToNew(mesh.nPoints(), -1);
146
147 forAll(meshPoints, i)
148 {
149 const label orig = meshPoints[i];
150 const label glob = pointToGlobal[i];
151
152 oldToNew[orig] = glob;
153 }
154
155 pointToGlobal.transfer(oldToNew);
156 }
157 }
158 }
159 else
160 {
161 // Non-parallel
162
163 nPoints = mesh.nPoints();
164 pointToGlobal.resize(nPoints);
165
166 if (allCells)
167 {
168 // All cells used, and thus all points
169
170 uniqueMeshPointLabels.resize(nPoints);
171
172 ListOps::identity(pointToGlobal);
173 ListOps::identity(uniqueMeshPointLabels);
174 }
175 else
176 {
177 // Mark up with -1 for unused entries
178 pointToGlobal = -1;
179
180 nPoints = 0;
181
182 // Pass 1: markup used points from cells
183
184 for (const label celli : this->cellIds())
185 {
186 for (const label facei : meshCells[celli])
187 {
188 for (const label pointi : mesh.faces()[facei])
189 {
190 if (pointToGlobal[pointi] == -1)
191 {
192 pointToGlobal[pointi] = nPoints++;
193 }
194 }
195 }
196 }
197
198 // Pass 2:
199 //
200 // Compact point numbering, preserving original point order
201 uniqueMeshPointLabels.resize(nPoints);
202
203 nPoints = 0;
204 forAll(pointToGlobal, pointi)
205 {
206 if (pointToGlobal[pointi] != -1)
207 {
208 pointToGlobal[pointi] = nPoints;
209
210 uniqueMeshPointLabels[nPoints] = pointi;
211
212 ++nPoints;
213 }
214 }
215 }
216 }
217
218 if (notNull(pointToGlobalRequest))
219 {
220 pointToGlobalRequest.transfer(pointToGlobal);
221 }
222
223 return nPoints;
224}
225
226
228(
229 const polyMesh& mesh,
230 labelList& uniqueMeshPointLabels,
231 bool parallel
232) const
233{
234 return meshPointMapppings
235 (
236 mesh,
237 const_cast<labelList&>(labelList::null()), // Ignore pointToGlobal
238 uniqueMeshPointLabels,
239 parallel
240 );
241}
242
243
244// ************************************************************************* //
Various functions to operate on Lists.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:137
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:180
void transfer(List< T > &list)
Definition: List.C:447
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
label uniqueMeshPoints(const polyMesh &mesh, labelList &uniqueMeshPointLabels, bool parallel) const
Globally unique mesh points. Required when writing point fields.
label size() const noexcept
Processor-local size of all elements.
Definition: ensightPart.H:154
const labelList & cellIds() const
Processor-local cell ids of all elements.
Definition: ensightCellsI.H:79
autoPtr< globalIndex > mergePoints(labelList &pointToGlobal, labelList &uniquePoints) const
Helper for merging (collocated!) mesh point data.
const Map< label > & meshPointMap() const
Per point that is to be duplicated the local index.
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
label nPoints() const noexcept
Number of mesh points.
label nCells() const noexcept
Number of mesh cells.
dynamicFvMesh & mesh
label nPoints
void identity(labelUList &map, label start=0)
Set identity map with (map[i] == i)
Definition: ListOps.C:203
List< label > labelList
A List of labels.
Definition: List.H:66
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
bool notNull(const T *ptr)
True if ptr is not a pointer (of type T) to the nullObject.
Definition: nullObject.H:207
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333