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-2019 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 
43 
44 Foam::topoSetSource::addToUsageTable Foam::setToFaceZone::usage_
45 (
46  setToFaceZone::typeName,
47  "\n Usage: setToFaceZone <faceSet>\n\n"
48  " Select all faces in the faceSet."
49  " Sets flipMap.\n\n"
50 );
51 
52 
53 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54 
56 (
57  const polyMesh& mesh,
58  const word& setName
59 )
60 :
62  setName_(setName)
63 {}
64 
65 
67 (
68  const polyMesh& mesh,
69  const dictionary& dict
70 )
71 :
73  setName_(dict.get<word>("faceSet"))
74 {
75  if (dict.found("cellSet"))
76  {
78  << "Ignoring entry 'cellSet' - maybe use setsToFaceZone instead ?"
79  << endl;
80  }
81 }
82 
83 
85 (
86  const polyMesh& mesh,
87  Istream& is
88 )
89 :
91  setName_(checkIs(is))
92 {}
93 
94 
95 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
96 
98 (
99  const topoSetSource::setAction action,
100  topoSet& set
101 ) const
102 {
103  if (!isA<faceZoneSet>(set))
104  {
106  << "Operation only allowed on a faceZoneSet." << endl;
107  }
108  else
109  {
110  faceZoneSet& zoneSet = refCast<faceZoneSet>(set);
111 
112  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
113  {
114  if (verbose_)
115  {
116  Info<< " Adding all faces from faceSet " << setName_
117  << " ..." << endl;
118  }
119 
120  // Load the sets
121  faceSet loadedSet(mesh_, setName_);
122  const labelHashSet& faceLabels = loadedSet;
123 
124  // Start off from copy
125  DynamicList<label> newAddressing(zoneSet.addressing());
126  DynamicList<bool> newFlipMap(zoneSet.flipMap());
127 
128  for (const label facei : faceLabels)
129  {
130  if (!zoneSet.found(facei))
131  {
132  newAddressing.append(facei);
133  newFlipMap.append(false);
134  }
135  }
136 
137  zoneSet.addressing().transfer(newAddressing);
138  zoneSet.flipMap().transfer(newFlipMap);
139  zoneSet.updateSet();
140  }
141  else if (action == topoSetSource::SUBTRACT)
142  {
143  if (verbose_)
144  {
145  Info<< " Removing all faces from faceSet " << setName_
146  << " ..." << endl;
147  }
148 
149  // Load the set
150  faceSet loadedSet(mesh_, setName_);
151 
152  // Start off empty
153  DynamicList<label> newAddressing(zoneSet.addressing().size());
154  DynamicList<bool> newFlipMap(zoneSet.flipMap().size());
155 
156  forAll(zoneSet.addressing(), i)
157  {
158  if (!loadedSet.found(zoneSet.addressing()[i]))
159  {
160  newAddressing.append(zoneSet.addressing()[i]);
161  newFlipMap.append(zoneSet.flipMap()[i]);
162  }
163  }
164  zoneSet.addressing().transfer(newAddressing);
165  zoneSet.flipMap().transfer(newFlipMap);
166  zoneSet.updateSet();
167  }
168  }
169 }
170 
171 
172 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::faceZoneSet::addressing
const labelList & addressing() const
Definition: faceZoneSet.H:107
Foam::setToFaceZone::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: setToFaceZone.C:98
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::DynamicList< label >
faceZoneSet.H
Foam::faceZoneSet::updateSet
void updateSet()
Sort addressing and make faceSet part consistent with addressing.
Definition: faceZoneSet.C:51
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:124
Foam::faceSet
A list of face labels.
Definition: faceSet.H:51
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:99
polyMesh.H
Foam::HashSet< label, Hash< label > >
Foam::faceZoneSet::flipMap
const boolList & flipMap() const
Definition: faceZoneSet.H:118
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::topoSet::found
virtual bool found(const label id) const
Has the given index?
Definition: topoSet.C:511
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:472
Foam::List::transfer
void transfer(List< T > &list)
Definition: List.C:436
Foam::faceZoneSet
Like faceSet but -reads data from faceZone -updates faceZone when writing.
Definition: faceZoneSet.H:52
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:66
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::topoSetSource
Base class of a source for a topoSet.
Definition: topoSetSource.H:66
setToFaceZone.H
IOWarningInFunction
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Definition: messageStream.H:306
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
Foam::setToFaceZone::setToFaceZone
setToFaceZone(const polyMesh &mesh, const word &setName)
Construct from components.
Definition: setToFaceZone.C:56