Loading...
Searching...
No Matches
setsToFaceZone.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-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
29#include "setsToFaceZone.H"
30#include "polyMesh.H"
31#include "faceZoneSet.H"
32#include "cellSet.H"
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37namespace Foam
38{
42
45}
46
47
48Foam::topoSetSource::addToUsageTable Foam::setsToFaceZone::usage_
49(
50 setsToFaceZone::typeName,
51 "\n Usage: setsToFaceZone <faceSet> <slaveCellSet>\n\n"
52 " Select all faces in the faceSet."
53 " Orientated so slave side is in cellSet.\n\n"
54);
55
56
57// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58
60(
61 const polyMesh& mesh,
62 const word& faceSetName,
63 const word& cellSetName,
64 const bool flip
65)
66:
68 faceSetName_(faceSetName),
69 cellSetName_(cellSetName),
70 flip_(flip)
71{}
72
73
75(
76 const polyMesh& mesh,
77 const dictionary& dict
78)
79:
81 faceSetName_(dict.get<word>("faceSet")),
82 cellSetName_(dict.get<word>("cellSet")),
83 flip_(dict.getOrDefault("flip", false))
84{}
85
86
88(
89 const polyMesh& mesh,
90 Istream& is
91)
92:
94 faceSetName_(checkIs(is)),
95 cellSetName_(checkIs(is)),
96 flip_(false)
97{}
98
99
100// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101
103(
104 const topoSetSource::setAction action,
105 topoSet& set
106) const
107{
108 if (!isA<faceZoneSet>(set))
109 {
111 << "Operation only allowed on a faceZoneSet." << endl;
112 return;
113 }
114 else
115 {
116 faceZoneSet& zoneSet = refCast<faceZoneSet>(set);
117
118 if (action == topoSetSource::ADD || action == topoSetSource::NEW)
119 {
120 if (verbose_)
121 {
122 Info<< " Adding all faces from face set: "
123 << faceSetName_ << "; orientation pointing ";
124
125 if (flip_)
126 {
127 Info<< "into";
128 }
129 else
130 {
131 Info<< "away from";
132 }
133
134 Info<< " cell set: " << cellSetName_ << " ..." << endl;
135 }
136
137 // Load the sets
138 faceSet fSet(mesh_, faceSetName_, IOobject::NO_REGISTER);
139 cellSet cSet(mesh_, cellSetName_, IOobject::NO_REGISTER);
140
141 // Start off from copy
142 DynamicList<label> newAddressing(zoneSet.addressing());
143 DynamicList<bool> newFlipMap(zoneSet.flipMap());
144
145 for (const label facei : fSet)
146 {
147 if (!zoneSet.found(facei))
148 {
149 bool flipFace = false;
150
151 const label own = mesh_.faceOwner()[facei];
152 const bool ownFound = cSet.found(own);
153
154 if (mesh_.isInternalFace(facei))
155 {
156 label nei = mesh_.faceNeighbour()[facei];
157 bool neiFound = cSet.found(nei);
158
159 if (ownFound && !neiFound)
160 {
161 flipFace = false;
162 }
163 else if (!ownFound && neiFound)
164 {
165 flipFace = true;
166 }
167 else
168 {
170 << "One of owner or neighbour of internal face "
171 << facei << " should be in cellSet "
172 << cSet.name()
173 << " to be able to determine orientation."
174 << endl
175 << "Face:" << facei << " own:" << own
176 << " OwnInCellSet:" << ownFound
177 << " nei:" << nei
178 << " NeiInCellSet:" << neiFound
179 << endl;
180 }
181 }
182 else
183 {
184 flipFace = !ownFound;
185 }
186
187
188 if (flip_)
189 {
190 flipFace = !flipFace;
191 }
192
193 newAddressing.append(facei);
194 newFlipMap.append(flipFace);
195 }
196 }
197
198 zoneSet.addressing().transfer(newAddressing);
199 zoneSet.flipMap().transfer(newFlipMap);
200 zoneSet.updateSet();
201 }
202 else if (action == topoSetSource::SUBTRACT)
203 {
204 if (verbose_)
205 {
206 Info<< " Removing all faces from face set: "
207 << faceSetName_ << " ..." << endl;
208 }
209
210 // Load the set
211 faceZoneSet loadedSet(mesh_, faceSetName_);
212
213 // Start off empty
214 DynamicList<label> newAddressing(zoneSet.addressing().size());
215 DynamicList<bool> newFlipMap(zoneSet.flipMap().size());
216
217 forAll(zoneSet.addressing(), i)
218 {
219 if (!loadedSet.found(zoneSet.addressing()[i]))
220 {
221 newAddressing.append(zoneSet.addressing()[i]);
222 newFlipMap.append(zoneSet.flipMap()[i]);
223 }
224 }
225 zoneSet.addressing().transfer(newAddressing);
226 zoneSet.flipMap().transfer(newFlipMap);
227 zoneSet.updateSet();
228 }
229 }
230}
231
232
233// ************************************************************************* //
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 append(const T &val)
Copy append an element to the end of this list.
@ NO_REGISTER
Do not request registration (bool: false).
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
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 collection of cell labels.
Definition cellSet.H:50
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 all faces in a given faceSet, which are oriented in slave cells of a given ...
setsToFaceZone(const polyMesh &mesh, const word &faceSetName, const word &cellSetName, const bool flip)
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
#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
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
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299