ENH: add boundaryToCell, patchToCell topoSetCellSources (#1060)

- can be used, for example, to visualize all wall cells - for quality
  or other purposes - without requiring an intermediate faceSet for
  the selection. Request arising from pending merge !213.
This commit is contained in:
Mark Olesen
2018-11-24 13:52:43 +01:00
parent ff18ab58c2
commit a139543e9c
6 changed files with 554 additions and 4 deletions

View File

@ -81,6 +81,14 @@ FoamFile
// //option all; // cell with all faces in faceSet
// }
//
// // All cells on boundaries
// source boundaryToCell;
//
// // Select cells associated with patch
// source patchToCell;
// patches ("patch.*")
// patch somePatch;
//
// // Select based on pointSet
// source pointToCell;
// sourceInfo
@ -144,7 +152,7 @@ FoamFile
// source surfaceToCell;
// sourceInfo
// {
// file "www.avl.com-geometry.stl";
// file "geometry.stl";
// useSurfaceOrientation false; // use closed surface inside/outside
// // test (ignores includeCut,
// // outsidePoints)
@ -235,9 +243,6 @@ FoamFile
//
// // All boundary faces
// source boundaryToFace;
// sourceInfo
// {
// }
//
// // All faces of faceZone
// source zoneToFace;

View File

@ -152,6 +152,7 @@ sets/topoSetSource/topoSetSource.C
cellSources = sets/cellSources
$(cellSources)/topoSetCellSource/topoSetCellSource.C
$(cellSources)/boundaryToCell/boundaryToCell.C
$(cellSources)/boxToCell/boxToCell.C
$(cellSources)/cellToCell/cellToCell.C
$(cellSources)/cylinderAnnulusToCell/cylinderAnnulusToCell.C
@ -162,6 +163,7 @@ $(cellSources)/fieldToCell/fieldToCell.C
$(cellSources)/labelToCell/labelToCell.C
$(cellSources)/nbrToCell/nbrToCell.C
$(cellSources)/nearestToCell/nearestToCell.C
$(cellSources)/patchToCell/patchToCell.C
$(cellSources)/pointToCell/pointToCell.C
$(cellSources)/regionToCell/regionToCell.C
$(cellSources)/rotatedBoxToCell/rotatedBoxToCell.C

View File

@ -0,0 +1,137 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 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 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 "boundaryToCell.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(boundaryToCell, 0);
addToRunTimeSelectionTable(topoSetSource, boundaryToCell, word);
addToRunTimeSelectionTable(topoSetSource, boundaryToCell, istream);
addToRunTimeSelectionTable(topoSetCellSource, boundaryToCell, word);
addToRunTimeSelectionTable(topoSetCellSource, boundaryToCell, istream);
addNamedToRunTimeSelectionTable
(
topoSetCellSource,
boundaryToCell,
word,
boundary
);
addNamedToRunTimeSelectionTable
(
topoSetCellSource,
boundaryToCell,
istream,
boundary
);
}
Foam::topoSetSource::addToUsageTable Foam::boundaryToCell::usage_
(
boundaryToCell::typeName,
"\n Usage: boundaryToCell\n\n"
" Select all boundary cells\n\n"
);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::boundaryToCell::combine(topoSet& set, const bool add) const
{
for
(
label facei = mesh().nInternalFaces();
facei < mesh().nFaces();
++facei
)
{
addOrDelete(set, mesh().faceOwner()[facei], add);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::boundaryToCell::boundaryToCell(const polyMesh& mesh)
:
topoSetCellSource(mesh)
{}
Foam::boundaryToCell::boundaryToCell
(
const polyMesh& mesh,
const dictionary&
)
:
topoSetCellSource(mesh)
{}
Foam::boundaryToCell::boundaryToCell
(
const polyMesh& mesh,
Istream&
)
:
topoSetCellSource(mesh)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::boundaryToCell::applyToSet
(
const topoSetSource::setAction action,
topoSet& set
) const
{
if (action == topoSetSource::ADD || action == topoSetSource::NEW)
{
if (verbose_)
{
Info<< " Adding all boundary cells ..." << endl;
}
combine(set, true);
}
else if (action == topoSetSource::SUBTRACT)
{
if (verbose_)
{
Info<< " Removing all boundary cells ..." << endl;
}
combine(set, false);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,107 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 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 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/>.
Class
Foam::boundaryToCell
Description
A topoSetCellSource to select all external (boundary) faces.
\heading Dictionary parameters
None
SourceFiles
boundaryToCell.C
\*---------------------------------------------------------------------------*/
#ifndef boundaryToCell_H
#define boundaryToCell_H
#include "topoSetCellSource.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class boundaryToCell Declaration
\*---------------------------------------------------------------------------*/
class boundaryToCell
:
public topoSetCellSource
{
// Private data
//- Add usage string
static addToUsageTable usage_;
// Private Member Functions
void combine(topoSet& set, const bool add) const;
public:
//- Runtime type information
TypeName("boundaryToCell");
// Constructors
//- Construct from components
boundaryToCell(const polyMesh& mesh);
//- Construct from dictionary
boundaryToCell(const polyMesh& mesh, const dictionary& unused);
//- Construct from Istream
boundaryToCell(const polyMesh& mesh, Istream& unused);
//- Destructor
virtual ~boundaryToCell() = default;
// Member Functions
virtual void applyToSet
(
const topoSetSource::setAction action,
topoSet& set
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,181 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 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 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 "patchToCell.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(patchToCell, 0);
addToRunTimeSelectionTable(topoSetSource, patchToCell, word);
addToRunTimeSelectionTable(topoSetSource, patchToCell, istream);
addToRunTimeSelectionTable(topoSetCellSource, patchToCell, word);
addToRunTimeSelectionTable(topoSetCellSource, patchToCell, istream);
addNamedToRunTimeSelectionTable
(
topoSetCellSource,
patchToCell,
word,
patch
);
addNamedToRunTimeSelectionTable
(
topoSetCellSource,
patchToCell,
istream,
patch
);
}
Foam::topoSetSource::addToUsageTable Foam::patchToCell::usage_
(
patchToCell::typeName,
"\n Usage: patchToCell patch\n\n"
" Select cells attached to patch. Note:accepts wildcards for patch.\n\n"
);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::patchToCell::combine(topoSet& set, const bool add) const
{
labelHashSet patchIDs = mesh_.boundaryMesh().patchSet
(
selectedPatches_,
true, // warn if not found
true // use patch groups if available
);
for (const label patchi : patchIDs)
{
const polyPatch& pp = mesh_.boundaryMesh()[patchi];
if (verbose_)
{
Info<< " Found matching patch " << pp.name()
<< " with " << pp.size() << " faces." << endl;
}
for
(
label facei = pp.start();
facei < pp.start() + pp.size();
++facei
)
{
addOrDelete(set, mesh_.faceOwner()[facei], add);
}
}
if (patchIDs.empty())
{
WarningInFunction
<< "Cannot find any patches matching "
<< flatOutput(selectedPatches_) << nl
<< "Valid names are " << flatOutput(mesh_.boundaryMesh().names())
<< endl;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::patchToCell::patchToCell
(
const polyMesh& mesh,
const wordRe& patchName
)
:
topoSetCellSource(mesh),
selectedPatches_(one(), patchName)
{}
Foam::patchToCell::patchToCell
(
const polyMesh& mesh,
const dictionary& dict
)
:
topoSetCellSource(mesh),
selectedPatches_()
{
// Look for 'patches' and 'patch', but accept 'name' as well
if (!dict.readIfPresent("patches", selectedPatches_))
{
selectedPatches_.resize(1);
selectedPatches_.first() =
dict.getCompat<wordRe>("patch", {{"name", 1806}});
}
}
Foam::patchToCell::patchToCell
(
const polyMesh& mesh,
Istream& is
)
:
topoSetCellSource(mesh),
selectedPatches_(one(), wordRe(checkIs(is)))
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::patchToCell::applyToSet
(
const topoSetSource::setAction action,
topoSet& set
) const
{
if (action == topoSetSource::ADD || action == topoSetSource::NEW)
{
if (verbose_)
{
Info<< " Adding cells associated with patches "
<< flatOutput(selectedPatches_) << " ..." << endl;
}
combine(set, true);
}
else if (action == topoSetSource::SUBTRACT)
{
if (verbose_)
{
Info<< " Removing cells associated with patches "
<< flatOutput(selectedPatches_) << " ..." << endl;
}
combine(set, false);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,118 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 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 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/>.
Class
Foam::patchToCell
Description
A topoSetCellSource to select cells associated with patches.
\heading Dictionary parameters
\table
Property | Description | Required | Default
patches | The face zone names or regexs | possibly |
patch | The face zone name or regex | possibly |
\endtable
Note
Must specify "patches" or "patch" (highest to lowest precedence).
SourceFiles
patchToCell.C
\*---------------------------------------------------------------------------*/
#ifndef patchToCell_H
#define patchToCell_H
#include "topoSetCellSource.H"
#include "wordRes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class patchToCell Declaration
\*---------------------------------------------------------------------------*/
class patchToCell
:
public topoSetCellSource
{
// Private Data
//- Add usage string
static addToUsageTable usage_;
//- Matcher for patches
wordRes selectedPatches_;
// Private Member Functions
void combine(topoSet& set, const bool add) const;
public:
//- Runtime type information
TypeName("patchToCell");
// Constructors
//- Construct from components
patchToCell(const polyMesh& mesh, const wordRe& patchName);
//- Construct from dictionary
patchToCell(const polyMesh& mesh, const dictionary& dict);
//- Construct from Istream
patchToCell(const polyMesh& mesh, Istream& is);
//- Destructor
virtual ~patchToCell() = default;
// Member Functions
virtual void applyToSet
(
const topoSetSource::setAction action,
topoSet& set
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //