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-2021 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)
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:
116{
117 rename(description);
118}
119
120
121// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
122
124{
126
127 forAll(count, typei)
128 {
129 count[typei] = size(elemType(typei));
130 }
131
132 return count;
133}
134
135
136Foam::label Foam::ensightFaces::total() const
137{
138 label nTotal = 0;
139 forAll(sizes_, typei)
140 {
141 nTotal += sizes_[typei];
142 }
143 return nTotal;
144}
145
146
148{
149 clearOut();
150
152
153 faceOrder_.clear();
154 flipMap_.clear();
155 sizes_ = Zero;
156 offsets_ = Zero;
157}
158
159
161{}
162
163
165{
166 forAll(sizes_, typei)
167 {
168 sizes_[typei] = size(elemType(typei));
169 }
170 // Can reduce FixedList with sumOp<label> in a single operation
171 Foam::reduce(sizes_, sumOp<label>());
172}
173
174
176{
177 // Some extra safety
178 if (faceOrder_.size() != size())
179 {
180 faceOrder_.clear();
181 }
182 if (flipMap_.size() != size())
183 {
184 flipMap_.clear();
185 }
186
187 // Sort by face Ids.
188 // Use to reorder flip maps and face-order too.
189
190 for (int typei=0; typei < nTypes; ++typei)
191 {
192 const labelRange sub(range(elemType(typei)));
193
194 if (!sub.empty())
195 {
196 SubList<label> ids(sub, addressing());
197 labelList order(Foam::sortedOrder(ids));
198
199 ids = reorder<labelList>(order, ids);
200
201 // Sort flip map as well
202 if (!flipMap_.empty())
203 {
204 SubList<bool> flips(flipMap_, sub);
205 flips = reorder<boolList>(order, flips);
206 }
207
208 // Sort face ordering as well
209 if (!faceOrder_.empty())
210 {
211 SubList<label> faceOrder(faceOrder_, sub);
212 faceOrder = reorder<labelList>(order, faceOrder);
213 }
214 }
215 }
216}
217
218
220{
221 const label len = faces.size();
222
223 // Pass 1: Count the shapes
224
225 sizes_ = Zero; // reset sizes
226 for (label listi = 0; listi < len; ++listi)
227 {
228 const auto etype = whatType(faces[listi]);
229
230 ++sizes_[etype];
231 }
232
233 resizeAll(); // adjust allocation
234 sizes_ = Zero; // reset sizes - use for local indexing here
235
236 // Pass 2: Assign face-id per shape type
237
238 for (label listi = 0; listi < len; ++listi)
239 {
240 const auto etype = whatType(faces[listi]);
241
242 add(etype, listi);
243 }
244}
245
246
248(
249 const UList<face>& faces,
250 const labelRange& range
251)
252{
253 const labelRange slice(range.subset0(faces.size()));
254
255 // Operate on a local slice
256 classify(SubList<face>(slice, faces));
257
258 // Fixup to use the real faceIds instead of the 0-based slice
259 incrAddressing(slice.start());
260}
261
262
264(
265 const UList<face>& faces,
266 const labelUList& addr,
267 const boolList& flipMap,
268 const bitSet& exclude
269)
270{
271 const label len = addr.size();
272 const bool useFlip = (len == flipMap.size());
273
274 // Pass 1: Count the shapes
275
276 sizes_ = Zero; // reset sizes
277 for (label listi = 0; listi < len; ++listi)
278 {
279 const label faceId = addr[listi];
280
281 if (!exclude.test(faceId))
282 {
283 const auto etype = whatType(faces[faceId]);
284
285 ++sizes_[etype];
286 }
287 }
288
289 resizeAll(); // adjust allocation
290 sizes_ = Zero; // reset sizes - use for local indexing here
291
292 label nUsed = addressing().size();
293
294 if (useFlip)
295 {
296 flipMap_.resize(nUsed);
297 flipMap_ = false;
298 }
299
300 faceOrder_.resize(nUsed);
301
302 // Pass 2: Assign face-id per shape type
303 // - also record the face order
304
305 nUsed = 0;
306 for (label listi = 0; listi < len; ++listi)
307 {
308 const label faceId = addr[listi];
309
310 if (!exclude.test(faceId))
311 {
312 const bool doFlip = useFlip && flipMap.test(listi);
313
314 const auto etype = whatType(faces[faceId]);
315
316 const label idx = add(etype, faceId, doFlip);
317
318 faceOrder_[nUsed] = idx;
319 ++nUsed;
320 }
321 }
322}
323
324
325void Foam::ensightFaces::writeDict(Ostream& os, const bool full) const
326{
327 os.beginBlock(type());
328
329 os.writeEntry("id", index()+1); // Ensight starts with 1
330 os.writeEntry("name", name());
331 os.writeEntry("size", size());
332
333 if (full)
334 {
335 for (int typei=0; typei < ensightFaces::nTypes; ++typei)
336 {
337 const auto etype = ensightFaces::elemType(typei);
338
340
341 faceIds(etype).writeList(os, 0) << endEntry; // Flat output
342 }
343 }
344
345 os.endBlock();
346}
347
348
349// ************************************************************************* //
scalar range
label n
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: FixedList.H:81
iterator begin() noexcept
Return an iterator to begin traversing the FixedList.
Definition: FixedListI.H:524
const Key & key() const
The key associated with the iterator.
bool empty() const noexcept
True if range is empty (zero-sized)
Definition: IntRangeI.H:436
IntType start() const noexcept
The (inclusive) lower value of the range.
Definition: IntRangeI.H:408
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:105
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:239
virtual Ostream & writeKeyword(const keyType &kw)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:57
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:87
A List obtained as a section of another List.
Definition: SubList.H:70
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:94
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type test(const label i) const
Definition: UList.H:518
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
bool test(const label pos) const
Test value at specified position, never auto-vivify entries.
Definition: bitSetI.H:521
Sorting/classification of faces (2D) into corresponding ensight types.
Definition: ensightFaces.H:75
FixedList< label, nTypes > sizes() const
Processor-local sizes per element type.
Definition: ensightFaces.C:123
void classify(const UList< face > &faces)
Classify the face types and set the element lists.
Definition: ensightFaces.C:219
void reduce()
Sum element counts across all processes.
Definition: ensightFaces.C:164
void sort()
Inplace sort element lists numerically.
Definition: ensightFaces.C:175
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
ensightFaces()
Default construct, with part index 0.
Definition: ensightFaces.C:103
label total() const
The global size of all element types.
Definition: ensightFaces.C:136
void clear()
Set addressable sizes to zero, free up addressing memory.
Definition: ensightFaces.C:147
void clearOut()
Clear any demand-driven data.
Definition: ensightFaces.C:160
Base class for ensightCells, ensightFaces, ensightOutputSurfaces.
Definition: ensightPart.H:54
void rename(const string &value)
Change the part name or description.
Definition: ensightPart.H:166
const labelList & addressing() const noexcept
Element addressing.
Definition: ensightPart.H:76
void clear()
Clear element addressing.
Definition: ensightPart.H:88
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::dictionary writeDict() const
Write to dictionary.
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:58
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
OBJstream os(runTime.globalPath()/outputName)
label faceId(-1)
Namespace for OpenFOAM.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Ostream & endEntry(Ostream &os)
Write end entry (';') followed by newline.
Definition: Ostream.H:398
labelList f(nPoints)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333