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-2025 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 {
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_.boundaryMesh();
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 :
149  setName_(setName),
150  option_(option)
151 {}
152 
153 
155 (
156  const polyMesh& mesh,
157  const dictionary& dict
158 )
159 :
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:433
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:476
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
A topoSetSource to select a faceSet from cells.
Definition: cellToFace.H:56
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: cellToFace.C:175
cellToFace(const polyMesh &mesh, const word &setName, const cellAction option)
Construct from components.
Definition: cellToFace.C:142
cellAction
Enumeration defining the valid options.
Definition: cellToFace.H:63
static const NamedEnum< cellAction, 2 > cellActionNames_
Names of the valid options.
Definition: cellToFace.H:69
virtual ~cellToFace()
Destructor.
Definition: cellToFace.C:168
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const Time & time() const
Return time.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1357
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:401
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1363
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
Base class of a source for a topoSet.
Definition: topoSetSource.H:64
void addOrDelete(topoSet &set, const label celli, const bool) const
Add (if bool) celli to set or delete celli from set.
Definition: topoSetSource.C:87
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
const polyMesh & mesh_
Definition: topoSetSource.H:99
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
static fileName localPath(const polyMesh &mesh, const word &name)
Name of file set will use.
Definition: topoSet.C:123
A class for handling words, derived from string.
Definition: word.H:62
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
label patchi
const fvPatchList & patches
Namespace for OpenFOAM.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
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)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
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
defineTypeNameAndDebug(combustionModel, 0)
void add(LagrangianPatchField< typename typeOfSum< Type1, Type2 >::type > &f, const LagrangianPatchField< Type1 > &f1, const LagrangianPatchField< Type2 > &f2)
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
dictionary dict