mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
nearestToPoint
This commit is contained in:
@ -107,6 +107,7 @@ $(pointSources)/faceToPoint/faceToPoint.C
|
|||||||
$(pointSources)/boxToPoint/boxToPoint.C
|
$(pointSources)/boxToPoint/boxToPoint.C
|
||||||
$(pointSources)/surfaceToPoint/surfaceToPoint.C
|
$(pointSources)/surfaceToPoint/surfaceToPoint.C
|
||||||
$(pointSources)/zoneToPoint/zoneToPoint.C
|
$(pointSources)/zoneToPoint/zoneToPoint.C
|
||||||
|
$(pointSources)/nearestToPoint/nearestToPoint.C
|
||||||
|
|
||||||
surfaceSets/surfaceSets.C
|
surfaceSets/surfaceSets.C
|
||||||
|
|
||||||
|
|||||||
154
src/meshTools/sets/pointSources/nearestToPoint/nearestToPoint.C
Normal file
154
src/meshTools/sets/pointSources/nearestToPoint/nearestToPoint.C
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by the
|
||||||
|
Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "nearestToPoint.H"
|
||||||
|
#include "polyMesh.H"
|
||||||
|
#include "meshSearch.H"
|
||||||
|
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
defineTypeNameAndDebug(nearestToPoint, 0);
|
||||||
|
|
||||||
|
addToRunTimeSelectionTable(topoSetSource, nearestToPoint, word);
|
||||||
|
|
||||||
|
addToRunTimeSelectionTable(topoSetSource, nearestToPoint, istream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::topoSetSource::addToUsageTable Foam::nearestToPoint::usage_
|
||||||
|
(
|
||||||
|
nearestToPoint::typeName,
|
||||||
|
"\n Usage: nearestToPoint (pt0 .. ptn)\n\n"
|
||||||
|
" Select the nearest point for each of the points pt0 ..ptn\n\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
|
void Foam::nearestToPoint::combine(topoSet& set, const bool add) const
|
||||||
|
{
|
||||||
|
// Do linear search since usually just a few points.
|
||||||
|
|
||||||
|
forAll(points_, pointI)
|
||||||
|
{
|
||||||
|
const pointField& pts = mesh_.points();
|
||||||
|
|
||||||
|
if (pts.size() > 0)
|
||||||
|
{
|
||||||
|
label minPointI = 0;
|
||||||
|
scalar minDistSqr = magSqr(pts[minPointI] - points_[pointI]);
|
||||||
|
|
||||||
|
for (label i = 1; i < pts.size(); i++)
|
||||||
|
{
|
||||||
|
scalar distSqr = magSqr(pts[i] - points_[pointI]);
|
||||||
|
|
||||||
|
if (distSqr < minDistSqr)
|
||||||
|
{
|
||||||
|
minDistSqr = distSqr;
|
||||||
|
minPointI = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addOrDelete(set, minPointI, add);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
// Construct from components
|
||||||
|
Foam::nearestToPoint::nearestToPoint
|
||||||
|
(
|
||||||
|
const polyMesh& mesh,
|
||||||
|
const pointField& points
|
||||||
|
)
|
||||||
|
:
|
||||||
|
topoSetSource(mesh),
|
||||||
|
points_(points)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Construct from dictionary
|
||||||
|
Foam::nearestToPoint::nearestToPoint
|
||||||
|
(
|
||||||
|
const polyMesh& mesh,
|
||||||
|
const dictionary& dict
|
||||||
|
)
|
||||||
|
:
|
||||||
|
topoSetSource(mesh),
|
||||||
|
points_(dict.lookup("points"))
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Construct from Istream
|
||||||
|
Foam::nearestToPoint::nearestToPoint
|
||||||
|
(
|
||||||
|
const polyMesh& mesh,
|
||||||
|
Istream& is
|
||||||
|
)
|
||||||
|
:
|
||||||
|
topoSetSource(mesh),
|
||||||
|
points_(checkIs(is))
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::nearestToPoint::~nearestToPoint()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
void Foam::nearestToPoint::applyToSet
|
||||||
|
(
|
||||||
|
const topoSetSource::setAction action,
|
||||||
|
topoSet& set
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
|
||||||
|
{
|
||||||
|
Info<< " Adding points nearest to " << points_ << endl;
|
||||||
|
|
||||||
|
combine(set, true);
|
||||||
|
}
|
||||||
|
else if (action == topoSetSource::DELETE)
|
||||||
|
{
|
||||||
|
Info<< " Removing points nearest to " << points_ << endl;
|
||||||
|
|
||||||
|
combine(set, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
122
src/meshTools/sets/pointSources/nearestToPoint/nearestToPoint.H
Normal file
122
src/meshTools/sets/pointSources/nearestToPoint/nearestToPoint.H
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by the
|
||||||
|
Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::nearestToPoint
|
||||||
|
|
||||||
|
Description
|
||||||
|
A topoSetSource to select points nearest to points.
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
nearestToPoint.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef nearestToPoint_H
|
||||||
|
#define nearestToPoint_H
|
||||||
|
|
||||||
|
#include "topoSetSource.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class nearestToPoint Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class nearestToPoint
|
||||||
|
:
|
||||||
|
public topoSetSource
|
||||||
|
{
|
||||||
|
|
||||||
|
// Private data
|
||||||
|
|
||||||
|
//- Add usage string
|
||||||
|
static addToUsageTable usage_;
|
||||||
|
|
||||||
|
//- points to select nearest to
|
||||||
|
pointField points_;
|
||||||
|
|
||||||
|
|
||||||
|
// Private Member Functions
|
||||||
|
|
||||||
|
void combine(topoSet& set, const bool add) const;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Runtime type information
|
||||||
|
TypeName("nearestToPoint");
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct from components
|
||||||
|
nearestToPoint
|
||||||
|
(
|
||||||
|
const polyMesh& mesh,
|
||||||
|
const pointField& points
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Construct from dictionary
|
||||||
|
nearestToPoint
|
||||||
|
(
|
||||||
|
const polyMesh& mesh,
|
||||||
|
const dictionary& dict
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Construct from Istream
|
||||||
|
nearestToPoint
|
||||||
|
(
|
||||||
|
const polyMesh& mesh,
|
||||||
|
Istream&
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
|
||||||
|
virtual ~nearestToPoint();
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
virtual void applyToSet
|
||||||
|
(
|
||||||
|
const topoSetSource::setAction action,
|
||||||
|
topoSet&
|
||||||
|
) const;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
Reference in New Issue
Block a user