Loading...
Searching...
No Matches
cellZoneSet.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-2017 OpenFOAM Foundation
9 Copyright (C) 2018-2024 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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 "cellZoneSet.H"
30#include "mapPolyMesh.H"
31#include "polyMesh.H"
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36
37namespace Foam
38{
43}
44
45
46// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47
49{
50 Foam::sort(addressing_);
51
53 cellSet::reserve(addressing_.size());
54 cellSet::set(addressing_);
55}
56
57
58// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
59
61(
62 const polyMesh& mesh,
63 const word& name,
64 const label initialCapacity,
67:
68 cellSet(mesh, name, initialCapacity, wOpt), // Construct no-read
69 mesh_(mesh)
70{}
71
72
74(
75 const polyMesh& mesh,
76 const word& name,
79)
80:
81 cellZoneSet(mesh, name, label(0), wOpt) // Construct no-read
82{
83 const auto& zones = mesh.cellZones();
84 const auto* zonePtr = zones.cfindZone(name);
85
86 if (!zonePtr)
87 {
89 {
91 << "Zone named " << name << " not found. "
92 << "List of available zone names: " << zones.names() << nl
93 << exit(FatalError);
94 }
95 }
96 else if (IOobjectOption::isAnyRead(rOpt))
97 {
98 const auto& zn = *zonePtr;
99 addressing_ = zn;
101
102 updateSet();
103 check(mesh.nCells());
104}
105
106
108(
109 const polyMesh& mesh,
110 const word& name,
111 const topoSet& set,
113)
114:
115 cellZoneSet(mesh, name, label(0), wOpt) // Construct no-read
116{
117 const auto* zonePtr = isA<cellZoneSet>(set);
118
119 if (zonePtr)
120 {
121 addressing_ = zonePtr->addressing();
122 }
123 else
124 {
125 addressing_ = set.sortedToc();
126 }
128 updateSet();
129}
130
131
132// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
133
134void Foam::cellZoneSet::invert(const label maxLen)
135{
136 // Count
137 label n = 0;
138
139 for (label celli = 0; celli < maxLen; ++celli)
140 {
141 if (!found(celli))
142 {
143 ++n;
144 }
145 }
146
147 // Fill
148 addressing_.resize_nocopy(n);
149 n = 0;
150
151 for (label celli = 0; celli < maxLen; ++celli)
152 {
153 if (!found(celli))
154 {
155 addressing_[n] = celli;
156 ++n;
158 }
159
160 updateSet();
161}
162
163
164void Foam::cellZoneSet::subset(const labelUList& elems)
165{
166 DynamicList<label> newAddressing(addressing_.size());
167
168 for (const label id : elems)
169 {
170 if (found(id))
171 {
172 newAddressing.push_back(id);
173 }
175
176 addressing_.transfer(newAddressing);
177 updateSet();
178}
179
180
181void Foam::cellZoneSet::subset(const topoSet& set)
182{
183 const auto* zonePtr = isA<cellZoneSet>(set);
184
185 if (zonePtr)
186 {
187 // Is a cellZoneSet
188 this->subset(zonePtr->addressing());
189 }
190 else
192 // Assume a cellSet
194 }
195}
196
197
198void Foam::cellZoneSet::addSet(const labelUList& elems)
199{
200 DynamicList<label> newAddressing(addressing_);
201
202 for (const label id : elems)
203 {
204 if (!found(id))
205 {
206 newAddressing.push_back(id);
207 }
209
210 addressing_.transfer(newAddressing);
211 updateSet();
212}
213
214
215void Foam::cellZoneSet::addSet(const topoSet& set)
216{
217 const auto* zonePtr = isA<cellZoneSet>(set);
218
219 if (zonePtr)
220 {
221 // Is a cellZoneSet
222 this->addSet(zonePtr->addressing());
223 }
224 else
226 // Assume a cellSet
228 }
229}
230
231
233{
234 DynamicList<label> newAddressing(addressing_.size());
235
236 const labelHashSet set(elems);
237
238 for (const label id : addressing_)
239 {
240 if (!set.found(id))
241 {
242 // Retain if not in the topoSet (parameter)
243 newAddressing.push_back(id);
244 }
246
247 addressing_.transfer(newAddressing);
248 updateSet();
249}
250
251
252void Foam::cellZoneSet::subtractSet(const topoSet& set)
253{
254 DynamicList<label> newAddressing(addressing_.size());
255
256 for (const label id : addressing_)
257 {
258 if (!set.found(id))
259 {
260 // Not found in zoneSet so add
261 newAddressing.push_back(id);
262 }
264
265 addressing_.transfer(newAddressing);
266 updateSet();
267}
268
269
270void Foam::cellZoneSet::sync(const polyMesh& mesh)
271{
274 // Take over contents of cellSet into addressing.
275 addressing_ = sortedToc();
276 updateSet();
277}
278
280Foam::label Foam::cellZoneSet::maxSize(const polyMesh& mesh) const
281{
282 return mesh.nCells();
283}
284
285
287(
288 IOstreamOption streamOpt,
289 const bool writeOnProc
290) const
291{
292 // Write shadow cellSet
293 const word oldTypeName = typeName;
294 const_cast<word&>(type()) = cellSet::typeName;
295 bool ok = cellSet::writeObject(streamOpt, writeOnProc);
296 const_cast<word&>(type()) = oldTypeName;
297
298 // Modify cellZone
299 auto& zones = const_cast<polyMesh&>(mesh_).cellZones();
300 auto* zonePtr = zones.findZone(name());
301
302 if (zonePtr)
303 {
304 zonePtr->resetAddressing(addressing_);
305 }
306 else
307 {
308 zones.emplace_back
309 (
310 name(),
311 addressing_,
312 zones.size(), // zoneID
313 zones
314 );
316 zones.clearAddressing();
317
318 return ok && zones.write(writeOnProc);
319}
320
321
322void Foam::cellZoneSet::updateMesh(const mapPolyMesh& morphMap)
323{
324 DynamicList<label> newAddressing(addressing_.size());
325
326 for (const label celli : addressing_)
327 {
328 label newCelli = morphMap.reverseCellMap()[celli];
329 if (newCelli >= 0)
330 {
331 newAddressing.push_back(newCelli);
332 }
334
335 addressing_.transfer(newAddressing);
336 updateSet();
337}
338
339
341(
342 Ostream& os,
343 const primitiveMesh& mesh,
344 const label maxLen
345) const
346{
347 cellSet::writeDebug(os, mesh, maxLen);
348}
349
350
351// ************************************************************************* //
bool found
label n
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
void push_back(const T &val)
Copy append an element to the end of this list.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition HashTable.C:156
void reserve(label numEntries)
Reserve space for at least the specified number of elements (not the number of buckets) and regenerat...
Definition HashTable.C:729
void clearStorage()
Remove all entries from table and the table itself.
Definition HashTable.C:767
label size() const noexcept
The number of elements in table.
Definition HashTable.H:358
bool isAnyRead() const noexcept
True if any reading may be required (ie, != NO_READ).
static bool isReadRequired(readOption opt) noexcept
True if (MUST_READ | READ_MODIFIED) bits are set.
readOption
Enumeration defining read preferences.
writeOption
Enumeration defining write preferences.
static bool isAnyRead(readOption opt) noexcept
True if any reading may be required (ie, != NO_READ).
A simple container for options an IOstream can normally have.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
virtual void sync(const polyMesh &mesh)
Sync cellSet across coupled patches.
Definition cellSet.H:227
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition cellSet.C:256
Like cellSet but -reads data from cellZone -updates cellZone when writing.
Definition cellZoneSet.H:50
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write cellZone using stream options.
virtual void invert(const label maxLen)
Invert contents.
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
virtual void sync(const polyMesh &mesh)
Sync cellSet across coupled patches; update cellZone from cellSet.
virtual void subset(const labelUList &elems)
Subset contents. Only elements present in both sets remain.
virtual void subtractSet(const labelUList &elems)
Subtract given elements from the set.
cellZoneSet(const polyMesh &mesh, const word &name, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, IOobjectOption::writeOption wOpt=IOobjectOption::NO_WRITE)
Construct from objectRegistry and name.
Definition cellZoneSet.C:67
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels.
virtual void addSet(const labelUList &elems)
Add given elements to the set.
void updateSet()
Sort addressing and make cellSet part consistent with addressing.
Definition cellZoneSet.C:41
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const labelList & reverseCellMap() const noexcept
Reverse cell map.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
void clearAddressing(const bool isMeshUpdate=false)
Clear addressing.
Cell-face mesh analysis engine.
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options.
General set of labels of mesh quantity (points, cells, faces).
Definition topoSet.H:63
virtual bool set(const label id)
Set an index.
Definition topoSet.C:545
virtual void check(const label maxSize)
Check limits on addressable range.
Definition topoSet.C:252
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeName(Type)
Define the typeName.
Definition className.H:113
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
OBJstream os(runTime.globalPath()/outputName)
auto & name
Namespace for OpenFOAM.
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
Definition typeInfo.H:172
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition HashSet.H:85
List< T > subset(const BoolListType &select, const UList< T > &input, const bool invert=false)
Extract elements of the input list when select is true.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition POSIX.C:801
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
Definition typeInfo.H:87
void sort(UList< T > &list)
Sort the list.
Definition UList.C:283
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
UList< label > labelUList
A UList of labels.
Definition UList.H:75
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50