faceZoneToCell.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-2016 OpenFOAM Foundation
9  Copyright (C) 2016-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 "faceZoneToCell.H"
30 #include "polyMesh.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(faceZoneToCell, 0);
38  addToRunTimeSelectionTable(topoSetSource, faceZoneToCell, word);
39  addToRunTimeSelectionTable(topoSetSource, faceZoneToCell, istream);
40  addToRunTimeSelectionTable(topoSetCellSource, faceZoneToCell, word);
41  addToRunTimeSelectionTable(topoSetCellSource, faceZoneToCell, istream);
42 }
43 
44 
45 Foam::topoSetSource::addToUsageTable Foam::faceZoneToCell::usage_
46 (
47  faceZoneToCell::typeName,
48  "\n Usage: faceZoneToCell zone master|slave\n\n"
49  " Select master or slave side of the faceZone."
50  " Note:accepts wildcards for zone.\n\n"
51 );
52 
53 
54 const Foam::Enum
55 <
57 >
58 Foam::faceZoneToCell::faceActionNames_
59 ({
60  { faceAction::MASTER, "master" },
61  { faceAction::SLAVE, "slave" },
62 });
63 
64 
65 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
66 
67 void Foam::faceZoneToCell::combine(topoSet& set, const bool add) const
68 {
69  bool hasMatched = false;
70 
71  for (const faceZone& zone : mesh_.faceZones())
72  {
73  if (selectedZones_.match(zone.name()))
74  {
75  hasMatched = true;
76 
77  const labelList& cellLabels =
78  (
79  option_ == MASTER
80  ? zone.masterCells()
81  : zone.slaveCells()
82  );
83 
84  if (verbose_)
85  {
86  Info<< " Found matching zone " << zone.name()
87  << " with " << cellLabels.size() << " cells on "
88  << faceActionNames_[option_] << " side" << endl;
89  }
90 
91  for (const label celli : cellLabels)
92  {
93  // Only do active cells
94  if (celli >= 0 && celli < mesh_.nCells())
95  {
96  addOrDelete(set, celli, add);
97  }
98  }
99  }
100  }
101 
102  if (!hasMatched)
103  {
105  << "Cannot find any faceZone matching "
106  << flatOutput(selectedZones_) << nl
107  << "Valid names: " << flatOutput(mesh_.faceZones().names())
108  << endl;
109  }
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
114 
116 (
117  const polyMesh& mesh,
118  const wordRe& zoneName,
119  const faceAction option
120 )
121 :
123  selectedZones_(one(), zoneName),
124  option_(option)
125 {}
126 
127 
129 (
130  const polyMesh& mesh,
131  const dictionary& dict
132 )
133 :
135  selectedZones_(),
136  option_(faceActionNames_.get("option", dict))
137 {
138  // Look for 'zones' and 'zone', but accept 'name' as well
139  if (!dict.readIfPresent("zones", selectedZones_))
140  {
141  selectedZones_.resize(1);
142  selectedZones_.first() =
143  dict.getCompat<wordRe>("zone", {{"name", 1806}});
144  }
145 }
146 
147 
149 (
150  const polyMesh& mesh,
151  Istream& is
152 )
153 :
155  selectedZones_(one(), wordRe(checkIs(is))),
156  option_(faceActionNames_.read(checkIs(is)))
157 {}
158 
159 
160 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
161 
163 (
164  const topoSetSource::setAction action,
165  topoSet& set
166 ) const
167 {
168  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
169  {
170  if (verbose_)
171  {
172  Info<< " Adding all " << faceActionNames_[option_]
173  << " cells of face zones "
174  << flatOutput(selectedZones_) << " ..." << endl;
175  }
176 
177  combine(set, true);
178  }
179  else if (action == topoSetSource::SUBTRACT)
180  {
181  if (verbose_)
182  {
183  Info<< " Removing all " << faceActionNames_[option_]
184  << " cells of face zones "
185  << flatOutput(selectedZones_) << " ..." << endl;
186  }
187 
188  combine(set, false);
189  }
190 }
191 
192 
193 // ************************************************************************* //
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::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:51
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:124
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::polyMesh::faceZones
const faceZoneMesh & faceZones() const
Return face zone mesh.
Definition: polyMesh.H:477
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::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:66
Foam::faceZoneToCell::faceAction
faceAction
Enumeration defining the valid options.
Definition: faceZoneToCell.H:95
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
Foam::faceZoneToCell::MASTER
Definition: faceZoneToCell.H:97
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::faceZoneToCell::faceZoneToCell
faceZoneToCell(const polyMesh &mesh, const wordRe &zoneName, const faceAction option)
Construct from components.
Definition: faceZoneToCell.C:116
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
faceZoneToCell.H
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::faceZoneToCell::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: faceZoneToCell.C:163
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:417