diff --git a/applications/utilities/preProcessing/createExternalCoupledPatchGeometry/Make/options b/applications/utilities/preProcessing/createExternalCoupledPatchGeometry/Make/options index 3c22d1310b..2a75a610c1 100644 --- a/applications/utilities/preProcessing/createExternalCoupledPatchGeometry/Make/options +++ b/applications/utilities/preProcessing/createExternalCoupledPatchGeometry/Make/options @@ -6,4 +6,5 @@ EXE_INC = \ EXE_LIBS = \ -lfiniteVolume \ -lmeshTools \ + -ldynamicMesh \ -lfieldFunctionObjects diff --git a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H index d9fed7b56b..061b2300a7 100644 --- a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H +++ b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -74,7 +74,6 @@ class regionFunctionObject : public stateFunctionObject { - protected: // Protected Member Data @@ -147,6 +146,15 @@ protected: bool cacheable = false ); + //- Store the field in an optional objectRegistry under the given name + template + bool storeInDb + ( + const word& fieldName, + const tmp& tfield, + const objectRegistry& obr + ); + //- Write field if present in the (sub) objectRegistry bool writeObject(const word& fieldName); diff --git a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObjectTemplates.C b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObjectTemplates.C index f253d83e05..c1c0f740b6 100644 --- a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObjectTemplates.C +++ b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObjectTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016 OpenFOAM Foundation - Copyright (C) 2016-2018 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -122,16 +122,20 @@ bool Foam::functionObjects::regionFunctionObject::store return false; } - if (fieldName.size() && foundObject(fieldName)) - { - const ObjectType& field = lookupObject(fieldName); + ObjectType* fieldptr; + if + ( + !fieldName.empty() + && (fieldptr = getObjectPtr(fieldName)) != nullptr + ) + { // If there is a result field already registered, assign to the new // result field. Otherwise transfer ownership of the new result field to // the object registry - if (&field != &tfield()) + if (fieldptr != &tfield()) { - const_cast(field) = tfield; + (*fieldptr) = tfield; } else { @@ -156,4 +160,31 @@ bool Foam::functionObjects::regionFunctionObject::store } +template +bool Foam::functionObjects::regionFunctionObject::storeInDb +( + const word& fieldName, + const tmp& tfield, + const objectRegistry& obr +) +{ + ObjectType* fieldptr; + if + ( + !fieldName.empty() + && (fieldptr = obr.getObjectPtr(fieldName)) != nullptr + ) + { + (*fieldptr) = tfield; + } + else + { + tfield.ref().rename(fieldName); + obr.objectRegistry::store(tfield.ptr()); + } + + return true; +} + + // ************************************************************************* // diff --git a/src/dynamicMesh/Make/files b/src/dynamicMesh/Make/files index 08723a0583..eedcd7fe8c 100644 --- a/src/dynamicMesh/Make/files +++ b/src/dynamicMesh/Make/files @@ -138,4 +138,6 @@ polyMeshFilter/polyMeshFilter.C pointPatchDist/externalPointEdgePoint.C pointPatchDist/pointPatchDist.C +zoneSubSet/zoneSubSet.C + LIB = $(FOAM_LIBBIN)/libdynamicMesh diff --git a/src/dynamicMesh/zoneSubSet/zoneSubSet.C b/src/dynamicMesh/zoneSubSet/zoneSubSet.C new file mode 100644 index 0000000000..34b60e6c2d --- /dev/null +++ b/src/dynamicMesh/zoneSubSet/zoneSubSet.C @@ -0,0 +1,139 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2021 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 "zoneSubSet.H" +#include "cellBitSet.H" +#include "haloToCell.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace Detail +{ + defineTypeNameAndDebug(zoneSubSet, 0); +} +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::Detail::zoneSubSet::correct() +{ + subsetter_.clear(); + haloCells_.clearStorage(); + + if (zoneMatcher_.empty()) + { + return false; + } + + // Select named zones + cellBitSet selectedCells + ( + subsetter_.baseMesh(), + subsetter_.baseMesh().cellZones().selection(zoneMatcher_) + ); + + if (debug) + { + Pout<< "Subsetting " + << selectedCells.addressing().count() + << " cells based on cellZones " + << flatOutput(zoneMatcher_) << endl; + } + + if (nLayers_ > 0) + { + // Add halo layer(s) + haloToCell haloSource(subsetter_.baseMesh(), nLayers_); + haloSource.verbose(false); + + // Before adding halo cells + haloCells_ = selectedCells.addressing(); + + haloSource.applyToSet(topoSetSource::ADD, selectedCells); + + // Halo cells: anything new, not in the original set + haloCells_ ^= selectedCells.addressing(); + } + + if (debug) + { + const label nHalo = haloCells_.count(); + const label nSubCell = selectedCells.addressing().count(); + + Info<< " overall " + << returnReduce(nSubCell, sumOp