ENH: optional innerRadius for searchable disk

- can be used directly, or in special cases like a searchable plane
  with a gap of things in the centre that are not to be sampled.
This commit is contained in:
Mark Olesen
2020-12-08 13:55:47 +01:00
parent 56b5234fbc
commit 8ad61f8e9d
4 changed files with 111 additions and 25 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2014-2017 OpenFOAM Foundation Copyright (C) 2014-2017 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -72,9 +72,8 @@ Foam::pointIndexHit Foam::searchableDisk::findNearest
v.normalise(); v.normalise();
// Clip to inner/outer radius
// Clip to radius. info.setPoint(origin() + radialLimits_.clip(magV)*v);
info.setPoint(origin() + min(magV, radius_)*v);
if (magSqr(sample - info.rawPoint()) < nearestDistSqr) if (magSqr(sample - info.rawPoint()) < nearestDistSqr)
{ {
@ -112,11 +111,10 @@ void Foam::searchableDisk::findLine
v.normalise(); v.normalise();
// Set (hit or miss) to intersection of ray and plane of disk // Set (hit or miss) to intersection of ray and plane of disk
info.setPoint(origin() + magV*v); info.setPoint(origin() + magV*v);
if (magV <= radius_) if (radialLimits_.contains(magV))
{ {
info.setHit(); info.setHit();
info.setIndex(0); info.setIndex(0);
@ -131,15 +129,15 @@ Foam::searchableDisk::searchableDisk
const IOobject& io, const IOobject& io,
const point& originPoint, const point& originPoint,
const vector& normalVector, const vector& normalVector,
const scalar radius const scalar outerRadius,
const scalar innerRadius
) )
: :
searchableSurface(io), searchableSurface(io),
plane(originPoint, normalVector), plane(originPoint, normalVector),
radius_(radius) radialLimits_(innerRadius, outerRadius)
{ {
// Rough approximation of bounding box // Rough approximation of bounding box
// vector span(radius_, radius_, radius_);
// See searchableCylinder // See searchableCylinder
vector span vector span
@ -148,7 +146,7 @@ Foam::searchableDisk::searchableDisk
sqrt(sqr(normal().x()) + sqr(normal().z())), sqrt(sqr(normal().x()) + sqr(normal().z())),
sqrt(sqr(normal().x()) + sqr(normal().y())) sqrt(sqr(normal().x()) + sqr(normal().y()))
); );
span *= radius_; span *= outerRadius;
bounds().min() = origin() - span; bounds().min() = origin() - span;
bounds().max() = origin() + span; bounds().max() = origin() + span;
@ -166,7 +164,8 @@ Foam::searchableDisk::searchableDisk
io, io,
dict.get<point>("origin"), dict.get<point>("origin"),
dict.get<vector>("normal"), dict.get<vector>("normal"),
dict.get<scalar>("radius") dict.get<scalar>("radius"),
dict.getOrDefault<scalar>("innerRadius", 0)
) )
{} {}
@ -177,8 +176,8 @@ const Foam::wordList& Foam::searchableDisk::regions() const
{ {
if (regions_.empty()) if (regions_.empty())
{ {
regions_.setSize(1); regions_.resize(1);
regions_[0] = "region0"; regions_.first() = "region0";
} }
return regions_; return regions_;
} }
@ -190,11 +189,11 @@ void Foam::searchableDisk::boundingSpheres
scalarField& radiusSqr scalarField& radiusSqr
) const ) const
{ {
centres.setSize(1); centres.resize(1);
centres[0] = origin(); radiusSqr.resize(1);
radiusSqr.setSize(1); centres[0] = origin();
radiusSqr[0] = sqr(radius_); radiusSqr[0] = sqr(radialLimits_.max());
// Add a bit to make sure all points are tested inside // Add a bit to make sure all points are tested inside
radiusSqr += Foam::sqr(SMALL); radiusSqr += Foam::sqr(SMALL);
@ -208,7 +207,7 @@ void Foam::searchableDisk::findNearest
List<pointIndexHit>& info List<pointIndexHit>& info
) const ) const
{ {
info.setSize(samples.size()); info.resize(samples.size());
forAll(samples, i) forAll(samples, i)
{ {
@ -224,7 +223,7 @@ void Foam::searchableDisk::findLine
List<pointIndexHit>& info List<pointIndexHit>& info
) const ) const
{ {
info.setSize(start.size()); info.resize(start.size());
forAll(start, i) forAll(start, i)
{ {

View File

@ -29,7 +29,7 @@ Class
Description Description
Searching on circular disk given as origin, normal (gets normalised) Searching on circular disk given as origin, normal (gets normalised)
and radius and radius. Optionally it can be an annular ring.
\heading Dictionary parameters \heading Dictionary parameters
\table \table
@ -38,6 +38,7 @@ Description
origin | centre of disk | yes | origin | centre of disk | yes |
normal | normal vector | yes | normal | normal vector | yes |
radius | disk radius | yes | radius | disk radius | yes |
innerRadius | inner disk radius | no | 0
\endtable \endtable
Note Note
@ -52,6 +53,7 @@ SourceFiles
#define searchableDisk_H #define searchableDisk_H
#include "plane.H" #include "plane.H"
#include "MinMax.H"
#include "searchableSurface.H" #include "searchableSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -70,10 +72,10 @@ class searchableDisk
{ {
private: private:
// Private Member Data // Private Data
//- Radius //- Inner/outer radial limits
const scalar radius_; const scalarMinMax radialLimits_;
//- Names of regions //- Names of regions
mutable wordList regions_; mutable wordList regions_;
@ -119,7 +121,8 @@ public:
const IOobject& io, const IOobject& io,
const point& originPoint, const point& originPoint,
const vector& normalVector, const vector& normalVector,
const scalar radius const scalar outerRadius,
const scalar innerRadius = 0
); );
//- Construct from dictionary (used by searchableSurface) //- Construct from dictionary (used by searchableSurface)
@ -247,7 +250,6 @@ public:
NotImplemented; NotImplemented;
return false; return false;
} }
}; };

View File

@ -45,6 +45,25 @@ sampled
${_sampleMesh} ${_sampleMesh}
surface plane-0.55.stl; surface plane-0.55.stl;
} }
outerplane-0.45
{
type distanceSurface;
// defaults:
distance 0;
signed true;
isoMethod topo;
surfaceType disk;
origin (0.45 0 0);
normal (1 0 0);
radius 0.09;
innerRadius 0.05;
topology largestRegion;
store true;
}
} }
} }

View File

@ -0,0 +1,66 @@
// -*- C++ -*-
// ************************************************************************* //
samplingDebug
{
type surfaces;
libs (sampling);
log true;
writeControl timeStep;
writeInterval 1;
fields (tracer0 U);
sampleScheme cellPoint;
interpolationScheme cellPoint;
surfaceFormat vtk;
formatOptions
{
ensight
{
collateTimes true;
// collateTimes false;
}
}
_sampleMesh
{
type meshedSurface;
source cells;
}
_diskOuter
{
surfaceType disk;
origin (0 0 0);
normal (1 0 0);
radius 0.09;
}
_distanceSurface
{
type distanceSurface;
distance 0;
signed true;
isoMethod topo;
}
surfaces
{
diskOuter
{
${_distanceSurface}
${_diskOuter}
origin (0.45 0 0);
innerRadius 0.05;
topology largestRegion;
}
}
}
// ************************************************************************* //