Commit d6e3e7f9 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

STYLE: code cleanup searchableSurface (issue #929)

- improve doxygen entries for searchable surfaces.

- support selection of searchable surfaces with shorter names.
  Eg,
      type   box | cylinder | ...;
  vs  type   searchableBox | searchableCylinder | ...;
parent 86e01ef2
......@@ -30,10 +30,8 @@ License
namespace Foam
{
defineTypeNameAndDebug(closedTriSurfaceMesh, 0);
addToRunTimeSelectionTable(searchableSurface, closedTriSurfaceMesh, dict);
defineTypeNameAndDebug(closedTriSurfaceMesh, 0);
addToRunTimeSelectionTable(searchableSurface, closedTriSurfaceMesh, dict);
}
......@@ -65,10 +63,4 @@ Foam::closedTriSurfaceMesh::closedTriSurfaceMesh
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::closedTriSurfaceMesh::~closedTriSurfaceMesh()
{}
// ************************************************************************* //
......@@ -52,7 +52,8 @@ class closedTriSurfaceMesh
:
public triSurfaceMesh
{
private:
// Private Member Functions
//- No copy construct
closedTriSurfaceMesh(const closedTriSurfaceMesh&) = delete;
......@@ -76,7 +77,7 @@ public:
closedTriSurfaceMesh(const IOobject& io);
//- Construct from IO and dictionary (used by searchableSurface).
// Dictionary may contain a 'scale' entry (eg, 0.001: mm -> m)
// Dictionary may contain a 'scale' entry (eg, 0.001: mm to m)
closedTriSurfaceMesh
(
const IOobject& io,
......@@ -84,9 +85,9 @@ public:
);
// Destructor
//- Destructor
virtual ~closedTriSurfaceMesh() = default;
virtual ~closedTriSurfaceMesh();
// Member Functions
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -32,7 +32,19 @@ License
namespace Foam
{
defineTypeNameAndDebug(searchableBox, 0);
addToRunTimeSelectionTable(searchableSurface, searchableBox, dict);
addToRunTimeSelectionTable
(
searchableSurface,
searchableBox,
dict
);
addNamedToRunTimeSelectionTable
(
searchableSurface,
searchableBox,
dict,
box
);
}
......@@ -47,6 +59,7 @@ void Foam::searchableBox::projectOntoCoordPlane
{
// Set point
info.rawPoint()[dir] = planePt[dir];
// Set face
if (planePt[dir] == min()[dir])
{
......@@ -92,7 +105,7 @@ Foam::pointIndexHit Foam::searchableBox::findNearest
// (for internal points) per direction what nearest cube side is
point near;
for (direction dir = 0; dir < vector::nComponents; dir++)
for (direction dir = 0; dir < vector::nComponents; ++dir)
{
if (info.rawPoint()[dir] < min()[dir])
{
......@@ -188,7 +201,7 @@ Foam::searchableBox::searchableBox
)
:
searchableSurface(io),
treeBoundBox(dict.lookup("min"), dict.lookup("max"))
treeBoundBox(dict.get<point>("min"), dict.get<point>("max"))
{
if (!contains(midpoint()))
{
......@@ -201,12 +214,6 @@ Foam::searchableBox::searchableBox
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::searchableBox::~searchableBox()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::wordList& Foam::searchableBox::regions() const
......@@ -222,8 +229,8 @@ const Foam::wordList& Foam::searchableBox::regions() const
Foam::tmp<Foam::pointField> Foam::searchableBox::coordinates() const
{
tmp<pointField> tCtrs(new pointField(6));
pointField& ctrs = tCtrs.ref();
auto tctrs = tmp<pointField>::New(6);
auto& ctrs = tctrs.ref();
const pointField pts(treeBoundBox::points());
const faceList& fcs = treeBoundBox::faces;
......@@ -233,7 +240,7 @@ Foam::tmp<Foam::pointField> Foam::searchableBox::coordinates() const
ctrs[i] = fcs[i].centre(pts);
}
return tCtrs;
return tctrs;
}
......@@ -255,9 +262,9 @@ void Foam::searchableBox::boundingSpheres
const face& f = fcs[i];
centres[i] = f.centre(pts);
forAll(f, fp)
for (const label pointi : f)
{
const point& pt = pts[f[fp]];
const point& pt = pts[pointi];
radiusSqr[i] = Foam::max
(
......@@ -303,7 +310,7 @@ Foam::pointIndexHit Foam::searchableBox::findNearestOnEdge
// (for internal points) per direction what nearest cube side is
point near;
for (direction dir = 0; dir < vector::nComponents; dir++)
for (direction dir = 0; dir < vector::nComponents; ++dir)
{
if (info.rawPoint()[dir] < min()[dir])
{
......@@ -405,7 +412,7 @@ Foam::pointIndexHit Foam::searchableBox::findLine
{
info.setHit();
for (direction dir = 0; dir < vector::nComponents; dir++)
for (direction dir = 0; dir < vector::nComponents; ++dir)
{
if (info.rawPoint()[dir] == min()[dir])
{
......@@ -602,20 +609,23 @@ void Foam::searchableBox::getVolumeType
) const
{
volType.setSize(points.size());
volType = volumeType::INSIDE;
forAll(points, pointi)
{
const point& pt = points[pointi];
for (direction dir = 0; dir < vector::nComponents; dir++)
volumeType vt = volumeType::INSIDE;
for (direction dir=0; dir < vector::nComponents; ++dir)
{
if (pt[dir] < min()[dir] || pt[dir] > max()[dir])
{
volType[pointi] = volumeType::OUTSIDE;
vt = volumeType::OUTSIDE;
break;
}
}
volType[pointi] = vt;
}
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -27,6 +27,14 @@ Class
Description
Searching on bounding box
\heading Dictionary parameters
\table
Property | Description | Required | Default
type | box / searchableBox | selector |
min | minimum point for bounding box | yes |
max | maximum point for bounding box | yes |
\endtable
SourceFiles
searchableBox.C
......@@ -43,8 +51,6 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
/*---------------------------------------------------------------------------*\
Class searchableBox Declaration
\*---------------------------------------------------------------------------*/
......@@ -54,8 +60,6 @@ class searchableBox
public searchableSurface,
public treeBoundBox
{
private:
// Private Member Data
mutable wordList regions_;
......@@ -109,14 +113,15 @@ public:
);
//- Destructor
virtual ~searchableBox();
virtual ~searchableBox() = default;
// Member Functions
//- Names of regions
virtual const wordList& regions() const;
//- Whether supports volume type below
//- Whether surface supports volume type (below)
virtual bool hasVolumeType() const
{
return true;
......@@ -248,12 +253,11 @@ public:
vectorField& normal
) const;
//- Determine type (inside/outside/mixed) for point. unknown if
// cannot be determined (e.g. non-manifold surface)
//- Determine type (inside/outside) for points.
virtual void getVolumeType
(
const pointField&,
List<volumeType>&
const pointField& points,
List<volumeType>& volType
) const;
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -31,7 +31,19 @@ License
namespace Foam
{
defineTypeNameAndDebug(searchableCone, 0);
addToRunTimeSelectionTable(searchableSurface, searchableCone, dict);
addToRunTimeSelectionTable
(
searchableSurface,
searchableCone,
dict
);
addNamedToRunTimeSelectionTable
(
searchableSurface,
searchableCone,
dict,
cone
);
}
......@@ -39,9 +51,7 @@ namespace Foam
Foam::tmp<Foam::pointField> Foam::searchableCone::coordinates() const
{
tmp<pointField> tCtrs(new pointField(1, 0.5*(point1_ + point2_)));
return tCtrs;
return tmp<pointField>::New(1, 0.5*(point1_ + point2_));
}
......@@ -71,13 +81,13 @@ void Foam::searchableCone::boundingSpheres
Foam::tmp<Foam::pointField> Foam::searchableCone::points() const
{
tmp<pointField> tPts(new pointField(2));
pointField& pts = tPts.ref();
auto tpts = tmp<pointField>::New(2);
auto& pts = tpts.ref();
pts[0] = point1_;
pts[1] = point2_;
return tPts;
return tpts;
}
......@@ -92,7 +102,7 @@ void Foam::searchableCone::findNearestAndNormal
vector v(sample - point1_);
// Decompose sample-point1 into normal and parallel component
scalar parallel = (v & unitDir_);
const scalar parallel = (v & unitDir_);
// Remove the parallel component and normalise
v -= parallel*unitDir_;
......@@ -338,8 +348,8 @@ void Foam::searchableCone::findLineAll
vector point1End(end-cone.point1_);
// Quick rejection of complete vector outside endcaps
scalar s1 = point1Start&(cone.unitDir_);
scalar s2 = point1End&(cone.unitDir_);
scalar s1 = point1Start & (cone.unitDir_);
scalar s2 = point1End & (cone.unitDir_);
if ((s1 < 0.0 && s2 < 0.0) || (s1 > cone.magDir_ && s2 > cone.magDir_))
{
......@@ -735,12 +745,12 @@ Foam::searchableCone::searchableCone
)
:
searchableSurface(io),
point1_(dict.lookup("point1")),
radius1_(readScalar(dict.lookup("radius1"))),
innerRadius1_(dict.lookupOrDefault("innerRadius1", 0.0)),
point2_(dict.lookup("point2")),
radius2_(readScalar(dict.lookup("radius2"))),
innerRadius2_(dict.lookupOrDefault("innerRadius2", 0.0)),
point1_(dict.get<point>("point1")),
radius1_(dict.get<scalar>("radius1")),
innerRadius1_(dict.lookupOrDefault<scalar>("innerRadius1", 0)),
point2_(dict.get<point>("point2")),
radius2_(dict.get<scalar>("radius2")),
innerRadius2_(dict.lookupOrDefault<scalar>("innerRadius2", 0)),
magDir_(mag(point2_-point1_)),
unitDir_((point2_-point1_)/magDir_)
{
......@@ -748,12 +758,6 @@ Foam::searchableCone::searchableCone
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::searchableCone::~searchableCone()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::wordList& Foam::searchableCone::regions() const
......@@ -775,6 +779,7 @@ void Foam::searchableCone::findNearest
) const
{
info.setSize(samples.size());
forAll(samples, i)
{
vector normal;
......@@ -1071,48 +1076,36 @@ void Foam::searchableCone::getVolumeType
) const
{
volType.setSize(points.size());
volType = volumeType::INSIDE;
forAll(points, pointI)
forAll(points, pointi)
{
const point& pt = points[pointI];
const point& pt = points[pointi];
volType[pointi] = volumeType::OUTSIDE;
vector v(pt - point1_);
// Decompose sample-point1 into normal and parallel component
scalar parallel = v & unitDir_;
scalar comp = parallel;
scalar compInner = parallel;
const scalar parallel = (v & unitDir_);
// Quick rejection. Left of point1 endcap, or right of point2 endcap
if (parallel < 0 || parallel > magDir_)
{
continue;
}
scalar radius_sec = radius1_+comp*(radius2_-radius1_)/magDir_;
const scalar radius_sec =
radius1_ + parallel * (radius2_-radius1_)/magDir_;
scalar radius_sec_inner =
innerRadius1_
+compInner*(innerRadius2_-innerRadius1_)/magDir_;
const scalar radius_sec_inner =
innerRadius1_ + parallel * (innerRadius2_-innerRadius1_)/magDir_;
if (parallel < 0)
{
// Left of point1 endcap
volType[pointI] = volumeType::OUTSIDE;
}
else if (parallel > magDir_)
{
// Right of point2 endcap
volType[pointI] = volumeType::OUTSIDE;
}
else
// Remove the parallel component
v -= parallel*unitDir_;
if (mag(v) >= radius_sec_inner && mag(v) <= radius_sec)
{
// Remove the parallel component
v -= parallel*unitDir_;
if (mag(v) >= radius_sec_inner && mag(v) <= radius_sec)
{
volType[pointI] = volumeType::INSIDE;
}
else
{
volType[pointI] = volumeType::OUTSIDE;
}
volType[pointi] = volumeType::INSIDE;
}
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -27,15 +27,16 @@ Class
Description
Searching on (optionally hollow) cone.
\heading Function object usage
\heading Dictionary parameters
\table
Property | Description | Required | Default value
point1 | coordinate of endpoint | yes |
radius1 | radius at point1 | yes | yes
innerRadius1 | inner radius at point1 | no |
point2 | coordinate of endpoint | yes |
radius2 | radius at point2 | yes | yes
innerRadius2 | inner radius at point2 | no |
Property | Description | Required | Default
type | code / searchableCone | selector |
point1 | coordinate of endpoint | yes |
radius1 | radius at point1 | yes |
innerRadius1| inner radius at point1 | no | 0
point2 | coordinate of endpoint | yes |
radius2 | radius at point2 | yes |
innerRadius2| inner radius at point2 | no | 0
\endtable
Note
......@@ -145,22 +146,22 @@ class searchableCone
public:
//- Runtime type information
TypeName("searchableCone");
TypeName("searchableCone");
// Constructors
//- Construct from components
searchableCone
(
const IOobject& io,
const point& point1,
const scalar radius1,
const scalar innerRadius1,
const point& point2,
const scalar radius2,
const scalar innerRadius2
);
searchableCone
(
const IOobject& io,
const point& point1,
const scalar radius1,
const scalar innerRadius1,
const point& point2,
const scalar radius2,
const scalar innerRadius2
);
//- Construct from dictionary (used by searchableSurface)
searchableCone
......@@ -171,15 +172,15 @@ public:
//- Destructor
virtual ~searchableCone();
virtual ~searchableCone() = default;
// Member Functions
//- Names of regions
virtual const wordList& regions() const;
//- Whether supports volume type below
//- Whether supports volume type (below)
virtual bool hasVolumeType() const
{
return true;
......@@ -262,12 +263,12 @@ public:
vectorField& normal
) const;
//- Determine type (inside/outside/mixed) for point. unknown if
// cannot be determined (e.g. non-manifold surface)
//- 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 pointField& points,
List<volumeType>& volType
) const;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -31,7 +31,19 @@ License
namespace Foam
{
defineTypeNameAndDebug(searchableCylinder, 0);
addToRunTimeSelectionTable(searchableSurface, searchableCylinder, dict);
addToRunTimeSelectionTable
(
searchableSurface,
searchableCylinder,
dict
);
addNamedToRunTimeSelectionTable
(
searchableSurface,
searchableCylinder,
dict,
cylinder
);
}
......@@ -39,9 +51,7 @@ namespace Foam
Foam::tmp<Foam::pointField> Foam::searchableCylinder::coordinates() const
{
tmp<pointField> tCtrs(new pointField(1, 0.5*(point1_ + point2_)));
return tCtrs;
return tmp<pointField>::New(1, 0.5*(point1_ + point2_));
}
......@@ -64,13 +74,13 @@ void Foam::searchableCylinder::boundingSpheres
Foam::tmp<Foam::pointField> Foam::searchableCylinder::points() const
{
tmp<pointField> tPts(new pointField(2));
pointField& pts = tPts.ref();
auto tpts = tmp<pointField>::New(2);