Files
openfoam/src/meshTools/sets/faceSources/cylinderToFace/cylinderToFace.C
Mark Olesen b3156b0d0f ENH: allow changing verbosity of topoSetSource (#1060)
- make topoSet set/unset methods virtual to allow overloading
2018-10-31 09:22:58 +00:00

171 lines
4.5 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "cylinderToFace.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(cylinderToFace, 0);
addToRunTimeSelectionTable(topoSetSource, cylinderToFace, word);
addToRunTimeSelectionTable(topoSetSource, cylinderToFace, istream);
addToRunTimeSelectionTable(topoSetFaceSource, cylinderToFace, word);
addToRunTimeSelectionTable(topoSetFaceSource, cylinderToFace, istream);
addNamedToRunTimeSelectionTable
(
topoSetFaceSource,
cylinderToFace,
word,
cylinder
);
addNamedToRunTimeSelectionTable
(
topoSetFaceSource,
cylinderToFace,
istream,
cylinder
);
}
Foam::topoSetSource::addToUsageTable Foam::cylinderToFace::usage_
(
cylinderToFace::typeName,
"\n Usage: cylinderToFace (p1X p1Y p1Z) (p2X p2Y p2Z) radius\n\n"
" Select all faces with face centre within bounding cylinder\n\n"
);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::cylinderToFace::combine(topoSet& set, const bool add) const
{
const vector axis = (point2_ - point1_);
const scalar rad2 = sqr(radius_);
const scalar magAxis2 = magSqr(axis);
const pointField& ctrs = mesh_.faceCentres();
forAll(ctrs, facei)
{
const vector d = ctrs[facei] - point1_;
const scalar magD = d & axis;
if ((magD > 0) && (magD < magAxis2))
{
const scalar d2 = (d & d) - sqr(magD)/magAxis2;
if (d2 < rad2)
{
addOrDelete(set, facei, add);
}
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::cylinderToFace::cylinderToFace
(
const polyMesh& mesh,
const point& point1,
const point& point2,
const scalar radius
)
:
topoSetFaceSource(mesh),
point1_(point1),
point2_(point2),
radius_(radius)
{}
Foam::cylinderToFace::cylinderToFace
(
const polyMesh& mesh,
const dictionary& dict
)
:
cylinderToFace
(
mesh,
dict.get<point>("p1"),
dict.get<point>("p2"),
dict.get<scalar>("radius")
)
{}
Foam::cylinderToFace::cylinderToFace
(
const polyMesh& mesh,
Istream& is
)
:
topoSetFaceSource(mesh),
point1_(checkIs(is)),
point2_(checkIs(is)),
radius_(readScalar(checkIs(is)))
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::cylinderToFace::applyToSet
(
const topoSetSource::setAction action,
topoSet& set
) const
{
if (action == topoSetSource::ADD || action == topoSetSource::NEW)
{
if (verbose_)
{
Info<< " Adding faces with centre within cylinder, with p1 = "
<< point1_ << ", p2 = " << point2_ << ", radius = " << radius_
<< endl;
}
combine(set, true);
}
else if (action == topoSetSource::SUBTRACT)
{
if (verbose_)
{
Info<< " Removing faces with centre within cylinder, with p1 = "
<< point1_ << ", p2 = " << point2_ << ", radius = " << radius_
<< endl;
}
combine(set, false);
}
}
// ************************************************************************* //