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-2018 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 "ensightFaces.H"
29 #include "error.H"
30 #include "polyMesh.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 const char* Foam::ensightFaces::elemNames[3] =
35  { "tria3", "quad4", "nsided" };
36 
37 
38 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
39 
40 namespace
41 {
42 
43 // Simple shape classifier
44 static inline Foam::ensightFaces::elemType whatType(const Foam::face& f)
45 {
46  return
47  (
48  f.size() == 3
49  ? Foam::ensightFaces::elemType::TRIA3
50  : f.size() == 4
51  ? Foam::ensightFaces::elemType::QUAD4
52  : Foam::ensightFaces::elemType::NSIDED
53  );
54 }
55 
56 } // End anonymous namespace
57 
58 
59 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
60 
61 // Only used in this file-scope
62 inline void Foam::ensightFaces::add
63 (
64  const face& f,
65  const label id,
66  const bool flip
67 )
68 {
69  const enum elemType what = whatType(f);
70 
71  // linear addressing:
72  const label index = offset(what) + sizes_[what]++;
73 
74  address_[index] = id;
75  if (flipMap_.size())
76  {
77  flipMap_[index] = flip;
78  }
79 }
80 
81 
82 void Foam::ensightFaces::resizeAll()
83 {
84  // overall required size
85  label n = 0;
86  forAll(sizes_, typei)
87  {
88  n += sizes_[typei];
89  }
90  address_.setSize(n, Zero);
91 
92  // assign corresponding sub-lists
93  n = 0;
94  forAll(sizes_, typei)
95  {
96  slices_[typei].setStart(n);
97  slices_[typei].setSize(sizes_[typei]);
98 
99  n += sizes_[typei];
100  }
101 
102  // normally assume no flipMap
103  flipMap_.clear();
104 }
105 
106 
107 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
108 
110 :
111  ensightFaces(0)
112 {}
113 
114 
116 :
117  index_(partIndex),
118  address_(),
119  flipMap_(),
120  slices_(),
121  sizes_(Zero)
122 {
123  resizeAll(); // adjust allocation/sizing
124 }
125 
126 
128 :
129  index_(obj.index_),
130  address_(obj.address_),
131  flipMap_(obj.flipMap_),
132  slices_(),
133  sizes_()
134 {
135  // Save the total (reduced) sizes
136  FixedList<label, 3> totSizes = obj.sizes_;
137 
138  // Need local sizes for the resize operation
139  this->sizes_ = obj.sizes();
140 
141  resizeAll(); // adjust allocation/sizing
142 
143  // Restore total (reduced) sizes
144  this->sizes_ = totSizes;
145 }
146 
147 
148 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
149 
151 {
153  forAll(slices_, typei)
154  {
155  count[typei] = slices_[typei].size();
156  }
157 
158  return count;
159 }
160 
161 
163 {
164  label n = 0;
165  forAll(sizes_, typei)
166  {
167  n += sizes_[typei];
168  }
169  return n;
170 }
171 
172 
174 {
175  sizes_ = Zero; // reset sizes
176  resizeAll();
177 }
178 
179 
181 {
182  // No listCombineGather, listCombineScatter for FixedList
183  forAll(sizes_, typei)
184  {
185  sizes_[typei] = slices_[typei].size();
186  Foam::reduce(sizes_[typei], sumOp<label>());
187  }
188 }
189 
190 
192 {
193  if (flipMap_.size() == address_.size())
194  {
195  // Must sort flip map as well
196  labelList order;
197 
198  forAll(slices_, typei)
199  {
200  if (slices_[typei].size())
201  {
202  SubList<label> idLst(address_, slices_[typei]);
203  SubList<bool> flip(flipMap_, slices_[typei]);
204 
205  Foam::sortedOrder(idLst, order);
206 
207  idLst = reorder<labelList>(order, idLst);
208  flip = reorder<boolList>(order, flip);
209  }
210  }
211  }
212  else
213  {
214  // no flip-maps, simpler to sort
215  forAll(slices_, typei)
216  {
217  if (slices_[typei].size())
218  {
219  SubList<label> idLst(address_, slices_[typei]);
220  Foam::sort(idLst);
221  }
222  }
223 
224  flipMap_.clear(); // for extra safety
225  }
226 }
227 
228 
230 {
231  const label sz = faces.size();
232 
233  // Pass 1: Count the shapes
234 
235  sizes_ = Zero; // reset sizes
236  for (label listi = 0; listi < sz; ++listi)
237  {
238  const enum elemType what = whatType(faces[listi]);
239  sizes_[what]++;
240  }
241 
242  resizeAll(); // adjust allocation
243  sizes_ = Zero; // reset sizes - use for local indexing here
244 
245  // Pass 2: Assign face-id per shape type
246 
247  for (label listi = 0; listi < sz; ++listi)
248  {
249  add(faces[listi], listi);
250  }
251 }
252 
253 
255 (
256  const faceList& faces,
257  const labelUList& addressing,
258  const boolList& flipMap,
259  const bitSet& exclude
260 )
261 {
262  const label sz = addressing.size();
263  const bool useFlip = (addressing.size() == flipMap.size());
264 
265  // Pass 1: Count the shapes
266 
267  sizes_ = Zero; // reset sizes
268  for (label listi = 0; listi < sz; ++listi)
269  {
270  const label faceId = addressing[listi];
271 
272  if (!exclude.test(faceId))
273  {
274  const enum elemType what = whatType(faces[faceId]);
275  sizes_[what]++;
276  }
277  }
278 
279  resizeAll(); // adjust allocation
280  sizes_ = Zero; // reset sizes - use for local indexing here
281 
282  if (useFlip)
283  {
284  flipMap_.setSize(address_.size(), false);
285  flipMap_ = false;
286  }
287 
288  // Pass 2: Assign face-id per shape type
289 
290  for (label listi = 0; listi < sz; ++listi)
291  {
292  const label faceId = addressing[listi];
293  const bool doFlip = useFlip && flipMap[listi];
294 
295  if (!exclude.test(faceId))
296  {
297  add(faces[faceId], faceId, doFlip);
298  }
299  }
300 }
301 
302 // ************************************************************************* //
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
ensightFaces.H
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Foam::bitSet::test
bool test(const label pos) const
Test value at specified position, never auto-vivify entries.
Definition: bitSetI.H:512
polyMesh.H
Foam::ensightFaces
Sorting/classification of faces (2D) into corresponding ensight types.
Definition: ensightFaces.H:51
Foam::sumOp
Definition: ops.H:213
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::ensightFaces::total
label total() const
The global number of all element types.
Definition: ensightFaces.C:162
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::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::ensightFaces::reduce
void reduce()
Sum element counts across all processes.
Definition: ensightFaces.C:180
faceId
label faceId(-1)
Foam::sort
void sort(UList< T > &a)
Definition: UList.C:241
Foam::ensightFaces::sizes
FixedList< label, 3 > sizes() const
The processor local sizes per element type.
Definition: ensightFaces.C:150
Foam::ensightFaces::elemNames
static const char * elemNames[3]
The ensight element type names.
Definition: ensightFaces.H:69
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
Foam::ensightFaces::classify
void classify(const faceList &faces)
Classify the face types, set element list.
Definition: ensightFaces.C:229
Foam::ensightFaces::ensightFaces
ensightFaces()
Construct null, with part index 0.
Definition: ensightFaces.C:109
Foam::ensightFaces::offset
label offset(const enum elemType what) const
Processor local starting offset of element type.
Definition: ensightFacesI.H:74
Foam::ensightFaces::elemType
elemType
Addressable ensight element types.
Definition: ensightFaces.H:58
Foam::ensightFaces::index
label index() const
The index in a list.
Definition: ensightFacesI.H:38
f
labelList f(nPoints)
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< label >
Foam::ensightFaces::clear
void clear()
Set addressable sizes to zero, free up addressing memory.
Definition: ensightFaces.C:173
Foam::FixedList< label, 3 >
Foam::UList< label >
Foam::ensightFaces::sort
void sort()
Sort element lists numerically.
Definition: ensightFaces.C:191
Foam::UList::size
void size(const label n) noexcept
Override size to be inconsistent with allocated storage.
Definition: UListI.H:360
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:74
Foam::sortedOrder
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.