From cf7dbf4d429185cb7570b3c2e87f3e999ae3e6f0 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 7 Apr 2022 11:25:57 +0200 Subject: [PATCH] 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) --- .../mesh/manipulation/subsetMesh/subsetMesh.C | 21 +- .../redistributePar/redistributePar.C | 5 +- src/dynamicMesh/Make/files | 3 +- .../fvMeshDistribute/fvMeshDistribute.C | 1 + .../fvMeshSubset/fvMeshSubsetter.C | 201 +++++++ .../fvMeshSubset/fvMeshSubsetter.H | 144 +++++ .../meshSubsetHelper.H | 0 .../polyTopoChange/removeCells.C | 15 +- .../polyTopoChange/removeCells.H | 16 +- src/dynamicMesh/zoneSubSet/zoneSubSet.C | 4 +- src/dynamicMesh/zoneSubSet/zoneSubSet.H | 4 +- src/finiteVolume/Make/files | 3 + src/finiteVolume/Make/options | 4 +- .../fvMesh}/fvMeshSubset/fvMeshSubset.C | 538 +++++++++--------- .../fvMesh}/fvMeshSubset/fvMeshSubset.H | 375 +++++------- .../fvMesh}/fvMeshSubset/fvMeshSubsetI.H | 22 +- .../fvMesh/fvMeshSubset}/fvMeshSubsetProxy.C | 2 +- .../fvMesh/fvMeshSubset}/fvMeshSubsetProxy.H | 6 +- .../fvMeshSubsetProxyTemplates.C | 0 .../fvMeshSubset/fvMeshSubsetTemplates.C} | 17 +- .../ensightWrite/ensightWriteUpdate.C | 4 +- .../utilities/vtkWrite/vtkWriteUpdate.C | 4 +- .../polyTopoChange/polyTopoChangeTemplates.C | 34 +- src/renumber/renumberMethods/Make/options | 2 - 24 files changed, 846 insertions(+), 579 deletions(-) create mode 100644 src/dynamicMesh/fvMeshSubset/fvMeshSubsetter.C create mode 100644 src/dynamicMesh/fvMeshSubset/fvMeshSubsetter.H rename src/dynamicMesh/{fvMeshSubsetProxy => fvMeshSubset}/meshSubsetHelper.H (100%) rename src/{dynamicMesh => finiteVolume/fvMesh}/fvMeshSubset/fvMeshSubset.C (82%) rename src/{dynamicMesh => finiteVolume/fvMesh}/fvMeshSubset/fvMeshSubset.H (59%) rename src/{dynamicMesh => finiteVolume/fvMesh}/fvMeshSubset/fvMeshSubsetI.H (87%) rename src/{dynamicMesh/fvMeshSubsetProxy => finiteVolume/fvMesh/fvMeshSubset}/fvMeshSubsetProxy.C (98%) rename src/{dynamicMesh/fvMeshSubsetProxy => finiteVolume/fvMesh/fvMeshSubset}/fvMeshSubsetProxy.H (99%) rename src/{dynamicMesh/fvMeshSubsetProxy => finiteVolume/fvMesh/fvMeshSubset}/fvMeshSubsetProxyTemplates.C (100%) rename src/{dynamicMesh/fvMeshSubset/fvMeshSubsetInterpolate.C => finiteVolume/fvMesh/fvMeshSubset/fvMeshSubsetTemplates.C} (96%) diff --git a/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C b/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C index d09c36f7a4..e808e56ec2 100644 --- a/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C +++ b/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License 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 "IOobjectList.H" #include "volFields.H" @@ -517,8 +517,8 @@ int main(int argc, char *argv[]) } - // Mesh subsetting engine - fvMeshSubset subsetter(mesh); + // Two-step mesh subsetting engine + fvMeshSubsetter subsetter(mesh); { bitSet selectedCells = @@ -530,13 +530,8 @@ int main(int argc, char *argv[]) if (exposedPatchIDs.size() == 1) { - // Single patch for exposed faces - subsetter.setCellSubset - ( - selectedCells, - exposedPatchIDs.first(), - true - ); + // Single patch for exposed faces (syncPar) + subsetter.reset(selectedCells, exposedPatchIDs.first(), true); } else { @@ -545,7 +540,7 @@ int main(int argc, char *argv[]) labelList exposedFaces ( - subsetter.getExposedFaces(selectedCells, true) + subsetter.getExposedFaces(selectedCells, true) // syncPar ); subsetter.setCellSubset @@ -553,7 +548,7 @@ int main(int argc, char *argv[]) selectedCells, exposedFaces, labelUIndList(nearestExposedPatch, exposedFaces)(), - true + true // syncPar ); } diff --git a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C index 788cfc4252..c12f538ffe 100644 --- a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C +++ b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C @@ -1031,10 +1031,7 @@ autoPtr redistributeAndWrite // Subset 0 cells, no parallel comms. // This is used to create zero-sized fields. - subsetterPtr.reset - ( - new fvMeshSubset(mesh, bitSet(), nonProcI, false) - ); + subsetterPtr.reset(new fvMeshSubset(mesh, zero{})); } diff --git a/src/dynamicMesh/Make/files b/src/dynamicMesh/Make/files index 8a51122298..aaabab8712 100644 --- a/src/dynamicMesh/Make/files +++ b/src/dynamicMesh/Make/files @@ -86,8 +86,7 @@ polyMeshAdder/polyMeshAdder.C fvMeshTools/fvMeshTools.C -fvMeshSubset/fvMeshSubset.C -fvMeshSubsetProxy/fvMeshSubsetProxy.C +fvMeshSubset/fvMeshSubsetter.C motionSmoother/motionSmoother.C motionSmoother/motionSmootherAlgo.C diff --git a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C index 69c6c08313..783971c731 100644 --- a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C +++ b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C @@ -28,6 +28,7 @@ License #include "fvMeshDistribute.H" #include "fvMeshAdder.H" +#include "fvMeshSubset.H" #include "faceCoupleInfo.H" #include "processorFvPatchField.H" #include "processorFvsPatchField.H" diff --git a/src/dynamicMesh/fvMeshSubset/fvMeshSubsetter.C b/src/dynamicMesh/fvMeshSubset/fvMeshSubsetter.C new file mode 100644 index 0000000000..0a98637c69 --- /dev/null +++ b/src/dynamicMesh/fvMeshSubset/fvMeshSubsetter.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#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 newMeshPtr; + autoPtr 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 + ); +} + + +// ************************************************************************* // diff --git a/src/dynamicMesh/fvMeshSubset/fvMeshSubsetter.H b/src/dynamicMesh/fvMeshSubset/fvMeshSubsetter.H new file mode 100644 index 0000000000..e4c34a6360 --- /dev/null +++ b/src/dynamicMesh/fvMeshSubset/fvMeshSubsetter.H @@ -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 . + +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 + +// ************************************************************************* // diff --git a/src/dynamicMesh/fvMeshSubsetProxy/meshSubsetHelper.H b/src/dynamicMesh/fvMeshSubset/meshSubsetHelper.H similarity index 100% rename from src/dynamicMesh/fvMeshSubsetProxy/meshSubsetHelper.H rename to src/dynamicMesh/fvMeshSubset/meshSubsetHelper.H diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/removeCells.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/removeCells.C index 10a2d14638..8be969216c 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/removeCells.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/removeCells.C @@ -71,20 +71,7 @@ inline void decrCount(const Foam::labelUList& list, Foam::labelList& counter) // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::removeCells::removeCells -( - const polyMesh& mesh -) -: - removeCells(mesh, true) -{} - - -Foam::removeCells::removeCells -( - const polyMesh& mesh, - const bool syncPar -) +Foam::removeCells::removeCells(const polyMesh& mesh, const bool syncPar) : mesh_(mesh), syncPar_(syncPar) diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/removeCells.H b/src/dynamicMesh/polyTopoChange/polyTopoChange/removeCells.H index e3d0ec431e..d3a3bb0cc2 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/removeCells.H +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/removeCells.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,8 +40,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef removeCells_H -#define removeCells_H +#ifndef Foam_removeCells_H +#define Foam_removeCells_H #include "labelList.H" #include "typeInfo.H" @@ -63,7 +63,7 @@ class mapPolyMesh; class removeCells { - // Private data + // Private Data //- Reference to mesh const polyMesh& mesh_; @@ -71,6 +71,7 @@ class removeCells //- Whether or not to synchronize parallel case. const bool syncPar_; + public: //- Runtime type information @@ -79,11 +80,8 @@ public: // Constructors - //- Construct from mesh. With parallel synchronization. - explicit removeCells(const polyMesh& mesh); - - //- Construct from mesh, optionally with parallel synchronization. - removeCells(const polyMesh& mesh, const bool syncPar); + //- Construct from mesh. Parallel synchronized by default + explicit removeCells(const polyMesh& mesh, const bool syncPar = true); //- Destructor diff --git a/src/dynamicMesh/zoneSubSet/zoneSubSet.C b/src/dynamicMesh/zoneSubSet/zoneSubSet.C index 34b60e6c2d..2aaa14fea6 100644 --- a/src/dynamicMesh/zoneSubSet/zoneSubSet.C +++ b/src/dynamicMesh/zoneSubSet/zoneSubSet.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -95,7 +95,7 @@ bool Foam::Detail::zoneSubSet::correct() << endl; } - subsetter_.setCellSubset(selectedCells.addressing()); + subsetter_.reset(selectedCells.addressing()); return true; } diff --git a/src/dynamicMesh/zoneSubSet/zoneSubSet.H b/src/dynamicMesh/zoneSubSet/zoneSubSet.H index 6a87af2025..438fd85df7 100644 --- a/src/dynamicMesh/zoneSubSet/zoneSubSet.H +++ b/src/dynamicMesh/zoneSubSet/zoneSubSet.H @@ -62,8 +62,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef zoneSubSet_H -#define zoneSubSet_H +#ifndef Foam_zoneSubSet_H +#define Foam_zoneSubSet_H #include "fvMeshSubset.H" diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index 93d591a892..a27e5e4be2 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -12,6 +12,9 @@ $(fvGeometryScheme)/stabilised/stabilisedFvGeometryScheme.C surfaceInterpolation = interpolation/surfaceInterpolation $(surfaceInterpolation)/surfaceInterpolation/surfaceInterpolation.C +fvMesh/fvMeshSubset/fvMeshSubset.C +fvMesh/fvMeshSubset/fvMeshSubsetProxy.C + fvMesh/singleCellFvMesh/singleCellFvMesh.C fvMesh/simplifiedFvMesh/simplifiedFvMesh/simplifiedFvMesh.C diff --git a/src/finiteVolume/Make/options b/src/finiteVolume/Make/options index 0927690c0d..851f94b6b3 100644 --- a/src/finiteVolume/Make/options +++ b/src/finiteVolume/Make/options @@ -1,12 +1,10 @@ EXE_INC = \ -I$(LIB_SRC)/fileFormats/lnInclude \ -I$(LIB_SRC)/surfMesh/lnInclude \ - -I$(LIB_SRC)/meshTools/lnInclude \ - -I$(LIB_SRC)/dynamicMesh/lnInclude + -I$(LIB_SRC)/meshTools/lnInclude LIB_LIBS = \ -lOpenFOAM \ -lfileFormats \ -lsurfMesh \ -lmeshTools - diff --git a/src/dynamicMesh/fvMeshSubset/fvMeshSubset.C b/src/finiteVolume/fvMesh/fvMeshSubset/fvMeshSubset.C similarity index 82% rename from src/dynamicMesh/fvMeshSubset/fvMeshSubset.C rename to src/finiteVolume/fvMesh/fvMeshSubset/fvMeshSubset.C index a60e205521..2466022c82 100644 --- a/src/dynamicMesh/fvMeshSubset/fvMeshSubset.C +++ b/src/finiteVolume/fvMesh/fvMeshSubset/fvMeshSubset.C @@ -27,15 +27,15 @@ License \*---------------------------------------------------------------------------*/ #include "fvMeshSubset.H" -#include "boolList.H" #include "BitOps.H" -#include "pointIndList.H" #include "Pstream.H" -#include "emptyPolyPatch.H" #include "cyclicPolyPatch.H" -#include "removeCells.H" -#include "polyTopoChange.H" -#include "mapPolyMesh.H" +#include "emptyPolyPatch.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +Foam::word Foam::fvMeshSubset::exposedPatchName("oldInternalFaces"); + // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // @@ -58,20 +58,63 @@ inline void markUsed } // End anonymous namespace -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -Foam::word Foam::fvMeshSubset::exposedPatchName("oldInternalFaces"); - - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -bool Foam::fvMeshSubset::checkCellSubset() const +namespace Foam { - 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 - << "setCellSubset()" << nl - << "before attempting to access subset data" + << "Mesh is not subsetted!" << nl << abort(FatalError); return false; @@ -118,7 +161,7 @@ void Foam::fvMeshSubset::calcFaceFlipMap() const void Foam::fvMeshSubset::doCoupledPatches ( const bool syncPar, - labelList& nCellsUsingFace + labelUList& nCellsUsingFace ) const { // Synchronize facesToSubset on both sides of coupled patches. @@ -186,8 +229,8 @@ void Foam::fvMeshSubset::doCoupledPatches && nbrCellsUsingFace[i] == 0 ) { - // Face's neighbour is no longer there. Mark face - // off as coupled + // Face's neighbour is no longer there. + // Mark face off as coupled nCellsUsingFace[pp.start()+i] = 3; ++nUncoupled; } @@ -229,7 +272,7 @@ void Foam::fvMeshSubset::doCoupledPatches reduce(nUncoupled, sumOp