nearestToPoint.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 "nearestToPoint.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::nearestToPoint::combine(topoSet& set, const bool add) const
42 {
43  // Do linear search since usually just a few points.
44 
45  forAll(points_, pointi)
46  {
47  const pointField& pts = mesh_.points();
48 
49  if (pts.size())
50  {
51  label minPointi = 0;
52  scalar minDistSqr = magSqr(pts[minPointi] - points_[pointi]);
53 
54  for (label i = 1; i < pts.size(); i++)
55  {
56  scalar distSqr = magSqr(pts[i] - points_[pointi]);
57 
58  if (distSqr < minDistSqr)
59  {
60  minDistSqr = distSqr;
61  minPointi = i;
62  }
63  }
64 
65  addOrDelete(set, minPointi, add);
66  }
67  }
68 }
69 
70 
71 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
72 
74 (
75  const polyMesh& mesh,
76  const pointField& points
77 )
78 :
79  topoSetSource(mesh),
80  points_(points)
81 {}
82 
83 
85 (
86  const polyMesh& mesh,
87  const dictionary& dict
88 )
89 :
90  topoSetSource(mesh),
91  points_(dict.lookup("points"))
92 {}
93 
94 
95 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
96 
98 {}
99 
100 
101 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
102 
104 (
105  const topoSetSource::setAction action,
106  topoSet& set
107 ) const
108 {
109  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
110  {
111  Info<< " Adding points nearest to " << points_ << endl;
112 
113  combine(set, true);
114  }
115  else if (action == topoSetSource::DELETE)
116  {
117  Info<< " Removing points nearest to " << points_ << endl;
118 
119  combine(set, false);
120  }
121 }
122 
123 
124 // ************************************************************************* //
#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 points nearest to points.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
virtual ~nearestToPoint()
Destructor.
nearestToPoint(const polyMesh &mesh, const pointField &points)
Construct from components.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1361
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
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
const pointField & points
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
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
dimensioned< scalar > magSqr(const dimensioned< Type > &)
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
dictionary dict