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-2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 const char* Foam::ensightCells::elemNames[5] =
37  { "tetra4", "pyramid5", "penta6", "hexa8", "nfaced" };
38 
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
42 void Foam::ensightCells::resizeAll()
43 {
44  // overall required size
45  label n = 0;
46  forAll(sizes_, typei)
47  {
48  n += sizes_[typei];
49  }
50  address_.setSize(n, Zero);
51 
52  // assign corresponding sub-lists
53  n = 0;
54  forAll(sizes_, typei)
55  {
56  slices_[typei].setStart(n);
57  slices_[typei].setSize(sizes_[typei]);
58 
59  n += sizes_[typei];
60  }
61 }
62 
63 
64 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
65 
67 :
68  ensightCells(0)
69 {}
70 
71 
73 :
74  index_(partIndex),
75  address_(),
76  slices_(),
77  sizes_(Zero)
78 {
79  resizeAll(); // adjust allocation/sizing
80 }
81 
82 
84 :
85  index_(obj.index_),
86  address_(obj.address_),
87  slices_(),
88  sizes_()
89 {
90  // Save the total (reduced) sizes
91  FixedList<label, 5> totSizes = obj.sizes_;
92 
93  // Need local sizes for the resize operation
94  this->sizes_ = obj.sizes();
95 
96  resizeAll(); // Adjust allocation/sizing
97 
98  // Restore total (reduced) sizes
99  this->sizes_ = totSizes;
100 }
101 
102 
103 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
104 
106 {
108  forAll(slices_, typei)
109  {
110  count[typei] = slices_[typei].size();
111  }
112 
113  return count;
114 }
115 
116 
118 {
119  label n = 0;
120  forAll(sizes_, typei)
121  {
122  n += sizes_[typei];
123  }
124  return n;
125 }
126 
127 
129 {
130  sizes_ = Zero; // reset sizes
131  resizeAll();
132 }
133 
134 
136 {
137  // No listCombineGather, listCombineScatter for FixedList
138  forAll(sizes_, typei)
139  {
140  sizes_[typei] = slices_[typei].size();
141  Foam::reduce(sizes_[typei], sumOp<label>());
142  }
143 }
144 
145 
147 {
148  forAll(slices_, typei)
149  {
150  if (slices_[typei].size())
151  {
152  SubList<label> idLst(address_, slices_[typei]);
153  Foam::sort(idLst);
154  }
155  }
156 }
157 
158 
159 template<class Addressing>
160 void Foam::ensightCells::classifyImpl
161 (
162  const polyMesh& mesh,
163  const Addressing& cellIds
164 )
165 {
166  // References to cell shape models
169  const cellModel& prism = cellModel::ref(cellModel::PRISM);
171 
172  const cellShapeList& shapes = mesh.cellShapes();
173 
174  // Pass 1: Count the shapes
175 
176  sizes_ = Zero; // reset sizes
177  for (const label id : cellIds)
178  {
179  const cellModel& model = shapes[id].model();
180 
181  enum elemType what = NFACED;
182  if (model == tet)
183  {
184  what = TETRA4;
185  }
186  else if (model == pyr)
187  {
188  what = PYRAMID5;
189  }
190  else if (model == prism)
191  {
192  what = PENTA6;
193  }
194  else if (model == hex)
195  {
196  what = HEXA8;
197  }
198 
199  sizes_[what]++;
200  }
201 
202  resizeAll(); // adjust allocation
203  sizes_ = Zero; // reset sizes - use for local indexing here
204 
205  // Pass 2: Assign cell-id per shape type
206 
207  for (const label id : cellIds)
208  {
209  const cellModel& model = shapes[id].model();
210 
211  enum elemType what = NFACED;
212  if (model == tet)
213  {
214  what = TETRA4;
215  }
216  else if (model == pyr)
217  {
218  what = PYRAMID5;
219  }
220  else if (model == prism)
221  {
222  what = PENTA6;
223  }
224  else if (model == hex)
225  {
226  what = HEXA8;
227  }
228 
229  // eg, the processor local cellId
230  labelUList slice = address_[slices_[what]];
231 
232  slice[sizes_[what]] = id;
233  sizes_[what]++;
234  }
235 }
236 
237 
239 {
240  // All mesh cells
241  classifyImpl(mesh, labelRange::identity(mesh.nCells()));
242 }
243 
244 
246 (
247  const polyMesh& mesh,
248  const labelUList& cellIds
249 )
250 {
251  classifyImpl(mesh, cellIds);
252 }
253 
254 
256 (
257  const polyMesh& mesh,
258  const bitSet& selection
259 )
260 {
261  classifyImpl(mesh, selection);
262 }
263 
264 
265 // ************************************************************************* //
Foam::ensightCells::elemNames
static const char * elemNames[5]
The ensight element type names.
Definition: ensightCells.H:73
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::cellModel::HEX
hex
Definition: cellModel.H:81
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Foam::ensightCells::sort
void sort()
Sort element lists numerically.
Definition: ensightCells.C:146
polyMesh.H
bitSet.H
Foam::cellModel::TET
tet
Definition: cellModel.H:85
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::sumOp
Definition: ops.H:213
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:51
Foam::primitiveMesh::nCells
label nCells() const
Number of mesh cells.
Definition: primitiveMeshI.H:96
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
error.H
Foam::ensightCells::ensightCells
ensightCells()
Construct null, with part index 0.
Definition: ensightCells.C:66
cellModel.H
Foam::sort
void sort(UList< T > &a)
Definition: UList.C:241
Foam::cellModel::PRISM
prism
Definition: cellModel.H:83
Foam::ensightCells::total
label total() const
The global number of all element types.
Definition: ensightCells.C:117
Foam::ensightCells
Sorting/classification of cells (3D) into corresponding ensight element types.
Definition: ensightCells.H:53
Foam::cellModel::ref
static const cellModel & ref(const modelType model)
Look up reference to cellModel by enumeration. Fatal on failure.
Definition: cellModels.C:157
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::primitiveMesh::cellShapes
const cellShapeList & cellShapes() const
Return cell shapes.
Definition: primitiveMesh.C:316
Foam::hex
IOstream & hex(IOstream &io)
Definition: IOstream.H:429
Foam::cellModel::PYR
pyr
Definition: cellModel.H:84
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:74
Foam::List< cellShape >
Foam::FixedList< label, 5 >
Foam::UList< label >
Foam::labelRange::identity
static labelRange identity(const label len, const label start=0) noexcept
Definition: labelRangeI.H:179
Foam::cellModel
Maps a geometry to a set of cell primitives.
Definition: cellModel.H:72
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:79
Foam::ensightCells::classify
void classify(const polyMesh &mesh)
Classify cell types and set the element lists.
Definition: ensightCells.C:238
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::ensightCells::sizes
FixedList< label, 5 > sizes() const
The processor local sizes per element type.
Definition: ensightCells.C:105
Foam::ensightCells::reduce
void reduce()
Sum element counts across all processes.
Definition: ensightCells.C:135
Foam::ensightCells::clear
void clear()
Set addressable sizes to zero, free up addressing memory.
Definition: ensightCells.C:128
ensightCells.H