ENH: searchableDisk: new searchable surface

This commit is contained in:
mattijs 2014-07-17 15:35:46 +01:00
parent c63e90ed9a
commit b0b62067d9
3 changed files with 576 additions and 0 deletions

View file

@ -64,6 +64,7 @@ indexedOctree/treeDataTriSurface.C
searchableSurface = searchableSurface
$(searchableSurface)/searchableBox.C
$(searchableSurface)/searchableCylinder.C
$(searchableSurface)/searchableDisk.C
$(searchableSurface)/searchablePlane.C
$(searchableSurface)/searchablePlate.C
$(searchableSurface)/searchableSphere.C

View file

@ -0,0 +1,329 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2014 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "searchableDisk.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(searchableDisk, 0);
addToRunTimeSelectionTable(searchableSurface, searchableDisk, dict);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::pointIndexHit Foam::searchableDisk::findNearest
(
const point& sample,
const scalar nearestDistSqr
) const
{
pointIndexHit info(false, sample, -1);
vector v(sample - origin_);
// Decompose sample-origin into normal and parallel component
scalar parallel = (v & normal_);
// Remove the parallel component and normalise
v -= parallel*normal_;
scalar magV = mag(v);
if (magV < ROOTVSMALL)
{
v = vector::zero;
}
else
{
v /= magV;
}
// Clip to radius.
info.setPoint(origin_ + min(magV, radius_)*v);
if (magSqr(sample - info.rawPoint()) < nearestDistSqr)
{
info.setHit();
info.setIndex(0);
}
return info;
}
void Foam::searchableDisk::findLine
(
const point& start,
const point& end,
pointIndexHit& info
) const
{
info = pointIndexHit(false, vector::zero, -1);
vector v(start - origin_);
// Decompose sample-origin into normal and parallel component
scalar parallel = (v & normal_);
if (sign(parallel) == sign((end - origin_) & normal_))
{
return;
}
// Remove the parallel component and normalise
v -= parallel*normal_;
scalar magV = mag(v);
if (magV < ROOTVSMALL)
{
v = vector::zero;
}
else
{
v /= magV;
}
// Set (hit or miss) to intersection of ray and plane of disk
info.setPoint(origin_ + magV*v);
if (magV <= radius_)
{
info.setHit();
info.setIndex(0);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::searchableDisk::searchableDisk
(
const IOobject& io,
const point& origin,
const point& normal,
const scalar radius
)
:
searchableSurface(io),
origin_(origin),
normal_(normal/mag(normal)),
radius_(radius)
{
// Rough approximation of bounding box
//vector span(radius_, radius_, radius_);
// See searchableCylinder
vector span
(
sqrt(sqr(normal_.y()) + sqr(normal_.z())),
sqrt(sqr(normal_.x()) + sqr(normal_.z())),
sqrt(sqr(normal_.x()) + sqr(normal_.y()))
);
span *= radius_;
bounds().min() = origin_ - span;
bounds().max() = origin_ + span;
}
Foam::searchableDisk::searchableDisk
(
const IOobject& io,
const dictionary& dict
)
:
searchableSurface(io),
origin_(dict.lookup("origin")),
normal_(dict.lookup("normal")),
radius_(readScalar(dict.lookup("radius")))
{
normal_ /= mag(normal_);
// Rough approximation of bounding box
//vector span(radius_, radius_, radius_);
// See searchableCylinder
vector span
(
sqrt(sqr(normal_.y()) + sqr(normal_.z())),
sqrt(sqr(normal_.x()) + sqr(normal_.z())),
sqrt(sqr(normal_.x()) + sqr(normal_.y()))
);
span *= radius_;
bounds().min() = origin_ - span;
bounds().max() = origin_ + span;
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::searchableDisk::~searchableDisk()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::wordList& Foam::searchableDisk::regions() const
{
if (regions_.empty())
{
regions_.setSize(1);
regions_[0] = "region0";
}
return regions_;
}
void Foam::searchableDisk::boundingSpheres
(
pointField& centres,
scalarField& radiusSqr
) const
{
centres.setSize(1);
centres[0] = origin_;
radiusSqr.setSize(1);
radiusSqr[0] = sqr(radius_);
// Add a bit to make sure all points are tested inside
radiusSqr += Foam::sqr(SMALL);
}
void Foam::searchableDisk::findNearest
(
const pointField& samples,
const scalarField& nearestDistSqr,
List<pointIndexHit>& info
) const
{
info.setSize(samples.size());
forAll(samples, i)
{
info[i] = findNearest(samples[i], nearestDistSqr[i]);
}
}
void Foam::searchableDisk::findLine
(
const pointField& start,
const pointField& end,
List<pointIndexHit>& info
) const
{
info.setSize(start.size());
forAll(start, i)
{
findLine(start[i], end[i], info[i]);
}
}
void Foam::searchableDisk::findLineAny
(
const pointField& start,
const pointField& end,
List<pointIndexHit>& info
) const
{
findLine(start, end, info);
}
void Foam::searchableDisk::findLineAll
(
const pointField& start,
const pointField& end,
List<List<pointIndexHit> >& info
) const
{
info.setSize(start.size());
forAll(start, i)
{
pointIndexHit inter;
findLine(start[i], end[i], inter);
if (inter.hit())
{
info[i].setSize(1);
info[i][0] = inter;
}
else
{
info[i].clear();
}
}
}
void Foam::searchableDisk::getRegion
(
const List<pointIndexHit>& info,
labelList& region
) const
{
region.setSize(info.size());
region = 0;
}
void Foam::searchableDisk::getNormal
(
const List<pointIndexHit>& info,
vectorField& normal
) const
{
normal.setSize(info.size());
normal = normal_;
}
void Foam::searchableDisk::getVolumeType
(
const pointField& points,
List<volumeType>& volType
) const
{
FatalErrorIn
(
"searchableDisk::getVolumeType(const pointField&"
", List<volumeType>&) const"
) << "Volume type not supported for disk."
<< exit(FatalError);
}
// ************************************************************************* //

View file

@ -0,0 +1,246 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2014 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
Class
Foam::searchableDisk
Description
Searching on circular disk given as origin, normal (gets normalised)
and radius
SourceFiles
searchableDisk.C
\*---------------------------------------------------------------------------*/
#ifndef searchableDisk_H
#define searchableDisk_H
#include "treeBoundBox.H"
#include "searchableSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class searchableDisk Declaration
\*---------------------------------------------------------------------------*/
class searchableDisk
:
public searchableSurface
{
private:
// Private Member Data
//- origin
const point origin_;
//- normal
vector normal_;
//- radius
const scalar radius_;
//- Names of regions
mutable wordList regions_;
// Private Member Functions
//- Find nearest point on disk
pointIndexHit findNearest
(
const point& sample,
const scalar nearestDistSqr
) const;
//- Find intersection with disk
void findLine
(
const point& start,
const point& end,
pointIndexHit&
) const;
//- Disallow default bitwise copy construct
searchableDisk(const searchableDisk&);
//- Disallow default bitwise assignment
void operator=(const searchableDisk&);
public:
//- Runtime type information
TypeName("searchableDisk");
// Constructors
//- Construct from components
searchableDisk
(
const IOobject& io,
const point& origin,
const point& normal,
const scalar radius
);
//- Construct from dictionary (used by searchableSurface)
searchableDisk
(
const IOobject& io,
const dictionary& dict
);
//- Destructor
virtual ~searchableDisk();
// Member Functions
virtual const wordList& regions() const;
//- Whether supports volume type below
virtual bool hasVolumeType() const
{
return false;
}
//- Range of local indices that can be returned.
virtual label size() const
{
return 1;
}
//- Get representative set of element coordinates
// Usually the element centres (should be of length size()).
virtual tmp<pointField> coordinates() const
{
tmp<pointField> tCtrs(new pointField(1, origin_));
return tCtrs;
}
//- Get bounding spheres (centre and radius squared), one per element.
// Any point on element is guaranteed to be inside.
virtual void boundingSpheres
(
pointField& centres,
scalarField& radiusSqr
) const;
//- Get the points that define the surface.
virtual tmp<pointField> points() const
{
return coordinates();
}
//- Does any part of the surface overlap the supplied bound box?
virtual bool overlaps(const boundBox& bb) const
{
notImplemented
(
"searchableDisk::overlaps(const boundBox&) const"
);
return false;
}
// Multiple point queries.
virtual void findNearest
(
const pointField& sample,
const scalarField& nearestDistSqr,
List<pointIndexHit>&
) const;
virtual void findLine
(
const pointField& start,
const pointField& end,
List<pointIndexHit>&
) const;
virtual void findLineAny
(
const pointField& start,
const pointField& end,
List<pointIndexHit>&
) const;
//- Get all intersections in order from start to end.
virtual void findLineAll
(
const pointField& start,
const pointField& end,
List<List<pointIndexHit> >&
) const;
//- From a set of points and indices get the region
virtual void getRegion
(
const List<pointIndexHit>&,
labelList& region
) const;
//- From a set of points and indices get the normal
virtual void getNormal
(
const List<pointIndexHit>&,
vectorField& normal
) const;
//- Determine type (inside/outside/mixed) for point. unknown if
// cannot be determined (e.g. non-manifold surface)
virtual void getVolumeType
(
const pointField&,
List<volumeType>&
) const;
// regIOobject implementation
bool writeData(Ostream&) const
{
notImplemented("searchableDisk::writeData(Ostream&) const");
return false;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //