zoneToCell.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 "zoneToCell.H"
30 #include "polyMesh.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(zoneToCell, 0);
38  addToRunTimeSelectionTable(topoSetSource, zoneToCell, word);
39  addToRunTimeSelectionTable(topoSetSource, zoneToCell, istream);
40  addToRunTimeSelectionTable(topoSetCellSource, zoneToCell, word);
41  addToRunTimeSelectionTable(topoSetCellSource, zoneToCell, istream);
43  (
44  topoSetCellSource,
45  zoneToCell,
46  word,
47  zone
48  );
50  (
51  topoSetCellSource,
52  zoneToCell,
53  istream,
54  zone
55  );
56 }
57 
58 
59 Foam::topoSetSource::addToUsageTable Foam::zoneToCell::usage_
60 (
61  zoneToCell::typeName,
62  "\n Usage: zoneToCell zone\n\n"
63  " Select all cells in the cellZone."
64  " Note:accepts wildcards for zone.\n\n"
65 );
66 
67 
68 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
69 
70 void Foam::zoneToCell::combine(topoSet& set, const bool add) const
71 {
72  bool hasMatched = false;
73 
74  for (const cellZone& zone : mesh_.cellZones())
75  {
76  if (selectedZones_.match(zone.name()))
77  {
78  hasMatched = true;
79 
80  const labelList& cellLabels = zone;
81 
82  if (verbose_)
83  {
84  Info<< " Found matching zone " << zone.name()
85  << " with " << cellLabels.size() << " cells." << endl;
86  }
87 
88  for (const label celli : cellLabels)
89  {
90  // Only do active cells
91  if (celli >= 0 && celli < mesh_.nCells())
92  {
93  addOrDelete(set, celli, add);
94  }
95  }
96  }
97  }
98 
99  if (!hasMatched)
100  {
102  << "Cannot find any cellZone matching "
103  << flatOutput(selectedZones_) << nl
104  << "Valid names: " << flatOutput(mesh_.cellZones().names())
105  << endl;
106  }
107 }
108 
109 
110 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
111 
113 (
114  const polyMesh& mesh,
115  const wordRe& zoneName
116 )
117 :
119  selectedZones_(one(), zoneName)
120 {}
121 
122 
124 (
125  const polyMesh& mesh,
126  const dictionary& dict
127 )
128 :
130  selectedZones_()
131 {
132  // Look for 'zones' and 'zone', but accept 'name' as well
133  if (!dict.readIfPresent("zones", selectedZones_))
134  {
135  selectedZones_.resize(1);
136  selectedZones_.first() =
137  dict.getCompat<wordRe>("zone", {{"name", 1806}});
138  }
139 }
140 
141 
143 (
144  const polyMesh& mesh,
145  Istream& is
146 )
147 :
149  selectedZones_(one(), wordRe(checkIs(is)))
150 {}
151 
152 
153 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
154 
156 (
157  const topoSetSource::setAction action,
158  topoSet& set
159 ) const
160 {
161  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
162  {
163  if (verbose_)
164  {
165  Info<< " Adding all cells of cell zones "
166  << flatOutput(selectedZones_) << " ..." << endl;
167  }
168 
169  combine(set, true);
170  }
171  else if (action == topoSetSource::SUBTRACT)
172  {
173  if (verbose_)
174  {
175  Info<< " Removing all cells of cell zones "
176  << flatOutput(selectedZones_) << " ..." << endl;
177  }
178 
179  combine(set, false);
180  }
181 }
182 
183 
184 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
Foam::topoSetSource::ADD
Add elements to the set.
Definition: topoSetSource.H:101
Foam::zoneToCell::zoneToCell
zoneToCell(const polyMesh &mesh, const wordRe &zoneName)
Construct from components.
Definition: zoneToCell.C:113
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:124
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const
Return cell zone mesh.
Definition: polyMesh.H:483
Foam::one
A class representing the concept of 1 (one), which can be used to avoid manipulating objects that are...
Definition: one.H:60
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
Foam::dictionary::getCompat
T getCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option=keyType::REGEX) const
Definition: dictionaryTemplates.C:108
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:106
polyMesh.H
Foam::wordRe
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:72
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::wordRes::match
bool match(const std::string &text, bool literal=false) const
Smart match as literal or regex, stopping on the first match.
Definition: wordResI.H:87
Foam::primitiveMesh::nCells
label nCells() const
Number of mesh cells.
Definition: primitiveMeshI.H:96
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::topoSetSource::verbose_
bool verbose_
Verbosity (default: true)
Definition: topoSetSource.H:154
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::ListListOps::combine
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:69
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
zoneToCell.H
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:66
Foam::zoneToCell::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: zoneToCell.C:156
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
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::topoSetSource::SUBTRACT
Subtract elements from the set.
Definition: topoSetSource.H:102
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::ZoneMesh::names
wordList names() const
A list of the zone names.
Definition: ZoneMesh.C:340
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::flatOutput
FlatOutput< Container > flatOutput(const Container &obj, label len=0)
Global flatOutput function.
Definition: FlatOutput.H:85
Foam::topoSetCellSource
Base class of a topoSet source for selecting cells.
Definition: topoSetCellSource.H:50
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
Definition: topoSetSource.C:170
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Reference to the mesh.
Definition: topoSetSource.H:151
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:417