setToFaceZone.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 -------------------------------------------------------------------------------
11 License
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 "setToFaceZone.H"
30 #include "polyMesh.H"
31 #include "faceZoneSet.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(setToFaceZone, 0);
39  addToRunTimeSelectionTable(topoSetSource, setToFaceZone, word);
40  addToRunTimeSelectionTable(topoSetSource, setToFaceZone, istream);
41 
42  addToRunTimeSelectionTable(topoSetFaceZoneSource, setToFaceZone, word);
43  addToRunTimeSelectionTable(topoSetFaceZoneSource, setToFaceZone, istream);
44 }
45 
46 
47 Foam::topoSetSource::addToUsageTable Foam::setToFaceZone::usage_
48 (
49  setToFaceZone::typeName,
50  "\n Usage: setToFaceZone <faceSet>\n\n"
51  " Select all faces in the faceSet."
52  " Sets flipMap.\n\n"
53 );
54 
55 
56 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
57 
59 (
60  const polyMesh& mesh,
61  const word& setName
62 )
63 :
65  setName_(setName)
66 {}
67 
68 
70 (
71  const polyMesh& mesh,
72  const dictionary& dict
73 )
74 :
76  setName_(dict.get<word>("faceSet"))
77 {
78  if (dict.found("cellSet"))
79  {
81  << "Ignoring entry 'cellSet' - maybe use setsToFaceZone instead ?"
82  << endl;
83  }
84 }
85 
86 
88 (
89  const polyMesh& mesh,
90  Istream& is
91 )
92 :
93  topoSetFaceZoneSource(mesh),
94  setName_(checkIs(is))
95 {}
96 
97 
98 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
99 
101 (
102  const topoSetSource::setAction action,
103  topoSet& set
104 ) const
105 {
106  if (!isA<faceZoneSet>(set))
107  {
109  << "Operation only allowed on a faceZoneSet." << endl;
110  return;
111  }
112  else
113  {
114  faceZoneSet& zoneSet = refCast<faceZoneSet>(set);
115 
116  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
117  {
118  if (verbose_)
119  {
120  Info<< " Adding all faces from face set: "
121  << setName_ << " ..." << endl;
122  }
123 
124  // Load the sets
125  faceSet loadedSet(mesh_, setName_);
126  const labelHashSet& faceLabels = loadedSet;
127 
128  // Start off from copy
129  DynamicList<label> newAddressing(zoneSet.addressing());
130  DynamicList<bool> newFlipMap(zoneSet.flipMap());
131 
132  for (const label facei : faceLabels)
133  {
134  if (!zoneSet.found(facei))
135  {
136  newAddressing.append(facei);
137  newFlipMap.append(false);
138  }
139  }
140 
141  zoneSet.addressing().transfer(newAddressing);
142  zoneSet.flipMap().transfer(newFlipMap);
143  zoneSet.updateSet();
144  }
145  else if (action == topoSetSource::SUBTRACT)
146  {
147  if (verbose_)
148  {
149  Info<< " Removing all faces from face set: "
150  << setName_ << " ..." << endl;
151  }
152 
153  // Load the set
154  faceSet loadedSet(mesh_, setName_);
155 
156  // Start off empty
157  DynamicList<label> newAddressing(zoneSet.addressing().size());
158  DynamicList<bool> newFlipMap(zoneSet.flipMap().size());
159 
160  forAll(zoneSet.addressing(), i)
161  {
162  if (!loadedSet.found(zoneSet.addressing()[i]))
163  {
164  newAddressing.append(zoneSet.addressing()[i]);
165  newFlipMap.append(zoneSet.flipMap()[i]);
166  }
167  }
168  zoneSet.addressing().transfer(newAddressing);
169  zoneSet.flipMap().transfer(newFlipMap);
170  zoneSet.updateSet();
171  }
172  }
173 }
174 
175 
176 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
void append(const T &val)
Append an element at the end of the list.
Definition: List.H:517
Create a new set and ADD elements to it.
Add elements to current set.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
labelList faceLabels(nFaceLabels)
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
dynamicFvMesh & mesh
A class for handling words, derived from Foam::string.
Definition: word.H:63
setAction
Enumeration defining various actions.
defineTypeNameAndDebug(combustionModel, 0)
setToFaceZone(const polyMesh &mesh, const word &setName)
Construct from components.
Definition: setToFaceZone.C:52
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
Subtract elements from current set.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: setToFaceZone.C:94
#define WarningInFunction
Report a warning using Foam::Warning.
Class with constructor to add usage string to table.
messageStream Info
Information stream (stdout output on master, null elsewhere)
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
The topoSetFaceZoneSource is a intermediate class for handling topoSet sources for selecting face zon...
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)