faceZoneToFaceZone.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 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 "faceZoneToFaceZone.H"
30 #include "polyMesh.H"
31 #include "faceZoneSet.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(faceZoneToFaceZone, 0);
39  addToRunTimeSelectionTable(topoSetSource, faceZoneToFaceZone, word);
40  addToRunTimeSelectionTable(topoSetSource, faceZoneToFaceZone, istream);
41 }
42 
43 
44 Foam::topoSetSource::addToUsageTable Foam::faceZoneToFaceZone::usage_
45 (
46  faceZoneToFaceZone::typeName,
47  "\n Usage: faceZoneToFaceZone <faceZone>\n\n"
48  " Select all faces in the faceZone\n\n"
49 );
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
55 (
56  const polyMesh& mesh,
57  const word& setName
58 )
59 :
61  setName_(setName)
62 {}
63 
64 
66 (
67  const polyMesh& mesh,
68  const dictionary& dict
69 )
70 :
72  setName_(dict.get<word>("zone"))
73 {}
74 
75 
77 (
78  const polyMesh& mesh,
79  Istream& is
80 )
81 :
83  setName_(checkIs(is))
84 {}
85 
86 
87 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
88 
90 (
91  const topoSetSource::setAction action,
92  topoSet& set
93 ) const
94 {
95  if (!isA<faceZoneSet>(set))
96  {
98  << "Operation only allowed on a faceZoneSet." << endl;
99  }
100  else
101  {
102  faceZoneSet& zoneSet = refCast<faceZoneSet>(set);
103 
104  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
105  {
106  if (verbose_)
107  {
108  Info<< " Adding all faces from faceZone " << setName_
109  << " ..." << endl;
110  }
111 
112  // Load the set
113  faceZoneSet loadedSet(mesh_, setName_);
114 
115  DynamicList<label> newAddressing(zoneSet.addressing());
116  DynamicList<bool> newFlipMap(zoneSet.flipMap());
117 
118  forAll(loadedSet.addressing(), i)
119  {
120  if (!zoneSet.found(loadedSet.addressing()[i]))
121  {
122  newAddressing.append(loadedSet.addressing()[i]);
123  newFlipMap.append(loadedSet.flipMap()[i]);
124  }
125  }
126  zoneSet.addressing().transfer(newAddressing);
127  zoneSet.flipMap().transfer(newFlipMap);
128  zoneSet.updateSet();
129  }
130  else if (action == topoSetSource::SUBTRACT)
131  {
132  if (verbose_)
133  {
134  Info<< " Removing all faces from faceZone " << setName_
135  << " ..." << endl;
136  }
137 
138  // Load the set
139  faceZoneSet loadedSet(mesh_, setName_);
140 
141  DynamicList<label> newAddressing(zoneSet.addressing().size());
142  DynamicList<bool> newFlipMap(zoneSet.flipMap().size());
143 
144  forAll(zoneSet.addressing(), i)
145  {
146  if (!loadedSet.found(zoneSet.addressing()[i]))
147  {
148  newAddressing.append(zoneSet.addressing()[i]);
149  newFlipMap.append(zoneSet.flipMap()[i]);
150  }
151  }
152  zoneSet.addressing().transfer(newAddressing);
153  zoneSet.flipMap().transfer(newFlipMap);
154  zoneSet.updateSet();
155  }
156  }
157 }
158 
159 
160 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::faceZoneSet::addressing
const labelList & addressing() const
Definition: faceZoneSet.H:107
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::faceZoneToFaceZone::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: faceZoneToFaceZone.C:90
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::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::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
faceZoneToFaceZone.H
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::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
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
Foam::faceZoneToFaceZone::faceZoneToFaceZone
faceZoneToFaceZone(const polyMesh &mesh, const word &setName)
Construct from components.
Definition: faceZoneToFaceZone.C:55