haloToCell.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) 2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "haloToCell.H"
29 #include "polyMesh.H"
30 #include "cellSet.H"
31 #include "syncTools.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(haloToCell, 0);
39  addToRunTimeSelectionTable(topoSetSource, haloToCell, word);
40  addToRunTimeSelectionTable(topoSetSource, haloToCell, istream);
41  addToRunTimeSelectionTable(topoSetCellSource, haloToCell, word);
42  addToRunTimeSelectionTable(topoSetCellSource, haloToCell, istream);
44  (
45  topoSetCellSource,
46  haloToCell,
47  word,
48  halo
49  );
51  (
52  topoSetCellSource,
53  haloToCell,
54  istream,
55  halo
56  );
57 }
58 
59 
60 Foam::topoSetSource::addToUsageTable Foam::haloToCell::usage_
61 (
62  haloToCell::typeName,
63  "\n Usage: haloToCell\n\n"
64  " Select halo cells\n\n"
65 );
66 
67 
68 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
69 
70 void Foam::haloToCell::combine(topoSet& set, const bool add) const
71 {
72  const cellList& cells = mesh_.cells();
73  const labelList& faceOwn = mesh_.faceOwner();
74  const labelList& faceNei = mesh_.faceNeighbour();
75 
76 
77  // The starting set of cells
78  bitSet current(cells.size());
79 
80  for (const label celli : set)
81  {
82  current.set(celli);
83  }
84 
85  // The perimeter faces of the cell set
86  bitSet outsideFaces(mesh_.nFaces());
87 
88  bitSet updates(cells.size());
89 
90  for (label stepi = 0; stepi < steps_; ++stepi)
91  {
92  // Mark up perimeter faces. Each mesh face is attached exactly
93  // (0,1,2) times to a cell in the set. Using flip() each time means
94  // the only 'on' bits correspond to faces that are attached once to
95  // the cell set - ie, faces on the perimeter of the set.
96 
97  outsideFaces.reset();
98  for (const label celli : current)
99  {
100  for (const label facei : cells[celli])
101  {
102  outsideFaces.flip(facei);
103  }
104  }
105 
106  // Use xor to eliminate perimeter faces that are actually attached
107  // on both sides of the interface.
108 
110  (
111  mesh_,
112  outsideFaces,
113  bitXorEqOp<unsigned int>()
114  );
115 
116  // Select all cells attached to the perimeter faces.
117  updates.reset();
118  for (const label facei : outsideFaces)
119  {
120  updates.set(faceOwn[facei]);
121  if (mesh_.isInternalFace(facei))
122  {
123  updates.set(faceNei[facei]);
124  }
125  }
126 
127  if (add)
128  {
129  // Restrict to cells not already in the current set
130  updates -= current;
131 
132  if (verbose_)
133  {
134  Info<< " Grow " << current.count()
135  << " by " << updates.count() << endl;
136  }
137 
138  // Add to current set for the next loop
139  current |= updates;
140  }
141  else
142  {
143  // Restrict to cells already in the current set
144  updates &= current;
145 
146  if (verbose_)
147  {
148  Info<< " Shrink " << current.count()
149  << " by " << updates.count() << endl;
150  }
151 
152  // Remove from current set for the next loop
153  current -= updates;
154  }
155 
156  if (updates.none())
157  {
158  break;
159  }
160 
161  addOrDelete(set, updates, add);
162  }
163 }
164 
165 
166 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
167 
169 (
170  const polyMesh& mesh,
171  const label steps
172 )
173 :
175  steps_(max(steps, 1))
176 {}
177 
178 
180 (
181  const polyMesh& mesh,
182  const dictionary& dict
183 )
184 :
185  haloToCell(mesh, dict.getOrDefault<label>("steps", 1))
186 {}
187 
188 
190 (
191  const polyMesh& mesh,
192  Istream& is
193 )
194 :
195  haloToCell(mesh, 1)
196 {}
197 
198 
199 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
200 
202 (
203  const topoSetSource::setAction action,
204  topoSet& set
205 ) const
206 {
207  if (action == topoSetSource::NEW)
208  {
209  if (verbose_)
210  {
211  Info<< " action=new option is not available for haloToCell" << nl
212  << " Cannot create new of halo (needs a starting set)"
213  << endl;
214  }
215 
216  set.clear();
217  }
218  else if (action == topoSetSource::ADD)
219  {
220  if (verbose_)
221  {
222  Info<< " Adding halo cells to the current set, using "
223  << steps_ << " step ..." << endl;
224  }
225 
226  combine(set, true);
227  }
228  else if (action == topoSetSource::SUBTRACT)
229  {
230  if (verbose_)
231  {
232  Info<< " Removing cells on the perimeter of current set, using "
233  << steps_ << " step ..." << endl;
234  }
235 
236  combine(set, false);
237  }
238 }
239 
240 
241 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::haloToCell::haloToCell
haloToCell(const polyMesh &mesh, const label steps=1)
Construct from components.
Definition: haloToCell.C:169
Foam::topoSetSource::ADD
Add elements to the set.
Definition: topoSetSource.H:101
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::primitiveMesh::nFaces
label nFaces() const
Number of mesh faces.
Definition: primitiveMeshI.H:90
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:124
Foam::haloToCell::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: haloToCell.C:202
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:138
haloToCell.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:99
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:106
polyMesh.H
syncTools.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::syncTools::syncFaceList
static void syncFaceList(const polyMesh &mesh, UList< T > &faceValues, const CombineOp &cop)
Synchronize values on all mesh faces.
Definition: syncTools.H:390
Foam::haloToCell
A topoSetCellSource to select cells attached to the outside of this cellSet, and add into/remove from...
Definition: haloToCell.H:148
Foam::topoSetSource::verbose_
bool verbose_
Verbosity (default: true)
Definition: topoSetSource.H:154
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::ListListOps::combine
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:69
Foam::polyMesh::faceOwner
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1107
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
Foam::cellList
List< cell > cellList
A List of cells.
Definition: cellListFwd.H:47
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::topoSetSource::SUBTRACT
Subtract elements from the set.
Definition: topoSetSource.H:102
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::primitiveMesh::isInternalFace
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
Definition: primitiveMeshI.H:102
Foam::topoSetCellSource
The topoSetCellSource is a intermediate class for handling topoSet sources for selecting cells.
Definition: topoSetCellSource.H:54
Foam::List::set
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
Definition: List.H:325
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
Definition: topoSetSource.C:170
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
cellSet.H
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Reference to the mesh.
Definition: topoSetSource.H:151
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:122
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::polyMesh::faceNeighbour
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1113