Added new faceSource rotatedBoxToFace for meshTools
This commit is contained in:
parent
ac941215d5
commit
e655cbc255
3 changed files with 327 additions and 0 deletions
|
@ -73,6 +73,7 @@ $(faceSources)/boundaryToFace/boundaryToFace.C
|
|||
$(faceSources)/zoneToFace/zoneToFace.C
|
||||
$(faceSources)/setToFace/setToFace.C
|
||||
$(faceSources)/boxToFace/boxToFace.C
|
||||
$(faceSources)/rotatedBoxToFace/rotatedBoxToFace.C
|
||||
|
||||
pointSources = sets/pointSources
|
||||
$(pointSources)/labelToPoint/labelToPoint.C
|
||||
|
|
|
@ -0,0 +1,193 @@
|
|||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | foam-extend: Open Source CFD
|
||||
\\ / O peration | Version: 4.0
|
||||
\\ / A nd | Web: http://www.foam-extend.org
|
||||
\\/ M anipulation | For copyright notice see file Copyright
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of foam-extend.
|
||||
|
||||
foam-extend 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.
|
||||
|
||||
foam-extend 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 foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rotatedBoxToFace.H"
|
||||
#include "polyMesh.H"
|
||||
#include "cellModeller.H"
|
||||
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
defineTypeNameAndDebug(rotatedBoxToFace, 0);
|
||||
|
||||
addToRunTimeSelectionTable(topoSetSource, rotatedBoxToFace, word);
|
||||
|
||||
addToRunTimeSelectionTable(topoSetSource, rotatedBoxToFace, istream);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Foam::topoSetSource::addToUsageTable Foam::rotatedBoxToFace::usage_
|
||||
(
|
||||
rotatedBoxToFace::typeName,
|
||||
"\n Usage: rotatedBoxToFace (originx originy originz)"
|
||||
" (ix iy iz) (jx jy jz) (kx ky kz)\n\n"
|
||||
" Select all faces with faceCentre within parallelopiped\n\n"
|
||||
);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::rotatedBoxToFace::combine(topoSet& set, const bool add) const
|
||||
{
|
||||
// Define a cell for the box
|
||||
pointField boxPoints(8);
|
||||
boxPoints[0] = origin_;
|
||||
boxPoints[1] = origin_ + i_;
|
||||
boxPoints[2] = origin_ + i_ + j_;
|
||||
boxPoints[3] = origin_ + j_;
|
||||
boxPoints[4] = origin_ + k_;
|
||||
boxPoints[5] = origin_ + k_ + i_;
|
||||
boxPoints[6] = origin_ + k_ + i_ + j_;
|
||||
boxPoints[7] = origin_ + k_ + j_;
|
||||
|
||||
labelList boxVerts(8);
|
||||
forAll(boxVerts, i)
|
||||
{
|
||||
boxVerts[i] = i;
|
||||
}
|
||||
|
||||
const cellModel& hex = *(cellModeller::lookup("hex"));
|
||||
|
||||
// Get outwards pointing faces.
|
||||
faceList boxFaces(cellShape(hex, boxVerts).faces());
|
||||
|
||||
// Precalculate normals
|
||||
vectorField boxFaceNormals(boxFaces.size());
|
||||
forAll(boxFaces, i)
|
||||
{
|
||||
boxFaceNormals[i] = boxFaces[i].normal(boxPoints);
|
||||
|
||||
Pout<< "Face:" << i << " position:" << boxFaces[i].centre(boxPoints)
|
||||
<< " normal:" << boxFaceNormals[i] << endl;
|
||||
}
|
||||
|
||||
// Check whether face centre is inside all faces of box.
|
||||
|
||||
const pointField& ctrs = mesh_.faceCentres();
|
||||
|
||||
forAll(ctrs, faceI)
|
||||
{
|
||||
bool inside = true;
|
||||
|
||||
forAll(boxFaces, i)
|
||||
{
|
||||
const face& f = boxFaces[i];
|
||||
|
||||
if (((ctrs[faceI] - boxPoints[f[0]]) & boxFaceNormals[i]) > 0)
|
||||
{
|
||||
inside = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (inside)
|
||||
{
|
||||
addOrDelete(set, faceI, add);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
// Construct from components
|
||||
Foam::rotatedBoxToFace::rotatedBoxToFace
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
const vector& origin,
|
||||
const vector& i,
|
||||
const vector& j,
|
||||
const vector& k
|
||||
)
|
||||
:
|
||||
topoSetSource(mesh),
|
||||
origin_(origin),
|
||||
i_(i),
|
||||
j_(j),
|
||||
k_(k)
|
||||
{}
|
||||
|
||||
|
||||
// Construct from dictionary
|
||||
Foam::rotatedBoxToFace::rotatedBoxToFace
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
topoSetSource(mesh),
|
||||
origin_(dict.lookup("origin")),
|
||||
i_(dict.lookup("i")),
|
||||
j_(dict.lookup("j")),
|
||||
k_(dict.lookup("k"))
|
||||
{}
|
||||
|
||||
|
||||
// Construct from Istream
|
||||
Foam::rotatedBoxToFace::rotatedBoxToFace(const polyMesh& mesh, Istream& is)
|
||||
:
|
||||
topoSetSource(mesh),
|
||||
origin_(is),
|
||||
i_(is),
|
||||
j_(is),
|
||||
k_(is)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::rotatedBoxToFace::~rotatedBoxToFace()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::rotatedBoxToFace::applyToSet
|
||||
(
|
||||
const topoSetSource::setAction action,
|
||||
topoSet& set
|
||||
) const
|
||||
{
|
||||
if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
|
||||
{
|
||||
Info<< " Adding faces with center within rotated box " << endl;
|
||||
|
||||
combine(set, true);
|
||||
}
|
||||
else if (action == topoSetSource::DELETE)
|
||||
{
|
||||
Info<< " Removing faces with center within rotated box " << endl;
|
||||
|
||||
combine(set, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
|
@ -0,0 +1,133 @@
|
|||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | foam-extend: Open Source CFD
|
||||
\\ / O peration | Version: 4.0
|
||||
\\ / A nd | Web: http://www.foam-extend.org
|
||||
\\/ M anipulation | For copyright notice see file Copyright
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of foam-extend.
|
||||
|
||||
foam-extend 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.
|
||||
|
||||
foam-extend 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 foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::rotatedBoxToFace
|
||||
|
||||
Description
|
||||
A topoSetSource to select faces based on face centres inside
|
||||
rotated/skewed box (parallelopiped?).
|
||||
|
||||
Box defined as origin and i,j,k vectors.
|
||||
E.g. box rotated 45 degrees around z-axis with sizes sqrt(0.2^2+0.2^2)
|
||||
(and extra large, 200 in z direction):
|
||||
@verbatim
|
||||
origin ( 0.4 0.4 -100);
|
||||
i ( 0.2 0.2 0);
|
||||
j (-0.2 0.2 0);
|
||||
k ( 0.0 0.0 100);
|
||||
@endverbatim
|
||||
|
||||
SourceFiles
|
||||
rotatedBoxToFace.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef rotatedBoxToFace_H
|
||||
#define rotatedBoxToFace_H
|
||||
|
||||
#include "topoSetSource.H"
|
||||
#include "treeBoundBox.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class rotatedBoxToFace Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class rotatedBoxToFace
|
||||
:
|
||||
public topoSetSource
|
||||
{
|
||||
|
||||
// Private data
|
||||
|
||||
//- Add usage string
|
||||
static addToUsageTable usage_;
|
||||
|
||||
|
||||
//- skewed box
|
||||
const vector origin_;
|
||||
const vector i_;
|
||||
const vector j_;
|
||||
const vector k_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
void combine(topoSet& set, const bool add) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("rotatedBoxToFace");
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
rotatedBoxToFace
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
const vector& origin,
|
||||
const vector& i,
|
||||
const vector& j,
|
||||
const vector& k
|
||||
);
|
||||
|
||||
//- Construct from dictionary
|
||||
rotatedBoxToFace(const polyMesh& mesh, const dictionary& dict);
|
||||
|
||||
//- Construct from Istream
|
||||
rotatedBoxToFace(const polyMesh& mesh, Istream&);
|
||||
|
||||
|
||||
// Destructor
|
||||
|
||||
virtual ~rotatedBoxToFace();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
virtual void applyToSet
|
||||
(
|
||||
const topoSetSource::setAction action,
|
||||
topoSet&
|
||||
) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
|
Reference in a new issue