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-2021 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  template<>
42  const char* Foam::NamedEnum
43  <
45  2
46  >::names[] =
47  {
48  "all",
49  "both"
50  };
51 }
52 
53 
55  Foam::cellToFace::cellActionNames_;
56 
57 
58 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
59 
60 void Foam::cellToFace::combine(topoSet& set, const bool add) const
61 {
62  // Load the set
63  if (!exists(mesh_.time().path()/topoSet::localPath(mesh_, setName_)))
64  {
65  SeriousError<< "Cannot load set "
66  << setName_ << endl;
67  }
68 
69  cellSet loadedSet(mesh_, setName_);
70 
71  if (option_ == ALL)
72  {
73  // Add all faces from cell
74  forAllConstIter(cellSet, loadedSet, iter)
75  {
76  const label celli = iter.key();
77  const labelList& cFaces = mesh_.cells()[celli];
78 
79  forAll(cFaces, cFacei)
80  {
81  addOrDelete(set, cFaces[cFacei], add);
82  }
83  }
84  }
85  else if (option_ == BOTH)
86  {
87  // Add all faces whose both neighbours are in set.
88 
89  const label nInt = mesh_.nInternalFaces();
90  const labelList& own = mesh_.faceOwner();
91  const labelList& nei = mesh_.faceNeighbour();
92  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
93 
94 
95  // Check all internal faces
96  for (label facei = 0; facei < nInt; facei++)
97  {
98  if (loadedSet.found(own[facei]) && loadedSet.found(nei[facei]))
99  {
100  addOrDelete(set, facei, add);
101  }
102  }
103 
104 
105  // Get coupled cell status
106  boolList neiInSet(mesh_.nFaces()-nInt, false);
107 
109  {
110  const polyPatch& pp = patches[patchi];
111 
112  if (pp.coupled())
113  {
114  label facei = pp.start();
115  forAll(pp, i)
116  {
117  neiInSet[facei-nInt] = loadedSet.found(own[facei]);
118  facei++;
119  }
120  }
121  }
123 
124 
125  // Check all boundary faces
127  {
128  const polyPatch& pp = patches[patchi];
129 
130  if (pp.coupled())
131  {
132  label facei = pp.start();
133  forAll(pp, i)
134  {
135  if (loadedSet.found(own[facei]) && neiInSet[facei-nInt])
136  {
137  addOrDelete(set, facei, add);
138  }
139  facei++;
140  }
141  }
142  }
143  }
144 }
145 
146 
147 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
148 
150 (
151  const polyMesh& mesh,
152  const word& setName,
153  const cellAction option
154 )
155 :
156  topoSetSource(mesh),
157  setName_(setName),
158  option_(option)
159 {}
160 
161 
163 (
164  const polyMesh& mesh,
165  const dictionary& dict
166 )
167 :
168  topoSetSource(mesh),
169  setName_(dict.lookup("set")),
170  option_(cellActionNames_.read(dict.lookup("option")))
171 {}
172 
173 
174 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
175 
177 {}
178 
179 
180 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
181 
183 (
184  const topoSetSource::setAction action,
185  topoSet& set
186 ) const
187 {
188  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
189  {
190  Info<< " Adding faces according to cellSet " << setName_
191  << " ..." << endl;
192 
193  combine(set, true);
194  }
195  else if (action == topoSetSource::DELETE)
196  {
197  Info<< " Removing faces according to cellSet " << setName_
198  << " ..." << endl;
199 
200  combine(set, false);
201  }
202 }
203 
204 
205 // ************************************************************************* //
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:434
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
Macros for easy insertion into run-time selection tables.
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:54
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:183
cellToFace(const polyMesh &mesh, const word &setName, const cellAction option)
Construct from components.
Definition: cellToFace.C:150
cellAction
Enumeration defining the valid options.
Definition: cellToFace.H:60
virtual ~cellToFace()
Destructor.
Definition: cellToFace.C:176
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
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:1387
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:403
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1393
label nInternalFaces() const
label nFaces() const
const cellList & cells() 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:96
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:65
static fileName localPath(const polyMesh &mesh, const word &name)
Name of file set will use.
A class for handling words, derived from string.
Definition: word.H:62
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
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
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
defineTypeNameAndDebug(combustionModel, 0)
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
dictionary dict