ENH: use "origin" for searchable sphere etc. (#1060)

- replaces "centre", using the same keyword as other objects
  (eg, plane, rotatedBox, coordinateSystem etc).
This commit is contained in:
Mark Olesen
2018-10-29 15:51:05 +00:00
parent c2e58dca64
commit 50fe195374
12 changed files with 72 additions and 68 deletions

View File

@ -57,18 +57,18 @@ Foam::pointIndexHit Foam::searchableSphere::findNearest
{
pointIndexHit info(false, sample, -1);
const vector n(sample - centre_);
const vector n(sample - origin_);
scalar magN = mag(n);
if (nearestDistSqr >= sqr(magN - radius_))
{
if (magN < ROOTVSMALL)
{
info.rawPoint() = centre_ + vector(1,0,0)*radius_;
info.rawPoint() = origin_ + vector(1,0,0)*radius_;
}
else
{
info.rawPoint() = centre_ + n/magN*radius_;
info.rawPoint() = origin_ + n/magN*radius_;
}
info.setHit();
info.setIndex(0);
@ -95,7 +95,7 @@ void Foam::searchableSphere::findLineAll
if (magSqrDir > ROOTVSMALL)
{
const vector toCentre(centre_-start);
const vector toCentre(origin_ - start);
scalar magSqrToCentre = magSqr(toCentre);
dir /= Foam::sqrt(magSqrDir);
@ -135,18 +135,18 @@ void Foam::searchableSphere::findLineAll
Foam::searchableSphere::searchableSphere
(
const IOobject& io,
const point& centre,
const point& origin,
const scalar radius
)
:
searchableSurface(io),
centre_(centre),
origin_(origin),
radius_(radius)
{
bounds() = boundBox
(
centre_ - radius_*vector::one,
centre_ + radius_*vector::one
origin_ - radius_*vector::one,
origin_ + radius_*vector::one
);
}
@ -157,23 +157,20 @@ Foam::searchableSphere::searchableSphere
const dictionary& dict
)
:
searchableSurface(io),
centre_(dict.get<point>("centre")),
radius_(dict.get<scalar>("radius"))
{
bounds() = boundBox
searchableSphere
(
centre_ - radius_*vector::one,
centre_ + radius_*vector::one
);
}
io,
dict.getCompat<vector>("origin", {{"centre", 1806}}),
dict.get<scalar>("radius")
)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::searchableSphere::overlaps(const boundBox& bb) const
{
return bb.overlaps(centre_, sqr(radius_));
return bb.overlaps(origin_, sqr(radius_));
}
@ -181,8 +178,8 @@ const Foam::wordList& Foam::searchableSphere::regions() const
{
if (regions_.empty())
{
regions_.setSize(1);
regions_[0] = "region0";
regions_.resize(1);
regions_.first() = "region0";
}
return regions_;
}
@ -195,10 +192,10 @@ void Foam::searchableSphere::boundingSpheres
scalarField& radiusSqr
) const
{
centres.setSize(1);
centres[0] = centre_;
centres.resize(1);
centres[0] = origin_;
radiusSqr.setSize(1);
radiusSqr.resize(1);
radiusSqr[0] = Foam::sqr(radius_);
// Add a bit to make sure all points are tested inside
@ -336,7 +333,7 @@ void Foam::searchableSphere::getNormal
{
if (info[i].hit())
{
normal[i] = normalised(info[i].hitPoint() - centre_);
normal[i] = normalised(info[i].hitPoint() - origin_);
}
else
{
@ -362,7 +359,7 @@ void Foam::searchableSphere::getVolumeType
volType[pointi] =
(
(magSqr(pt - centre_) <= rad2)
(magSqr(pt - origin_) <= rad2)
? volumeType::INSIDE : volumeType::OUTSIDE
);
}

View File

@ -29,10 +29,11 @@ Description
\heading Dictionary parameters
\table
Property | Description | Required | Default
type | sphere / searchableSphere | selector |
centre | The sphere centre | yes |
radius | The (outside) radius of sphere | yes |
Property | Description | Required | Default
type | sphere / searchableSphere | selector |
origin | The origin (centre) of the sphere | yes |
radius | The (outside) radius of sphere | yes |
centre | Alternative for 'origin' | no |
\endtable
SourceFiles
@ -64,7 +65,7 @@ private:
// Private Member Data
//- Centre point of the sphere
const point centre_;
const point origin_;
//- The outer radius of the sphere
const scalar radius_;
@ -151,7 +152,7 @@ public:
// Usually the element centres (should be of length size()).
virtual tmp<pointField> coordinates() const
{
return tmp<pointField>::New(1, centre_);
return tmp<pointField>::New(1, origin_);
}
//- Get bounding spheres (centre and radius squared), one per element.

View File

@ -55,7 +55,7 @@ void Foam::sphereToCell::combine(topoSet& set, const bool add) const
forAll(ctrs, celli)
{
if (magSqr(ctrs[celli] - centre_) <= rad2)
if (magSqr(ctrs[celli] - origin_) <= rad2)
{
addOrDelete(set, celli, add);
}
@ -68,12 +68,12 @@ void Foam::sphereToCell::combine(topoSet& set, const bool add) const
Foam::sphereToCell::sphereToCell
(
const polyMesh& mesh,
const point& centre,
const point& origin,
const scalar radius
)
:
topoSetSource(mesh),
centre_(centre),
origin_(origin),
radius_(radius)
{}
@ -84,9 +84,12 @@ Foam::sphereToCell::sphereToCell
const dictionary& dict
)
:
topoSetSource(mesh),
centre_(dict.get<point>("centre")),
radius_(dict.get<scalar>("radius"))
sphereToCell
(
mesh,
dict.getCompat<vector>("origin", {{"centre", 1806}}),
dict.get<scalar>("radius")
)
{}
@ -97,7 +100,7 @@ Foam::sphereToCell::sphereToCell
)
:
topoSetSource(mesh),
centre_(checkIs(is)),
origin_(checkIs(is)),
radius_(readScalar(checkIs(is)))
{}
@ -112,15 +115,15 @@ void Foam::sphereToCell::applyToSet
{
if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
{
Info<< " Adding cells with centre within sphere, with centre = "
<< centre_ << " and radius = " << radius_ << endl;
Info<< " Adding cells within a sphere with centre = "
<< origin_ << " and radius = " << radius_ << endl;
combine(set, true);
}
else if (action == topoSetSource::DELETE)
{
Info<< " Removing cells with centre within sphere, with centre = "
<< centre_ << " and radius = " << radius_ << endl;
Info<< " Removing cells within a sphere with centre = "
<< origin_ << " and radius = " << radius_ << endl;
combine(set, false);
}

View File

@ -29,9 +29,10 @@ Description
\heading Dictionary parameters
\table
Property | Description | Required | Default
centre | The sphere centre | yes |
radius | The (outside) radius of sphere | yes |
Property | Description | Required | Default
origin | The origin (centre) of the sphere | yes |
radius | The (outside) radius of sphere | yes |
centre | Alternative for 'origin' | no |
\endtable
SourceFiles
@ -64,7 +65,7 @@ class sphereToCell
static addToUsageTable usage_;
//- Centre point of the sphere
point centre_;
point origin_;
//- The outer radius of the sphere
scalar radius_;
@ -87,7 +88,7 @@ public:
sphereToCell
(
const polyMesh& mesh,
const point& centre,
const point& origin,
const scalar radius
);
@ -104,7 +105,7 @@ public:
// Member Functions
virtual sourceType setType() const
virtual topoSetSource::sourceType setType() const
{
return CELLSETSOURCE;
}