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-2021 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 {
36 }
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 void Foam::nbrToCell::combine(topoSet& set, const bool add) const
42 {
43  const cellList& cells = mesh().cells();
44  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
45 
46  boolList isCoupled(mesh_.nFaces()-mesh_.nInternalFaces(), false);
47 
49  {
50  const polyPatch& pp = patches[patchi];
51 
52  if (pp.coupled())
53  {
54  label facei = pp.start();
55  forAll(pp, i)
56  {
57  isCoupled[facei-mesh_.nInternalFaces()] = true;
58  facei++;
59  }
60  }
61  }
62 
63  forAll(cells, celli)
64  {
65  const cell& cFaces = cells[celli];
66 
67  label nNbrCells = 0;
68 
69  forAll(cFaces, i)
70  {
71  label facei = cFaces[i];
72 
73  if (mesh_.isInternalFace(facei))
74  {
75  nNbrCells++;
76  }
77  else if (isCoupled[facei-mesh_.nInternalFaces()])
78  {
79  nNbrCells++;
80  }
81  }
82 
83  if (nNbrCells <= minNbrs_)
84  {
85  addOrDelete(set, celli, add);
86  }
87  }
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
92 
94 (
95  const polyMesh& mesh,
96  const label minNbrs
97 )
98 :
99  topoSetSource(mesh),
100  minNbrs_(minNbrs)
101 {}
102 
103 
105 (
106  const polyMesh& mesh,
107  const dictionary& dict
108 )
109 :
110  topoSetSource(mesh),
111  minNbrs_(dict.lookup<label>("neighbours"))
112 {}
113 
114 
115 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
116 
118 {}
119 
120 
121 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
122 
124 (
125  const topoSetSource::setAction action,
126  topoSet& set
127 ) const
128 {
129  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
130  {
131  Info<< " Adding cells with only " << minNbrs_ << " or less"
132  " neighbouring cells" << " ..." << endl;
133 
134  combine(set, true);
135  }
136  else if (action == topoSetSource::DELETE)
137  {
138  Info<< " Removing cells with only " << minNbrs_ << " or less"
139  " neighbouring cells" << " ..." << endl;
140 
141  combine(set, false);
142  }
143 }
144 
145 
146 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
A topoSetSource to select cells based on number of neighbouring cells (i.e. number of internal or cou...
Definition: nbrToCell.H:52
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: nbrToCell.C:124
nbrToCell(const polyMesh &mesh, const label minNbrs)
Construct from components.
Definition: nbrToCell.C:94
virtual ~nbrToCell()
Destructor.
Definition: nbrToCell.C:117
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:403
label nInternalFaces() const
label nFaces() const
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
const cellList & cells() const
Base class of a source for a topoSet.
Definition: topoSetSource.H:64
void addOrDelete(topoSet &set, const label celli, const bool) const
Add (if bool) celli to set or delete celli from set.
Definition: topoSetSource.C:96
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
const polyMesh & mesh_
Definition: topoSetSource.H:99
const polyMesh & mesh() const
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:65
A class for handling words, derived from string.
Definition: word.H:62
label patchi
const cellShapeList & cells
const fvPatchList & patches
Namespace for OpenFOAM.
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
List< cell > cellList
list of cells
Definition: cellList.H:42
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
defineTypeNameAndDebug(combustionModel, 0)
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
dictionary dict