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-2020 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 
40  auto& zones = this->storedZones();
41 
42  label count = 0;
43  for (surfZone& zn : zones)
44  {
45  zn.start() = count;
46  count += zn.size();
47  }
48 
49  if (!zones.empty())
50  {
51  if (count < this->size())
52  {
54  << "more faces " << this->size() << " than zones " << count
55  << " ... extending final zone" << nl;
56 
57  zones.last().size() += count - this->size();
58  }
59  else if (count > this->size())
60  {
62  << "more zones " << count << " than faces " << this->size()
63  << exit(FatalError);
64  }
65  }
66 }
67 
68 
69 template<class Face>
71 (
72  DynamicList<Face>& unsortedFaces,
73  DynamicList<label>& zoneIds,
74  DynamicList<label>& elemIds,
75  bool sorted
76 )
77 {
78  // Basic sanity check
79  const label nInputFaces = unsortedFaces.size();
80 
81  if (sorted || zoneIds.size() != nInputFaces)
82  {
83  // Sorting not required or not possible
84  zoneIds.clear();
85  sorted = true;
86  }
87 
88  if (elemIds.size() != nInputFaces)
89  {
90  elemIds.clear();
91  }
92 
93  if (sorted)
94  {
95  // No additional sorting required
96  this->storedFaces().transfer(unsortedFaces);
97  this->storedFaceIds().transfer(elemIds);
98  return;
99  }
100 
101  // The sorted order, based on zone-ids
102 
104  Foam::sortedOrder(zoneIds, faceMap);
105  zoneIds.clear();
106 
107  auto& newFaces = this->storedFaces();
108  newFaces.resize(nInputFaces);
109 
110  // Faces in sorted order
111  forAll(newFaces, facei)
112  {
113  // Can use transfer, faceMap is unique
114  newFaces[facei].transfer(unsortedFaces[faceMap[facei]]);
115  }
116 
117  auto& newFaceIds = this->storedFaceIds();
118  newFaceIds.resize(elemIds.size());
119 
120  // Element ids in sorted order
121  forAll(newFaceIds, facei)
122  {
123  newFaceIds[facei] = elemIds[faceMap[facei]];
124  }
125 }
126 
127 
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129 
130 template<class Face>
132 (
133  const UList<surfZone>& srfZones,
134  const bool cullEmpty
135 )
136 {
137  auto& zones = this->storedZones();
138  zones.resize(zones.size());
139 
140  label nZone = 0;
141 
142  forAll(zones, zonei)
143  {
144  if (srfZones[zonei].size() || !cullEmpty)
145  {
146  zones[nZone] = surfZone(srfZones[zonei], nZone);
147  ++nZone;
148  }
149  }
150 
151  zones.resize(nZone);
152 }
153 
154 
155 template<class Face>
157 (
158  const labelUList& sizes,
159  const UList<word>& names,
160  const bool cullEmpty
161 )
162 {
163  auto& zones = this->storedZones();
164  zones.resize(sizes.size());
165 
166  label start = 0;
167  label nZone = 0;
168 
169  forAll(zones, zonei)
170  {
171  if (sizes[zonei] || !cullEmpty)
172  {
173  zones[nZone] = surfZone
174  (
175  names[zonei],
176  sizes[zonei],
177  start,
178  nZone
179  );
180  start += sizes[zonei];
181  ++nZone;
182  }
183  }
184 
185  zones.resize(nZone);
186 }
187 
188 
189 template<class Face>
191 (
192  const labelUList& sizes,
193  const bool cullEmpty
194 )
195 {
196  auto& zones = this->storedZones();
197  zones.resize(sizes.size());
198 
199  label start = 0;
200  label nZone = 0;
201 
202  forAll(zones, zonei)
203  {
204  if (sizes[zonei] || !cullEmpty)
205  {
206  zones[nZone] = surfZone
207  (
208  surfZone::defaultName(nZone),
209  sizes[zonei],
210  start,
211  nZone
212  );
213  start += sizes[zonei];
214  ++nZone;
215  }
216  }
217 
218  zones.resize(nZone);
219 }
220 
221 
222 template<class Face>
224 {
225  // Normally a no-op, only the specializations are used.
226  return false;
227 }
228 
229 
230 template<class Face>
232 {
233  this->storedZones().clear();
234 }
235 
236 
237 // ************************************************************************* //
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: 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::MeshedSurface::addZonesToFaces
bool addZonesToFaces()
Propagate zone information on face regions.
Definition: MeshedSurfaceZones.C:223
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::MeshedSurface::addZones
virtual void addZones(const UList< surfZone > &, const bool cullEmpty=false)
Add surface zones.
Definition: MeshedSurfaceZones.C:132
Foam::DynamicList::clear
void clear()
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:348
Foam::MeshedSurface::removeZones
virtual void removeZones()
Remove surface zones.
Definition: MeshedSurfaceZones.C:231
Foam::defaultName
static const word defaultName("coeffs")
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:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
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:71
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
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.
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:303
MeshedSurface.H