Merge branch 'feature-object-registry-search' into 'develop'

Feature object registry search

See merge request Development/OpenFOAM-plus!232
This commit is contained in:
Mark Olesen
2019-02-07 08:59:07 +00:00
committed by Andrew Heather
11 changed files with 148 additions and 83 deletions

View File

@ -1,2 +1,2 @@
api=1812 api=1901
patch=190129 patch=0

View File

@ -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() void Foam::objectRegistry::clear()
{ {
// Free anything owned by the registry // Free anything owned by the registry
@ -367,6 +373,67 @@ void Foam::objectRegistry::rename(const word& newName)
} }
bool Foam::objectRegistry::found
(
const word& name,
const bool recursive
) const
{
return cfindIOobject(name, recursive);
}
const Foam::regIOobject* Foam::objectRegistry::cfindIOobject
(
const word& name,
const bool recursive
) const
{
const_iterator iter = cfind(name);
if (iter.found())
{
return iter.val();
}
else if (recursive && this->parentNotTime())
{
return parent_.cfindIOobject(name, recursive);
}
return nullptr;
}
const Foam::regIOobject* Foam::objectRegistry::findIOobject
(
const word& name,
const bool recursive
) const
{
return cfindIOobject(name, recursive);
}
Foam::regIOobject* Foam::objectRegistry::findIOobject
(
const word& name,
const bool recursive
)
{
return const_cast<regIOobject*>(cfindIOobject(name, recursive));
}
Foam::regIOobject* Foam::objectRegistry::getIOobjectPtr
(
const word& name,
const bool recursive
) const
{
return const_cast<regIOobject*>(cfindIOobject(name, recursive));
}
bool Foam::objectRegistry::modified() const bool Foam::objectRegistry::modified() const
{ {
for (const_iterator iter = cbegin(); iter != cend(); ++iter) for (const_iterator iter = cbegin(); iter != cend(); ++iter)

View File

@ -340,6 +340,59 @@ public:
template<class Type> template<class Type>
HashTable<Type*> lookupClass(const bool strict = false); HashTable<Type*> lookupClass(const bool strict = false);
//- Can the regIOobject object be found (by name).
//
// \param recursive search parent registries
bool found(const word& name, const bool recursive = false) const;
//- Return const pointer to the regIOobject.
//
// \param recursive search parent registries
//
// \return nullptr if the object was not found.
const regIOobject* cfindIOobject
(
const word& name,
const bool recursive = false
) const;
//- Return const pointer to the regIOobject.
//
// \param recursive search parent registries
//
// \return nullptr if the object was not found.
const regIOobject* findIOobject
(
const word& name,
const bool recursive = false
) const;
//- Return non-const pointer to the regIOobject.
//
// \param recursive search parent registries
//
// \return nullptr if the object was not found.
regIOobject* findIOobject
(
const word& name,
const bool recursive = false
);
//- Return non-const pointer to the regIOobject,
//- using a const-cast to have it behave like a mutable.
// Exercise caution when using.
//
// \param recursive search parent registries.
//
// \return nullptr if the object was not found.
regIOobject* getIOobjectPtr
(
const word& name,
const bool recursive = false
) const;
//- Is the named Type found? //- Is the named Type found?
// //
// \param recursive search parent registries // \param recursive search parent registries
@ -438,6 +491,10 @@ public:
//- object is ownedByRegistry //- object is ownedByRegistry
bool checkOut(regIOobject& io) const; 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 //- Clear all entries from the registry
// Performs a checkOut() for all objects that are ownedByRegistry // Performs a checkOut() for all objects that are ownedByRegistry
void clear(); void clear();

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2015 OpenFOAM Foundation | Copyright (C) 2011-2015 OpenFOAM Foundation
@ -391,23 +391,7 @@ const Type* Foam::objectRegistry::cfindObject
const bool recursive const bool recursive
) const ) const
{ {
const_iterator iter = cfind(name); return dynamic_cast<const Type*>(this->cfindIOobject(name, recursive));
if (iter.found())
{
const Type* ptr = dynamic_cast<const Type*>(iter());
if (ptr)
{
return ptr;
}
}
else if (recursive && this->parentNotTime())
{
return parent_.cfindObject<Type>(name, recursive);
}
return nullptr;
} }
@ -429,9 +413,7 @@ Type* Foam::objectRegistry::findObject
const bool recursive const bool recursive
) )
{ {
const Type* ptr = this->cfindObject<Type>(name, recursive); return const_cast<Type*>(this->cfindObject<Type>(name, recursive));
return const_cast<Type*>(ptr);
} }
@ -442,9 +424,7 @@ Type* Foam::objectRegistry::getObjectPtr
const bool recursive const bool recursive
) const ) const
{ {
const Type* ptr = this->cfindObject<Type>(name, recursive); return const_cast<Type*>(this->cfindObject<Type>(name, recursive));
return const_cast<Type*>(ptr);
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2009-2011, 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -152,7 +152,7 @@ void Foam::functionObjects::fieldAverageItem::evolve(const objectRegistry& obr)
const word fieldName = windowFieldNames_.pop(); const word fieldName = windowFieldNames_.pop();
//Info<< "evolve: removing field: " << fieldName << endl; //Info<< "evolve: removing field: " << fieldName << endl;
obr.checkOut(*obr[fieldName]); obr.checkOut(fieldName);
} }
} }
} }
@ -164,22 +164,19 @@ void Foam::functionObjects::fieldAverageItem::clear
bool fullClean 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_) for (const word& fieldName : windowFieldNames_)
{ {
if (obr.found(fieldName)) obr.checkOut(fieldName);
{
obr.checkOut(*obr[fieldName]);
}
} }
if (totalTime_ < 0 || fullClean) if (totalTime_ < 0 || fullClean)

View File

@ -46,11 +46,9 @@ namespace functionObjects
void Foam::functionObjects::momentum::purgeFields() void Foam::functionObjects::momentum::purgeFields()
{ {
objectRegistry& obr = const_cast<objectRegistry&>(obr_); obr_.checkOut(scopedName("momentum"));
obr_.checkOut(scopedName("angularMomentum"));
obr.erase(scopedName("momentum")); obr_.checkOut(scopedName("angularVelocity"));
obr.erase(scopedName("angularMomentum"));
obr.erase(scopedName("angularVelocity"));
} }

View File

@ -49,24 +49,6 @@ namespace Foam
bool Foam::surfMeshSamplers::verbose_ = false; 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 * * * * * * * * * * * // // * * * * * * * * * * * * * 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; return true;
} }

View File

@ -157,14 +157,6 @@ class surfMeshSamplers
// Private Member Functions // 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) //- Hard-coded derived field (rho * U)
// \return true if field did not previously exist // \return true if field did not previously exist
bool add_rhoU(const word& derivedName); bool add_rhoU(const word& derivedName);

View File

@ -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 Foam::basicThermo::basicThermo
( (
const fvMesh& mesh, const fvMesh& mesh,
@ -326,7 +317,7 @@ Foam::autoPtr<Foam::basicThermo> Foam::basicThermo::New
Foam::basicThermo::~basicThermo() Foam::basicThermo::~basicThermo()
{ {
lookupAndCheckout("p"); db().checkOut("p");
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2010, 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation | Copyright (C) 2011-2017 OpenFOAM Foundation
@ -105,9 +105,6 @@ protected:
bool& isOwner bool& isOwner
); );
//- Lookup and check out field
void lookupAndCheckout(const char* name) const;
//- Return the enthalpy/internal energy field boundary types //- Return the enthalpy/internal energy field boundary types
// by interrogating the temperature field boundary types // by interrogating the temperature field boundary types
wordList heBoundaryTypes(); wordList heBoundaryTypes();

View File

@ -1,5 +1,5 @@
#-------------------------------*- makefile -*--------------------------------- #-------------------------------*- makefile -*---------------------------------
WM_VERSION = OPENFOAM=1812 WM_VERSION = OPENFOAM=1901
AR = ar AR = ar
ARFLAGS = cr ARFLAGS = cr