diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C index e5ba7cf781f88ae194f3414ae1260920f23a16c6..cb5965df22290e277122b5b90631eead27f0ea78 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.C @@ -285,6 +285,12 @@ bool Foam::objectRegistry::checkOut(regIOobject& io) const } +bool Foam::objectRegistry::checkOut(const word& key) const +{ + return const_cast<objectRegistry&>(*this).erase(key); +} + + void Foam::objectRegistry::clear() { // Free anything owned by the registry diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H index af6c0a3450ccd690b01efd4371c568ecb2166900..1bb7248212218dd0acd26a9b35d511f6b12199ef 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.H @@ -438,6 +438,10 @@ public: //- object is ownedByRegistry bool checkOut(regIOobject& io) const; + //- Remove a regIOobject by name from registry and frees memory if the + //- object is ownedByRegistry + bool checkOut(const word& key) const; + //- Clear all entries from the registry // Performs a checkOut() for all objects that are ownedByRegistry void clear(); diff --git a/src/functionObjects/field/fieldAverage/fieldAverageItem/fieldAverageItem.C b/src/functionObjects/field/fieldAverage/fieldAverageItem/fieldAverageItem.C index 8ac5a9dafec1bd8afb8cd446ca76552f75fc1c78..7864b12bbbfa37a5358b6b87a2c35c0a61c06953 100644 --- a/src/functionObjects/field/fieldAverage/fieldAverageItem/fieldAverageItem.C +++ b/src/functionObjects/field/fieldAverage/fieldAverageItem/fieldAverageItem.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2009-2011, 2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2011, 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -152,7 +152,7 @@ void Foam::functionObjects::fieldAverageItem::evolve(const objectRegistry& obr) const word fieldName = windowFieldNames_.pop(); //Info<< "evolve: removing field: " << fieldName << endl; - obr.checkOut(*obr[fieldName]); + obr.checkOut(fieldName); } } } @@ -164,22 +164,19 @@ void Foam::functionObjects::fieldAverageItem::clear bool fullClean ) { - if (mean_ && obr.found(meanFieldName_)) + if (mean_) { - obr.checkOut(*obr[meanFieldName_]); + obr.checkOut(meanFieldName_); } - if (prime2Mean_ && obr.found(prime2MeanFieldName_)) + if (prime2Mean_) { - obr.checkOut(*obr[prime2MeanFieldName_]); + obr.checkOut(prime2MeanFieldName_); } for (const word& fieldName : windowFieldNames_) { - if (obr.found(fieldName)) - { - obr.checkOut(*obr[fieldName]); - } + obr.checkOut(fieldName); } if (totalTime_ < 0 || fullClean) diff --git a/src/functionObjects/field/momentum/momentum.C b/src/functionObjects/field/momentum/momentum.C index 342b46eb9783b94b06c32d96c4a40e98b4e6b791..260253bf00b563f985b822aec58651f24d351226 100644 --- a/src/functionObjects/field/momentum/momentum.C +++ b/src/functionObjects/field/momentum/momentum.C @@ -46,11 +46,9 @@ namespace functionObjects void Foam::functionObjects::momentum::purgeFields() { - objectRegistry& obr = const_cast<objectRegistry&>(obr_); - - obr.erase(scopedName("momentum")); - obr.erase(scopedName("angularMomentum")); - obr.erase(scopedName("angularVelocity")); + obr_.checkOut(scopedName("momentum")); + obr_.checkOut(scopedName("angularMomentum")); + obr_.checkOut(scopedName("angularVelocity")); } diff --git a/src/sampling/surfMeshSample/surfMeshSamplers/surfMeshSamplers.C b/src/sampling/surfMeshSample/surfMeshSamplers/surfMeshSamplers.C index 5cf3391d5da5b743694829056fcbfb063c93cfaa..42cc4509b680f78c1ad8bdc3da7b8b431a73c680 100644 --- a/src/sampling/surfMeshSample/surfMeshSamplers/surfMeshSamplers.C +++ b/src/sampling/surfMeshSample/surfMeshSamplers/surfMeshSamplers.C @@ -49,24 +49,6 @@ namespace Foam bool Foam::surfMeshSamplers::verbose_ = false; -void Foam::surfMeshSamplers::checkOutNames -( - const objectRegistry& registry, - const UList<word>& names -) -{ - objectRegistry& reg = const_cast<objectRegistry&>(registry); - - for (const word& fldName : names) - { - objectRegistry::iterator iter = reg.find(fldName); - if (iter.found()) - { - registry.checkOut(*iter()); - } - } -} - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -297,7 +279,11 @@ bool Foam::surfMeshSamplers::execute() } } - checkOutNames(db, cleanup); + // Cleanup any locally introduced names + for (const word& fieldName : cleanup) + { + db.checkOut(fieldName); + } return true; } diff --git a/src/sampling/surfMeshSample/surfMeshSamplers/surfMeshSamplers.H b/src/sampling/surfMeshSample/surfMeshSamplers/surfMeshSamplers.H index 19cd1bb8fa46e1fd8e3060420409c5038d1f6467..ecd729dabee8230eba8ba4b20326a2b0ea85432c 100644 --- a/src/sampling/surfMeshSample/surfMeshSamplers/surfMeshSamplers.H +++ b/src/sampling/surfMeshSample/surfMeshSamplers/surfMeshSamplers.H @@ -157,14 +157,6 @@ class surfMeshSamplers // Private Member Functions - //- Remove items by name from objectRegistry - static void checkOutNames - ( - const objectRegistry& registry, - const UList<word>& names - ); - - //- Hard-coded derived field (rho * U) // \return true if field did not previously exist bool add_rhoU(const word& derivedName); diff --git a/src/thermophysicalModels/basic/basicThermo/basicThermo.C b/src/thermophysicalModels/basic/basicThermo/basicThermo.C index dd4909dfd48e1a66dc1181034b00d332f22650e9..88341dc0bb16c0f6a8f19f2d38173c2cb5cc4174 100644 --- a/src/thermophysicalModels/basic/basicThermo/basicThermo.C +++ b/src/thermophysicalModels/basic/basicThermo/basicThermo.C @@ -160,15 +160,6 @@ Foam::volScalarField& Foam::basicThermo::lookupOrConstruct } -void Foam::basicThermo::lookupAndCheckout(const char* name) const -{ - if (db().foundObject<volScalarField>(name)) - { - db().checkOut(*db()[name]); - } -} - - Foam::basicThermo::basicThermo ( const fvMesh& mesh, @@ -326,7 +317,7 @@ Foam::autoPtr<Foam::basicThermo> Foam::basicThermo::New Foam::basicThermo::~basicThermo() { - lookupAndCheckout("p"); + db().checkOut("p"); } diff --git a/src/thermophysicalModels/basic/basicThermo/basicThermo.H b/src/thermophysicalModels/basic/basicThermo/basicThermo.H index bb98338380ebde498a9fbdc88a12cfc960653603..337373c685bdff2ff4dfbf4e7dcfab3e75b23731 100644 --- a/src/thermophysicalModels/basic/basicThermo/basicThermo.H +++ b/src/thermophysicalModels/basic/basicThermo/basicThermo.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010, 2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2010, 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2017 OpenFOAM Foundation @@ -105,9 +105,6 @@ protected: bool& isOwner ); - //- Lookup and check out field - void lookupAndCheckout(const char* name) const; - //- Return the enthalpy/internal energy field boundary types // by interrogating the temperature field boundary types wordList heBoundaryTypes();