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-2022 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 void Foam::cellToFace::combine
72 (
73  topoSet& set,
74  const bool add,
75  const word& setName
76 ) const
77 {
78  // Load the set
79  if (!exists(mesh_.time().path()/topoSet::localPath(mesh_, setName)))
80  {
81  SeriousError<< "Cannot load set "
82  << setName << endl;
83  }
84 
85  cellSet loadedSet(mesh_, setName);
86  const labelHashSet& cellLabels = loadedSet;
87 
88  if (option_ == ALL)
89  {
90  // Add all faces from cell
91  for (const label celli : cellLabels)
92  {
93  const labelList& cFaces = mesh_.cells()[celli];
94 
95  addOrDelete(set, cFaces, add);
96  }
97  }
98  else if (option_ == BOTH)
99  {
100  // Add all faces whose both neighbours are in set.
101 
102  const label nInt = mesh_.nInternalFaces();
103  const labelList& own = mesh_.faceOwner();
104  const labelList& nei = mesh_.faceNeighbour();
105  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
106 
107 
108  // Check all internal faces
109  for (label facei = 0; facei < nInt; ++facei)
110  {
111  if (cellLabels.found(own[facei]) && cellLabels.found(nei[facei]))
112  {
113  addOrDelete(set, facei, add);
114  }
115  }
116 
117 
118  // Get coupled cell status
119  boolList neiInSet(mesh_.nBoundaryFaces(), false);
120 
121  for (const polyPatch& pp : patches)
122  {
123  if (pp.coupled())
124  {
125  label facei = pp.start();
126  forAll(pp, i)
127  {
128  neiInSet[facei-nInt] = cellLabels.found(own[facei]);
129  ++facei;
130  }
131  }
132  }
134 
135 
136  // Check all boundary faces
137  for (const polyPatch& pp : patches)
138  {
139  if (pp.coupled())
140  {
141  label facei = pp.start();
142  forAll(pp, i)
143  {
144  if (cellLabels.found(own[facei]) && neiInSet[facei-nInt])
145  {
146  addOrDelete(set, facei, add);
147  }
148  ++facei;
149  }
150  }
151  }
152  }
153  else if (option_ == OUTSIDE)
154  {
155  // Add all faces where only one neighbour is in set.
156 
157  const label nInt = mesh_.nInternalFaces();
158  const labelList& own = mesh_.faceOwner();
159  const labelList& nei = mesh_.faceNeighbour();
160  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
161 
162 
163  // Check all internal faces
164  for (label facei = 0; facei < nInt; ++facei)
165  {
166  if (cellLabels.found(own[facei]) != cellLabels.found(nei[facei]))
167  {
168  addOrDelete(set, facei, add);
169  }
170  }
171 
172 
173  // Get coupled cell status
174  boolList neiInSet(mesh_.nBoundaryFaces(), false);
175 
176  for (const polyPatch& pp : patches)
177  {
178  if (pp.coupled())
179  {
180  label facei = pp.start();
181  forAll(pp, i)
182  {
183  neiInSet[facei-nInt] = cellLabels.found(own[facei]);
184  ++facei;
185  }
186  }
187  }
189 
190 
191  // Check all boundary faces
192  for (const polyPatch& pp : patches)
193  {
194  label facei = pp.start();
195  forAll(pp, i)
196  {
197  if (cellLabels.found(own[facei]) != neiInSet[facei-nInt])
198  {
199  addOrDelete(set, facei, add);
200  }
201  ++facei;
202  }
203  }
204  }
205  else
206  {
208  << "Selected option is not available"
209  << ", option: " << cellActionNames_[option_]
210  << exit(FatalError);
211  }
212 }
213 
214 
215 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
216 
218 (
219  const polyMesh& mesh,
220  const word& setName,
221  const cellAction option
222 )
223 :
225  names_(one{}, setName),
226  option_(option)
227 {}
228 
229 
231 (
232  const polyMesh& mesh,
233  const dictionary& dict
234 )
235 :
236  topoSetFaceSource(mesh),
237  names_(),
238  option_(cellActionNames_.get("option", dict))
239 {
240  // Look for 'sets' or 'set'
241  if (!dict.readIfPresent("sets", names_))
242  {
243  names_.resize(1);
244  dict.readEntry("set", names_.front());
245  }
246 }
247 
248 
250 (
251  const polyMesh& mesh,
252  Istream& is
253 )
254 :
255  topoSetFaceSource(mesh),
256  names_(one{}, word(checkIs(is))),
257  option_(cellActionNames_.read(checkIs(is)))
258 {}
259 
260 
261 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
262 
264 (
265  const topoSetSource::setAction action,
266  topoSet& set
267 ) const
268 {
269  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
270  {
271  if (verbose_)
272  {
273  Info<< " Adding faces according to cell sets: "
274  << flatOutput(names_) << nl;
275  }
276 
277  for (const word& setName : names_)
278  {
279  combine(set, true, setName);
280  }
281  }
282  else if (action == topoSetSource::SUBTRACT)
283  {
284  if (verbose_)
285  {
286  Info<< " Removing faces according to cell sets: "
287  << flatOutput(names_) << nl;
288  }
289 
290  for (const word& setName : names_)
291  {
292  combine(set, false, setName);
293  }
294  }
295 }
296 
297 
298 // ************************************************************************* //
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
fileName path() const
Return path = rootPath/caseName. Same as TimePaths::path()
Definition: Time.H:503
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:160
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:598
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1122
cellAction
Enumeration defining the valid options.
Definition: cellToFace.H:180
Create a new set and ADD elements to it.
Add elements to current set.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
T & front()
Access first element of the list, position [0].
Definition: UListI.H:237
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.
#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:608
const Time & time() const noexcept
Return time registry.
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:257
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:211
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)
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
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues)
Swap coupled boundary face values. Uses eqOp.
Definition: syncTools.H:485
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