patchDistanceToCell.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) 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 "patchDistanceToCell.H"
27 #include "patchWave.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(patchDistanceToCell, 0);
35  addToRunTimeSelectionTable(topoSetSource, patchDistanceToCell, word);
36  addToRunTimeSelectionTable(topoSetSource, patchDistanceToCell, istream);
37 }
38 
39 
40 Foam::topoSetSource::addToUsageTable Foam::patchDistanceToCell::usage_
41 (
42  patchDistanceToCell::typeName,
43  "\n Usage: patchDistanceToCell (<patches>) distance\n\n"
44  " Select cells that are below a distance from a list of patches\n\n"
45 );
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 void Foam::patchDistanceToCell::combine(topoSet& set, const bool add) const
51 {
52  const patchWave pw
53  (
54  mesh_,
55  mesh_.boundaryMesh().patchSet(patches_)
56  );
57 
58  forAll(pw.distance(), celli)
59  {
60  if (pw.distance()[celli] < distance_)
61  {
62  addOrDelete(set, celli, add);
63  }
64  }
65 }
66 
67 
68 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
69 
71 (
72  const polyMesh& mesh,
73  const dictionary& dict
74 )
75 :
76  topoSetSource(mesh),
77  patches_
78  (
79  dict.found("patches")
80  ? dict.lookup<wordReList>("patches")
81  : wordReList(1, dict.lookup<wordRe>("patch"))
82  ),
83  distance_(dict.lookup<scalar>("distance"))
84 {}
85 
86 
88 (
89  const polyMesh& mesh,
90  Istream& is
91 )
92 :
93  topoSetSource(mesh),
94  patches_(),
95  distance_()
96 {
97  token firstToken(is);
98  is.putBack(firstToken);
99 
100  if (firstToken == token::BEGIN_LIST)
101  {
102  is >> patches_;
103  }
104  else
105  {
106  patches_ = wordReList(1, word(is));
107  }
108 
109  is >> distance_;
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
114 
116 {}
117 
118 
119 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 
122 (
123  const topoSetSource::setAction action,
124  topoSet& set
125 ) const
126 {
127  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
128  {
129  Info<< " Adding cells a distance less than " << distance_
130  << " from patches " << patches_ << " ..." << endl;
131 
132  combine(set, true);
133  }
134  else if (action == topoSetSource::DELETE)
135  {
136  Info<< " Removing cells a distance less than " << distance_
137  << " from patches " << patches_ << " ..." << endl;
138 
139  combine(set, false);
140  }
141 }
142 
143 
144 // ************************************************************************* //
virtual ~patchDistanceToCell()
Destructor.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:643
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A token holds items read from Istream.
Definition: token.H:72
void putBack(const token &)
Put back token.
Definition: Istream.C:30
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
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
A class for handling words, derived from string.
Definition: word.H:59
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:74
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
Class with constructor to add usage string to table.
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:50
patchDistanceToCell(const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844