MeshedSurfaceZones.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "MeshedSurface.H"
30 #include "ListOps.H"
31 
32 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
33 
34 template<class Face>
36 {
37  // extra safety, ensure we have at some zones
38  // and they cover all the faces - fix start silently
39  surfZoneList& zones = this->storedZones();
40  if (zones.size())
41  {
42  label count = 0;
43  forAll(zones, zoneI)
44  {
45  zones[zoneI].start() = count;
46  count += zones[zoneI].size();
47  }
48 
49  if (count < this->size())
50  {
52  << "more faces " << this->size() << " than zones " << count
53  << " ... extending final zone"
54  << endl;
55 
56  zones.last().size() += count - this->size();
57  }
58  else if (count > this->size())
59  {
61  << "more zones " << count << " than faces " << this->size()
62  << exit(FatalError);
63  }
64  }
65 }
66 
67 
68 template<class Face>
70 (
71  DynamicList<Face>& unsortedFaces,
72  DynamicList<label>& zoneIds,
73  const bool sorted
74 )
75 {
76  List<Face> oldFaces(std::move(unsortedFaces));
77  List<label> zones(std::move(zoneIds));
78 
79  if (sorted)
80  {
81  // Already sorted - simply transfer faces
82  this->storedFaces().transfer(oldFaces);
83  zones.clear();
84  return;
85  }
86 
87  // Determine the sorted order:
88  // use sortedOrder directly since we discard the intermediate list anyhow
90  zones.clear();
91 
92  // Sorted faces
93  List<Face> newFaces(faceMap.size());
94  forAll(faceMap, facei)
95  {
96  // use transfer to recover memory where possible
97  newFaces[facei].transfer(oldFaces[faceMap[facei]]);
98  }
99  this->storedFaces().transfer(newFaces);
100 }
101 
102 
103 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
104 
105 template<class Face>
107 (
108  const UList<surfZone>& srfZones,
109  const bool cullEmpty
110 )
111 {
112  label nZone = 0;
113 
114  surfZoneList& zones = this->storedZones();
115  zones.setSize(zones.size());
116  forAll(zones, zoneI)
117  {
118  if (srfZones[zoneI].size() || !cullEmpty)
119  {
120  zones[nZone] = surfZone(srfZones[zoneI], nZone);
121  ++nZone;
122  }
123  }
124  zones.setSize(nZone);
125 }
126 
127 
128 template<class Face>
130 (
131  const labelUList& sizes,
132  const UList<word>& names,
133  const bool cullEmpty
134 )
135 {
136  label start = 0;
137  label nZone = 0;
138 
139  surfZoneList& zones = this->storedZones();
140  zones.setSize(sizes.size());
141  forAll(zones, zoneI)
142  {
143  if (sizes[zoneI] || !cullEmpty)
144  {
145  zones[nZone] = surfZone
146  (
147  names[zoneI],
148  sizes[zoneI],
149  start,
150  nZone
151  );
152  start += sizes[zoneI];
153  ++nZone;
154  }
155  }
156  zones.setSize(nZone);
157 }
158 
159 
160 template<class Face>
162 (
163  const labelUList& sizes,
164  const bool cullEmpty
165 )
166 {
167  label start = 0;
168  label nZone = 0;
169 
170  surfZoneList& zones = this->storedZones();
171  zones.setSize(sizes.size());
172  forAll(zones, zoneI)
173  {
174  if (sizes[zoneI] || !cullEmpty)
175  {
176  zones[nZone] = surfZone
177  (
178  word("zone") + ::Foam::name(nZone),
179  sizes[zoneI],
180  start,
181  nZone
182  );
183  start += sizes[zoneI];
184  ++nZone;
185  }
186  }
187  zones.setSize(nZone);
188 }
189 
190 
191 template<class Face>
193 {
194  // Normally a no-op, only the specializations are used.
195  return false;
196 }
197 
198 
199 template<class Face>
201 {
202  this->storedZones().clear();
203 }
204 
205 
206 // ************************************************************************* //
Foam::MeshedSurface::checkZones
void checkZones()
Basic sanity check on zones.
Definition: MeshedSurfaceZones.C:35
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:94
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:57
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::MeshedSurface::sortFacesAndStore
void sortFacesAndStore(DynamicList< Face > &unsortedFaces, DynamicList< label > &zoneIds, const bool sorted)
Sort faces by zones and store sorted faces.
Definition: MeshedSurfaceZones.C:70
Foam::MeshedSurface::addZonesToFaces
bool addZonesToFaces()
Propagate zone information on face regions.
Definition: MeshedSurfaceZones.C:192
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
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
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::MeshedSurface::addZones
virtual void addZones(const UList< surfZone > &, const bool cullEmpty=false)
Add surface zones.
Definition: MeshedSurfaceZones.C:107
Foam::MeshedSurface::removeZones
virtual void removeZones()
Remove surface zones.
Definition: MeshedSurfaceZones.C:200
Foam::FatalError
error FatalError
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
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< surfZone >
Foam::surfZone
A surface zone on a MeshedSurface.
Definition: surfZone.H:65
Foam::start
label ListType::const_reference const label start
Definition: ListOps.H:408
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::List::clear
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:115
Foam::UList::size
void size(const label n) noexcept
Override size to be inconsistent with allocated storage.
Definition: UListI.H:360
ListOps.H
Various functions to operate on Lists.
Foam::sortedOrder
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
MeshedSurface.H