faceToCell.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 "faceToCell.H"
30 #include "polyMesh.H"
31 #include "faceSet.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(faceToCell, 0);
39  addToRunTimeSelectionTable(topoSetSource, faceToCell, word);
40  addToRunTimeSelectionTable(topoSetSource, faceToCell, istream);
41  addToRunTimeSelectionTable(topoSetCellSource, faceToCell, word);
42  addToRunTimeSelectionTable(topoSetCellSource, faceToCell, istream);
43 }
44 
45 
46 Foam::topoSetSource::addToUsageTable Foam::faceToCell::usage_
47 (
48  faceToCell::typeName,
49  "\n Usage: faceToCell <faceSet> neighbour|owner|any|all\n\n"
50  " Select cells that are the owner|neighbour|any"
51  " of the faces in the faceSet or where all faces are in the faceSet\n\n"
52 );
53 
54 const Foam::Enum
55 <
57 >
58 Foam::faceToCell::faceActionNames_
59 ({
60  { faceAction::ANY, "any" },
61  { faceAction::ALL, "all" },
62  { faceAction::OWNER, "owner" },
63  { faceAction::NEIGHBOUR, "neighbour" },
64 });
65 
66 
67 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
68 
69 template<class Selector>
70 void Foam::faceToCell::combineImpl
71 (
72  topoSet& set,
73  const bool add,
74  const Selector& faceLabels
75 ) const
76 {
77  // Handle owner/neighbour/any selection
78  for (const label facei : faceLabels)
79  {
80  if ((option_ == OWNER) || (option_ == ANY))
81  {
82  const label celli = mesh_.faceOwner()[facei];
83 
84  addOrDelete(set, celli, add);
85  }
86 
87  if (mesh_.isInternalFace(facei))
88  {
89  if ((option_ == NEIGHBOUR) || (option_ == ANY))
90  {
91  const label celli = mesh_.faceNeighbour()[facei];
92 
93  addOrDelete(set, celli, add);
94  }
95  }
96  }
97 
98  // Handle all selection.
99  if (option_ == ALL)
100  {
101  // Count number of selected faces per cell.
102 
103  Map<label> facesPerCell(faceLabels.size());
104 
105  for (const label facei : faceLabels)
106  {
107  // Count faces on owner
108  ++(facesPerCell(mesh_.faceOwner()[facei], 0));
109 
110  if (mesh_.isInternalFace(facei))
111  {
112  // Count faces on neighbour
113  ++(facesPerCell(mesh_.faceNeighbour()[facei], 0));
114  }
115  }
116 
117  // Include cells that are referenced as many times as they have faces
118  // -> all faces in set.
119  forAllConstIters(facesPerCell, iter)
120  {
121  const label celli = iter.key();
122  const label count = iter.val();
123 
124  if (count == mesh_.cells()[celli].size())
125  {
126  addOrDelete(set, celli, add);
127  }
128  }
129  }
130 }
131 
132 
133 void Foam::faceToCell::combine
134 (
135  topoSet& set,
136  const bool add,
137  const word& setName
138 ) const
139 {
140  if (isZone_)
141  {
142  const labelList& faceLabels = mesh_.faceZones()[setName];
143 
144  combineImpl(set, add, faceLabels);
145  }
146  else
147  {
148  // Load the set
149  faceSet loadedSet(mesh_, setName, IOobject::NO_REGISTER);
150  const labelHashSet& faceLabels = loadedSet;
151 
152  combineImpl(set, add, faceLabels);
153  }
154 }
155 
156 
157 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
158 
160 (
161  const polyMesh& mesh,
162  const word& setName,
163  const faceAction option
164 )
165 :
166  topoSetCellSource(mesh),
167  names_(Foam::one{}, setName),
168  isZone_(false),
169  option_(option)
170 {}
171 
172 
174 (
175  const polyMesh& mesh,
176  const dictionary& dict
177 )
178 :
179  topoSetCellSource(mesh, dict),
180  names_(),
181  isZone_(topoSetSource::readNames(dict, names_)),
182  option_(faceActionNames_.get("option", dict))
183 {}
184 
185 
187 (
188  const polyMesh& mesh,
189  Istream& is
190 )
191 :
193  names_(Foam::one{}, word(checkIs(is))),
194  isZone_(false),
195  option_(faceActionNames_.read(checkIs(is)))
196 {}
197 
198 
199 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
200 
202 (
203  const topoSetSource::setAction action,
204  topoSet& set
205 ) const
206 {
207  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
208  {
209  if (verbose_)
210  {
211  Info<< " Adding cells according to face "
212  << (isZone_ ? "zones: " : "sets: ")
213  << flatOutput(names_) << nl;
214  }
215 
216  for (const word& setName : names_)
217  {
218  combine(set, true, setName);
219  }
220  }
221  else if (action == topoSetSource::SUBTRACT)
222  {
223  if (verbose_)
224  {
225  Info<< " Removing cells according to face "
226  << (isZone_ ? "zones: " : "sets: ")
227  << flatOutput(names_) << nl;
228  }
229 
230  for (const word& setName : names_)
231  {
232  combine(set, false, setName);
233  }
234  }
235 }
236 
237 
238 // ************************************************************************* //
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
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1122
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
const cellList & cells() const
The topoSetCellSource is a intermediate class for handling topoSet sources for selecting cells...
labelList faceLabels(nFaceLabels)
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.
bool isInternalFace(const label faceIndex) const noexcept
Return true if given face label is internal to the mesh.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:62
dynamicFvMesh & mesh
setAction
Enumeration defining various actions.
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1116
const polyMesh & mesh_
Reference to the mesh.
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.
faceToCell(const polyMesh &mesh, const word &setName, const faceAction option)
Construct from components.
Definition: faceToCell.C:153
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.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
faceAction
Enumeration defining the valid options.
Definition: faceToCell.H:192
List< label > labelList
A List of labels.
Definition: List.H:62
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: faceToCell.C:195
Do not request registration (bool: false)
Namespace for OpenFOAM.
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
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