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-2020 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 void Foam::faceToCell::combine
70 (
71  topoSet& set,
72  const bool add,
73  const word& setName
74 ) const
75 {
76  // Load the set
77  faceSet loadedSet(mesh_, setName);
78 
79  const labelHashSet& faceLabels = loadedSet;
80 
81  // Handle owner/neighbour/any selection
82  for (const label facei : faceLabels)
83  {
84  if ((option_ == OWNER) || (option_ == ANY))
85  {
86  const label celli = mesh_.faceOwner()[facei];
87 
88  addOrDelete(set, celli, add);
89  }
90 
91  if (mesh_.isInternalFace(facei))
92  {
93  if ((option_ == NEIGHBOUR) || (option_ == ANY))
94  {
95  const label celli = mesh_.faceNeighbour()[facei];
96 
97  addOrDelete(set, celli, add);
98  }
99  }
100  }
101 
102  // Handle all selection.
103  if (option_ == ALL)
104  {
105  // Count number of selected faces per cell.
106 
107  Map<label> facesPerCell(loadedSet.size());
108 
109  for (const label facei : faceLabels)
110  {
111  // Count faces on owner
112  ++(facesPerCell(mesh_.faceOwner()[facei], 0));
113 
114  if (mesh_.isInternalFace(facei))
115  {
116  // Count faces on neighbour
117  ++(facesPerCell(mesh_.faceNeighbour()[facei], 0));
118  }
119  }
120 
121  // Include cells that are referenced as many times as they have faces
122  // -> all faces in set.
123  forAllConstIters(facesPerCell, iter)
124  {
125  const label celli = iter.key();
126  const label count = iter.val();
127 
128  if (count == mesh_.cells()[celli].size())
129  {
130  addOrDelete(set, celli, add);
131  }
132  }
133  }
134 }
135 
136 
137 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
138 
140 (
141  const polyMesh& mesh,
142  const word& setName,
143  const faceAction option
144 )
145 :
147  names_(one{}, setName),
148  option_(option)
149 {}
150 
151 
153 (
154  const polyMesh& mesh,
155  const dictionary& dict
156 )
157 :
158  topoSetCellSource(mesh),
159  names_(),
160  option_(faceActionNames_.get("option", dict))
161 {
162  // Look for 'sets' or 'set'
163  if (!dict.readIfPresent("sets", names_))
164  {
165  names_.resize(1);
166  dict.readEntry("set", names_.first());
167  }
168 }
169 
170 
172 (
173  const polyMesh& mesh,
174  Istream& is
175 )
176 :
177  topoSetCellSource(mesh),
178  names_(one{}, word(checkIs(is))),
179  option_(faceActionNames_.read(checkIs(is)))
180 {}
181 
182 
183 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
184 
186 (
187  const topoSetSource::setAction action,
188  topoSet& set
189 ) const
190 {
191  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
192  {
193  if (verbose_)
194  {
195  Info<< " Adding cells according to faceSet "
196  << flatOutput(names_) << nl;
197  }
198 
199  for (const word& setName : names_)
200  {
201  combine(set, true, setName);
202  }
203  }
204  else if (action == topoSetSource::SUBTRACT)
205  {
206  if (verbose_)
207  {
208  Info<< " Removing cells according to faceSet "
209  << flatOutput(names_) << nl;
210  }
211 
212  for (const word& setName : names_)
213  {
214  combine(set, false, setName);
215  }
216  }
217 }
218 
219 
220 // ************************************************************************* //
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:118
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:132
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1110
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:49
T & first()
Access first element of the list, position [0].
Definition: UList.H:798
const cellList & cells() const
The topoSetCellSource is a intermediate class for handling topoSet sources for selecting cells...
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.
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:1104
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
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Subtract elements from current set.
faceToCell(const polyMesh &mesh, const word &setName, const faceAction option)
Construct from components.
Definition: faceToCell.C:133
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Class with constructor to add usage string to table.
messageStream Info
Information stream (stdout output on master, null elsewhere)
faceAction
Enumeration defining the valid options.
Definition: faceToCell.H:183
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: faceToCell.C:179
Namespace for OpenFOAM.
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:57
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225