setToCellZone.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 "setToCellZone.H"
30 #include "polyMesh.H"
31 #include "cellZoneSet.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(setToCellZone, 0);
39  addToRunTimeSelectionTable(topoSetSource, setToCellZone, word);
40  addToRunTimeSelectionTable(topoSetSource, setToCellZone, istream);
41 
42  addToRunTimeSelectionTable(topoSetCellZoneSource, setToCellZone, word);
43  addToRunTimeSelectionTable(topoSetCellZoneSource, setToCellZone, istream);
44 }
45 
46 
47 Foam::topoSetSource::addToUsageTable Foam::setToCellZone::usage_
48 (
49  setToCellZone::typeName,
50  "\n Usage: setToCellZone <cellSet>\n\n"
51  " Select all cells in the cellSet.\n\n"
52 );
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
58 (
59  const polyMesh& mesh,
60  const word& setName
61 )
62 :
64  setName_(setName)
65 {}
66 
67 
69 (
70  const polyMesh& mesh,
71  const dictionary& dict
72 )
73 :
75  setName_(dict.get<word>("set"))
76 {}
77 
78 
80 (
81  const polyMesh& mesh,
82  Istream& is
83 )
84 :
86  setName_(checkIs(is))
87 {}
88 
89 
90 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
91 
93 (
94  const topoSetSource::setAction action,
95  topoSet& set
96 ) const
97 {
98  if (!isA<cellZoneSet>(set))
99  {
101  << "Operation only allowed on a cellZoneSet." << endl;
102  return;
103  }
104  else
105  {
106  cellZoneSet& zoneSet = refCast<cellZoneSet>(set);
107 
108  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
109  {
110  if (verbose_)
111  {
112  Info<< " Adding all cells from cellSet " << setName_
113  << " ..." << endl;
114  }
115 
116  // Load the sets
117  cellSet fSet(mesh_, setName_);
118 
119  // Start off from copy
120  DynamicList<label> newAddressing(zoneSet.addressing());
121 
122  for (const label celli : fSet)
123  {
124  if (!zoneSet.found(celli))
125  {
126  newAddressing.append(celli);
127  }
128  }
129 
130  zoneSet.addressing().transfer(newAddressing);
131  zoneSet.updateSet();
132  }
133  else if (action == topoSetSource::SUBTRACT)
134  {
135  if (verbose_)
136  {
137  Info<< " Removing all cells from cellSet " << setName_
138  << " ..." << endl;
139  }
140 
141  // Load the set
142  cellSet loadedSet(mesh_, setName_);
143 
144  // Start off empty
145  DynamicList<label> newAddressing(zoneSet.addressing().size());
146 
147  forAll(zoneSet.addressing(), i)
148  {
149  if (!loadedSet.found(zoneSet.addressing()[i]))
150  {
151  newAddressing.append(zoneSet.addressing()[i]);
152  }
153  }
154  zoneSet.addressing().transfer(newAddressing);
155  zoneSet.updateSet();
156  }
157  }
158 }
159 
160 
161 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::DynamicList< label >
Foam::cellZoneSet::updateSet
void updateSet()
Sort addressing and make cellSet part consistent with addressing.
Definition: cellZoneSet.C:47
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:129
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:100
Foam::setToCellZone::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: setToCellZone.C:93
polyMesh.H
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:296
Foam::topoSet::found
virtual bool found(const label id) const
Has the given index?
Definition: topoSet.C:508
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 (stdout output on master, null elsewhere)
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:511
Foam::List::transfer
void transfer(List< T > &list)
Definition: List.C:456
Foam::cellZoneSet::addressing
const labelList & addressing() const
Definition: cellZoneSet.H:104
Foam::cellZoneSet
Like cellSet but -reads data from cellZone -updates cellZone when writing.
Definition: cellZoneSet.H:51
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
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:123
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::cellSet
A collection of cell labels.
Definition: cellSet.H:51
setToCellZone.H
cellZoneSet.H
Foam::topoSetCellZoneSource
The topoSetCellZoneSource is a intermediate class for handling topoSet sources for selecting cell zon...
Definition: topoSetCellZoneSource.H:57
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::setToCellZone::setToCellZone
setToCellZone(const polyMesh &mesh, const word &setName)
Construct from components.
Definition: setToCellZone.C:58