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 | Copyright (C) 2011 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  {
47  WarningIn
48  (
49  "MeshedSurface::checkZones()\n"
50  )
51  << "more faces " << this->size() << " than zones " << count
52  << " ... extending final zone"
53  << endl;
54 
55  zones.last().size() += count - this->size();
56  }
57  else if (count > this->size())
58  {
60  (
61  "MeshedSurface::checkZones()\n"
62  )
63  << "more zones " << count << " than faces " << this->size()
64  << exit(FatalError);
65  }
66  }
67 }
68 
69 
70 template<class Face>
72 (
73  const Xfer<List<Face> >& unsortedFaces,
74  const Xfer<List<label> >& zoneIds,
75  const bool sorted
76 )
77 {
78  List<Face> oldFaces(unsortedFaces);
79  List<label> zones(zoneIds);
80 
81  if (sorted)
82  {
83  // already sorted - simply transfer faces
84  this->storedFaces().transfer(oldFaces);
85  }
86  else
87  {
88  // unsorted - determine the sorted order:
89  // avoid SortableList since we discard the main list anyhow
91  sortedOrder(zones, faceMap);
92  zones.clear();
93 
94  // sorted faces
95  List<Face> newFaces(faceMap.size());
96  forAll(faceMap, faceI)
97  {
98  // use transfer to recover memory where possible
99  newFaces[faceI].transfer(oldFaces[faceMap[faceI]]);
100  }
101  this->storedFaces().transfer(newFaces);
102  }
103  zones.clear();
104 }
105 
106 
107 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
108 
109 template<class Face>
111 (
112  const UList<surfZone>& srfZones,
113  const bool cullEmpty
114 )
115 {
116  label nZone = 0;
117 
118  surfZoneList& zones = this->storedZones();
119  zones.setSize(zones.size());
120  forAll(zones, zoneI)
121  {
122  if (srfZones[zoneI].size() || !cullEmpty)
123  {
124  zones[nZone] = surfZone(srfZones[zoneI], nZone);
125  nZone++;
126  }
127  }
128  zones.setSize(nZone);
129 }
130 
131 
132 template<class Face>
134 (
135  const labelUList& sizes,
136  const UList<word>& names,
137  const bool cullEmpty
138 )
139 {
140  label start = 0;
141  label nZone = 0;
142 
143  surfZoneList& zones = this->storedZones();
144  zones.setSize(sizes.size());
145  forAll(zones, zoneI)
146  {
147  if (sizes[zoneI] || !cullEmpty)
148  {
149  zones[nZone] = surfZone
150  (
151  names[zoneI],
152  sizes[zoneI],
153  start,
154  nZone
155  );
156  start += sizes[zoneI];
157  nZone++;
158  }
159  }
160  zones.setSize(nZone);
161 }
162 
163 
164 template<class Face>
166 (
167  const labelUList& sizes,
168  const bool cullEmpty
169 )
170 {
171  label start = 0;
172  label nZone = 0;
173 
174  surfZoneList& zones = this->storedZones();
175  zones.setSize(sizes.size());
176  forAll(zones, zoneI)
177  {
178  if (sizes[zoneI] || !cullEmpty)
179  {
180  zones[nZone] = surfZone
181  (
182  word("zone") + ::Foam::name(nZone),
183  sizes[zoneI],
184  start,
185  nZone
186  );
187  start += sizes[zoneI];
188  nZone++;
189  }
190  }
191  zones.setSize(nZone);
192 }
193 
194 
195 template<class Face>
197 {
198  this->storedZones().clear();
199 }
200 
201 
202 // ************************************************************************* //
virtual void removeZones()
Remove surface zones.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
T & last()
Return the last element of the list.
Definition: UListI.H:131
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
void sortFacesAndStore(const Xfer< List< Face > > &unsortedFaces, const Xfer< List< label > > &zoneIds, const bool sorted)
Sort faces by zones and store sorted faces.
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
A class for handling words, derived from string.
Definition: word.H:59
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
void clear()
Clear the list, i.e. set size to zero.
Definition: List.C:379
void setSize(const label)
Reset size of List.
Definition: List.C:318
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define WarningIn(functionName)
Report a warning using Foam::Warning.
#define forAll(list, i)
Definition: UList.H:421
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
A surface zone on a MeshedSurface.
Definition: surfZone.H:62
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
virtual void addZones(const UList< surfZone > &, const bool cullEmpty=false)
Add surface zones.
void checkZones()
Basic sanity check on zones.
error FatalError
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:60