Loading...
Searching...
No Matches
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-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 "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:
92 rename(description);
93}
94
95
96// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
97
99{
101
102 for (int typei = 0; typei < nTypes; ++typei)
103 {
104 count[typei] = size(elemType(typei));
105 }
106
107 return count;
108}
109
110
111Foam::label Foam::ensightCells::totalSize() const noexcept
112{
113 label count = 0;
114 for (label n : sizes_)
116 count += n;
117 }
118 return count;
119}
120
121
123{
124 clearOut();
125
128 manifold_ = false;
129 sizes_ = Zero;
130 offsets_ = Zero;
132
133
135{}
136
137
139{
140 for (int typei = 0; typei < nTypes; ++typei)
142 sizes_[typei] = size(elemType(typei));
143 }
144 Foam::reduce(sizes_, sumOp<label>());
145}
146
147
149{
150 for (int typei=0; typei < nTypes; ++typei)
151 {
152 const labelRange sub(range(elemType(typei)));
153
154 if (!sub.empty())
155 {
156 SubList<label> ids(addressing(), sub);
157
158 Foam::sort(ids);
159 }
160 }
161}
162
163
164template<class Addressing>
165void Foam::ensightCells::classifyImpl
166(
167 const polyMesh& mesh,
168 const Addressing& cellIds
169)
170{
172
173 // References to cell shape models
178
179 const cellShapeList& shapes = mesh.cellShapes();
180
181 // Pass 1: Count the shapes
182
183 sizes_ = Zero; // reset sizes
184 for (const label id : cellIds)
185 {
186 const cellModel& model = shapes[id].model();
187
188 elemType etype(elemType::NFACED);
189 if (model == tet)
190 {
191 etype = elemType::TETRA4;
192 }
193 else if (model == pyr)
194 {
195 etype = elemType::PYRAMID5;
196 }
197 else if (model == prism)
198 {
199 etype = elemType::PENTA6;
200 }
201 else if (model == hex)
202 {
203 etype = elemType::HEXA8;
204 }
205
206 ++sizes_[etype];
207 }
208
209 resizeAll(); // adjust allocation
210 sizes_ = Zero; // reset sizes - use for local indexing here
211
212
213 // Pass 2: Assign cell-id per shape type
214
215 for (const label id : cellIds)
216 {
217 const cellModel& model = shapes[id].model();
218
219 elemType etype(elemType::NFACED);
220 if (model == tet)
221 {
222 etype = elemType::TETRA4;
223 }
224 else if (model == pyr)
225 {
226 etype = elemType::PYRAMID5;
227 }
228 else if (model == prism)
229 {
230 etype = elemType::PENTA6;
231 }
232 else if (model == hex)
233 {
234 etype = elemType::HEXA8;
236
237 add(etype, id);
238 }
239}
240
241
243{
244 // All mesh cells
245 classifyImpl(mesh, labelRange(mesh.nCells()));
246}
247
248
250(
251 const polyMesh& mesh,
253)
254{
255 classifyImpl(mesh, cellIds);
256}
257
258
260(
261 const polyMesh& mesh,
262 const bitSet& selection
263)
264{
265 classifyImpl(mesh, selection);
266}
267
268
269void Foam::ensightCells::writeDict(Ostream& os, const bool full) const
270{
271 os.beginBlock(type());
272
273 os.writeEntry("id", index()+1); // Ensight starts with 1
274 os.writeEntry("name", name());
275 os.writeEntry("size", size());
276
277 if (full)
278 {
279 for (int typei=0; typei < ensightCells::nTypes; ++typei)
280 {
281 const auto etype = ensightCells::elemType(typei);
282
283 os.writeKeyword(ensightCells::key(etype));
284
285 cellIds(etype).writeList(os, 0) << endEntry; // Flat output
286 }
287 }
288
289 os.endBlock();
290}
291
292
293// ************************************************************************* //
scalar range
label n
A 1D vector of objects of type <T> with a fixed length <N>.
Definition FixedList.H:73
bool empty() const noexcept
True if range is empty (zero-sized).
Definition IntRange.H:198
void resize(const label len)
Adjust allocated size of list.
Definition ListI.H:153
static FOAM_NO_DANGLING_REFERENCE const manifoldCellsMeshObject & New(const polyMesh &mesh, Args &&... args)
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
A non-owning sub-view of a List (allocated or unallocated storage).
Definition SubList.H:61
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
Maps a geometry to a set of cell primitives.
Definition cellModel.H:73
static const cellModel & ref(const modelType model)
Look up reference to cellModel by enumeration. Fatal on failure.
Definition cellModels.C:150
Sorting/classification of cells (3D) into corresponding ensight element types.
static const char * key(const elemType etype) noexcept
The ensight element name for the specified 'Cell' type.
label totalSize() const noexcept
The global size of all element types.
void reduce()
Sum element counts across all processes.
void sort()
Sort element lists numerically.
void classify(const polyMesh &mesh)
Classify cell types and set the element lists.
static constexpr int nTypes
Number of 'Cell' element types (5).
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.
ensightCells()
Default construct, with part index 0.
static const char * elemNames[nTypes]
The ensight 'Cell' element type names.
elemType
Supported ensight 'Cell' element types.
void clear()
Set addressable sizes to zero, free up addressing memory.
FixedList< label, nTypes > sizes() const
Processor-local sizes per element type.
const labelList & cellIds() const
Processor-local cell ids of all elements.
void clearOut()
Clear any demand-driven data.
void rename(const string &value)
Change the part name or description.
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 range or interval of labels defined by a start and a size.
Definition labelRange.H:66
bool manifold() const
True if any manifold cells detected (globally) Triggers demand-driven filtering if required.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
const cellShapeList & cellShapes() const
Return cell shapes.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
auto & name
Namespace for OpenFOAM.
IOstream & hex(IOstream &io)
Definition IOstream.H:579
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)
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
void sort(UList< T > &list)
Sort the list.
Definition UList.C:283
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
List< cellShape > cellShapeList
List of cellShape.