MeshedSurfaceZones.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "MeshedSurface.H"
27 
28 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
29 
30 template<class Face>
32 {
33  // extra safety, ensure we have at some zones
34  // and they cover all the faces - fix start silently
35  surfZoneList& zones = this->storedZones();
36  if (zones.size())
37  {
38  label count = 0;
39  forAll(zones, zoneI)
40  {
41  zones[zoneI].start() = count;
42  count += zones[zoneI].size();
43  }
44 
45  if (count < this->size())
46  {
48  << "more faces " << this->size() << " than zones " << count
49  << " ... extending final zone"
50  << endl;
51 
52  zones.last().size() += count - this->size();
53  }
54  else if (count > this->size())
55  {
57  << "more zones " << count << " than faces " << this->size()
58  << exit(FatalError);
59  }
60  }
61 }
62 
63 
64 template<class Face>
66 (
67  List<Face>&& unsortedFaces,
68  List<label>&& zoneIds,
69  const bool sorted
70 )
71 {
72  List<Face> oldFaces(unsortedFaces);
73  List<label> zones(zoneIds);
74 
75  if (sorted)
76  {
77  // already sorted - simply transfer faces
78  this->storedFaces().transfer(oldFaces);
79  }
80  else
81  {
82  // unsorted - determine the sorted order:
83  // avoid SortableList since we discard the main list anyhow
85  sortedOrder(zones, faceMap);
86  zones.clear();
87 
88  // sorted faces
89  List<Face> newFaces(faceMap.size());
90  forAll(faceMap, facei)
91  {
92  // use transfer to recover memory where possible
93  newFaces[facei].transfer(oldFaces[faceMap[facei]]);
94  }
95  this->storedFaces().transfer(newFaces);
96  }
97  zones.clear();
98 }
99 
100 
101 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
102 
103 template<class Face>
105 (
106  const UList<surfZone>& srfZones,
107  const bool cullEmpty
108 )
109 {
110  label nZone = 0;
111 
112  surfZoneList& zones = this->storedZones();
113  zones.setSize(zones.size());
114  forAll(zones, zoneI)
115  {
116  if (srfZones[zoneI].size() || !cullEmpty)
117  {
118  zones[nZone] = surfZone(srfZones[zoneI], nZone);
119  nZone++;
120  }
121  }
122  zones.setSize(nZone);
123 }
124 
125 
126 template<class Face>
128 (
129  const labelUList& sizes,
130  const UList<word>& names,
131  const bool cullEmpty
132 )
133 {
134  label start = 0;
135  label nZone = 0;
136 
137  surfZoneList& zones = this->storedZones();
138  zones.setSize(sizes.size());
139  forAll(zones, zoneI)
140  {
141  if (sizes[zoneI] || !cullEmpty)
142  {
143  zones[nZone] = surfZone
144  (
145  names[zoneI],
146  sizes[zoneI],
147  start,
148  nZone
149  );
150  start += sizes[zoneI];
151  nZone++;
152  }
153  }
154  zones.setSize(nZone);
155 }
156 
157 
158 template<class Face>
160 (
161  const labelUList& sizes,
162  const bool cullEmpty
163 )
164 {
165  label start = 0;
166  label nZone = 0;
167 
168  surfZoneList& zones = this->storedZones();
169  zones.setSize(sizes.size());
170  forAll(zones, zoneI)
171  {
172  if (sizes[zoneI] || !cullEmpty)
173  {
174  zones[nZone] = surfZone
175  (
176  word("zone") + ::Foam::name(nZone),
177  sizes[zoneI],
178  start,
179  nZone
180  );
181  start += sizes[zoneI];
182  nZone++;
183  }
184  }
185  zones.setSize(nZone);
186 }
187 
188 
189 template<class Face>
191 {
192  this->storedZones().clear();
193 }
194 
195 
196 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
void setSize(const label)
Reset size of List.
Definition: List.C:281
virtual void addZones(const UList< surfZone > &, const bool cullEmpty=false)
Add surface zones.
void sortFacesAndStore(List< Face > &&unsortedFaces, List< label > &&zoneIds, const bool sorted)
Sort faces by zones and store sorted faces.
virtual void removeZones()
Remove surface zones.
void checkZones()
Basic sanity check on zones.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
T & last()
Return the last element of the list.
Definition: UListI.H:128
A surface zone on a MeshedSurface.
Definition: surfZone.H:65
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
#define WarningInFunction
Report a warning using Foam::Warning.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
error FatalError
label count(const ListType &l, typename ListType::const_reference x)
Count the number of occurrences of a value in a list.
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.