nbrToCell.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "nbrToCell.H"
27 #include "polyMesh.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(nbrToCell, 0);
35  addToRunTimeSelectionTable(topoSetSource, nbrToCell, word);
36  addToRunTimeSelectionTable(topoSetSource, nbrToCell, istream);
37 }
38 
39 
40 Foam::topoSetSource::addToUsageTable Foam::nbrToCell::usage_
41 (
42  nbrToCell::typeName,
43  "\n Usage: nbrToCell <nNeighbours>\n\n"
44  " Select all cells with <= nNeighbours neighbouring cells\n\n"
45 );
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 void Foam::nbrToCell::combine(topoSet& set, const bool add) const
51 {
52  const cellList& cells = mesh().cells();
53  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
54 
55  boolList isCoupled(mesh_.nFaces()-mesh_.nInternalFaces(), false);
56 
57  forAll(patches, patchi)
58  {
59  const polyPatch& pp = patches[patchi];
60 
61  if (pp.coupled())
62  {
63  label facei = pp.start();
64  forAll(pp, i)
65  {
66  isCoupled[facei-mesh_.nInternalFaces()] = true;
67  facei++;
68  }
69  }
70  }
71 
72  forAll(cells, celli)
73  {
74  const cell& cFaces = cells[celli];
75 
76  label nNbrCells = 0;
77 
78  forAll(cFaces, i)
79  {
80  label facei = cFaces[i];
81 
82  if (mesh_.isInternalFace(facei))
83  {
84  nNbrCells++;
85  }
86  else if (isCoupled[facei-mesh_.nInternalFaces()])
87  {
88  nNbrCells++;
89  }
90  }
91 
92  if (nNbrCells <= minNbrs_)
93  {
94  addOrDelete(set, celli, add);
95  }
96  }
97 }
98 
99 
100 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
101 
103 (
104  const polyMesh& mesh,
105  const label minNbrs
106 )
107 :
108  topoSetSource(mesh),
109  minNbrs_(minNbrs)
110 {}
111 
112 
114 (
115  const polyMesh& mesh,
116  const dictionary& dict
117 )
118 :
119  topoSetSource(mesh),
120  minNbrs_(dict.lookup<label>("neighbours"))
121 {}
122 
123 
125 (
126  const polyMesh& mesh,
127  Istream& is
128 )
129 :
130  topoSetSource(mesh),
131  minNbrs_(readLabel(checkIs(is)))
132 {}
133 
134 
135 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
136 
138 {}
139 
140 
141 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
142 
144 (
145  const topoSetSource::setAction action,
146  topoSet& set
147 ) const
148 {
149  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
150  {
151  Info<< " Adding cells with only " << minNbrs_ << " or less"
152  " neighbouring cells" << " ..." << endl;
153 
154  combine(set, true);
155  }
156  else if (action == topoSetSource::DELETE)
157  {
158  Info<< " Removing cells with only " << minNbrs_ << " or less"
159  " neighbouring cells" << " ..." << endl;
160 
161  combine(set, false);
162  }
163 }
164 
165 
166 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
virtual ~nbrToCell()
Destructor.
Definition: nbrToCell.C:137
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
const cellList & cells() const
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
dynamicFvMesh & mesh
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
label readLabel(Istream &is)
Definition: label.H:64
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
label patchi
Class with constructor to add usage string to table.
nbrToCell(const polyMesh &mesh, const label minNbrs)
Construct from components.
Definition: nbrToCell.C:103
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: nbrToCell.C:144
List< cell > cellList
list of cells
Definition: cellList.H:42
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:812