Loading...
Searching...
No Matches
setAndNormalToFaceZone.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) 2013-2016 OpenFOAM Foundation
9 Copyright (C) 2018-2020 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
30#include "polyMesh.H"
31#include "faceZoneSet.H"
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36namespace Foam
37{
43 (
46 word
47 );
49 (
53 );
54}
55
56
57Foam::topoSetSource::addToUsageTable Foam::setAndNormalToFaceZone::usage_
58(
59 setAndNormalToFaceZone::typeName,
60 "\n Usage: setAndNormalToFaceZone <faceSet> <normal>\n\n"
61 " Select all faces in the faceSet and orient using normal.\n\n"
62);
63
64
65// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
66
68(
69 const polyMesh& mesh,
70 const word& setName,
71 const vector& normal
72)
75 setName_(setName),
76 normal_(normal)
77{}
78
79
81(
82 const polyMesh& mesh,
83 const dictionary& dict
84)
87 setName_(dict.get<word>("faceSet")),
88 normal_(dict.get<vector>("normal"))
89{}
90
91
93(
94 const polyMesh& mesh,
95 Istream& is
96)
97:
99 setName_(checkIs(is)),
100 normal_(checkIs(is))
101{}
102
103
104// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
105
107(
108 const topoSetSource::setAction action,
109 topoSet& set
110) const
111{
112 if (!isA<faceZoneSet>(set))
113 {
115 << "Operation only allowed on a faceZoneSet." << endl;
116 return;
117 }
118 else
119 {
120 faceZoneSet& zoneSet = refCast<faceZoneSet>(set);
121
122 if (action == topoSetSource::ADD || action == topoSetSource::NEW)
123 {
124 if (verbose_)
125 {
126 Info<< " Adding all faces from face set: "
127 << setName_ << " ..." << endl;
128 }
129
130 // Load the sets
131 faceSet loadedSet(mesh_, setName_, IOobject::NO_REGISTER);
132 const labelHashSet& faceLabels = loadedSet;
133
134 // Start off from copy
135 DynamicList<label> newAddressing(zoneSet.addressing());
136 DynamicList<bool> newFlipMap(zoneSet.flipMap());
137
138 const faceList& faces = mesh_.faces();
139 const pointField& points = mesh_.points();
140
141 for (const label facei : faceLabels)
142 {
143 if (!zoneSet.found(facei))
144 {
145 newAddressing.append(facei);
146
147 const vector n = faces[facei].areaNormal(points);
148 if ((n & normal_) > 0)
149 {
150 newFlipMap.append(false);
151 }
152 else
153 {
154 newFlipMap.append(true);
155 }
156 }
157 }
158
159 zoneSet.addressing().transfer(newAddressing);
160 zoneSet.flipMap().transfer(newFlipMap);
161 zoneSet.updateSet();
162 }
163 else if (action == topoSetSource::SUBTRACT)
164 {
165 if (verbose_)
166 {
167 Info<< " Removing all faces from face set: "
168 << setName_ << " ..." << endl;
169 }
170
171 // Load the set
172 faceSet loadedSet(mesh_, setName_, IOobject::NO_REGISTER);
173
174 // Start off empty
175 DynamicList<label> newAddressing(zoneSet.addressing().size());
176 DynamicList<bool> newFlipMap(zoneSet.flipMap().size());
177
178 forAll(zoneSet.addressing(), i)
179 {
180 if (!loadedSet.found(zoneSet.addressing()[i]))
181 {
182 newAddressing.append(zoneSet.addressing()[i]);
183 newFlipMap.append(zoneSet.flipMap()[i]);
184 }
185 }
186 zoneSet.addressing().transfer(newAddressing);
187 zoneSet.flipMap().transfer(newFlipMap);
188 zoneSet.updateSet();
189 }
190 }
191}
192
193
194// ************************************************************************* //
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.
labelList faceLabels(nFaceLabels)
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
void append(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 list of face labels.
Definition faceSet.H:50
Like faceSet but -reads data from faceZone -updates faceZone when writing.
Definition faceZoneSet.H:50
const boolList & flipMap() const noexcept
const labelList & addressing() const noexcept
void updateSet()
Sort addressing and make faceSet part consistent with addressing.
Definition faceZoneSet.C:45
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
A topoSetSource to select faces based on usage in a faceSet, where the normal vector is used to orien...
setAndNormalToFaceZone(const polyMesh &mesh, const word &setName, const vector &normal)
Construct from components.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
The topoSetFaceZoneSource is a intermediate class for handling topoSet sources for selecting face zon...
topoSetFaceZoneSource(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
const pointField & points
#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).
List< face > faceList
List of faces.
Definition faceListFwd.H:41
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
vectorField pointField
pointField is a vectorField.
Vector< scalar > vector
Definition vector.H:57
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299