objectRegistry functionality
While attempting to use the subRegistry functionality to add extra information onto the mesh obr, I noticed some odd behaviour. Delving into the code, it seems to be related to how the lookupObject works. It implicitly includes a upwards recursion into the parent registry, only stopping when it hits Time. This means that adding subRegistry2("name=abc") to subRegistry1 will fail if the parent of subRegistry1 already contained an objectRegistry with the name "abc". Test-objectRegistry.C
I think we need to make this recursion an optional parameter (default = true for compatibility) to at least a few methods. It would also be a nice time to add this, for symmetry with dictionary lookupEntryPtr:
//- Lookup and return pointer to the object of the given Type,
// return nullptr if the object was not found or had the incorrect type
template<class Type>
const Type* lookupObjectPtr(const word& name, bool recursive=true) const;
//- Lookup and return the object of the given Type,
// return nullptr if the object was not found or had the incorrect type
template<class Type>
Type* lookupObjectPtr(const word& name, bool recursive=true) const;
Then use like this:
volScalarField* fieldPtr = mesh().lookupObjectPtr<volScalarField>("foo");
if (fieldPtr)
{
volScalarField& fld = *fieldPtr;
...
}
Instead of
if (mesh().foundObject<volScalarField>("foo"))
{
volScalarField& fld = const_cast<volScalarField&>(mesh().lookupObject<volScalarField>("foo"));
...
}