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-2026 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 "patchDistWave.H"
28 #include "wallPoint.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(patchDistanceToCell, 0);
36  addToRunTimeSelectionTable(topoSetSource, patchDistanceToCell, word);
37 }
38 
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
42 void Foam::patchDistanceToCell::combine(topoSet& set, const bool add) const
43 {
44  // Mesh wave to determine wall distance
45  scalarField distance(mesh_.nCells());
47  (
48  mesh_,
49  mesh_.boundary().patchSet(patches_),
50  distance
51  );
52 
53  // Add cells below the distance threshold to the set
54  forAll(distance, celli)
55  {
56  if (distance[celli] < distance_)
57  {
58  addOrDelete(set, celli, add);
59  }
60  }
61 }
62 
63 
64 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
65 
67 (
68  const polyMesh& mesh,
69  const dictionary& dict
70 )
71 :
72  topoSetSource(mesh),
73  patches_
74  (
75  dict.found("patches")
76  ? dict.lookup<wordReList>("patches")
77  : wordReList(1, dict.lookup<wordRe>("patch"))
78  ),
79  distance_(dict.lookup<scalar>("distance", dimLength))
80 {}
81 
82 
83 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
84 
86 {}
87 
88 
89 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
90 
92 (
93  const topoSetSource::setAction action,
94  topoSet& set
95 ) const
96 {
97  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
98  {
99  Info<< " Adding cells a distance less than " << distance_
100  << " from patches " << patches_ << " ..." << endl;
101 
102  combine(set, true);
103  }
104  else if (action == topoSetSource::DELETE)
105  {
106  Info<< " Removing cells a distance less than " << distance_
107  << " from patches " << patches_ << " ..." << endl;
108 
109  combine(set, false);
110  }
111 }
112 
113 
114 // ************************************************************************* //
bool found
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
patchDistanceToCell(const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
virtual ~patchDistanceToCell()
Destructor.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool usePatchGroups=true) const
Return the patch set corresponding to the given names.
const polyBoundaryMesh & boundary() const
Return boundary mesh.
Definition: polyMesh.H:393
label nCells() const
void addOrDelete(topoSet &set, const label celli, const bool) const
Add (if bool) celli to set or delete celli from set.
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
const polyMesh & mesh_
Definition: topoSetSource.H:99
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
label calculate(const polyMesh &mesh, const labelHashSet &patchIDs, scalarField &cellDistance)
Calculate distance data from patches.
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
Namespace for OpenFOAM.
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
void add(GeometricField< typename typeOfSum< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
const dimensionSet & dimLength
Definition: dimensions.C:141
messageStream Info
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:50
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
dictionary dict