Loading...
Searching...
No Matches
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-2023 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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"
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35namespace Foam
36{
42}
43
44
45Foam::topoSetSource::addToUsageTable Foam::faceZoneToCell::usage_
46(
47 faceZoneToCell::typeName,
48 "\n Usage: faceZoneToCell zone front|back|both\n\n"
49 " Select front, back or both sides of the faceZone."
50 " Note:accepts wildcards for zone.\n\n"
51);
52
53
54const Foam::Enum
55<
57>
58Foam::faceZoneToCell::faceActionNames_
59({
60 { faceAction::FRONT, "front" },
61 { faceAction::BACK, "back" },
62 { faceAction::BOTH, "both" },
63 // Compatibility
64 { faceAction::FRONT, "master" },
65 { faceAction::BACK, "slave" },
66});
67
68
69// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
70
71void Foam::faceZoneToCell::combine
72(
73 topoSet& set,
74 const labelUList& zoneIDs,
75 const bool add,
76 const bool verbosity
77) const
78{
79 const label nZones = mesh_.faceZones().size();
80
81 if (zoneIDs.empty() || !nZones)
82 {
83 return; // Nothing to do
84 }
85
86 for (const label zonei : zoneIDs)
87 {
88 if (zonei < 0 || zonei >= nZones)
89 {
90 continue;
91 }
92
93 const auto& zone = mesh_.faceZones()[zonei];
94
95 if (verbosity)
96 {
97 Info<< " Using matching zone " << zone.name();
98
99 if (option_ == faceAction::FRONT)
100 {
101 Info<< " [front] cells:";
102 }
103 else if (option_ == faceAction::BACK)
104 {
105 Info<< " : [back] cells:";
106 }
107 if (option_ == faceAction::BOTH)
108 {
109 Info<< " : [front/back] cells:";
110 }
111 }
112
113 if (option_ == faceAction::FRONT || option_ == faceAction::BOTH)
114 {
115 const labelList& cellLabels = zone.frontCells();
116
117 if (verbosity)
118 {
119 Info<< ' ' << returnReduce(cellLabels.size(), sumOp<label>());
120 }
121
122 for (const label celli : cellLabels)
123 {
124 // Only do active cells
125 if (celli >= 0 && celli < mesh_.nCells())
126 {
127 addOrDelete(set, celli, add);
128 }
129 }
130 }
131
132 if (option_ == faceAction::BACK || option_ == faceAction::BOTH)
133 {
134 const labelList& cellLabels = zone.backCells();
135
136 if (verbosity)
137 {
138 Info<< ' ' << returnReduce(cellLabels.size(), sumOp<label>());
139 }
140
141 for (const label celli : cellLabels)
142 {
143 // Only do active cells
144 if (celli >= 0 && celli < mesh_.nCells())
145 {
146 addOrDelete(set, celli, add);
147 }
148 }
149 }
150
151 if (verbosity)
152 {
153 Info<< endl;
154 }
155 }
156}
157
158
159void Foam::faceZoneToCell::combine(topoSet& set, const bool add) const
160{
161 if (zoneMatcher_.empty())
162 {
163 return; // Nothing to do
164 }
165
166 const labelList matched(mesh_.faceZones().indices(zoneMatcher_));
167
168 if (matched.empty())
169 {
171 << "Cannot find any faceZone matching "
172 << flatOutput(zoneMatcher_) << nl
173 << "Valid names: " << flatOutput(mesh_.faceZones().names())
174 << endl;
175
176 return; // Nothing to do
177 }
179 combine(set, matched, add, verbose_);
180}
181
182
183// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
184
186(
187 const polyMesh& mesh,
188 const wordRes& zoneSelector,
189 const faceAction option
190)
193 zoneMatcher_(zoneSelector),
194 option_(option)
195{}
196
197
199(
200 const polyMesh& mesh,
201 const wordRe& zoneName,
202 const faceAction option
203)
206 zoneMatcher_(one{}, zoneName),
207 option_(option)
208{}
209
210
212(
213 const polyMesh& mesh,
214 const dictionary& dict
215)
216:
218 zoneMatcher_(),
219 option_(faceActionNames_.get("option", dict))
220{
221 // Look for 'zones' and 'zone', but accept 'name' as well
222 if (!dict.readIfPresent("zones", zoneMatcher_))
224 zoneMatcher_.resize(1);
225 zoneMatcher_.front() = dict.getCompat<wordRe>("zone", {{"name", 1806}});
226 }
227}
228
229
231(
232 const polyMesh& mesh,
233 Istream& is
234)
235:
236 topoSetCellSource(mesh),
237 zoneMatcher_(one{}, wordRe(checkIs(is))),
238 option_(faceActionNames_.read(checkIs(is)))
239{}
240
241
242// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
245{
246 return zoneMatcher_;
247}
248
250void Foam::faceZoneToCell::zones(const wordRes& zonesSelector)
251{
252 zoneMatcher_ = zonesSelector;
253}
254
255
257{
258 zoneMatcher_.resize(1);
259 zoneMatcher_.front() = zoneName;
260}
261
262
264(
265 const topoSetSource::setAction action,
266 topoSet& set
267) const
268{
269 if (action == topoSetSource::ADD || action == topoSetSource::NEW)
270 {
271 if (verbose_ && !zoneMatcher_.empty())
272 {
273 Info<< " Adding all " << faceActionNames_[option_]
274 << " cells of face zones "
275 << flatOutput(zoneMatcher_) << " ..." << endl;
276 }
277
278 combine(set, true);
279 }
280 else if (action == topoSetSource::SUBTRACT)
281 {
282 if (verbose_ && !zoneMatcher_.empty())
283 {
284 Info<< " Removing all " << faceActionNames_[option_]
285 << " cells of face zones "
286 << flatOutput(zoneMatcher_) << " ..." << endl;
287 }
288
289 combine(set, false);
290 }
291}
292
293
294// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
void resize(const label len)
Adjust allocated size of list.
Definition ListI.H:153
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A topoSetCellSource to select cells based on front or back side of given faceZone(s).
faceZoneToCell(const polyMesh &mesh, const wordRes &zoneSelector, const faceAction option)
Construct from mesh, zones selector and selection option.
const wordRes & zones() const noexcept
Return the current zones selector.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
faceAction
Enumeration defining the valid options.
@ BOTH
Both front and back side of faces.
@ FRONT
The front (positive normal) side of the faces.
@ BACK
The back (negative normal) side of the faces.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition one.H:57
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
The topoSetCellSource is a intermediate class for handling topoSet sources for selecting cells.
topoSetCellSource(const polyMesh &mesh)
Construct from mesh.
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
setAction
Enumeration defining various actions.
@ SUBTRACT
Subtract elements from current set.
@ ADD
Add elements to current set.
@ NEW
Create a new set and ADD elements to it.
bool verbose_
Output verbosity (default: true).
const polyMesh & mesh() const noexcept
Reference to the mesh.
const polyMesh & mesh_
Reference to the mesh.
static Istream & checkIs(Istream &is)
Check state of stream.
General set of labels of mesh quantity (points, cells, faces).
Definition topoSet.H:63
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition wordRe.H:81
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
const labelIOList & zoneIDs
Definition correctPhi.H:59
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition int32.H:127
List< label > labelList
A List of labels.
Definition List.H:62
messageStream Info
Information stream (stdout output on master, null elsewhere).
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
void add(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
const direction noexcept
Definition scalarImpl.H:265
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dict add("bounds", meshBb)
dictionary dict