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 {
38  defineTypeNameAndDebug(cellToFace, 0);
39  addToRunTimeSelectionTable(topoSetSource, cellToFace, word);
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 
108  forAll(patches, patchi)
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  }
122  syncTools::swapBoundaryFaceList(mesh_, neiInSet);
123 
124 
125  // Check all boundary faces
126  forAll(patches, patchi)
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 // ************************************************************************* //
const fvPatchList & patches
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
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
static fileName localPath(const polyMesh &mesh, const word &name)
Name of file set will use.
cellAction
Enumeration defining the valid options.
Definition: cellToFace.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
Definition: polyPatch.H:316
messageStream SeriousError
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:113
A class for handling words, derived from string.
Definition: word.H:59
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
virtual ~cellToFace()
Destructor.
Definition: cellToFace.C:176
Foam::polyBoundaryMesh.
cellToFace(const polyMesh &mesh, const word &setName, const cellAction option)
Construct from components.
Definition: cellToFace.C:150
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
label patchi
A collection of cell labels.
Definition: cellSet.H:48
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:306
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: cellToFace.C:183
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &l)
Swap coupled boundary face values.
Definition: syncTools.H:436
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Namespace for OpenFOAM.
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:77
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864