faceZoneToCell.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(faceZoneToCell, 0);
35  addToRunTimeSelectionTable(topoSetSource, faceZoneToCell, word);
36  addToRunTimeSelectionTable(topoSetSource, faceZoneToCell, istream);
37 
38  template<>
39  const char* Foam::NamedEnum
40  <
42  2
43  >::names[] =
44  {
45  "master",
46  "slave"
47  };
48 }
49 
50 
51 Foam::topoSetSource::addToUsageTable Foam::faceZoneToCell::usage_
52 (
53  faceZoneToCell::typeName,
54  "\n Usage: faceZoneToCell zone master|slave\n\n"
55  " Select master or slave side of the faceZone."
56  " Note:accepts wildcards for zone.\n\n"
57 );
58 
59 
61  Foam::faceZoneToCell::faceActionNames_;
62 
63 
64 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
65 
66 void Foam::faceZoneToCell::combine(topoSet& set, const bool add) const
67 {
68  bool hasMatched = false;
69 
70  forAll(mesh_.faceZones(), i)
71  {
72  const faceZone& zone = mesh_.faceZones()[i];
73 
74  if (zoneName_.match(zone.name()))
75  {
76  const labelList& cellLabels =
77  (
78  option_ == MASTER
79  ? zone.masterCells()
80  : zone.slaveCells()
81  );
82 
83  Info<< " Found matching zone " << zone.name()
84  << " with " << cellLabels.size() << " cells on selected side."
85  << endl;
86 
87  hasMatched = true;
88 
89  forAll(cellLabels, i)
90  {
91  // Only do active cells
92  if (cellLabels[i] >= 0 && cellLabels[i] < mesh_.nCells())
93  {
94  addOrDelete(set, cellLabels[i], add);
95  }
96  }
97  }
98  }
99 
100  if (!hasMatched)
101  {
103  << "Cannot find any faceZone named " << zoneName_ << endl
104  << "Valid names are " << mesh_.faceZones().names() << endl;
105  }
106 }
107 
108 
109 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
110 
112 (
113  const polyMesh& mesh,
114  const word& zoneName,
115  const faceAction option
116 )
117 :
118  topoSetSource(mesh),
119  zoneName_(zoneName),
120  option_(option)
121 {}
122 
123 
125 (
126  const polyMesh& mesh,
127  const dictionary& dict
128 )
129 :
130  topoSetSource(mesh),
131  zoneName_(dict.lookup("name")),
132  option_(faceActionNames_.read(dict.lookup("option")))
133 {}
134 
135 
137 (
138  const polyMesh& mesh,
139  Istream& is
140 )
141 :
142  topoSetSource(mesh),
143  zoneName_(checkIs(is)),
144  option_(faceActionNames_.read(checkIs(is)))
145 {}
146 
147 
148 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
149 
151 {}
152 
153 
154 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
155 
157 (
158  const topoSetSource::setAction action,
159  topoSet& set
160 ) const
161 {
162  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
163  {
164  Info<< " Adding all " << faceActionNames_[option_]
165  << " cells of faceZone " << zoneName_ << " ..." << endl;
166 
167  combine(set, true);
168  }
169  else if (action == topoSetSource::DELETE)
170  {
171  Info<< " Removing all " << faceActionNames_[option_]
172  << " cells of faceZone " << zoneName_ << " ..." << endl;
173 
174  combine(set, false);
175  }
176 }
177 
178 
179 // ************************************************************************* //
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
const labelList & masterCells() const
Return labels of master cells (cells next to the master face.
Definition: faceZone.C:323
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
virtual ~faceZoneToCell()
Destructor.
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
faceAction
Enumeration defining the valid options.
Base class for zones.
Definition: zone.H:57
A class for handling words, derived from string.
Definition: word.H:59
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
const word & name() const
Return name.
Definition: zone.H:147
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
const labelList & slaveCells() const
Return labels of slave cells.
Definition: faceZone.C:334
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
faceZoneToCell(const polyMesh &mesh, const word &zoneName, const faceAction option)
Construct from components.
#define WarningInFunction
Report a warning using Foam::Warning.
Class with constructor to add usage string to table.
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576