nearestToCell.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-2025 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 "nearestToCell.H"
27 #include "meshSearch.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(nearestToCell, 0);
35  addToRunTimeSelectionTable(topoSetSource, nearestToCell, word);
36 }
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 void Foam::nearestToCell::combine(topoSet& set, const bool add) const
42 {
43  const meshSearch& searchEngine = meshSearch::New(mesh_);
44 
45  forAll(points_, pointi)
46  {
47  addOrDelete(set, searchEngine.findNearestCell(points_[pointi]), add);
48  }
49 }
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
55 (
56  const polyMesh& mesh,
57  const pointField& points
58 )
59 :
60  topoSetSource(mesh),
61  points_(points)
62 {}
63 
64 
66 (
67  const polyMesh& mesh,
68  const dictionary& dict
69 )
70 :
71  topoSetSource(mesh),
72  points_(dict.lookup<List<point>>("points", dimLength))
73 {}
74 
75 
76 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
77 
79 {}
80 
81 
82 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
83 
85 (
86  const topoSetSource::setAction action,
87  topoSet& set
88 ) const
89 {
90  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
91  {
92  Info<< " Adding cells nearest to " << points_ << endl;
93 
94  combine(set, true);
95  }
96  else if (action == topoSetSource::DELETE)
97  {
98  Info<< " Removing cells nearest to " << points_ << endl;
99 
100  combine(set, false);
101  }
102 }
103 
104 
105 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
static const meshSearch & New(const polyMesh &mesh, const pointInCellShapes=pointInCellShapes::tets)
Lookup or construct from mesh and cell decomposition option.
Definition: meshSearch.C:61
nearestToCell(const polyMesh &mesh, const pointField &points)
Construct from components.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
virtual ~nearestToCell()
Destructor.
Motion of the mesh specified as a list of pointMeshMovers.
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)
const pointField & points
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
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
vector point
Point is a vector.
Definition: point.H:41
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
dictionary dict