cellToFace.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 "cellToFace.H"
27 #include "polyMesh.H"
28 #include "cellSet.H"
29 #include "Time.H"
30 #include "syncTools.H"
31 #include "OSspecific.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(cellToFace, 0);
39  addToRunTimeSelectionTable(topoSetSource, cellToFace, word);
40 }
41 
44 {
45  "all",
46  "both"
47 };
48 
49 
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 
52 void Foam::cellToFace::combine(topoSet& set, const bool add) const
53 {
54  // Load the set
55  if (!exists(mesh_.time().path()/topoSet::localPath(mesh_, setName_)))
56  {
57  SeriousError<< "Cannot load set "
58  << setName_ << endl;
59  }
60 
61  cellSet loadedSet(mesh_, setName_);
62 
63  if (option_ == ALL)
64  {
65  // Add all faces from cell
66  forAllConstIter(cellSet, loadedSet, iter)
67  {
68  const label celli = iter.key();
69  const labelList& cFaces = mesh_.cells()[celli];
70 
71  forAll(cFaces, cFacei)
72  {
73  addOrDelete(set, cFaces[cFacei], add);
74  }
75  }
76  }
77  else if (option_ == BOTH)
78  {
79  // Add all faces whose both neighbours are in set.
80 
81  const label nInt = mesh_.nInternalFaces();
82  const labelList& own = mesh_.faceOwner();
83  const labelList& nei = mesh_.faceNeighbour();
84  const polyBoundaryMesh& patches = mesh_.boundary();
85 
86 
87  // Check all internal faces
88  for (label facei = 0; facei < nInt; facei++)
89  {
90  if (loadedSet.found(own[facei]) && loadedSet.found(nei[facei]))
91  {
92  addOrDelete(set, facei, add);
93  }
94  }
95 
96 
97  // Get coupled cell status
98  boolList neiInSet(mesh_.nFaces()-nInt, false);
99 
101  {
102  const polyPatch& pp = patches[patchi];
103 
104  if (pp.coupled())
105  {
106  label facei = pp.start();
107  forAll(pp, i)
108  {
109  neiInSet[facei-nInt] = loadedSet.found(own[facei]);
110  facei++;
111  }
112  }
113  }
115 
116 
117  // Check all boundary faces
119  {
120  const polyPatch& pp = patches[patchi];
121 
122  if (pp.coupled())
123  {
124  label facei = pp.start();
125  forAll(pp, i)
126  {
127  if (loadedSet.found(own[facei]) && neiInSet[facei-nInt])
128  {
129  addOrDelete(set, facei, add);
130  }
131  facei++;
132  }
133  }
134  }
135  }
136 }
137 
138 
139 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
140 
142 (
143  const polyMesh& mesh,
144  const word& setName,
145  const cellAction option
146 )
147 :
148  topoSetSource(mesh),
149  setName_(setName),
150  option_(option)
151 {}
152 
153 
155 (
156  const polyMesh& mesh,
157  const dictionary& dict
158 )
159 :
160  topoSetSource(mesh),
161  setName_(dict.lookup("set")),
162  option_(cellActionNames_.read(dict.lookup("option")))
163 {}
164 
165 
166 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
167 
169 {}
170 
171 
172 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
173 
175 (
176  const topoSetSource::setAction action,
177  topoSet& set
178 ) const
179 {
180  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
181  {
182  Info<< " Adding faces according to cellSet " << setName_
183  << " ..." << endl;
184 
185  combine(set, true);
186  }
187  else if (action == topoSetSource::DELETE)
188  {
189  Info<< " Removing faces according to cellSet " << setName_
190  << " ..." << endl;
191 
192  combine(set, false);
193  }
194 }
195 
196 
197 // ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
Macros for easy insertion into run-time selection tables.
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:55
fileName path() const
Explicitly inherit path from TimePaths to disambiguate from.
Definition: TimePaths.H:138
virtual ~cellToFace()
Destructor.
cellToFace(const polyMesh &mesh, const word &setName, const cellAction option)
Construct from components.
static const NamedEnum< cellAction, 2 > cellActionNames_
Names of the valid options.
Definition: cellToFace.H:69
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
const Time & time() const
Return time.
const polyBoundaryMesh & boundary() const
Return boundary mesh.
Definition: polyMesh.H:393
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1321
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1327
label nInternalFaces() const
const cellList & cells() const
label nFaces() const
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &l)
Swap coupled boundary face values.
Definition: syncTools.H:436
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
static fileName localPath(const polyMesh &mesh, const word &name)
Name of file set will use.
Definition: topoSet.C:123
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
label patchi
const fvPatchList & patches
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: labelList.H:56
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
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
bool exists(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist (as directory or file) in the file system?
Definition: POSIX.C:520
messageStream Info
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
messageStream SeriousError
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
dictionary dict