ENH: relocate/refactor fvMeshSubset

- direct construct and reset method for creating a zero-sized (dummy)
  subMesh. Has no exposed faces and no parallel synchronization
  required.

- core mapping (interpolate) functionality with direct handling
  of subsetting in fvMeshSubset (src/finiteVolume).
  Does not use dynamicMesh topology changes

- two-step subsetting as fvMeshSubsetter (src/dynamicMesh).
  Does use dynamicMesh topology changes.
  This is apparently only needed by the subsetMesh application itself.

DEFEATURE: remove deprecated setLargeCellSubset() method

- was deprecated JUL-2018, now removed (see issue #951)
This commit is contained in:
Mark Olesen 2022-04-07 11:25:57 +02:00
parent 6e21d6f78c
commit cf7dbf4d42
24 changed files with 846 additions and 579 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd. Copyright (C) 2016-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -42,7 +42,7 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "fvMeshSubset.H" #include "fvMeshSubsetter.H" // Not fvMeshSubset (need two-step subsetting)
#include "argList.H" #include "argList.H"
#include "IOobjectList.H" #include "IOobjectList.H"
#include "volFields.H" #include "volFields.H"
@ -517,8 +517,8 @@ int main(int argc, char *argv[])
} }
// Mesh subsetting engine // Two-step mesh subsetting engine
fvMeshSubset subsetter(mesh); fvMeshSubsetter subsetter(mesh);
{ {
bitSet selectedCells = bitSet selectedCells =
@ -530,13 +530,8 @@ int main(int argc, char *argv[])
if (exposedPatchIDs.size() == 1) if (exposedPatchIDs.size() == 1)
{ {
// Single patch for exposed faces // Single patch for exposed faces (syncPar)
subsetter.setCellSubset subsetter.reset(selectedCells, exposedPatchIDs.first(), true);
(
selectedCells,
exposedPatchIDs.first(),
true
);
} }
else else
{ {
@ -545,7 +540,7 @@ int main(int argc, char *argv[])
labelList exposedFaces labelList exposedFaces
( (
subsetter.getExposedFaces(selectedCells, true) subsetter.getExposedFaces(selectedCells, true) // syncPar
); );
subsetter.setCellSubset subsetter.setCellSubset
@ -553,7 +548,7 @@ int main(int argc, char *argv[])
selectedCells, selectedCells,
exposedFaces, exposedFaces,
labelUIndList(nearestExposedPatch, exposedFaces)(), labelUIndList(nearestExposedPatch, exposedFaces)(),
true true // syncPar
); );
} }

View File

@ -1031,10 +1031,7 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
// Subset 0 cells, no parallel comms. // Subset 0 cells, no parallel comms.
// This is used to create zero-sized fields. // This is used to create zero-sized fields.
subsetterPtr.reset subsetterPtr.reset(new fvMeshSubset(mesh, zero{}));
(
new fvMeshSubset(mesh, bitSet(), nonProcI, false)
);
} }

View File

@ -86,8 +86,7 @@ polyMeshAdder/polyMeshAdder.C
fvMeshTools/fvMeshTools.C fvMeshTools/fvMeshTools.C
fvMeshSubset/fvMeshSubset.C fvMeshSubset/fvMeshSubsetter.C
fvMeshSubsetProxy/fvMeshSubsetProxy.C
motionSmoother/motionSmoother.C motionSmoother/motionSmoother.C
motionSmoother/motionSmootherAlgo.C motionSmoother/motionSmootherAlgo.C

View File

@ -28,6 +28,7 @@ License
#include "fvMeshDistribute.H" #include "fvMeshDistribute.H"
#include "fvMeshAdder.H" #include "fvMeshAdder.H"
#include "fvMeshSubset.H"
#include "faceCoupleInfo.H" #include "faceCoupleInfo.H"
#include "processorFvPatchField.H" #include "processorFvPatchField.H"
#include "processorFvsPatchField.H" #include "processorFvsPatchField.H"

View File

@ -0,0 +1,201 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-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 "fvMeshSubsetter.H"
#include "mapPolyMesh.H"
#include "polyTopoChange.H"
#include "removeCells.H"
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
// Helper: extract cells-to-remove from cells-to-keep
static bitSet invertCellSelection
(
const label nCells,
const bitSet& selectedCells
)
{
// Work on a copy
bitSet cellsToRemove(selectedCells);
// Ensure we have the full range
cellsToRemove.resize(nCells, false);
// Invert the selection
cellsToRemove.flip();
return cellsToRemove;
}
// Helper: extract cells-to-remove from cells-to-keep
static inline bitSet invertCellSelection
(
const label nCells,
const label regioni,
const labelUList& regions
)
{
return BitSetOps::create
(
nCells,
regioni,
regions,
false // on=false: invert return cells to remove
);
}
} // End namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fvMeshSubsetter::removeCellsImpl
(
const bitSet& cellsToRemove,
const labelList& exposedFaces,
const labelList& patchIDs,
const bool syncPar
)
{
// Clear out all existing maps
clear();
// Mesh changing engine.
polyTopoChange meshMod(baseMesh());
removeCells cellRemover(baseMesh(), syncPar);
cellRemover.setRefinement
(
cellsToRemove,
exposedFaces,
patchIDs,
meshMod
);
// Create mesh, return map from old to new mesh.
autoPtr<fvMesh> newMeshPtr;
autoPtr<mapPolyMesh> map = meshMod.makeMesh
(
newMeshPtr,
IOobject
(
baseMesh().name(),
baseMesh().time().timeName(),
baseMesh().time(),
IOobject::READ_IF_PRESENT, // read fv* if present
IOobject::NO_WRITE
),
baseMesh(),
syncPar
);
reset
(
std::move(newMeshPtr),
labelList(map().pointMap()),
labelList(map().faceMap()),
labelList(map().cellMap()),
identity(baseMesh().boundaryMesh().size())
);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::labelList Foam::fvMeshSubsetter::getExposedFaces
(
const bitSet& selectedCells,
const bool syncPar
) const
{
return
Foam::removeCells(baseMesh(), syncPar).getExposedFaces
(
invertCellSelection(baseMesh().nCells(), selectedCells)
);
}
Foam::labelList Foam::fvMeshSubsetter::getExposedFaces
(
const label regioni,
const labelUList& regions,
const bool syncPar
) const
{
return
Foam::removeCells(baseMesh(), syncPar).getExposedFaces
(
invertCellSelection(baseMesh().nCells(), regioni, regions)
);
}
void Foam::fvMeshSubsetter::setCellSubset
(
const bitSet& selectedCells,
const labelList& exposedFaces,
const labelList& patchIDs,
const bool syncPar
)
{
removeCellsImpl
(
invertCellSelection(baseMesh().nCells(), selectedCells),
exposedFaces,
patchIDs,
syncPar
);
}
void Foam::fvMeshSubsetter::setCellSubset
(
const label regioni,
const labelList& regions,
const labelList& exposedFaces,
const labelList& patchIDs,
const bool syncCouples
)
{
removeCellsImpl
(
invertCellSelection(baseMesh().nCells(), regioni, regions),
exposedFaces,
patchIDs,
syncCouples
);
}
// ************************************************************************* //

View File

@ -0,0 +1,144 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-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::fvMeshSubsetter
Description
Extends Foam::fvMeshSubset with two-step subsetting
(uses polyTopoChange modification).
SourceFiles
fvMeshSubsetter.C
\*---------------------------------------------------------------------------*/
#ifndef Foam_fvMeshSubsetter_H
#define Foam_fvMeshSubsetter_H
#include "fvMeshSubset.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class fvMeshSubsetter Declaration
\*---------------------------------------------------------------------------*/
class fvMeshSubsetter
:
public fvMeshSubset
{
// Private Member Functions
//- Forwarding to Foam::removeCells
void removeCellsImpl
(
const bitSet& cellsToRemove,
const labelList& exposedFaces,
const labelList& patchIDs,
const bool syncPar
);
//- No copy construct
fvMeshSubsetter(const fvMeshSubsetter&) = delete;
//- No copy assignment
void operator=(const fvMeshSubset&) = delete;
public:
// Constructors
//- Inherit constructors from fvMeshSubset
using fvMeshSubset::fvMeshSubset;
// Member Functions
//- Inherit all one-step subsetting
using fvMeshSubset::setCellSubset;
// Two-step subsetting
//- Get labels of exposed faces.
// These are
// - internal faces that become boundary faces
// - coupled faces that become uncoupled (since one of the
// sides gets deleted)
labelList getExposedFaces
(
const bitSet& selectedCells,
const bool syncPar = true
) const;
//- Get labels of exposed faces.
// These are
// - internal faces that become boundary faces
// - coupled faces that become uncoupled (since one of the
// sides gets deleted)
labelList getExposedFaces
(
const label regioni,
const labelUList& regions,
const bool syncPar = true
) const;
//- For every exposed face (from above getExposedFaces)
// Uses supplied (existing!) patches
void setCellSubset
(
const bitSet& selectedCells,
const labelList& exposedFaces,
const labelList& patchIDs,
const bool syncPar = true
);
//- For every exposed face (from above getExposedFaces)
// Uses supplied (existing!) patches
void setCellSubset
(
const label regioni,
const labelList& regions,
const labelList& exposedFaces,
const labelList& patchIDs,
const bool syncPar = true
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -71,20 +71,7 @@ inline void decrCount(const Foam::labelUList& list, Foam::labelList& counter)
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::removeCells::removeCells Foam::removeCells::removeCells(const polyMesh& mesh, const bool syncPar)
(
const polyMesh& mesh
)
:
removeCells(mesh, true)
{}
Foam::removeCells::removeCells
(
const polyMesh& mesh,
const bool syncPar
)
: :
mesh_(mesh), mesh_(mesh),
syncPar_(syncPar) syncPar_(syncPar)

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -40,8 +40,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef removeCells_H #ifndef Foam_removeCells_H
#define removeCells_H #define Foam_removeCells_H
#include "labelList.H" #include "labelList.H"
#include "typeInfo.H" #include "typeInfo.H"
@ -63,7 +63,7 @@ class mapPolyMesh;
class removeCells class removeCells
{ {
// Private data // Private Data
//- Reference to mesh //- Reference to mesh
const polyMesh& mesh_; const polyMesh& mesh_;
@ -71,6 +71,7 @@ class removeCells
//- Whether or not to synchronize parallel case. //- Whether or not to synchronize parallel case.
const bool syncPar_; const bool syncPar_;
public: public:
//- Runtime type information //- Runtime type information
@ -79,11 +80,8 @@ public:
// Constructors // Constructors
//- Construct from mesh. With parallel synchronization. //- Construct from mesh. Parallel synchronized by default
explicit removeCells(const polyMesh& mesh); explicit removeCells(const polyMesh& mesh, const bool syncPar = true);
//- Construct from mesh, optionally with parallel synchronization.
removeCells(const polyMesh& mesh, const bool syncPar);
//- Destructor //- Destructor

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd. Copyright (C) 2021-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -95,7 +95,7 @@ bool Foam::Detail::zoneSubSet::correct()
<< endl; << endl;
} }
subsetter_.setCellSubset(selectedCells.addressing()); subsetter_.reset(selectedCells.addressing());
return true; return true;
} }

View File

@ -62,8 +62,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef zoneSubSet_H #ifndef Foam_zoneSubSet_H
#define zoneSubSet_H #define Foam_zoneSubSet_H
#include "fvMeshSubset.H" #include "fvMeshSubset.H"

View File

@ -12,6 +12,9 @@ $(fvGeometryScheme)/stabilised/stabilisedFvGeometryScheme.C
surfaceInterpolation = interpolation/surfaceInterpolation surfaceInterpolation = interpolation/surfaceInterpolation
$(surfaceInterpolation)/surfaceInterpolation/surfaceInterpolation.C $(surfaceInterpolation)/surfaceInterpolation/surfaceInterpolation.C
fvMesh/fvMeshSubset/fvMeshSubset.C
fvMesh/fvMeshSubset/fvMeshSubsetProxy.C
fvMesh/singleCellFvMesh/singleCellFvMesh.C fvMesh/singleCellFvMesh/singleCellFvMesh.C
fvMesh/simplifiedFvMesh/simplifiedFvMesh/simplifiedFvMesh.C fvMesh/simplifiedFvMesh/simplifiedFvMesh/simplifiedFvMesh.C

View File

@ -1,12 +1,10 @@
EXE_INC = \ EXE_INC = \
-I$(LIB_SRC)/fileFormats/lnInclude \ -I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/surfMesh/lnInclude \ -I$(LIB_SRC)/surfMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude
-I$(LIB_SRC)/dynamicMesh/lnInclude
LIB_LIBS = \ LIB_LIBS = \
-lOpenFOAM \ -lOpenFOAM \
-lfileFormats \ -lfileFormats \
-lsurfMesh \ -lsurfMesh \
-lmeshTools -lmeshTools

View File

@ -27,15 +27,15 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "fvMeshSubset.H" #include "fvMeshSubset.H"
#include "boolList.H"
#include "BitOps.H" #include "BitOps.H"
#include "pointIndList.H"
#include "Pstream.H" #include "Pstream.H"
#include "emptyPolyPatch.H"
#include "cyclicPolyPatch.H" #include "cyclicPolyPatch.H"
#include "removeCells.H" #include "emptyPolyPatch.H"
#include "polyTopoChange.H"
#include "mapPolyMesh.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
Foam::word Foam::fvMeshSubset::exposedPatchName("oldInternalFaces");
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
@ -58,20 +58,63 @@ inline void markUsed
} // End anonymous namespace } // End anonymous namespace
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam
Foam::word Foam::fvMeshSubset::exposedPatchName("oldInternalFaces");
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::fvMeshSubset::checkCellSubset() const
{ {
if (!fvMeshSubsetPtr_)
// Perform a subset of a subset
static labelList subsetSubset
(
const label nElems,
const labelUList& selectedElements, // First subset
const labelUList& subsetMap // Subset within first subset
)
{
if (selectedElements.empty() || subsetMap.empty())
{
// Trivial case
return labelList();
}
// Mark selected elements.
const bitSet selected(nElems, selectedElements);
// Count subset of selected elements
label n = 0;
forAll(subsetMap, i)
{
if (selected[subsetMap[i]])
{
++n;
}
}
// Collect selected elements
labelList subsettedElements(n);
n = 0;
forAll(subsetMap, i)
{
if (selected[subsetMap[i]])
{
subsettedElements[n] = i;
++n;
}
}
return subsettedElements;
}
} // End namespace Foam
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
bool Foam::fvMeshSubset::checkHasSubMesh() const
{
if (!subMeshPtr_)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "setCellSubset()" << nl << "Mesh is not subsetted!" << nl
<< "before attempting to access subset data"
<< abort(FatalError); << abort(FatalError);
return false; return false;
@ -118,7 +161,7 @@ void Foam::fvMeshSubset::calcFaceFlipMap() const
void Foam::fvMeshSubset::doCoupledPatches void Foam::fvMeshSubset::doCoupledPatches
( (
const bool syncPar, const bool syncPar,
labelList& nCellsUsingFace labelUList& nCellsUsingFace
) const ) const
{ {
// Synchronize facesToSubset on both sides of coupled patches. // Synchronize facesToSubset on both sides of coupled patches.
@ -186,8 +229,8 @@ void Foam::fvMeshSubset::doCoupledPatches
&& nbrCellsUsingFace[i] == 0 && nbrCellsUsingFace[i] == 0
) )
{ {
// Face's neighbour is no longer there. Mark face // Face's neighbour is no longer there.
// off as coupled // Mark face off as coupled
nCellsUsingFace[pp.start()+i] = 3; nCellsUsingFace[pp.start()+i] = 3;
++nUncoupled; ++nUncoupled;
} }
@ -229,7 +272,7 @@ void Foam::fvMeshSubset::doCoupledPatches
reduce(nUncoupled, sumOp<label>()); reduce(nUncoupled, sumOp<label>());
} }
if (nUncoupled > 0) if (nUncoupled)
{ {
Info<< "Uncoupled " << nUncoupled << " faces on coupled patches. " Info<< "Uncoupled " << nUncoupled << " faces on coupled patches. "
<< "(processorPolyPatch, cyclicPolyPatch)" << endl; << "(processorPolyPatch, cyclicPolyPatch)" << endl;
@ -237,107 +280,32 @@ void Foam::fvMeshSubset::doCoupledPatches
} }
void Foam::fvMeshSubset::removeCellsImpl
(
const bitSet& cellsToRemove,
const labelList& exposedFaces,
const labelList& patchIDs,
const bool syncCouples
)
{
// Mesh changing engine.
polyTopoChange meshMod(baseMesh());
removeCells cellRemover(baseMesh(), syncCouples);
cellRemover.setRefinement
(
cellsToRemove,
exposedFaces,
patchIDs,
meshMod
);
// Create mesh, return map from old to new mesh.
autoPtr<mapPolyMesh> map = meshMod.makeMesh
(
fvMeshSubsetPtr_,
IOobject
(
baseMesh().name(),
baseMesh().time().timeName(),
baseMesh().time(),
IOobject::READ_IF_PRESENT, // read fv* if present
IOobject::NO_WRITE
),
baseMesh(),
syncCouples
);
pointMap_ = map().pointMap();
faceMap_ = map().faceMap();
cellMap_ = map().cellMap();
patchMap_ = identity(baseMesh().boundaryMesh().size());
}
Foam::labelList Foam::fvMeshSubset::subsetSubset
(
const label nElems,
const labelUList& selectedElements,
const labelUList& subsetMap
)
{
// Mark selected elements.
const bitSet selected(nElems, selectedElements);
// Count subset of selected elements
label n = 0;
forAll(subsetMap, i)
{
if (selected[subsetMap[i]])
{
++n;
}
}
// Collect selected elements
labelList subsettedElements(n);
n = 0;
forAll(subsetMap, i)
{
if (selected[subsetMap[i]])
{
subsettedElements[n] = i;
++n;
}
}
return subsettedElements;
}
void Foam::fvMeshSubset::subsetZones() void Foam::fvMeshSubset::subsetZones()
{ {
// Keep all zones, even if zero size. // Keep all zones, even if zero size.
#ifdef FULLDEBUG
checkHasSubMesh();
#endif
auto& newSubMesh = subMeshPtr_();
// PointZones // PointZones
const pointZoneMesh& pointZones = baseMesh().pointZones(); const pointZoneMesh& pointZones = baseMesh().pointZones();
List<pointZone*> pZonePtrs(pointZones.size()); List<pointZone*> pZones(pointZones.size());
forAll(pointZones, zonei) forAll(pointZones, zonei)
{ {
const pointZone& pz = pointZones[zonei]; const pointZone& pz = pointZones[zonei];
pZonePtrs[zonei] = new pointZone pZones[zonei] = new pointZone
( (
pz.name(), pz.name(),
subsetSubset(baseMesh().nPoints(), pz, pointMap()), subsetSubset(baseMesh().nPoints(), pz, pointMap()),
zonei, zonei,
fvMeshSubsetPtr_().pointZones() newSubMesh.pointZones()
); );
} }
@ -348,7 +316,7 @@ void Foam::fvMeshSubset::subsetZones()
const faceZoneMesh& faceZones = baseMesh().faceZones(); const faceZoneMesh& faceZones = baseMesh().faceZones();
List<faceZone*> fZonePtrs(faceZones.size()); List<faceZone*> fZones(faceZones.size());
forAll(faceZones, zonei) forAll(faceZones, zonei)
{ {
@ -361,14 +329,7 @@ void Foam::fvMeshSubset::subsetZones()
labelList zone(baseMesh().nFaces(), Zero); labelList zone(baseMesh().nFaces(), Zero);
forAll(fz, j) forAll(fz, j)
{ {
if (fz.flipMap()[j]) zone[fz[j]] = (fz.flipMap()[j] ? 1 : -1);
{
zone[fz[j]] = 1;
}
else
{
zone[fz[j]] = -1;
}
} }
// Select faces // Select faces
@ -400,72 +361,38 @@ void Foam::fvMeshSubset::subsetZones()
} }
} }
fZonePtrs[zonei] = new faceZone fZones[zonei] = new faceZone
( (
fz.name(), fz.name(),
subAddressing, subAddressing,
subFlipStatus, subFlipStatus,
zonei, zonei,
fvMeshSubsetPtr_().faceZones() newSubMesh.faceZones()
); );
} }
// Cell Zones // Cell Zones
const cellZoneMesh& cellZones = baseMesh().cellZones(); const cellZoneMesh& cellZones = baseMesh().cellZones();
List<cellZone*> cZonePtrs(cellZones.size()); List<cellZone*> cZones(cellZones.size());
forAll(cellZones, zonei) forAll(cellZones, zonei)
{ {
const cellZone& cz = cellZones[zonei]; const cellZone& cz = cellZones[zonei];
cZonePtrs[zonei] = new cellZone cZones[zonei] = new cellZone
( (
cz.name(), cz.name(),
subsetSubset(baseMesh().nCells(), cz, cellMap()), subsetSubset(baseMesh().nCells(), cz, cellMap()),
zonei, zonei,
fvMeshSubsetPtr_().cellZones() newSubMesh.cellZones()
); );
} }
// Add the zones // Add the zones
fvMeshSubsetPtr_().addZones(pZonePtrs, fZonePtrs, cZonePtrs); newSubMesh.addZones(pZones, fZones, cZones);
}
Foam::bitSet Foam::fvMeshSubset::getCellsToRemove
(
const bitSet& selectedCells
) const
{
// Work on a copy
bitSet cellsToRemove(selectedCells);
// Ensure we have the full range
cellsToRemove.resize(baseMesh().nCells(), false);
// Invert the selection
cellsToRemove.flip();
return cellsToRemove;
}
Foam::bitSet Foam::fvMeshSubset::getCellsToRemove
(
const label regioni,
const labelUList& regions
) const
{
return BitSetOps::create
(
baseMesh().nCells(),
regioni,
regions,
false // on=false: invert return cells to remove
);
} }
@ -474,7 +401,7 @@ Foam::bitSet Foam::fvMeshSubset::getCellsToRemove
Foam::fvMeshSubset::fvMeshSubset(const fvMesh& baseMesh) Foam::fvMeshSubset::fvMeshSubset(const fvMesh& baseMesh)
: :
baseMesh_(baseMesh), baseMesh_(baseMesh),
fvMeshSubsetPtr_(nullptr), subMeshPtr_(nullptr),
faceFlipMapPtr_(nullptr), faceFlipMapPtr_(nullptr),
pointMap_(), pointMap_(),
faceMap_(), faceMap_(),
@ -483,31 +410,25 @@ Foam::fvMeshSubset::fvMeshSubset(const fvMesh& baseMesh)
{} {}
Foam::fvMeshSubset::fvMeshSubset Foam::fvMeshSubset::fvMeshSubset(const fvMesh& baseMesh, const Foam::zero)
(
const fvMesh& baseMesh,
const bitSet& selectedCells,
const label patchID,
const bool syncCouples
)
: :
fvMeshSubset(baseMesh) fvMeshSubset(baseMesh)
{ {
setCellSubset(selectedCells, patchID, syncCouples); reset(Foam::zero{});
} }
Foam::fvMeshSubset::fvMeshSubset Foam::fvMeshSubset::fvMeshSubset
( (
const fvMesh& baseMesh, const fvMesh& baseMesh,
const labelHashSet& selectedCells, const bitSet& selectedCells,
const label patchID, const label patchID,
const bool syncCouples const bool syncPar
) )
: :
fvMeshSubset(baseMesh) fvMeshSubset(baseMesh)
{ {
setCellSubset(selectedCells, patchID, syncCouples); reset(selectedCells, patchID, syncPar);
} }
@ -516,12 +437,26 @@ Foam::fvMeshSubset::fvMeshSubset
const fvMesh& baseMesh, const fvMesh& baseMesh,
const labelUList& selectedCells, const labelUList& selectedCells,
const label patchID, const label patchID,
const bool syncCouples const bool syncPar
) )
: :
fvMeshSubset(baseMesh) fvMeshSubset(baseMesh)
{ {
setCellSubset(selectedCells, patchID, syncCouples); reset(selectedCells, patchID, syncPar);
}
Foam::fvMeshSubset::fvMeshSubset
(
const fvMesh& baseMesh,
const labelHashSet& selectedCells,
const label patchID,
const bool syncPar
)
:
fvMeshSubset(baseMesh)
{
reset(selectedCells, patchID, syncPar);
} }
@ -531,12 +466,12 @@ Foam::fvMeshSubset::fvMeshSubset
const label regioni, const label regioni,
const labelUList& regions, const labelUList& regions,
const label patchID, const label patchID,
const bool syncCouples const bool syncPar
) )
: :
fvMeshSubset(baseMesh) fvMeshSubset(baseMesh)
{ {
setCellSubset(regioni, regions, patchID, syncCouples); reset(regioni, regions, patchID, syncPar);
} }
@ -544,7 +479,7 @@ Foam::fvMeshSubset::fvMeshSubset
void Foam::fvMeshSubset::clear() void Foam::fvMeshSubset::clear()
{ {
fvMeshSubsetPtr_.reset(nullptr); subMeshPtr_.reset(nullptr);
faceFlipMapPtr_.reset(nullptr); faceFlipMapPtr_.reset(nullptr);
pointMap_.clear(); pointMap_.clear();
@ -554,13 +489,104 @@ void Foam::fvMeshSubset::clear()
} }
void Foam::fvMeshSubset::setCellSubset void Foam::fvMeshSubset::reset()
{
clear();
}
void Foam::fvMeshSubset::reset
(
autoPtr<fvMesh>&& subMeshPtr,
labelList&& pointMap,
labelList&& faceMap,
labelList&& cellMap,
labelList&& patchMap
)
{
subMeshPtr_.reset(std::move(subMeshPtr));
faceFlipMapPtr_.reset(nullptr);
pointMap_ = std::move(pointMap);
faceMap_ = std::move(faceMap);
cellMap_ = std::move(cellMap);
patchMap_ = std::move(patchMap);
// Sanity
if (!subMeshPtr_)
{
clear();
}
}
void Foam::fvMeshSubset::reset(const Foam::zero)
{
clear();
// Create zero-sized subMesh
subMeshPtr_.reset
(
new fvMesh
(
IOobject
(
baseMesh_.name(),
baseMesh_.time().timeName(),
baseMesh_.time(),
IOobject::READ_IF_PRESENT, // Read fv* if present
IOobject::NO_WRITE
),
Foam::zero{} // zero-sized
// Uses syncPar (bounds) - should generally be OK
)
);
auto& newSubMesh = subMeshPtr_();
// Clone non-processor patches
{
const polyBoundaryMesh& oldBoundary = baseMesh_.boundaryMesh();
const polyBoundaryMesh& newBoundary = newSubMesh.boundaryMesh();
polyPatchList newPatches(oldBoundary.nNonProcessor());
patchMap_ = identity(newPatches.size());
forAll(newPatches, patchi)
{
newPatches.set
(
patchi,
oldBoundary[patchi].clone
(
newBoundary,
patchi,
0, // patch size
0 // patch start
)
);
}
newSubMesh.addFvPatches(newPatches);
}
// Add the zones
subsetZones();
}
void Foam::fvMeshSubset::reset
( (
const bitSet& selectedCells, const bitSet& selectedCells,
const label patchID, const label patchID,
const bool syncPar const bool syncPar
) )
{ {
// Clear all old maps and pointers
clear();
const cellList& oldCells = baseMesh().cells(); const cellList& oldCells = baseMesh().cells();
const faceList& oldFaces = baseMesh().faces(); const faceList& oldFaces = baseMesh().faces();
const pointField& oldPoints = baseMesh().points(); const pointField& oldPoints = baseMesh().points();
@ -587,9 +613,6 @@ void Foam::fvMeshSubset::setCellSubset
<< abort(FatalError); << abort(FatalError);
} }
// Clear all old maps and pointers
clear();
// The selected cells - sorted in ascending order // The selected cells - sorted in ascending order
cellMap_ = selectedCells.sortedToc(); cellMap_ = selectedCells.sortedToc();
@ -623,6 +646,7 @@ void Foam::fvMeshSubset::setCellSubset
labelList nCellsUsingFace(oldFaces.size(), Zero); labelList nCellsUsingFace(oldFaces.size(), Zero);
label nFacesInSet = 0; label nFacesInSet = 0;
forAll(oldFaces, oldFacei) forAll(oldFaces, oldFacei)
{ {
bool faceUsed = false; bool faceUsed = false;
@ -648,7 +672,7 @@ void Foam::fvMeshSubset::setCellSubset
++nFacesInSet; ++nFacesInSet;
} }
} }
faceMap_.setSize(nFacesInSet); faceMap_.resize(nFacesInSet);
// Handle coupled faces. Modifies patch faces to be uncoupled to 3. // Handle coupled faces. Modifies patch faces to be uncoupled to 3.
doCoupledPatches(syncPar, nCellsUsingFace); doCoupledPatches(syncPar, nCellsUsingFace);
@ -878,7 +902,7 @@ void Foam::fvMeshSubset::setCellSubset
// //
// Create new points // Create new points
// //
pointField newPoints(pointUIndList(oldPoints, pointMap_)); pointField newPoints(oldPoints, pointMap_);
// //
@ -972,7 +996,7 @@ void Foam::fvMeshSubset::setCellSubset
// surfaceInterpolation cannot find its fvSchemes. // surfaceInterpolation cannot find its fvSchemes.
// It will try to read, for example. "system/region0SubSet/fvSchemes" // It will try to read, for example. "system/region0SubSet/fvSchemes"
// //
fvMeshSubsetPtr_ = autoPtr<fvMesh>::New subMeshPtr_ = autoPtr<fvMesh>::New
( (
IOobject IOobject
( (
@ -991,8 +1015,8 @@ void Foam::fvMeshSubset::setCellSubset
// Add old patches // Add old patches
List<polyPatch*> newBoundary(nbSize); polyPatchList newBoundary(nbSize);
patchMap_.setSize(nbSize); patchMap_.resize(nbSize);
label nNewPatches = 0; label nNewPatches = 0;
label patchStart = nInternalFaces; label patchStart = nInternalFaces;
@ -1065,24 +1089,32 @@ void Foam::fvMeshSubset::setCellSubset
map[patchFacei] = oldPatches[oldPatchi].whichFace(oldFacei); map[patchFacei] = oldPatches[oldPatchi].whichFace(oldFacei);
} }
newBoundary[nNewPatches] = oldPatches[oldPatchi].clone newBoundary.set
( (
fvMeshSubsetPtr_().boundaryMesh(),
nNewPatches, nNewPatches,
map, oldPatches[oldPatchi].clone
patchStart (
).ptr(); subMeshPtr_().boundaryMesh(),
nNewPatches,
map,
patchStart
)
);
} }
else else
{ {
// Clone (even if 0 size) // Clone (even if 0 size)
newBoundary[nNewPatches] = oldPatches[oldPatchi].clone newBoundary.set
( (
fvMeshSubsetPtr_().boundaryMesh(),
nNewPatches, nNewPatches,
newSize, oldPatches[oldPatchi].clone
patchStart (
).ptr(); subMeshPtr_().boundaryMesh(),
nNewPatches,
newSize,
patchStart
)
);
} }
patchStart += newSize; patchStart += newSize;
@ -1104,14 +1136,18 @@ void Foam::fvMeshSubset::setCellSubset
// Newly created patch so is at end. Check if any faces in it. // Newly created patch so is at end. Check if any faces in it.
if (oldInternalSize > 0) if (oldInternalSize > 0)
{ {
newBoundary[nNewPatches] = new emptyPolyPatch newBoundary.set
( (
exposedPatchName,
boundaryPatchSizes[oldInternalPatchID],
patchStart,
nNewPatches, nNewPatches,
fvMeshSubsetPtr_().boundaryMesh(), new emptyPolyPatch
emptyPolyPatch::typeName (
exposedPatchName,
boundaryPatchSizes[oldInternalPatchID],
patchStart,
nNewPatches,
subMeshPtr_().boundaryMesh(),
emptyPolyPatch::typeName
)
); );
//Pout<< " " << exposedPatchName << " : " //Pout<< " " << exposedPatchName << " : "
@ -1148,24 +1184,32 @@ void Foam::fvMeshSubset::setCellSubset
map[patchFacei] = oldPatches[oldPatchi].whichFace(oldFacei); map[patchFacei] = oldPatches[oldPatchi].whichFace(oldFacei);
} }
newBoundary[nNewPatches] = oldPatches[oldPatchi].clone newBoundary.set
( (
fvMeshSubsetPtr_().boundaryMesh(),
nNewPatches, nNewPatches,
map, oldPatches[oldPatchi].clone
patchStart (
).ptr(); subMeshPtr_().boundaryMesh(),
nNewPatches,
map,
patchStart
)
);
} }
else else
{ {
// Patch still exists. Add it // Patch still exists. Add it
newBoundary[nNewPatches] = oldPatches[oldPatchi].clone newBoundary.set
( (
fvMeshSubsetPtr_().boundaryMesh(),
nNewPatches, nNewPatches,
newSize, oldPatches[oldPatchi].clone
patchStart (
).ptr(); subMeshPtr_().boundaryMesh(),
nNewPatches,
newSize,
patchStart
)
);
} }
//Pout<< " " << oldPatches[oldPatchi].name() << " : " //Pout<< " " << oldPatches[oldPatchi].name() << " : "
@ -1178,26 +1222,26 @@ void Foam::fvMeshSubset::setCellSubset
// Reset the patch lists // Reset the patch lists
newBoundary.setSize(nNewPatches); newBoundary.resize(nNewPatches);
patchMap_.setSize(nNewPatches); patchMap_.resize(nNewPatches);
// Add the fvPatches // Add the fvPatches
fvMeshSubsetPtr_().addFvPatches(newBoundary, syncPar); subMeshPtr_().addFvPatches(newBoundary, syncPar);
// Subset and add any zones // Subset and add any zones
subsetZones(); subsetZones();
} }
void Foam::fvMeshSubset::setCellSubset void Foam::fvMeshSubset::reset
( (
const labelUList& selectedCells, const labelUList& selectedCells,
const label patchID, const label patchID,
const bool syncPar const bool syncPar
) )
{ {
setCellSubset reset
( (
BitSetOps::create(baseMesh().nCells(), selectedCells), BitSetOps::create(baseMesh().nCells(), selectedCells),
patchID, patchID,
@ -1206,14 +1250,14 @@ void Foam::fvMeshSubset::setCellSubset
} }
void Foam::fvMeshSubset::setCellSubset void Foam::fvMeshSubset::reset
( (
const labelHashSet& selectedCells, const labelHashSet& selectedCells,
const label patchID, const label patchID,
const bool syncPar const bool syncPar
) )
{ {
setCellSubset reset
( (
BitSetOps::create(baseMesh().nCells(), selectedCells), BitSetOps::create(baseMesh().nCells(), selectedCells),
patchID, patchID,
@ -1222,7 +1266,7 @@ void Foam::fvMeshSubset::setCellSubset
} }
void Foam::fvMeshSubset::setCellSubset void Foam::fvMeshSubset::reset
( (
const label regioni, const label regioni,
const labelUList& regions, const labelUList& regions,
@ -1230,7 +1274,7 @@ void Foam::fvMeshSubset::setCellSubset
const bool syncPar const bool syncPar
) )
{ {
setCellSubset reset
( (
BitSetOps::create(baseMesh().nCells(), regioni, regions), BitSetOps::create(baseMesh().nCells(), regioni, regions),
patchID, patchID,
@ -1239,66 +1283,4 @@ void Foam::fvMeshSubset::setCellSubset
} }
Foam::labelList Foam::fvMeshSubset::getExposedFaces
(
const bitSet& selectedCells,
const bool syncCouples
) const
{
return
removeCells(baseMesh(), syncCouples)
.getExposedFaces(getCellsToRemove(selectedCells));
}
Foam::labelList Foam::fvMeshSubset::getExposedFaces
(
const label regioni,
const labelUList& regions,
const bool syncCouples
) const
{
return
removeCells(baseMesh(), syncCouples)
.getExposedFaces(getCellsToRemove(regioni, regions));
}
void Foam::fvMeshSubset::setCellSubset
(
const bitSet& selectedCells,
const labelList& exposedFaces,
const labelList& patchIDs,
const bool syncCouples
)
{
removeCellsImpl
(
getCellsToRemove(selectedCells),
exposedFaces,
patchIDs,
syncCouples
);
}
void Foam::fvMeshSubset::setCellSubset
(
const label selectRegion,
const labelList& regions,
const labelList& exposedFaces,
const labelList& patchIDs,
const bool syncCouples
)
{
removeCellsImpl
(
getCellsToRemove(selectRegion, regions),
exposedFaces,
patchIDs,
syncCouples
);
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd. Copyright (C) 2016-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -28,19 +28,23 @@ Class
Foam::fvMeshSubset Foam::fvMeshSubset
Description Description
Given the original mesh and the list of selected cells, it creates the Holds a reference to the original mesh (the baseMesh)
mesh consisting only of the desired cells, with the mapping list for and optionally to a subset of that mesh (the subMesh)
points, faces, and cells. with mapping lists for points, faces, and cells.
Puts all exposed internal faces into either Can be constructed or reset to subset on the list of selected cells,
which it creates as subMesh consisting only of the desired cells,
with the mapping list for points, faces, and cells.
Places all exposed internal faces into either
- a user supplied patch - a user supplied patch
- a newly created patch "oldInternalFaces" - a newly created patch "oldInternalFaces"
- setCellSubset does coupled patch subsetting as well. If it detects - reset() does coupled patch subsetting as well.
a face on a coupled patch 'losing' its neighbour it will move the If it detects a face on a coupled patch 'losing' its neighbour
face into the oldInternalFaces patch. it will move the face into the oldInternalFaces patch.
- if a user supplied patch is used it is up to the destination - if a user supplied patch is used, it is up to the destination
patchField to handle exposed internal faces (mapping from face -1). patchField to handle exposed internal faces (mapping from face -1).
If not provided the default is to assign the internalField. All the If not provided the default is to assign the internalField. All the
basic patch field types (e.g. fixedValue) will give a warning and basic patch field types (e.g. fixedValue) will give a warning and
@ -49,18 +53,20 @@ Description
SourceFiles SourceFiles
fvMeshSubset.C fvMeshSubset.C
fvMeshSubsetI.H
fvMeshSubsetTemplates.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef fvMeshSubset_H #ifndef Foam_fvMeshSubset_H
#define fvMeshSubset_H #define Foam_fvMeshSubset_H
#include "fvMesh.H" #include "fvMesh.H"
#include "pointMesh.H" #include "pointMesh.H"
#include "surfaceMesh.H"
#include "GeometricField.H" #include "GeometricField.H"
#include "bitSet.H" #include "bitSet.H"
#include "HashSet.H" #include "HashSet.H"
#include "surfaceMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -75,11 +81,11 @@ class fvMeshSubset
{ {
// Private Data // Private Data
//- Mesh to subset from //- The base mesh to subset from
const fvMesh& baseMesh_; const fvMesh& baseMesh_;
//- Demand-driven subset mesh pointer //- Demand-driven subset mesh (pointer)
autoPtr<fvMesh> fvMeshSubsetPtr_; autoPtr<fvMesh> subMeshPtr_;
//- Optional face mapping array with flip encoded (-1/+1) //- Optional face mapping array with flip encoded (-1/+1)
mutable autoPtr<labelList> faceFlipMapPtr_; mutable autoPtr<labelList> faceFlipMapPtr_;
@ -99,53 +105,26 @@ class fvMeshSubset
// Private Member Functions // Private Member Functions
//- Check if subset has been performed //- Modify nCellsUsingFace for coupled faces becoming 'uncoupled.
bool checkCellSubset() const; void doCoupledPatches
(
const bool syncPar,
labelUList& nCellsUsingFace
) const;
//- Create zones for subMesh
void subsetZones();
//- Calculate face flip map //- Calculate face flip map
void calcFaceFlipMap() const; void calcFaceFlipMap() const;
//- Adapt nCellsUsingFace for coupled faces becoming 'uncoupled'.
void doCoupledPatches
(
const bool syncPar,
labelList& nCellsUsingFace
) const;
//- Forwarding to Foam::removeCells protected:
void removeCellsImpl
(
const bitSet& cellsToRemove,
const labelList& exposedFaces,
const labelList& patchIDs,
const bool syncCouples
);
// Protected Member Functions
//- Subset of subset //- FatalError if subset has not been performed
static labelList subsetSubset bool checkHasSubMesh() const;
(
const label nElems,
const labelUList& selectedElements,
const labelUList& subsetMap
);
//- Create zones for submesh
void subsetZones();
//- Helper: extract cells-to-remove from cells-to-keep
bitSet getCellsToRemove
(
const bitSet& selectedCells
) const;
//- Helper: extract cells-to-remove from cells-to-keep
bitSet getCellsToRemove
(
const label regioni,
const labelUList& regions
) const;
//- No copy construct //- No copy construct
fvMeshSubset(const fvMeshSubset&) = delete; fvMeshSubset(const fvMeshSubset&) = delete;
@ -164,11 +143,14 @@ public:
// Constructors // Constructors
//- Construct given a mesh to subset //- Construct using the entire mesh (no subset)
explicit fvMeshSubset(const fvMesh& baseMesh); explicit fvMeshSubset(const fvMesh& baseMesh);
//- Construct a zero-sized subset mesh, non-processor patches only
fvMeshSubset(const fvMesh& baseMesh, const Foam::zero);
//- Construct for a cell-subset of the given mesh //- Construct for a cell-subset of the given mesh
// See setCellSubset() for more details. // See reset() for more details.
fvMeshSubset fvMeshSubset
( (
const fvMesh& baseMesh, const fvMesh& baseMesh,
@ -178,7 +160,7 @@ public:
); );
//- Construct for a cell-subset of the given mesh //- Construct for a cell-subset of the given mesh
// See setCellSubset() for more details. // See reset() for more details.
fvMeshSubset fvMeshSubset
( (
const fvMesh& baseMesh, const fvMesh& baseMesh,
@ -188,7 +170,7 @@ public:
); );
//- Construct for a cell-subset of the given mesh //- Construct for a cell-subset of the given mesh
// See setCellSubset() for more details. // See reset() for more details.
fvMeshSubset fvMeshSubset
( (
const fvMesh& baseMesh, const fvMesh& baseMesh,
@ -198,7 +180,7 @@ public:
); );
//- Construct for a cell-subset of the given mesh //- Construct for a cell-subset of the given mesh
// See setCellSubset() for more details. // See reset() for more details.
fvMeshSubset fvMeshSubset
( (
const fvMesh& baseMesh, const fvMesh& baseMesh,
@ -246,42 +228,59 @@ public:
// Edit // Edit
//- Reset maps and subsetting //- Reset subMesh and all maps
void clear(); void clear();
//- Reset subMesh and all maps. Same as clear()
void reset();
//- Define cell subset based on the selectedCells. //- Reset to a zero-sized subset mesh, non-processor patches only
// Create "oldInternalFaces" patch for exposed void reset(const Foam::zero);
// internal faces (patchID==-1) or use supplied patch.
// Handles coupled patches if necessary by making coupled patch //- Reset from components
// face part of patchID (so uncoupled) void reset
void setCellSubset (
autoPtr<fvMesh>&& subMeshPtr, //!< Mesh subset
labelList&& pointMap, //!< Point mapping
labelList&& faceMap, //!< Face mapping
labelList&& cellMap, //!< Cell mapping
labelList&& patchMap //!< Patch mapping
);
//- Use the specified subset of cells.
//
// \par selectedCells The subset of cells to use
// \par patchID Patch id for exposed internal faces.
// Uses existing or creates "oldInternalFaces" for patchID == -1.
// \par syncPar
//
// \note Handles coupled patches if necessary by making
// coupled patch faces part of patchID (ie, uncoupled)
void reset
( (
const bitSet& selectedCells, const bitSet& selectedCells,
const label patchID = -1, const label patchID = -1,
const bool syncPar = true const bool syncPar = true
); );
//- Define cell subset, using the specified cells //- Use the specified subset of cells.
//- to define the selection void reset
void setCellSubset
( (
const labelUList& selectedCells, const labelUList& selectedCells,
const label patchID = -1, const label patchID = -1,
const bool syncPar = true const bool syncPar = true
); );
//- Define cell subset, using the specified cells //- Use the specified subset of cells.
//- labelHashSet to define the selection void reset
void setCellSubset
( (
const labelHashSet& selectedCells, const labelHashSet& selectedCells,
const label patchID = -1, const label patchID = -1,
const bool syncPar = true const bool syncPar = true
); );
//- Define cell subset, using the cells for which region == regioni. //- Use the cells of cells corresponding to where region == regioni.
void setCellSubset void reset
( (
const label regioni, const label regioni,
const labelUList& regions, const labelUList& regions,
@ -290,57 +289,68 @@ public:
); );
// Two-step subsetting // Legacy method names (v2112 and earlier)
//- Get labels of exposed faces. //- Use the specified subset of cells. Same as reset()
// These are void setCellSubset
// - internal faces that become boundary faces
// - coupled faces that become uncoupled (since one of the
// sides gets deleted)
labelList getExposedFaces
( (
const bitSet& selectedCells, const bitSet& selectedCells,
const bool syncCouples = true const label patchID = -1,
) const; const bool syncPar = true
)
{
reset(selectedCells, patchID, syncPar);
}
//- Get labels of exposed faces. //- Use the specified subset of cells. Same as reset()
// These are void setCellSubset
// - internal faces that become boundary faces (
// - coupled faces that become uncoupled (since one of the const labelUList& selectedCells,
// sides gets deleted) const label patchID = -1,
labelList getExposedFaces const bool syncPar = true
)
{
reset(selectedCells, patchID, syncPar);
}
//- Use the specified subset of cells. Same as reset()
void setCellSubset
(
const labelHashSet& selectedCells,
const label patchID = -1,
const bool syncPar = true
)
{
reset(selectedCells, patchID, syncPar);
}
//- Use the specified subset of cells. Same as reset()
void setCellSubset
( (
const label regioni, const label regioni,
const labelUList& regions, const labelUList& regions,
const bool syncCouples = true const label patchID = -1,
) const; const bool syncPar = true
)
{
reset(regioni, regions, patchID, syncPar);
}
//- For every exposed face (from above getExposedFaces)
// used supplied (existing!) patch // Field Mapping (static functions)
void setCellSubset
//- Map volume internal (dimensioned) field
template<class Type>
static tmp<DimensionedField<Type, volMesh>>
interpolate
( (
const bitSet& selectedCells, const DimensionedField<Type, volMesh>&,
const labelList& exposedFaces, const fvMesh& sMesh,
const labelList& patchIDs, const labelUList& cellMap
const bool syncCouples = true
); );
//- For every exposed face (from above getExposedFaces) //- Map volume field.
// used supplied (existing!) patch // Optionally allow unmapped faces not to produce a warning
void setCellSubset
(
const label regioni,
const labelList& regions,
const labelList& exposedFaces,
const labelList& patchIDs,
const bool syncCouples = true
);
// Field Mapping
//- Map volume field. Optionally allow unmapped faces not to produce
// a warning
template<class Type> template<class Type>
static tmp<GeometricField<Type, fvPatchField, volMesh>> static tmp<GeometricField<Type, fvPatchField, volMesh>>
interpolate interpolate
@ -353,16 +363,9 @@ public:
const bool allowUnmapped = false const bool allowUnmapped = false
); );
template<class Type> //- Map surface field.
tmp<GeometricField<Type, fvPatchField, volMesh>> // Optionally negates value if flipping a face
interpolate // (from exposing an internal face)
(
const GeometricField<Type, fvPatchField, volMesh>&,
const bool allowUnmapped = false
) const;
//- Map surface field. Optionally negates value if flipping
// a face (from exposing an internal face)
template<class Type> template<class Type>
static tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> static tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>
interpolate interpolate
@ -374,16 +377,6 @@ public:
const labelUList& faceMap const labelUList& faceMap
); );
//- Map surface field. Optionally allow unmapped faces not to produce
// a warning (not currently used)
template<class Type>
tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>
interpolate
(
const GeometricField<Type, fvsPatchField, surfaceMesh>&,
const bool allowUnmapped = false
) const;
//- Map point field //- Map point field
template<class Type> template<class Type>
static tmp<GeometricField<Type, pointPatchField, pointMesh>> static tmp<GeometricField<Type, pointPatchField, pointMesh>>
@ -395,27 +388,11 @@ public:
const labelUList& pointMap const labelUList& pointMap
); );
//- Map point field. Optionally allow unmapped points not to produce
// a warning (not currently used)
template<class Type>
tmp<GeometricField<Type, pointPatchField, pointMesh>>
interpolate
(
const GeometricField<Type, pointPatchField, pointMesh>&,
const bool allowUnmapped = false
) const;
//- Map dimensioned field // Field Mapping
template<class Type>
static tmp<DimensionedField<Type, volMesh>>
interpolate
(
const DimensionedField<Type, volMesh>&,
const fvMesh& sMesh,
const labelUList& cellMap
);
//- Map Dimensioned. Optional unmapped argument not used //- Map volume internal (dimensioned) field
//- Optional unmapped argument (currently unused)
template<class Type> template<class Type>
tmp<DimensionedField<Type, volMesh>> tmp<DimensionedField<Type, volMesh>>
interpolate interpolate
@ -424,73 +401,37 @@ public:
const bool allowUnmapped = false const bool allowUnmapped = false
) const; ) const;
//- Map volume field.
// Compatibility // Optionally allow unmapped faces not to produce a warning
template<class Type>
//- Deprecated(2018-07) old method name and old parameter ordering. tmp<GeometricField<Type, fvPatchField, volMesh>>
// \deprecated(2018-07) - use setCellSubset() method interpolate
inline void setLargeCellSubset
( (
const labelUList& region, const GeometricField<Type, fvPatchField, volMesh>&,
const label currentRegion, const bool allowUnmapped = false
const label patchID = -1, ) const;
const bool syncCouples = true
)
{
Info<< "WARNING: using highly deprecated method: "
<< "fvMeshSubset::setLargeCellSubset()" << nl;
setCellSubset //- Map surface field.
( // Optionally allow unmapped faces not to produce a warning
currentRegion, // (currently unused)
region, template<class Type>
patchID, tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>
syncCouples interpolate
);
}
//- Deprecated(2018-07) old method name
// \deprecated(2018-07) - use setCellSubset() method
inline void setLargeCellSubset
( (
const labelHashSet& globalCellMap, const GeometricField<Type, fvsPatchField, surfaceMesh>&,
const label patchID = -1, const bool allowUnmapped = false
const bool syncPar = true ) const;
)
{
Info<< "WARNING: using highly deprecated method: "
<< "fvMeshSubset::setLargeCellSubset()" << nl;
setCellSubset(globalCellMap, patchID, syncPar); //- Map point field.
} // Optionally allow unmapped points not to produce a warning
// (currently unused)
template<class Type>
//- Deprecated(2018-07) method tmp<GeometricField<Type, pointPatchField, pointMesh>>
// For every exposed face (from getExposedFaces) use supplied interpolate
// (existing!) patch ids
// \deprecated(2018-07) - use setCellSubset() method
inline void setLargeCellSubset
( (
const labelList& regions, const GeometricField<Type, pointPatchField, pointMesh>&,
const label regioni, const bool allowUnmapped = false
const labelList& exposedFaces, ) const;
const labelList& patchIDs,
const bool syncCouples = true
)
{
Info<< "WARNING: using highly deprecated method: "
<< "fvMeshSubset::setLargeCellSubset()" << nl;
setCellSubset
(
regioni,
regions,
exposedFaces,
patchIDs,
syncCouples
);
}
}; };
@ -505,7 +446,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository #ifdef NoRepository
#include "fvMeshSubsetInterpolate.C" #include "fvMeshSubsetTemplates.C"
#endif #endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -35,35 +35,35 @@ inline const Foam::fvMesh& Foam::fvMeshSubset::baseMesh() const noexcept
inline const Foam::fvMesh& Foam::fvMeshSubset::mesh() const noexcept inline const Foam::fvMesh& Foam::fvMeshSubset::mesh() const noexcept
{ {
return fvMeshSubsetPtr_ ? *fvMeshSubsetPtr_ : baseMesh_; return subMeshPtr_ ? *subMeshPtr_ : baseMesh_;
} }
inline bool Foam::fvMeshSubset::hasSubMesh() const noexcept inline bool Foam::fvMeshSubset::hasSubMesh() const noexcept
{ {
return bool(fvMeshSubsetPtr_); return bool(subMeshPtr_);
} }
inline const Foam::fvMesh& Foam::fvMeshSubset::subMesh() const inline const Foam::fvMesh& Foam::fvMeshSubset::subMesh() const
{ {
checkCellSubset(); checkHasSubMesh();
return *fvMeshSubsetPtr_; return *subMeshPtr_;
} }
inline Foam::fvMesh& Foam::fvMeshSubset::subMesh() inline Foam::fvMesh& Foam::fvMeshSubset::subMesh()
{ {
checkCellSubset(); checkHasSubMesh();
return *fvMeshSubsetPtr_; return *subMeshPtr_;
} }
inline const Foam::labelList& Foam::fvMeshSubset::pointMap() const inline const Foam::labelList& Foam::fvMeshSubset::pointMap() const
{ {
checkCellSubset(); checkHasSubMesh();
return pointMap_; return pointMap_;
} }
@ -71,7 +71,7 @@ inline const Foam::labelList& Foam::fvMeshSubset::pointMap() const
inline const Foam::labelList& Foam::fvMeshSubset::faceMap() const inline const Foam::labelList& Foam::fvMeshSubset::faceMap() const
{ {
checkCellSubset(); checkHasSubMesh();
return faceMap_; return faceMap_;
} }
@ -90,7 +90,7 @@ inline const Foam::labelList& Foam::fvMeshSubset::faceFlipMap() const
inline const Foam::labelList& Foam::fvMeshSubset::cellMap() const inline const Foam::labelList& Foam::fvMeshSubset::cellMap() const
{ {
checkCellSubset(); checkHasSubMesh();
return cellMap_; return cellMap_;
} }
@ -98,7 +98,7 @@ inline const Foam::labelList& Foam::fvMeshSubset::cellMap() const
inline const Foam::labelList& Foam::fvMeshSubset::patchMap() const inline const Foam::labelList& Foam::fvMeshSubset::patchMap() const
{ {
checkCellSubset(); checkHasSubMesh();
return patchMap_; return patchMap_;
} }

View File

@ -197,7 +197,7 @@ bool Foam::fvMeshSubsetProxy::correct(bool verbose)
if (changed || selectedCells_.empty()) if (changed || selectedCells_.empty())
{ {
subsetter_.setCellSubset(selectedCells_, exposedPatchId_); subsetter_.reset(selectedCells_, exposedPatchId_);
} }
return returnReduce(changed, orOp<bool>()); return returnReduce(changed, orOp<bool>());

View File

@ -37,11 +37,11 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef fvMeshSubsetProxy_H #ifndef Foam_fvMeshSubsetProxy_H
#define fvMeshSubsetProxy_H #define Foam_fvMeshSubsetProxy_H
#include "wordRes.H"
#include "fvMeshSubset.H" #include "fvMeshSubset.H"
#include "wordRes.H"
#include "zeroGradientFvPatchField.H" #include "zeroGradientFvPatchField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -34,7 +34,7 @@ License
#include "directPointPatchFieldMapper.H" #include "directPointPatchFieldMapper.H"
#include "flipOp.H" #include "flipOp.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Type> template<class Type>
Foam::tmp Foam::tmp
@ -145,6 +145,7 @@ Foam::fvMeshSubset::interpolate
// allowUnmapped : special mode for if we do not want to be // allowUnmapped : special mode for if we do not want to be
// warned for unmapped faces (e.g. from fvMeshDistribute). // warned for unmapped faces (e.g. from fvMeshDistribute).
const bool hasUnmapped = mapper.hasUnmapped(); const bool hasUnmapped = mapper.hasUnmapped();
if (allowUnmapped) if (allowUnmapped)
{ {
@ -190,6 +191,8 @@ Foam::fvMeshSubset::interpolate
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
Foam::tmp Foam::tmp
< <
@ -213,6 +216,8 @@ Foam::fvMeshSubset::interpolate
} }
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Type> template<class Type>
Foam::tmp Foam::tmp
< <
@ -375,6 +380,8 @@ Foam::fvMeshSubset::interpolate
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
Foam::tmp Foam::tmp
< <
@ -397,6 +404,8 @@ Foam::fvMeshSubset::interpolate
} }
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Type> template<class Type>
Foam::tmp Foam::tmp
< <
@ -528,6 +537,8 @@ Foam::fvMeshSubset::interpolate
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
Foam::tmp Foam::tmp
< <
@ -549,6 +560,8 @@ Foam::fvMeshSubset::interpolate
} }
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Type> template<class Type>
Foam::tmp Foam::tmp
< <
@ -581,6 +594,8 @@ Foam::fvMeshSubset::interpolate
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
Foam::tmp Foam::tmp
< <

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -125,7 +125,7 @@ bool Foam::functionObjects::ensightWrite::updateSubset
} }
} }
subsetter.setCellSubset(cellsToSelect.addressing()); subsetter.reset(cellsToSelect.addressing());
return true; return true;
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -123,7 +123,7 @@ bool Foam::functionObjects::vtkWrite::updateSubset
} }
} }
subsetter.setCellSubset(cellsToSelect.addressing()); subsetter.reset(cellsToSelect.addressing());
return true; return true;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd. Copyright (C) 2017-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -242,7 +242,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChange::makeMesh
{ {
const polyBoundaryMesh& oldPatches = mesh.boundaryMesh(); const polyBoundaryMesh& oldPatches = mesh.boundaryMesh();
List<polyPatch*> newBoundary(patchMap.size()); polyPatchList newBoundary(patchMap.size());
forAll(patchMap, patchi) forAll(patchMap, patchi)
{ {
@ -250,25 +250,33 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChange::makeMesh
if (oldPatchi != -1) if (oldPatchi != -1)
{ {
newBoundary[patchi] = oldPatches[oldPatchi].clone newBoundary.set
( (
newMesh.boundaryMesh(),
patchi, patchi,
patchSizes[patchi], oldPatches[oldPatchi].clone
patchStarts[patchi] (
).ptr(); newMesh.boundaryMesh(),
patchi,
patchSizes[patchi],
patchStarts[patchi]
)
);
} }
else else
{ {
// Added patch // Added patch
newBoundary[patchi] = new emptyPolyPatch newBoundary.set
( (
"patch" + Foam::name(patchi),
patchSizes[patchi],
patchStarts[patchi],
patchi, patchi,
newMesh.boundaryMesh(), new emptyPolyPatch
word::null (
"patch" + Foam::name(patchi),
patchSizes[patchi],
patchStarts[patchi],
patchi,
newMesh.boundaryMesh(),
word::null
)
); );
} }
} }

View File

@ -1,10 +1,8 @@
EXE_INC = \ EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/parallel/decompose/decompositionMethods/lnInclude -I$(LIB_SRC)/parallel/decompose/decompositionMethods/lnInclude
LIB_LIBS = \ LIB_LIBS = \
-lmeshTools \ -lmeshTools \
-ldynamicMesh \
-ldecompositionMethods -ldecompositionMethods