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-2021 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>
35 void Foam::MeshedSurface<Face>::checkZones(const bool verbose)
36 {
37  auto& zones = this->storedZones();
38 
39  // Check that zones (if any) they cover the faces
40  // - fix the start silently
41 
42  bool zonesTooBig(false);
43 
44  const label maxCount = this->size();
45 
46  label start = 0;
47  for (surfZone& zn : zones)
48  {
49  zn.start() = start;
50  start += zn.size();
51  if (start > maxCount)
52  {
53  zonesTooBig = true; // Zones exceed what is required
54  zn.size() = (maxCount - zn.start());
55  start = (zn.start() + zn.size());
56  }
57  }
58 
59  if (!zones.empty())
60  {
61  surfZone& zn = zones.last();
62 
63  if ((zn.start() + zn.size()) < maxCount)
64  {
65  // Zones address less than expected - extend final zone
66  zn.size() += maxCount - zn.start();
67 
68  if (verbose)
69  {
71  << "Surface has more faces " << maxCount
72  << " than zone addressing ... extending final zone" << nl;
73  }
74  }
75  else if (zonesTooBig)
76  {
77  if (verbose)
78  {
80  << "Surface has more zone addressing than faces "
81  << maxCount
82  << " ... trucated/resized accordingly" << nl;
83  }
84  }
85  }
86 }
87 
88 
89 template<class Face>
91 (
92  DynamicList<Face>& unsortedFaces,
93  DynamicList<label>& zoneIds,
94  DynamicList<label>& elemIds,
95  bool sorted
96 )
97 {
98  // Basic sanity check
99  const label nInputFaces = unsortedFaces.size();
100 
101  if (sorted || zoneIds.size() != nInputFaces)
102  {
103  // Sorting not required or not possible
104  zoneIds.clear();
105  sorted = true;
106  }
107 
108  if (elemIds.size() != nInputFaces)
109  {
110  elemIds.clear();
111  }
112 
113  if (sorted)
114  {
115  // No additional sorting required
116  this->storedFaces().transfer(unsortedFaces);
117  this->storedFaceIds().transfer(elemIds);
118  return;
119  }
120 
121  // The sorted order, based on zone-ids
122 
124  Foam::sortedOrder(zoneIds, faceMap);
125  zoneIds.clear();
126 
127  auto& newFaces = this->storedFaces();
128  newFaces.resize(nInputFaces);
129 
130  // Faces in sorted order
131  forAll(newFaces, facei)
132  {
133  // Can use transfer, faceMap is unique
134  newFaces[facei].transfer(unsortedFaces[faceMap[facei]]);
135  }
136 
137  auto& newFaceIds = this->storedFaceIds();
138  newFaceIds.resize(elemIds.size());
139 
140  // Element ids in sorted order
141  forAll(newFaceIds, facei)
142  {
143  newFaceIds[facei] = elemIds[faceMap[facei]];
144  }
145 }
146 
147 
148 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
149 
150 template<class Face>
152 (
153  const UList<surfZone>& srfZones,
154  const bool cullEmpty
155 )
156 {
157  auto& zones = this->storedZones();
158  zones.resize(zones.size());
159 
160  label nZone = 0;
161 
162  forAll(zones, zonei)
163  {
164  if (srfZones[zonei].size() || !cullEmpty)
165  {
166  zones[nZone] = surfZone(srfZones[zonei], nZone);
167  ++nZone;
168  }
169  }
170 
171  zones.resize(nZone);
172 }
173 
174 
175 template<class Face>
177 (
178  const labelUList& sizes,
179  const UList<word>& names,
180  const bool cullEmpty
181 )
182 {
183  auto& zones = this->storedZones();
184  zones.resize(sizes.size());
185 
186  label start = 0;
187  label nZone = 0;
188 
189  forAll(zones, zonei)
190  {
191  if (sizes[zonei] || !cullEmpty)
192  {
193  zones[nZone] = surfZone
194  (
195  names[zonei],
196  sizes[zonei],
197  start,
198  nZone
199  );
200  start += sizes[zonei];
201  ++nZone;
202  }
203  }
204 
205  zones.resize(nZone);
206 }
207 
208 
209 template<class Face>
211 (
212  const labelUList& sizes,
213  const bool cullEmpty
214 )
215 {
216  auto& zones = this->storedZones();
217  zones.resize(sizes.size());
218 
219  label start = 0;
220  label nZone = 0;
221 
222  forAll(zones, zonei)
223  {
224  if (sizes[zonei] || !cullEmpty)
225  {
226  zones[nZone] = surfZone
227  (
228  surfZone::defaultName(nZone),
229  sizes[zonei],
230  start,
231  nZone
232  );
233  start += sizes[zonei];
234  ++nZone;
235  }
236  }
237 
238  zones.resize(nZone);
239 }
240 
241 
242 template<class Face>
244 {
245  // Normally a no-op, only the specializations are used.
246  return false;
247 }
248 
249 
250 template<class Face>
252 {
253  this->storedZones().clear();
254 }
255 
256 
257 // ************************************************************************* //
Foam::surfZone::start
label start() const
The start label of this zone in the face list.
Definition: surfZone.H:128
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeTopological.C:94
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::DynamicList::clear
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:391
Foam::MeshedSurface::addZonesToFaces
bool addZonesToFaces()
Propagate zone information on face regions.
Definition: MeshedSurfaceZones.C:243
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::MeshedSurface::checkZones
void checkZones(const bool verbose=true)
Sanity check/resizing on zones.
Definition: MeshedSurfaceZones.C:35
Foam::MeshedSurface::addZones
virtual void addZones(const UList< surfZone > &, const bool cullEmpty=false)
Add surface zones.
Definition: MeshedSurfaceZones.C:152
Foam::MeshedSurface::removeZones
virtual void removeZones()
Remove surface zones.
Definition: MeshedSurfaceZones.C:251
Foam::surfZone::size
label size() const
The size of this zone in the face list.
Definition: surfZone.H:140
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::MeshedSurface::sortFacesAndStore
void sortFacesAndStore(DynamicList< Face > &unsortedFaces, DynamicList< label > &zoneIds, DynamicList< label > &elemIds, bool sorted)
Sort faces by zones and store sorted faces.
Definition: MeshedSurfaceZones.C:91
Foam::List< label >
Foam::surfZone
A surface zone on a MeshedSurface.
Definition: surfZone.H:56
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
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::UList::size
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Foam::PtrListOps::names
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
MeshedSurface.H