mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
adding cyclinderToCell cell source
This commit is contained in:
@ -87,6 +87,7 @@ $(cellSources)/nearestToCell/nearestToCell.C
|
||||
$(cellSources)/nbrToCell/nbrToCell.C
|
||||
$(cellSources)/zoneToCell/zoneToCell.C
|
||||
$(cellSources)/sphereToCell/sphereToCell.C
|
||||
$(cellSources)/cylinderToCell/cylinderToCell.C
|
||||
|
||||
faceSources = sets/faceSources
|
||||
$(faceSources)/faceToFace/faceToFace.C
|
||||
|
||||
151
src/meshTools/sets/cellSources/cylinderToCell/cylinderToCell.C
Normal file
151
src/meshTools/sets/cellSources/cylinderToCell/cylinderToCell.C
Normal file
@ -0,0 +1,151 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ 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 2 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, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "cylinderToCell.H"
|
||||
#include "polyMesh.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(cylinderToCell, 0);
|
||||
addToRunTimeSelectionTable(topoSetSource, cylinderToCell, word);
|
||||
addToRunTimeSelectionTable(topoSetSource, cylinderToCell, istream);
|
||||
}
|
||||
|
||||
|
||||
Foam::topoSetSource::addToUsageTable Foam::cylinderToCell::usage_
|
||||
(
|
||||
cylinderToCell::typeName,
|
||||
"\n Usage: cylinderToCell (p1X p1Y p1Z) (p2X p2Y p2Z) radius\n\n"
|
||||
" Select all cells with cell centre within bounding cylinder\n\n"
|
||||
);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::cylinderToCell::combine(topoSet& set, const bool add) const
|
||||
{
|
||||
const vector axis = p2_ - p1_;
|
||||
const scalar rad2 = sqr(radius_);
|
||||
const scalar magAxis2 = magSqr(axis);
|
||||
|
||||
const pointField& ctrs = mesh_.cellCentres();
|
||||
|
||||
forAll(ctrs, cellI)
|
||||
{
|
||||
vector d = ctrs[cellI] - p1_;
|
||||
scalar magD = d & axis;
|
||||
|
||||
if ((magD > 0) && (magD < magAxis2))
|
||||
{
|
||||
scalar d2 = (d & d) - sqr(magD)/magAxis2;
|
||||
if (d2 < rad2)
|
||||
{
|
||||
addOrDelete(set, cellI, add);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::cylinderToCell::cylinderToCell
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
const vector& p1,
|
||||
const vector& p2,
|
||||
const scalar radius
|
||||
)
|
||||
:
|
||||
topoSetSource(mesh),
|
||||
p1_(p1),
|
||||
p2_(p2),
|
||||
radius_(radius)
|
||||
{}
|
||||
|
||||
|
||||
Foam::cylinderToCell::cylinderToCell
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
topoSetSource(mesh),
|
||||
p1_(dict.lookup("p1")),
|
||||
p2_(dict.lookup("p2")),
|
||||
radius_(readScalar(dict.lookup("radius")))
|
||||
{}
|
||||
|
||||
|
||||
// Construct from Istream
|
||||
Foam::cylinderToCell::cylinderToCell
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
Istream& is
|
||||
)
|
||||
:
|
||||
topoSetSource(mesh),
|
||||
p1_(checkIs(is)),
|
||||
p2_(checkIs(is)),
|
||||
radius_(readScalar(checkIs(is)))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::cylinderToCell::~cylinderToCell()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::cylinderToCell::applyToSet
|
||||
(
|
||||
const topoSetSource::setAction action,
|
||||
topoSet& set
|
||||
) const
|
||||
{
|
||||
if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
|
||||
{
|
||||
Info<< " Adding cells with centre within cylinder, with p1 = "
|
||||
<< p1_ << ", p2 = " << p2_ << " and radius = " << radius_ << endl;
|
||||
|
||||
combine(set, true);
|
||||
}
|
||||
else if (action == topoSetSource::DELETE)
|
||||
{
|
||||
Info<< " Removing cells with centre within sphere, with p1 = "
|
||||
<< p1_ << ", p2 = " << p2_ << " and radius = " << radius_ << endl;
|
||||
|
||||
combine(set, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
131
src/meshTools/sets/cellSources/cylinderToCell/cylinderToCell.H
Normal file
131
src/meshTools/sets/cellSources/cylinderToCell/cylinderToCell.H
Normal file
@ -0,0 +1,131 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\/ 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 2 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, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::cylinderToCell
|
||||
|
||||
Description
|
||||
A topoSetSource to select cells based on cell centres inside a cylinder.
|
||||
|
||||
SourceFiles
|
||||
cylinderToCell.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef cylinderToCell_H
|
||||
#define cylinderToCell_H
|
||||
|
||||
#include "topoSetSource.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class cylinderToCell Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class cylinderToCell
|
||||
:
|
||||
public topoSetSource
|
||||
{
|
||||
|
||||
// Private data
|
||||
|
||||
//- Add usage string
|
||||
static addToUsageTable usage_;
|
||||
|
||||
//- First point on cylinder axis
|
||||
vector p1_;
|
||||
|
||||
//- Second point on cylinder axis
|
||||
vector p2_;
|
||||
|
||||
//- Radius
|
||||
scalar radius_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
void combine(topoSet& set, const bool add) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("cylinderToCell");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
cylinderToCell
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
const vector& p1,
|
||||
const vector& p2,
|
||||
const scalar radius
|
||||
);
|
||||
|
||||
//- Construct from dictionary
|
||||
cylinderToCell
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
//- Construct from Istream
|
||||
cylinderToCell
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
Istream&
|
||||
);
|
||||
|
||||
|
||||
// Destructor
|
||||
|
||||
virtual ~cylinderToCell();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
virtual void applyToSet
|
||||
(
|
||||
const topoSetSource::setAction action,
|
||||
topoSet&
|
||||
) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user