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-2026 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 }
37 
40 {
41  "master",
42  "slave"
43 };
44 
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
48 void Foam::faceZoneToCell::combine(topoSet& set, const bool add) const
49 {
50  forAll(mesh_.faceZones(), i)
51  {
52  const faceZone& fZone = mesh_.faceZones()[i];
53 
54  if (zoneName_.match(fZone.name()))
55  {
56  Info<< " Found matching zone " << fZone.name() << endl;
57 
58  const labelList& faces = fZone;
59  const labelList& own = mesh_.faceOwner();
60  const labelList& nei = mesh_.faceNeighbour();
61 
62  if (fZone.oriented())
63  {
64  const boolList& flipMap = fZone.flipMap();
65 
66  forAll(faces, facei)
67  {
68  if
69  (
70  option_ == MASTER
71  && !flipMap[facei]
72  && mesh_.isInternalFace(faces[facei]))
73  {
74  addOrDelete(set, nei[faces[facei]], add);
75  }
76  else
77  {
78  addOrDelete(set, own[faces[facei]], add);
79  }
80  }
81  }
82  else
83  {
84  forAll(faces, facei)
85  {
86  if (option_ == MASTER && mesh_.isInternalFace(faces[facei]))
87  {
88  addOrDelete(set, nei[faces[facei]], add);
89  }
90  else
91  {
92  addOrDelete(set, own[faces[facei]], add);
93  }
94  }
95  }
96  }
97  }
98 }
99 
100 
101 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
102 
104 (
105  const polyMesh& mesh,
106  const word& zoneName,
107  const faceAction option
108 )
109 :
110  topoSetSource(mesh),
111  zoneName_(zoneName),
112  option_(option)
113 {}
114 
115 
117 (
118  const polyMesh& mesh,
119  const dictionary& dict
120 )
121 :
122  topoSetSource(mesh),
123  zoneName_(dict.lookupBackwardsCompatible({"zone", "name"})),
124  option_(faceActionNames_.read(dict.lookup("option")))
125 {}
126 
127 
128 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
129 
131 {}
132 
133 
134 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
135 
137 (
138  const topoSetSource::setAction action,
139  topoSet& set
140 ) const
141 {
142  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
143  {
144  Info<< " Adding all " << faceActionNames_[option_]
145  << " cells of faceZone " << zoneName_ << " ..." << endl;
146 
147  combine(set, true);
148  }
149  else if (action == topoSetSource::DELETE)
150  {
151  Info<< " Removing all " << faceActionNames_[option_]
152  << " cells of faceZone " << zoneName_ << " ..." << endl;
153 
154  combine(set, false);
155  }
156 }
157 
158 
159 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:55
virtual ~faceZoneToCell()
Destructor.
static const NamedEnum< faceAction, 2 > faceActionNames_
Names of the valid options.
faceZoneToCell(const polyMesh &mesh, const word &zoneName, const faceAction option)
Construct from components.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1321
const faceZoneList & faceZones() const
Return face zones.
Definition: polyMesh.H:432
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1327
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
void addOrDelete(topoSet &set, const label celli, const bool) const
Add (if bool) celli to set or delete celli from set.
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
const polyMesh & mesh_
Definition: topoSetSource.H:99
bool match(const std::string &, bool literalMatch=false) const
Smart match as regular expression or as a string.
Definition: wordReI.H:202
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: labelList.H:56
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
void add(GeometricField< typename typeOfSum< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
messageStream Info
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
dictionary dict