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 | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "faceZoneToCell.H"
27 #include "polyMesh.H"
28 
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(faceZoneToCell, 0);
36  addToRunTimeSelectionTable(topoSetSource, faceZoneToCell, word);
37  addToRunTimeSelectionTable(topoSetSource, faceZoneToCell, istream);
38 
39  template<>
40  const char* Foam::NamedEnum
41  <
43  2
44  >::names[] =
45  {
46  "master",
47  "slave"
48  };
49 }
50 
51 
53 (
54  faceZoneToCell::typeName,
55  "\n Usage: faceZoneToCell zone master|slave\n\n"
56  " Select master or slave side of the faceZone."
57  " Note:accepts wildcards for zone.\n\n"
58 );
59 
60 
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  forAll(mesh_.faceZones(), i)
72  {
73  const faceZone& zone = mesh_.faceZones()[i];
74 
75  if (zoneName_.match(zone.name()))
76  {
77  const labelList& cellLabels =
78  (
79  option_ == MASTER
80  ? zone.masterCells()
81  : zone.slaveCells()
82  );
83 
84  Info<< " Found matching zone " << zone.name()
85  << " with " << cellLabels.size() << " cells on selected side."
86  << endl;
87 
88  hasMatched = true;
89 
90  forAll(cellLabels, i)
91  {
92  // Only do active cells
93  if (cellLabels[i] < mesh_.nCells())
94  {
95  addOrDelete(set, cellLabels[i], add);
96  }
97  }
98  }
99  }
100 
101  if (!hasMatched)
102  {
104  << "Cannot find any faceZone named " << zoneName_ << endl
105  << "Valid names are " << mesh_.faceZones().names() << endl;
106  }
107 }
108 
109 
110 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
111 
112 // Construct from components
114 (
115  const polyMesh& mesh,
116  const word& zoneName,
117  const faceAction option
118 )
119 :
121  zoneName_(zoneName),
122  option_(option)
123 {}
124 
125 
126 // Construct from dictionary
128 (
129  const polyMesh& mesh,
130  const dictionary& dict
131 )
132 :
134  zoneName_(dict.lookup("name")),
135  option_(faceActionNames_.read(dict.lookup("option")))
136 {}
137 
138 
139 // Construct from Istream
141 (
142  const polyMesh& mesh,
143  Istream& is
144 )
145 :
147  zoneName_(checkIs(is)),
148  option_(faceActionNames_.read(checkIs(is)))
149 {}
150 
151 
152 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
153 
155 {}
156 
157 
158 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
159 
161 (
162  const topoSetSource::setAction action,
163  topoSet& set
164 ) const
165 {
166  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
167  {
168  Info<< " Adding all " << faceActionNames_[option_]
169  << " cells of faceZone " << zoneName_ << " ..." << endl;
170 
171  combine(set, true);
172  }
173  else if (action == topoSetSource::DELETE)
174  {
175  Info<< " Removing all " << faceActionNames_[option_]
176  << " cells of faceZone " << zoneName_ << " ..." << endl;
177 
178  combine(set, false);
179  }
180 }
181 
182 
183 // ************************************************************************* //
Foam::faceZoneToCell::zoneName_
wordRe zoneName_
Name/regular expression of faceZone.
Definition: faceZoneToCell.H:71
Foam::topoSetSource::ADD
@ ADD
Definition: topoSetSource.H:87
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::faceZoneToCell::combine
void combine(topoSet &set, const bool add) const
Definition: faceZoneToCell.C:67
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::ListListOps::combine
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:100
Foam::faceZoneToCell::~faceZoneToCell
virtual ~faceZoneToCell()
Destructor.
Definition: faceZoneToCell.C:154
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::zone
Base class for zones.
Definition: zone.H:57
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
Foam::wordRe::match
bool match(const std::string &, bool literalMatch=false) const
Smart match as regular expression or as a string.
Definition: wordReI.H:202
Foam::topoSetSource::NEW
@ NEW
Definition: topoSetSource.H:85
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::polyMesh::faceZones
const faceZoneMesh & faceZones() const
Return face zone mesh.
Definition: polyMesh.H:463
Foam::faceZoneToCell::faceZoneToCell
faceZoneToCell(const polyMesh &mesh, const word &zoneName, const faceAction option)
Construct from components.
Definition: faceZoneToCell.C:114
Foam::primitiveMesh::nCells
label nCells() const
Definition: primitiveMeshI.H:64
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::Info
messageStream Info
Foam::topoSetSource::DELETE
@ DELETE
Definition: topoSetSource.H:88
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
Foam::faceZoneToCell::faceAction
faceAction
Enumeration defining the valid options.
Definition: faceZoneToCell.H:55
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
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:870
Foam::faceZoneToCell::MASTER
@ MASTER
Definition: faceZoneToCell.H:57
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::topoSetSource
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
Foam::zone::name
const word & name() const
Return name.
Definition: zone.H:150
Foam::ZoneMesh::names
wordList names() const
Return a list of zone names.
Definition: ZoneMesh.C:263
Foam::faceZoneToCell::option_
faceAction option_
Option.
Definition: faceZoneToCell.H:74
Foam::faceZoneToCell::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: faceZoneToCell.C:161
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
faceZoneToCell.H
Foam::faceZoneToCell::usage_
static addToUsageTable usage_
Add usage string.
Definition: faceZoneToCell.H:68
Foam::faceZoneToCell::faceActionNames_
static const NamedEnum< faceAction, 2 > faceActionNames_
Definition: faceZoneToCell.H:65
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Definition: topoSetSource.H:126
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label cellI, const bool) const
Add (if bool) cellI to set or delete cellI from set.
Definition: topoSetSource.C:140
Foam::NamedEnum
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52