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 <
56  Foam::faceZoneToCell::faceAction
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 
115 Foam::faceZoneToCell::faceZoneToCell
116 (
117  const polyMesh& mesh,
118  const wordRe& zoneName,
119  const faceAction option
120 )
121 :
122  topoSetCellSource(mesh),
123  selectedZones_(one(), zoneName),
124  option_(option)
125 {}
126 
127 
128 Foam::faceZoneToCell::faceZoneToCell
129 (
130  const polyMesh& mesh,
131  const dictionary& dict
132 )
133 :
134  topoSetCellSource(mesh),
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 
148 Foam::faceZoneToCell::faceZoneToCell
149 (
150  const polyMesh& mesh,
151  Istream& is
152 )
153 :
154  topoSetCellSource(mesh),
155  selectedZones_(one(), wordRe(checkIs(is))),
156  option_(faceActionNames_.read(checkIs(is)))
157 {}
158 
159 
160 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
161 
162 void Foam::faceZoneToCell::applyToSet
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:71
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:57
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:124
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:107
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:99
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:106
polyMesh.H
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
dict
dictionary dict
Definition: searchingEngine.H:14
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::nl
constexpr char nl
Definition: Ostream.H:385
Foam::flatOutput
FlatOutput< Container > flatOutput(const Container &obj, label len=0)
Global flatOutput function.
Definition: FlatOutput.H:85
faceZoneToCell.H
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:298