cellToFace.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2018-2024 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "cellToFace.H"
30 #include "polyMesh.H"
31 #include "cellSet.H"
32 #include "Time.H"
33 #include "syncTools.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(cellToFace, 0);
41  addToRunTimeSelectionTable(topoSetSource, cellToFace, word);
42  addToRunTimeSelectionTable(topoSetSource, cellToFace, istream);
43  addToRunTimeSelectionTable(topoSetFaceSource, cellToFace, word);
44  addToRunTimeSelectionTable(topoSetFaceSource, cellToFace, istream);
45 }
46 
47 
48 Foam::topoSetSource::addToUsageTable Foam::cellToFace::usage_
49 (
50  cellToFace::typeName,
51  "\n Usage: cellToFace <cellSet> all|both|outside\n\n"
52  " Select -all : all faces of cells in the cellSet\n"
53  " -both: faces where both neighbours are in the cellSet\n\n"
54 );
55 
56 
57 const Foam::Enum
58 <
60 >
61 Foam::cellToFace::cellActionNames_
62 ({
63  { cellAction::ALL, "all" },
64  { cellAction::BOTH, "both" },
65  { cellAction::OUTSIDE, "outside" }
66 });
67 
68 
69 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
70 
71 template<class Selector>
72 void Foam::cellToFace::combineImpl
73 (
74  topoSet& set,
75  const bool add,
76  const Selector& cellLabels
77 ) const
78 {
79  if (option_ == ALL)
80  {
81  // Add all faces from cell
82  for (const label celli : cellLabels)
83  {
84  const labelList& cFaces = mesh_.cells()[celli];
85 
86  addOrDelete(set, cFaces, add);
87  }
88  }
89  else if (option_ == BOTH)
90  {
91  // Add all faces whose both neighbours are in set.
92 
93  const label nInt = mesh_.nInternalFaces();
94  const labelList& own = mesh_.faceOwner();
95  const labelList& nei = mesh_.faceNeighbour();
96  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
97 
98 
99  // Check all internal faces
100  for (label facei = 0; facei < nInt; ++facei)
101  {
102  if (cellLabels.found(own[facei]) && cellLabels.found(nei[facei]))
103  {
104  addOrDelete(set, facei, add);
105  }
106  }
107 
108 
109  // Get coupled cell status
110  boolList neiInSet(mesh_.nBoundaryFaces(), false);
111 
112  for (const polyPatch& pp : patches)
113  {
114  if (pp.coupled())
115  {
116  label facei = pp.start();
117  forAll(pp, i)
118  {
119  neiInSet[facei-nInt] = cellLabels.found(own[facei]);
120  ++facei;
121  }
122  }
123  }
125 
126 
127  // Check all boundary faces
128  for (const polyPatch& pp : patches)
129  {
130  if (pp.coupled())
131  {
132  label facei = pp.start();
133  forAll(pp, i)
134  {
135  if (cellLabels.found(own[facei]) && neiInSet[facei-nInt])
136  {
137  addOrDelete(set, facei, add);
138  }
139  ++facei;
140  }
141  }
142  }
143  }
144  else if (option_ == OUTSIDE)
145  {
146  // Add all faces where only one neighbour is in set.
147 
148  const label nInt = mesh_.nInternalFaces();
149  const labelList& own = mesh_.faceOwner();
150  const labelList& nei = mesh_.faceNeighbour();
151  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
152 
153 
154  // Check all internal faces
155  for (label facei = 0; facei < nInt; ++facei)
156  {
157  if (cellLabels.found(own[facei]) != cellLabels.found(nei[facei]))
158  {
159  addOrDelete(set, facei, add);
160  }
161  }
162 
163 
164  // Get coupled cell status
165  boolList neiInSet(mesh_.nBoundaryFaces(), false);
166 
167  for (const polyPatch& pp : patches)
168  {
169  if (pp.coupled())
170  {
171  label facei = pp.start();
172  forAll(pp, i)
173  {
174  neiInSet[facei-nInt] = cellLabels.found(own[facei]);
175  ++facei;
176  }
177  }
178  }
180 
181 
182  // Check all boundary faces
183  for (const polyPatch& pp : patches)
184  {
185  label facei = pp.start();
186  forAll(pp, i)
187  {
188  if (cellLabels.found(own[facei]) != neiInSet[facei-nInt])
189  {
190  addOrDelete(set, facei, add);
191  }
192  ++facei;
193  }
194  }
195  }
196  else
197  {
199  << "Selected option is not available"
200  << ", option: " << cellActionNames_[option_]
201  << exit(FatalError);
202  }
203 }
204 
205 
206 void Foam::cellToFace::combine
207 (
208  topoSet& set,
209  const bool add,
210  const word& setName
211 ) const
212 {
213  if (isZone_)
214  {
215  const labelList& cellLabels = mesh_.cellZones()[setName];
216 
217  combineImpl(set, add, cellLabels);
218  }
219  else
220  {
221  // Load the set
222  if (!exists(mesh_.time().path()/topoSet::localPath(mesh_, setName)))
223  {
225  << "Cannot load set " << setName << endl;
226  }
227 
228  cellSet loadedSet(mesh_, setName, IOobject::NO_REGISTER);
229  const labelHashSet& cellLabels = loadedSet;
230 
231  combineImpl(set, add, cellLabels);
232  }
233 }
234 
235 
236 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
237 
239 (
240  const polyMesh& mesh,
241  const word& setName,
242  const cellAction option
243 )
244 :
245  topoSetFaceSource(mesh),
246  names_(Foam::one{}, setName),
247  isZone_(false),
248  option_(option)
249 {}
250 
251 
253 (
254  const polyMesh& mesh,
255  const dictionary& dict
256 )
257 :
258  topoSetFaceSource(mesh, dict),
259  names_(),
260  isZone_(topoSetSource::readNames(dict, names_)),
261  option_(cellActionNames_.get("option", dict))
262 {}
263 
264 
266 (
267  const polyMesh& mesh,
268  Istream& is
269 )
270 :
272  names_(Foam::one{}, word(checkIs(is))),
273  isZone_(false),
274  option_(cellActionNames_.read(checkIs(is)))
275 {}
276 
277 
278 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
279 
281 (
282  const topoSetSource::setAction action,
283  topoSet& set
284 ) const
285 {
286  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
287  {
288  if (verbose_)
289  {
290  Info<< " Adding faces according to cell "
291  << (isZone_ ? "zones: " : "sets: ")
292  << flatOutput(names_) << nl;
293  }
294 
295  for (const word& setName : names_)
296  {
297  combine(set, true, setName);
298  }
299  }
300  else if (action == topoSetSource::SUBTRACT)
301  {
302  if (verbose_)
303  {
304  Info<< " Removing faces according to cell "
305  << (isZone_ ? "zones: " : "sets: ")
306  << flatOutput(names_) << nl;
307  }
308 
309  for (const word& setName : names_)
310  {
311  combine(set, false, setName);
312  }
313  }
314 }
315 
316 
317 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:608
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1122
cellAction
Enumeration defining the valid options.
Definition: cellToFace.H:191
Create a new set and ADD elements to it.
Add elements to current set.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues, const bool parRun=UPstream::parRun())
Swap coupled boundary face values. Uses eqOp.
Definition: syncTools.H:524
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
const cellList & cells() const
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when &#39;add&#39; is true.
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:62
dynamicFvMesh & mesh
messageStream SeriousError
Error stream (stdout output on all processes), with additional &#39;FOAM Serious Error&#39; header text...
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:609
The topoSetFaceSource is a intermediate class for handling topoSet sources for selecting faces...
setAction
Enumeration defining various actions.
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1116
bool exists(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Definition: POSIX.C:835
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: cellToFace.C:274
label nInternalFaces() const noexcept
Number of internal faces.
const polyMesh & mesh_
Reference to the mesh.
cellToFace(const polyMesh &mesh, const word &setName, const cellAction option)
Construct from components.
Definition: cellToFace.C:232
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
Subtract elements from current set.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: error.H:64
Class with constructor to add usage string to table.
const polyBoundaryMesh & patches
messageStream Info
Information stream (stdout output on master, null elsewhere)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
List< label > labelList
A List of labels.
Definition: List.H:62
label nBoundaryFaces() const noexcept
Number of boundary faces (== nFaces - nInternalFaces)
List< bool > boolList
A List of bools.
Definition: List.H:60
static fileName localPath(const polyMesh &mesh, const word &name)
Name of file set will use.
Definition: topoSet.C:127
Do not request registration (bool: false)
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:56
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225