Loading...
Searching...
No Matches
setToPointZone.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 "setToPointZone.H"
30#include "polyMesh.H"
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36namespace Foam
37{
41
44}
45
46
47Foam::topoSetSource::addToUsageTable Foam::setToPointZone::usage_
48(
49 setToPointZone::typeName,
50 "\n Usage: setToPointZone <pointSet>\n\n"
51 " Select all points in the pointSet.\n\n"
52);
53
54
55// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56
58(
59 const polyMesh& mesh,
60 const word& setName
62:
64 setName_(setName)
65{}
66
67
69(
70 const polyMesh& mesh,
71 const dictionary& dict
73:
75 setName_(dict.get<word>("set"))
76{}
77
78
80(
81 const polyMesh& mesh,
82 Istream& is
83)
84:
86 setName_(checkIs(is))
87{}
88
89
90// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
91
93(
94 const topoSetSource::setAction action,
95 topoSet& set
96) const
97{
98 if (!isA<pointZoneSet>(set))
99 {
101 << "Operation only allowed on a pointZoneSet." << endl;
102 return;
103 }
104 else
105 {
106 pointZoneSet& zoneSet = refCast<pointZoneSet>(set);
107
108 if (action == topoSetSource::ADD || action == topoSetSource::NEW)
109 {
110 if (verbose_)
111 {
112 Info<< " Adding all points from point set: "
113 << setName_ << " ..." << endl;
114 }
115
116 // Load the set
117 pointSet loadedSet(mesh_, setName_, IOobject::NO_REGISTER);
118 const labelHashSet& pointLabels = loadedSet;
119
120 // Start off from copy
121 DynamicList<label> newAddressing(zoneSet.addressing());
122
123 for (const label pointi : pointLabels)
124 {
125 if (!zoneSet.found(pointi))
126 {
127 newAddressing.push_back(pointi);
128 }
129 }
130
131 zoneSet.addressing().transfer(newAddressing);
132 zoneSet.updateSet();
133 }
134 else if (action == topoSetSource::SUBTRACT)
135 {
136 if (verbose_)
137 {
138 Info<< " Removing all points from point set: "
139 << setName_ << " ..." << endl;
140 }
141
142 // Load the set
143 pointSet loadedSet(mesh_, setName_, IOobject::NO_REGISTER);
144
145 // Start off empty
146 DynamicList<label> newAddressing(zoneSet.addressing().size());
147
148 for (const label pointi : zoneSet.addressing())
149 {
150 if (!loadedSet.found(pointi))
151 {
152 newAddressing.push_back(pointi);
153 }
154 }
155 zoneSet.addressing().transfer(newAddressing);
156 zoneSet.updateSet();
157 }
158 }
159}
160
161
162// ************************************************************************* //
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.
@ NO_REGISTER
Do not request registration (bool: false).
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition List.C:347
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A set of point labels.
Definition pointSet.H:50
Like pointSet but -reads data from pointZone -updates pointZone when writing.
const labelList & addressing() const noexcept
void updateSet()
Sort addressing and make pointSet part consistent with addressing.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
A topoSetSource to convert a pointSet to a pointZone (and associated pointSet).
setToPointZone(const polyMesh &mesh, const word &setName)
Construct from components.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
The topoSetPointZoneSource is a intermediate class for handling topoSet sources for selecting point z...
topoSetPointZoneSource(const polyMesh &mesh)
Construct from mesh.
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
setAction
Enumeration defining various actions.
@ SUBTRACT
Subtract elements from current set.
@ ADD
Add elements to current set.
@ NEW
Create a new set and ADD elements to it.
bool verbose_
Output verbosity (default: true).
const polyMesh & mesh() const noexcept
Reference to the mesh.
const polyMesh & mesh_
Reference to the mesh.
static Istream & checkIs(Istream &is)
Check state of stream.
General set of labels of mesh quantity (points, cells, faces).
Definition topoSet.H:63
virtual bool found(const label id) const
Has the given index?
Definition topoSet.C:539
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
#define WarningInFunction
Report a warning using Foam::Warning.
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
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
Definition typeInfo.H:87
labelList pointLabels(nPoints, -1)
dictionary dict