Loading...
Searching...
No Matches
ensightFaces.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) 2016-2025 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 "error.H"
30#include "polyMesh.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
37}
38
39const char* Foam::ensightFaces::elemNames[3] =
40{
41 "tria3", "quad4", "nsided"
42};
43
44static_assert
45(
47 "Support exactly 3 face types (tria3, quad4, nsided)"
48);
49
50
51// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
52
53namespace
54{
55
56// Trivial shape classifier
57inline Foam::ensightFaces::elemType whatType(const Foam::face& f) noexcept
58{
59 return
60 (
61 f.size() == 3
63 : f.size() == 4
66 );
67}
68
69} // End anonymous namespace
70
71
72// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
73
74void Foam::ensightFaces::resizeAll()
75{
76 // Invalidate any previous face ordering
77 faceOrder_.clear();
78
79 // Invalidate any previous flipMap
80 flipMap_.clear();
81
82 // Assign sub-list offsets, determine overall size
83
84 label len = 0;
85
86 auto iter = offsets_.begin();
87
88 *iter = 0;
89 for (const label n : sizes_)
90 {
91 len += n;
92
93 *(++iter) = len;
94 }
95
96 // The addressing space
97 addressing().resize(len, Zero);
98}
99
100
101// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
102
104:
105 ensightPart(),
106 faceOrder_(),
107 flipMap_(),
108 offsets_(Zero),
109 sizes_(Zero)
110{}
111
112
113Foam::ensightFaces::ensightFaces(const string& description)
114:
117 rename(description);
118}
119
120
121// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
122
124{
126
127 for (int typei = 0; typei < nTypes; ++typei)
128 {
129 count[typei] = size(elemType(typei));
130 }
131
132 return count;
133}
134
135
136Foam::label Foam::ensightFaces::totalSize() const noexcept
137{
138 label count = 0;
139 for (label n : sizes_)
141 count += n;
142 }
143 return count;
144}
145
146
148{
149 clearOut();
150
152
153 faceOrder_.clear();
154 flipMap_.clear();
155 sizes_ = Zero;
156 offsets_ = Zero;
158
159
161{}
162
163
165{
166 for (int typei = 0; typei < nTypes; ++typei)
168 sizes_[typei] = size(elemType(typei));
169 }
170 Foam::reduce(sizes_, sumOp<label>());
171}
172
173
175{
176 // Some extra safety
177 if (faceOrder_.size() != size())
178 {
179 faceOrder_.clear();
180 }
181 if (flipMap_.size() != size())
182 {
183 flipMap_.clear();
184 }
185
186 // Sort by face Ids.
187 // Use to reorder flip maps and face-order too.
188
189 for (int typei=0; typei < nTypes; ++typei)
190 {
191 const labelRange sub(range(elemType(typei)));
192
193 if (!sub.empty())
194 {
195 SubList<label> ids(sub, addressing());
196 const labelList order(Foam::sortedOrder(ids));
197
198 ids = UIndirectList<label>(ids, order).list();
199
200 // Sort flip map as well
201 if (!flipMap_.empty())
202 {
203 SubList<bool> flips(flipMap_, sub);
204 flips = UIndirectList<bool>(flips, order).list();
205 }
206
207 // Sort face ordering as well
208 if (!faceOrder_.empty())
209 {
210 SubList<label> faceOrder(faceOrder_, sub);
212 }
213 }
214 }
215}
216
217
219{
220 const label len = faces.size();
221
222 // Pass 1: Count the shapes
223
224 sizes_ = Zero; // reset sizes
225 for (label listi = 0; listi < len; ++listi)
226 {
227 const auto etype = whatType(faces[listi]);
228
229 ++sizes_[etype];
230 }
231
232 resizeAll(); // adjust allocation
233 sizes_ = Zero; // reset sizes - use for local indexing here
234
235 // Pass 2: Assign face-id per shape type
236
237 for (label listi = 0; listi < len; ++listi)
238 {
239 const auto etype = whatType(faces[listi]);
240
241 add(etype, listi);
242 }
243}
244
245
247(
248 const UList<face>& faces,
249 const labelRange& range
250)
251{
252 const labelRange slice(range.subset0(faces.size()));
253
254 // Operate on a local slice
255 classify(SubList<face>(slice, faces));
256
257 // Fixup to use the real faceIds instead of the 0-based slice
258 incrAddressing(slice.start());
259}
260
261
263(
264 const UList<face>& faces,
265 const labelUList& addr,
266 const boolList& flipMap,
267 const bitSet& exclude
268)
269{
270 const label len = addr.size();
271 const bool useFlip = (len == flipMap.size());
272
273 // Pass 1: Count the shapes
274
275 sizes_ = Zero; // reset sizes
276 for (label listi = 0; listi < len; ++listi)
277 {
278 const label faceId = addr[listi];
279
280 if (!exclude.test(faceId))
281 {
282 const auto etype = whatType(faces[faceId]);
283
284 ++sizes_[etype];
285 }
286 }
287
288 resizeAll(); // adjust allocation
289 sizes_ = Zero; // reset sizes - use for local indexing here
290
291 label nUsed = addressing().size();
292
293 if (useFlip)
294 {
295 flipMap_.resize(nUsed);
296 flipMap_ = false;
297 }
298
299 faceOrder_.resize(nUsed);
300
301 // Pass 2: Assign face-id per shape type
302 // - also record the face order
303
304 nUsed = 0;
305 for (label listi = 0; listi < len; ++listi)
306 {
307 const label faceId = addr[listi];
308
309 if (!exclude.test(faceId))
310 {
311 const bool doFlip = useFlip && flipMap.test(listi);
312
313 const auto etype = whatType(faces[faceId]);
314
315 const label idx = add(etype, faceId, doFlip);
316
317 faceOrder_[nUsed] = idx;
318 ++nUsed;
319 }
320 }
321}
322
323
324void Foam::ensightFaces::writeDict(Ostream& os, const bool full) const
325{
326 os.beginBlock(type());
327
328 os.writeEntry("id", index()+1); // Ensight starts with 1
329 os.writeEntry("name", name());
330 os.writeEntry("size", size());
331
332 if (full)
333 {
334 for (int typei=0; typei < ensightFaces::nTypes; ++typei)
335 {
336 const auto etype = ensightFaces::elemType(typei);
337
339
340 faceIds(etype).writeList(os, 0) << endEntry; // Flat output
341 }
342 }
343
344 os.endBlock();
345}
346
347
348// ************************************************************************* //
scalar range
label n
A 1D vector of objects of type <T> with a fixed length <N>.
Definition FixedList.H:73
List< T > list() const
Return the addressed elements as a List.
bool empty() const noexcept
True if range is empty (zero-sized).
Definition IntRange.H:198
IntType start() const noexcept
The (inclusive) lower value of the range.
Definition IntRange.H:218
void resize(const label len)
Adjust allocated size of list.
Definition ListI.H:153
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
virtual Ostream & endBlock()
Write end block group.
Definition Ostream.C:108
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition Ostream.H:331
virtual Ostream & writeKeyword(const keyType &kw)
Write the keyword followed by an appropriate indentation.
Definition Ostream.C:60
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition Ostream.C:90
A non-owning sub-view of a List (allocated or unallocated storage).
Definition SubList.H:61
A List with indirect addressing. Like IndirectList but does not store addressing.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
bool test(const label i) const
Test bool value at specified position, always false for out-of-range access.
Definition UList.H:852
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
bool test(const label pos) const
Test for True value at specified position, never auto-vivify entries.
Definition bitSet.H:334
Sorting/classification of faces (2D) into corresponding ensight types.
FixedList< label, nTypes > sizes() const
Processor-local sizes per element type.
labelRange range(const elemType etype) const
Processor-local offset/size of element type.
static const char * key(const elemType etype) noexcept
The ensight element name for the specified 'Face' type.
void classify(const UList< face > &faces)
Classify the face types and set the element lists.
const labelList & faceIds() const noexcept
Processor-local face ids of all elements.
const labelList & faceOrder() const noexcept
Processor-local face order (where applicable).
label totalSize() const noexcept
The global size of all element types.
void reduce()
Sum element counts across all processes.
void sort()
Inplace sort element lists numerically.
static constexpr int nTypes
Number of 'Face' element types (3).
virtual void writeDict(Ostream &os, const bool full=false) const
Write information about the object as a dictionary, optionally write all element addresses.
label size(const elemType etype) const
Processor-local size of the specified element type.
static const char * elemNames[nTypes]
The ensight 'Face' element type names.
elemType
Supported ensight 'Face' element types.
ensightFaces()
Default construct, with part index 0.
void clear()
Set addressable sizes to zero, free up addressing memory.
const boolList & flipMap() const
Processor-local flip-map of all elements.
void clearOut()
Clear any demand-driven data.
Base class for ensightCells, ensightFaces, ensightOutputSurfaces.
Definition ensightPart.H:50
void rename(const string &value)
Change the part name or description.
void incrAddressing(const label off)
Increase addressing by specified offset value.
Definition ensightPart.C:34
label index() const noexcept
The index in a list (0-based).
const labelList & addressing() const noexcept
Element addressing.
Definition ensightPart.H:85
ensightPart()
Default construct. Index=0, identifier = -1.
Definition ensightPart.C:54
void clear()
Clear element addressing.
A face is a list of labels corresponding to mesh vertices.
Definition face.H:71
A range or interval of labels defined by a start and a size.
Definition labelRange.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
OBJstream os(runTime.globalPath()/outputName)
auto & name
label faceId(-1)
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition POSIX.C:801
void add(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
List< bool > boolList
A List of bools.
Definition List.H:60
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
const direction noexcept
Definition scalarImpl.H:265
Ostream & endEntry(Ostream &os)
Write end entry (';') followed by newline.
Definition Ostream.H:553
UList< label > labelUList
A UList of labels.
Definition UList.H:75
labelList f(nPoints)