mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: cellToFaceZone: new topoSetSource
This commit is contained in:
@ -224,6 +224,7 @@ $(faceZoneSources)/setToFaceZone/setToFaceZone.C
|
|||||||
$(faceZoneSources)/setAndNormalToFaceZone/setAndNormalToFaceZone.C
|
$(faceZoneSources)/setAndNormalToFaceZone/setAndNormalToFaceZone.C
|
||||||
$(faceZoneSources)/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.C
|
$(faceZoneSources)/searchableSurfaceToFaceZone/searchableSurfaceToFaceZone.C
|
||||||
$(faceZoneSources)/planeToFaceZone/planeToFaceZone.C
|
$(faceZoneSources)/planeToFaceZone/planeToFaceZone.C
|
||||||
|
$(faceZoneSources)/cellToFaceZone/cellToFaceZone.C
|
||||||
|
|
||||||
cellZoneSources = topoSet/cellZoneSources
|
cellZoneSources = topoSet/cellZoneSources
|
||||||
$(cellZoneSources)/topoSetCellZoneSource/topoSetCellZoneSource.C
|
$(cellZoneSources)/topoSetCellZoneSource/topoSetCellZoneSource.C
|
||||||
|
|||||||
@ -0,0 +1,287 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2022 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 "cellToFaceZone.H"
|
||||||
|
#include "polyMesh.H"
|
||||||
|
#include "faceZoneSet.H"
|
||||||
|
#include "cellSet.H"
|
||||||
|
#include "syncTools.H"
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
defineTypeNameAndDebug(cellToFaceZone, 0);
|
||||||
|
addToRunTimeSelectionTable(topoSetSource, cellToFaceZone, word);
|
||||||
|
addToRunTimeSelectionTable(topoSetSource, cellToFaceZone, istream);
|
||||||
|
|
||||||
|
addToRunTimeSelectionTable(topoSetFaceZoneSource, cellToFaceZone, word);
|
||||||
|
addToRunTimeSelectionTable(topoSetFaceZoneSource, cellToFaceZone, istream);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::topoSetSource::addToUsageTable Foam::cellToFaceZone::usage_
|
||||||
|
(
|
||||||
|
cellToFaceZone::typeName,
|
||||||
|
"\n Usage: cellToFaceZone <slaveCellSet>\n\n"
|
||||||
|
" Select all outside faces in the cellSet."
|
||||||
|
" Orientated so slave side is in cellSet.\n\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
|
void Foam::cellToFaceZone::selectFaces
|
||||||
|
(
|
||||||
|
const cellSet& cSet,
|
||||||
|
bitSet& selectedFace,
|
||||||
|
bitSet& doFlip
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
selectedFace.setSize(mesh_.nFaces());
|
||||||
|
selectedFace = false;
|
||||||
|
|
||||||
|
doFlip.setSize(mesh_.nFaces());
|
||||||
|
doFlip = false;
|
||||||
|
|
||||||
|
|
||||||
|
// Add all faces whose both neighbours are in set.
|
||||||
|
|
||||||
|
const label nInt = mesh_.nInternalFaces();
|
||||||
|
const labelList& own = mesh_.faceOwner();
|
||||||
|
const labelList& nei = mesh_.faceNeighbour();
|
||||||
|
const polyBoundaryMesh& patches = mesh_.boundaryMesh();
|
||||||
|
|
||||||
|
|
||||||
|
// Check all internal faces
|
||||||
|
for (label facei = 0; facei < nInt; ++facei)
|
||||||
|
{
|
||||||
|
const bool ownFound = cSet.found(own[facei]);
|
||||||
|
const bool neiFound = cSet.found(nei[facei]);
|
||||||
|
|
||||||
|
if (ownFound && !neiFound)
|
||||||
|
{
|
||||||
|
selectedFace.set(facei);
|
||||||
|
doFlip.set(facei, flip_);
|
||||||
|
}
|
||||||
|
else if (!ownFound && neiFound)
|
||||||
|
{
|
||||||
|
selectedFace.set(facei);
|
||||||
|
doFlip.set(facei, !flip_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get coupled cell status
|
||||||
|
boolList neiInSet(mesh_.nBoundaryFaces(), false);
|
||||||
|
|
||||||
|
for (const polyPatch& pp : patches)
|
||||||
|
{
|
||||||
|
if (pp.coupled())
|
||||||
|
{
|
||||||
|
label facei = pp.start();
|
||||||
|
forAll(pp, i)
|
||||||
|
{
|
||||||
|
neiInSet[facei-nInt] = cSet.found(own[facei]);
|
||||||
|
++facei;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
syncTools::swapBoundaryFaceList(mesh_, neiInSet);
|
||||||
|
|
||||||
|
|
||||||
|
// Check all boundary faces
|
||||||
|
for (const polyPatch& pp : patches)
|
||||||
|
{
|
||||||
|
label facei = pp.start();
|
||||||
|
forAll(pp, i)
|
||||||
|
{
|
||||||
|
const bool ownFound = cSet.found(own[facei]);
|
||||||
|
const bool neiFound = neiInSet[facei-nInt];
|
||||||
|
|
||||||
|
if (ownFound && !neiFound)
|
||||||
|
{
|
||||||
|
selectedFace.set(facei);
|
||||||
|
doFlip.set(facei, flip_);
|
||||||
|
}
|
||||||
|
else if (!ownFound && neiFound)
|
||||||
|
{
|
||||||
|
selectedFace.set(facei);
|
||||||
|
doFlip.set(facei, !flip_);
|
||||||
|
}
|
||||||
|
++facei;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::cellToFaceZone::cellToFaceZone
|
||||||
|
(
|
||||||
|
const polyMesh& mesh,
|
||||||
|
const word& setName,
|
||||||
|
const bool flip
|
||||||
|
)
|
||||||
|
:
|
||||||
|
topoSetFaceZoneSource(mesh),
|
||||||
|
names_(one{}, setName),
|
||||||
|
flip_(flip)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::cellToFaceZone::cellToFaceZone
|
||||||
|
(
|
||||||
|
const polyMesh& mesh,
|
||||||
|
const dictionary& dict
|
||||||
|
)
|
||||||
|
:
|
||||||
|
topoSetFaceZoneSource(mesh),
|
||||||
|
names_(),
|
||||||
|
flip_(dict.getOrDefault("flip", false))
|
||||||
|
{
|
||||||
|
// Look for 'sets' or 'set'
|
||||||
|
if (!dict.readIfPresent("sets", names_))
|
||||||
|
{
|
||||||
|
names_.resize(1);
|
||||||
|
dict.readEntry("set", names_.first());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::cellToFaceZone::cellToFaceZone
|
||||||
|
(
|
||||||
|
const polyMesh& mesh,
|
||||||
|
Istream& is
|
||||||
|
)
|
||||||
|
:
|
||||||
|
topoSetFaceZoneSource(mesh),
|
||||||
|
names_(one{}, word(checkIs(is))),
|
||||||
|
flip_(false)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
void Foam::cellToFaceZone::applyToSet
|
||||||
|
(
|
||||||
|
const topoSetSource::setAction action,
|
||||||
|
topoSet& set
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
if (!isA<faceZoneSet>(set))
|
||||||
|
{
|
||||||
|
WarningInFunction
|
||||||
|
<< "Operation only allowed on a faceZoneSet." << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
faceZoneSet& zoneSet = refCast<faceZoneSet>(set);
|
||||||
|
|
||||||
|
if (action == topoSetSource::ADD || action == topoSetSource::NEW)
|
||||||
|
{
|
||||||
|
if (verbose_)
|
||||||
|
{
|
||||||
|
if (flip_)
|
||||||
|
{
|
||||||
|
Info<< " Adding all faces on outside of cellSet "
|
||||||
|
<< flatOutput(names_)
|
||||||
|
<< "; orientation pointing into cellSet" << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Info<< " Adding all faces on outside of cellSet "
|
||||||
|
<< flatOutput(names_)
|
||||||
|
<< "; orientation pointing away from cellSet" << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bitSet selectedFace(mesh_.nFaces());
|
||||||
|
bitSet doFlip(mesh_.nFaces());
|
||||||
|
for (const word& setName : names_)
|
||||||
|
{
|
||||||
|
// Load the sets
|
||||||
|
cellSet cSet(mesh_, setName);
|
||||||
|
// Select outside faces
|
||||||
|
selectFaces(cSet, selectedFace, doFlip);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start off from copy
|
||||||
|
DynamicList<label> newAddressing(zoneSet.addressing());
|
||||||
|
DynamicList<bool> newFlipMap(zoneSet.flipMap());
|
||||||
|
|
||||||
|
for (const label facei : selectedFace)
|
||||||
|
{
|
||||||
|
if (!zoneSet.found(facei))
|
||||||
|
{
|
||||||
|
newAddressing.append(facei);
|
||||||
|
newFlipMap.append(doFlip[facei]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
zoneSet.addressing().transfer(newAddressing);
|
||||||
|
zoneSet.flipMap().transfer(newFlipMap);
|
||||||
|
zoneSet.updateSet();
|
||||||
|
}
|
||||||
|
else if (action == topoSetSource::SUBTRACT)
|
||||||
|
{
|
||||||
|
if (verbose_)
|
||||||
|
{
|
||||||
|
Info<< " Removing all faces on outside of cellSet "
|
||||||
|
<< flatOutput(names_)
|
||||||
|
<< " ..." << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
bitSet selectedFace(mesh_.nFaces());
|
||||||
|
bitSet doFlip(mesh_.nFaces());
|
||||||
|
for (const word& setName : names_)
|
||||||
|
{
|
||||||
|
// Load the sets
|
||||||
|
cellSet cSet(mesh_, setName);
|
||||||
|
// Select outside faces
|
||||||
|
selectFaces(cSet, selectedFace, doFlip);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start off empty
|
||||||
|
DynamicList<label> newAddressing(zoneSet.addressing().size());
|
||||||
|
DynamicList<bool> newFlipMap(zoneSet.flipMap().size());
|
||||||
|
|
||||||
|
for (const label facei : selectedFace)
|
||||||
|
{
|
||||||
|
newAddressing.append(facei);
|
||||||
|
newFlipMap.append(doFlip[facei]);
|
||||||
|
}
|
||||||
|
zoneSet.addressing().transfer(newAddressing);
|
||||||
|
zoneSet.flipMap().transfer(newFlipMap);
|
||||||
|
zoneSet.updateSet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -0,0 +1,190 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2022 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/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::cellToFaceZone
|
||||||
|
|
||||||
|
Description
|
||||||
|
A \c topoSetSource to select faces with only one
|
||||||
|
neighbour (i.e. outside) in a specified \c cellSet.
|
||||||
|
|
||||||
|
This is just a shortcut for
|
||||||
|
- extracting outside faces as a \c faceSet (\c cellToFace with \c outside).
|
||||||
|
- using \c setsToFaceZone to convert \c faceSet
|
||||||
|
and \c cellSet to oriented \c faceZone.
|
||||||
|
|
||||||
|
Operands:
|
||||||
|
\table
|
||||||
|
Operand | Type | Location
|
||||||
|
input | cellSet(s) | constant/polyMesh/sets/\<set\>
|
||||||
|
output | faceZone | constant/polyMesh/faceZones
|
||||||
|
\endtable
|
||||||
|
|
||||||
|
Usage
|
||||||
|
Minimal example by using \c system/topoSetDict.actions:
|
||||||
|
\verbatim
|
||||||
|
{
|
||||||
|
// Mandatory entries
|
||||||
|
name <name>;
|
||||||
|
type faceZoneSet;
|
||||||
|
action <action>;
|
||||||
|
source cellToFaceZone;
|
||||||
|
|
||||||
|
// Select either of the below
|
||||||
|
|
||||||
|
// Option-1
|
||||||
|
sets
|
||||||
|
(
|
||||||
|
<word>
|
||||||
|
<word>
|
||||||
|
...
|
||||||
|
);
|
||||||
|
|
||||||
|
// Option-2
|
||||||
|
set <word>;
|
||||||
|
|
||||||
|
// Optional entries
|
||||||
|
flip <bool>;
|
||||||
|
}
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
where the entries mean:
|
||||||
|
\table
|
||||||
|
Property | Description | Type | Reqd | Deflt
|
||||||
|
name | Name of faceZone | word | yes | -
|
||||||
|
type | Type name: faceZoneSet | word | yes | -
|
||||||
|
action | Action applied on faces - see below | word | yes | -
|
||||||
|
source | Source name: cellToFaceZone | word | yes | -
|
||||||
|
set(s) | Name of input cellSet(s) containing the slave cells <!--
|
||||||
|
--> | word | yes | -
|
||||||
|
flip | Flag to select master/slave cells | bool | no | false
|
||||||
|
\endtable
|
||||||
|
|
||||||
|
Options for the \c action entry:
|
||||||
|
\verbatim
|
||||||
|
new | Create a new faceZone from selected faces
|
||||||
|
add | Add selected faces of a faceZoneSet into this faceZone
|
||||||
|
subtract | Remove selected faces of a faceZoneSet from this faceZone
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
Notes
|
||||||
|
- \c flip=true sets the orientation of faces
|
||||||
|
pointing into the \c cellSet, and vice versa.
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
cellToFaceZone.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef Foam_cellToFaceZone_H
|
||||||
|
#define Foam_cellToFaceZone_H
|
||||||
|
|
||||||
|
#include "topoSetFaceZoneSource.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
// Forward Declarations
|
||||||
|
class cellSet;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class cellToFaceZone Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class cellToFaceZone
|
||||||
|
:
|
||||||
|
public topoSetFaceZoneSource
|
||||||
|
{
|
||||||
|
// Private Data
|
||||||
|
|
||||||
|
//- Add usage string
|
||||||
|
static addToUsageTable usage_;
|
||||||
|
|
||||||
|
//- Names of cellSets to use
|
||||||
|
wordList names_;
|
||||||
|
|
||||||
|
//- Whether cellSet is slave cells or master cells
|
||||||
|
const bool flip_;
|
||||||
|
|
||||||
|
|
||||||
|
// Private Member Functions
|
||||||
|
|
||||||
|
//- Select outside faces of cellSet
|
||||||
|
void selectFaces
|
||||||
|
(
|
||||||
|
const cellSet& cSet,
|
||||||
|
bitSet& selectedFace,
|
||||||
|
bitSet& doFlip
|
||||||
|
) const;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Runtime type information
|
||||||
|
TypeName("cellToFaceZone");
|
||||||
|
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct from components
|
||||||
|
cellToFaceZone
|
||||||
|
(
|
||||||
|
const polyMesh& mesh,
|
||||||
|
const word& cellSetName,
|
||||||
|
const bool flip
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Construct from dictionary
|
||||||
|
cellToFaceZone(const polyMesh& mesh, const dictionary& dict);
|
||||||
|
|
||||||
|
//- Construct from Istream
|
||||||
|
cellToFaceZone(const polyMesh& mesh, Istream& is);
|
||||||
|
|
||||||
|
|
||||||
|
//- Destructor
|
||||||
|
virtual ~cellToFaceZone() = default;
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
virtual void applyToSet
|
||||||
|
(
|
||||||
|
const topoSetSource::setAction action,
|
||||||
|
topoSet& set
|
||||||
|
) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -439,6 +439,15 @@ actions
|
|||||||
// flip true;
|
// flip true;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
{
|
||||||
|
name cellToFaceZone1;
|
||||||
|
type faceZoneSet;
|
||||||
|
action new;
|
||||||
|
source cellToFaceZone;
|
||||||
|
set cylinder1;
|
||||||
|
flip true;
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
name pointBox1;
|
name pointBox1;
|
||||||
type pointSet;
|
type pointSet;
|
||||||
|
|||||||
Reference in New Issue
Block a user