Loading...
Searching...
No Matches
pointZoneSet.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 "pointZoneSet.H"
30#include "mapPolyMesh.H"
31#include "polyMesh.H"
32#include "processorPolyPatch.H"
36// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37
38namespace Foam
39{
44}
45
46
47// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48
50{
51 Foam::sort(addressing_);
52
54 pointSet::reserve(addressing_.size());
55 pointSet::set(addressing_);
56}
57
58
59// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
60
62(
63 const polyMesh& mesh,
64 const word& name,
65 const label initialCapacity,
68:
69 pointSet(mesh, name, initialCapacity, wOpt), // Construct no-read
70 mesh_(mesh)
71{}
72
73
75(
76 const polyMesh& mesh,
77 const word& name,
80)
81:
82 pointZoneSet(mesh, name, label(0), wOpt) // Construct no-read
83{
84 const auto& zones = mesh.pointZones();
85 const auto* zonePtr = zones.cfindZone(name);
86
87 if (!zonePtr)
88 {
90 {
92 << "Zone named " << name << " not found. "
93 << "List of available zone names: " << zones.names() << nl
94 << exit(FatalError);
95 }
96 }
97 else if (IOobjectOption::isAnyRead(rOpt))
98 {
99 const auto& zn = *zonePtr;
100 addressing_ = zn;
102
103 updateSet();
104 check(mesh.nPoints());
105}
106
107
109(
110 const polyMesh& mesh,
111 const word& name,
112 const topoSet& set,
114)
115:
116 pointZoneSet(mesh, name, label(0), wOpt) // Construct no-read
117{
118 const auto* zonePtr = isA<pointZoneSet>(set);
119
120 if (zonePtr)
121 {
122 addressing_ = zonePtr->addressing();
123 }
124 else
125 {
126 addressing_ = set.sortedToc();
127 }
129 updateSet();
130}
131
132
133// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
134
135void Foam::pointZoneSet::invert(const label maxLen)
136{
137 // Count
138 label n = 0;
139
140 for (label id = 0; id < maxLen; ++id)
141 {
142 if (!found(id))
143 {
144 ++n;
145 }
146 }
147
148 // Fill
149 addressing_.resize_nocopy(n);
150 n = 0;
151
152 for (label id = 0; id < maxLen; ++id)
153 {
154 if (!found(id))
155 {
156 addressing_[n] = id;
157 ++n;
158 }
159 }
160 updateSet();
161}
162
163
164void Foam::pointZoneSet::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::pointZoneSet::subset(const topoSet& set)
182{
183 const auto* zonePtr = isA<pointZoneSet>(set);
184
185 if (zonePtr)
186 {
187 // Is a pointZoneSet
188 this->subset(zonePtr->addressing());
189 }
190 else
192 // Assume a pointSet
194 }
195}
196
197
198void Foam::pointZoneSet::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::pointZoneSet::addSet(const topoSet& set)
216{
217 const auto* zonePtr = isA<pointZoneSet>(set);
218
219 if (zonePtr)
220 {
221 // Is a pointZoneSet
222 this->addSet(zonePtr->addressing());
223 }
224 else
226 // Assume a pointSet
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::pointZoneSet::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 // Retain if not in the topoSet (parameter)
261 newAddressing.push_back(id);
262 }
264
265 addressing_.transfer(newAddressing);
266 updateSet();
267}
268
269
270void Foam::pointZoneSet::sync(const polyMesh& mesh)
271{
274 // Take over contents of pointSet into addressing.
275 addressing_ = sortedToc();
276 updateSet();
277}
278
280Foam::label Foam::pointZoneSet::maxSize(const polyMesh& mesh) const
281{
282 return mesh.nPoints();
283}
284
285
287(
288 IOstreamOption streamOpt,
289 const bool writeOnProc
290) const
291{
292 // Write shadow pointSet
293 const word oldTypeName = typeName;
294 const_cast<word&>(type()) = pointSet::typeName;
295 bool ok = pointSet::writeObject(streamOpt, writeOnProc);
296 const_cast<word&>(type()) = oldTypeName;
297
298 // Modify pointZone
299 auto& zones = const_cast<polyMesh&>(mesh_).pointZones();
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::pointZoneSet::updateMesh(const mapPolyMesh& morphMap)
323{
324 DynamicList<label> newAddressing(addressing_.size());
325
326 for (const label pointi : addressing_)
327 {
328 const label newPointi = morphMap.reversePointMap()[pointi];
329 if (newPointi >= 0)
330 {
331 newAddressing.push_back(newPointi);
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 pointSet::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
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const labelList & reversePointMap() const noexcept
Reverse point map.
pointSet(const IOobject &io)
Construct from IOobject.
Definition pointSet.C:42
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches. Adds coupled points to set.
Definition pointSet.C:153
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition pointSet.C:240
Like pointSet but -reads data from pointZone -updates pointZone when writing.
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write pointZone using stream options.
virtual void invert(const label maxLen)
Invert contents.
pointZoneSet(const polyMesh &mesh, const word &name, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, IOobjectOption::writeOption wOpt=IOobjectOption::NO_WRITE)
Construct from objectRegistry and name.
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
virtual void sync(const polyMesh &mesh)
Sync pointZoneSet across coupled patches.
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.
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 pointSet part consistent with addressing.
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
label newPointi