nbrToCell.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 | Copyright (C) 2011 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"
28 
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 defineTypeNameAndDebug(nbrToCell, 0);
37 
38 addToRunTimeSelectionTable(topoSetSource, nbrToCell, word);
39 
40 addToRunTimeSelectionTable(topoSetSource, nbrToCell, istream);
41 
42 }
43 
44 
46 (
47  nbrToCell::typeName,
48  "\n Usage: nbrToCell <nNeighbours>\n\n"
49  " Select all cells with <= nNeighbours neighbouring cells\n\n"
50 );
51 
52 
53 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
54 
55 void Foam::nbrToCell::combine(topoSet& set, const bool add) const
56 {
57  const cellList& cells = mesh().cells();
59 
60  boolList isCoupled(mesh_.nFaces()-mesh_.nInternalFaces(), false);
61 
62  forAll(patches, patchI)
63  {
64  const polyPatch& pp = patches[patchI];
65 
66  if (pp.coupled())
67  {
68  label faceI = pp.start();
69  forAll(pp, i)
70  {
71  isCoupled[faceI-mesh_.nInternalFaces()] = true;
72  faceI++;
73  }
74  }
75  }
76 
77  forAll(cells, cellI)
78  {
79  const cell& cFaces = cells[cellI];
80 
81  label nNbrCells = 0;
82 
83  forAll(cFaces, i)
84  {
85  label faceI = cFaces[i];
86 
87  if (mesh_.isInternalFace(faceI))
88  {
89  nNbrCells++;
90  }
91  else if (isCoupled[faceI-mesh_.nInternalFaces()])
92  {
93  nNbrCells++;
94  }
95  }
96 
97  if (nNbrCells <= minNbrs_)
98  {
99  addOrDelete(set, cellI, add);
100  }
101  }
102 }
103 
104 
105 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
106 
107 // Construct from components
109 (
110  const polyMesh& mesh,
111  const label minNbrs
112 )
113 :
115  minNbrs_(minNbrs)
116 {}
117 
118 
119 // Construct from dictionary
121 (
122  const polyMesh& mesh,
123  const dictionary& dict
124 )
125 :
127  minNbrs_(readLabel(dict.lookup("neighbours")))
128 {}
129 
130 
131 // Construct from Istream
133 (
134  const polyMesh& mesh,
135  Istream& is
136 )
137 :
139  minNbrs_(readLabel(checkIs(is)))
140 {}
141 
142 
143 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
144 
146 {}
147 
148 
149 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
150 
152 (
153  const topoSetSource::setAction action,
154  topoSet& set
155 ) const
156 {
157  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
158  {
159  Info<< " Adding cells with only " << minNbrs_ << " or less"
160  " neighbouring cells" << " ..." << endl;
161 
162  combine(set, true);
163  }
164  else if (action == topoSetSource::DELETE)
165  {
166  Info<< " Removing cells with only " << minNbrs_ << " or less"
167  " neighbouring cells" << " ..." << endl;
168 
169  combine(set, false);
170  }
171 }
172 
173 
174 // ************************************************************************* //
Foam::nbrToCell::combine
void combine(topoSet &set, const bool add) const
Definition: nbrToCell.C:55
Foam::nbrToCell::~nbrToCell
virtual ~nbrToCell()
Destructor.
Definition: nbrToCell.C:145
Foam::topoSetSource::ADD
@ ADD
Definition: topoSetSource.H:87
Foam::nbrToCell::nbrToCell
nbrToCell(const polyMesh &mesh, const label minNbrs)
Construct from components.
Definition: nbrToCell.C:109
Foam::polyBoundaryMesh
Foam::polyBoundaryMesh.
Definition: polyBoundaryMesh.H:60
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::ListListOps::combine
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:100
Foam::polyPatch::coupled
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
Definition: polyPatch.H:322
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:136
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
Foam::topoSetSource::NEW
@ NEW
Definition: topoSetSource.H:85
polyMesh.H
Foam::topoSetSource::mesh
const polyMesh & mesh() const
Definition: topoSetSource.H:274
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::label
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
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::Info
messageStream Info
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::topoSetSource::DELETE
@ DELETE
Definition: topoSetSource.H:88
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::primitiveMesh::nInternalFaces
label nInternalFaces() const
Definition: primitiveMeshI.H:52
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:870
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::topoSetSource
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
Foam::nbrToCell::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: nbrToCell.C:152
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:312
Foam::primitiveMesh::nFaces
label nFaces() const
Definition: primitiveMeshI.H:58
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::nbrToCell::usage_
static addToUsageTable usage_
Add usage string.
Definition: nbrToCell.H:57
Foam::primitiveMesh::isInternalFace
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
Definition: primitiveMeshI.H:70
Foam::readLabel
label readLabel(Istream &is)
Definition: label.H:64
nbrToCell.H
patches
patches[0]
Definition: createSingleCellMesh.H:36
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Definition: topoSetSource.H:126
Foam::nbrToCell::minNbrs_
label minNbrs_
Number of internal faces on cell.
Definition: nbrToCell.H:60
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label cellI, const bool) const
Add (if bool) cellI to set or delete cellI from set.
Definition: topoSetSource.C:140