Loading...
Searching...
No Matches
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-2023 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"
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::meshPointMappings
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 Pstream::reduceAnd(allCells);
103
104 if (allCells)
105 {
106 // All cells used, and thus all points
107
108 autoPtr<globalIndex> globalPointsPtr =
109 mesh.globalData().mergePoints
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_nocopy(nPoints);
165
166 if (allCells)
167 {
168 // All cells used, and thus all points
169
170 uniqueMeshPointLabels.resize_nocopy(nPoints);
171
172 Foam::identity(pointToGlobal);
173 Foam::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 meshPointMappings
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:156
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition HashTableI.H:152
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition List.C:347
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
Definition ListI.H:171
void resize(const label len)
Adjust allocated size of list.
Definition ListI.H:153
static const List< label > & null() noexcept
Definition List.H:138
A HashTable to objects of type <T> with a label key.
Definition Map.H:54
static FOAM_NO_DANGLING_REFERENCE const manifoldCellsMeshObject & New(const polyMesh &mesh, Args &&... args)
static void reduceAnd(bool &value, const int communicator=worldComm)
Logical (and) reduction (MPI_AllReduce).
static bool & parRun() noexcept
Test if this a parallel run.
Definition UPstream.H:1681
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
label uniqueMeshPoints(const polyMesh &mesh, labelList &uniqueMeshPointLabels, bool parallel) const
Globally unique mesh points. Required when writing point fields.
Map< label > meshPointMap(const polyMesh &mesh) const
Mesh point map.
label size() const noexcept
Processor-local size of all elements.
const labelList & cellIds() const
Processor-local cell ids of all elements.
autoPtr< globalIndex > mergePoints(labelList &pointToGlobal, labelList &uniquePoints) const
Helper for merging (collocated!) mesh point data.
const cellList & cells() const
Return the (optionally compacted) cell list Triggers demand-driven filtering if required.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
virtual const faceList & faces() const
Return raw faces.
Definition polyMesh.C:1088
const globalMeshData & globalData() const
Return parallel info (demand-driven).
Definition polyMesh.C:1296
label nPoints() const noexcept
Number of mesh points.
dynamicFvMesh & mesh
label nPoints
List< label > labelList
A List of labels.
Definition List.H:62
List< face > faceList
List of faces.
Definition faceListFwd.H:41
List< cell > cellList
List of cell.
Definition cellListFwd.H:41
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...
bool notNull(const T *ptr) noexcept
True if ptr is not a pointer (of type T) to the nullObject.
Definition nullObject.H:267
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299