ensightCells.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 "ensightCells.H"
29#include "error.H"
30#include "bitSet.H"
31#include "polyMesh.H"
32#include "cellModel.H"
34
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36
37namespace Foam
38{
40}
41
42const char* Foam::ensightCells::elemNames[5] =
43{
44 "tetra4", "pyramid5", "penta6", "hexa8", "nfaced"
45};
46
47static_assert
48(
50 "Support exactly 5 cell types (tetra4, pyramid5, penta6, hexa8, nfaced)"
51);
52
53
54// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
55
56void Foam::ensightCells::resizeAll()
57{
58 // Assign sub-list offsets, determine overall size
59
60 label len = 0;
61
62 auto iter = offsets_.begin();
63
64 *iter = 0;
65 for (const label n : sizes_)
66 {
67 len += n;
68
69 *(++iter) = len;
70 }
71
72 // The addressing space
73 addressing().resize(len, Zero);
74}
75
76
77// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
78
80:
82 manifold_(false),
83 offsets_(Zero),
84 sizes_(Zero)
85{}
86
87
88Foam::ensightCells::ensightCells(const string& description)
89:
91{
92 rename(description);
93}
94
95
96// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
97
99{
101
102 forAll(count, typei)
103 {
104 count[typei] = size(elemType(typei));
105 }
106
107 return count;
108}
109
110
111Foam::label Foam::ensightCells::total() const
112{
113 label nTotal = 0;
114 forAll(sizes_, typei)
115 {
116 nTotal += sizes_[typei];
117 }
118 return nTotal;
119}
120
121
123{
124 clearOut();
125
127
128 manifold_ = false;
129 sizes_ = Zero;
130 offsets_ = Zero;
131}
132
133
135{}
136
137
139{
140 forAll(sizes_, typei)
141 {
142 sizes_[typei] = size(elemType(typei));
143 }
144 // Can reduce FixedList with sumOp<label> in a single operation
145 Foam::reduce(sizes_, sumOp<label>());
146}
147
148
150{
151 for (int typei=0; typei < nTypes; ++typei)
152 {
153 const labelRange sub(range(elemType(typei)));
154
155 if (!sub.empty())
156 {
157 SubList<label> ids(addressing(), sub);
158
159 Foam::sort(ids);
160 }
161 }
162}
163
164
165template<class Addressing>
166void Foam::ensightCells::classifyImpl
167(
168 const polyMesh& mesh,
169 const Addressing& cellIds
170)
171{
172 manifold_ = manifoldCellsMeshObject::New(mesh).manifold();
173
174 // References to cell shape models
179
180 const cellShapeList& shapes = mesh.cellShapes();
181
182 // Pass 1: Count the shapes
183
184 sizes_ = Zero; // reset sizes
185 for (const label id : cellIds)
186 {
187 const cellModel& model = shapes[id].model();
188
189 elemType etype(NFACED);
190 if (model == tet)
191 {
192 etype = TETRA4;
193 }
194 else if (model == pyr)
195 {
196 etype = PYRAMID5;
197 }
198 else if (model == prism)
199 {
200 etype = PENTA6;
201 }
202 else if (model == hex)
203 {
204 etype = HEXA8;
205 }
206
207 ++sizes_[etype];
208 }
209
210 resizeAll(); // adjust allocation
211 sizes_ = Zero; // reset sizes - use for local indexing here
212
213
214 // Pass 2: Assign cell-id per shape type
215
216 for (const label id : cellIds)
217 {
218 const cellModel& model = shapes[id].model();
219
220 elemType etype(NFACED);
221 if (model == tet)
222 {
223 etype = TETRA4;
224 }
225 else if (model == pyr)
226 {
227 etype = PYRAMID5;
228 }
229 else if (model == prism)
230 {
231 etype = PENTA6;
232 }
233 else if (model == hex)
234 {
235 etype = HEXA8;
236 }
237
238 add(etype, id);
239 }
240}
241
242
244{
245 // All mesh cells
246 classifyImpl(mesh, labelRange(mesh.nCells()));
247}
248
249
251(
252 const polyMesh& mesh,
253 const labelUList& cellIds
254)
255{
256 classifyImpl(mesh, cellIds);
257}
258
259
261(
262 const polyMesh& mesh,
263 const bitSet& selection
264)
265{
266 classifyImpl(mesh, selection);
267}
268
269
270void Foam::ensightCells::writeDict(Ostream& os, const bool full) const
271{
272 os.beginBlock(type());
273
274 os.writeEntry("id", index()+1); // Ensight starts with 1
275 os.writeEntry("name", name());
276 os.writeEntry("size", size());
277
278 if (full)
279 {
280 for (int typei=0; typei < ensightCells::nTypes; ++typei)
281 {
282 const auto etype = ensightCells::elemType(typei);
283
285
286 cellIds(etype).writeList(os, 0) << endEntry; // Flat output
287 }
288 }
289
290 os.endBlock();
291}
292
293
294// ************************************************************************* //
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
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
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
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
Maps a geometry to a set of cell primitives.
Definition: cellModel.H:73
@ PRISM
prism
Definition: cellModel.H:83
reference ref() const
A reference to the entry (Error if not found)
Definition: dictionary.H:225
Sorting/classification of cells (3D) into corresponding ensight element types.
Definition: ensightCells.H:58
void reduce()
Sum element counts across all processes.
Definition: ensightCells.C:138
void sort()
Sort element lists numerically.
Definition: ensightCells.C:149
void classify(const polyMesh &mesh)
Classify cell types and set the element lists.
Definition: ensightCells.C:243
static constexpr int nTypes
Number of 'Cell' element types (5)
Definition: ensightCells.H:75
ensightCells()
Default construct, with part index 0.
Definition: ensightCells.C:79
static const char * elemNames[nTypes]
The ensight 'Cell' element type names.
Definition: ensightCells.H:78
elemType
Supported ensight 'Cell' element types.
Definition: ensightCells.H:66
label total() const
The global size of all element types.
Definition: ensightCells.C:111
void clear()
Set addressable sizes to zero, free up addressing memory.
Definition: ensightCells.C:122
FixedList< label, nTypes > sizes() const
Processor-local sizes per element type.
Definition: ensightCells.C:98
void clearOut()
Clear any demand-driven data.
Definition: ensightCells.C:134
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
Foam::dictionary writeDict() const
Write to dictionary.
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:58
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
const cellShapeList & cellShapes() const
Return cell shapes.
label nCells() const noexcept
Number of mesh cells.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
const cellModel & hex
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
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)
void sort(UList< T > &list)
Sort the list.
Definition: UList.C:342
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
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333