diff --git a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.C b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.C index 2a24995c34..43627cd4f2 100644 --- a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.C +++ b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.C @@ -95,6 +95,39 @@ bool Foam::functionObjects::stateFunctionObject::foundProperty } +bool Foam::functionObjects::stateFunctionObject::getDict +( + const word& entryName, + dictionary& dict +) const +{ + return getObjectDict(name(), entryName, dict); +} + + +bool Foam::functionObjects::stateFunctionObject::getObjectDict +( + const word& objectName, + const word& entryName, + dictionary& dict +) const +{ + const IOdictionary& stateDict = this->stateDict(); + + if (stateDict.found(objectName)) + { + const dictionary& baseDict = stateDict.subDict(objectName); + if (baseDict.found(entryName) && baseDict.isDict(entryName)) + { + dict = baseDict.subDict(entryName); + return true; + } + } + + return false; +} + + Foam::word Foam::functionObjects::stateFunctionObject::resultType ( const word& entryName diff --git a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.H b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.H index 20a5c66919..09cd289b9e 100644 --- a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.H +++ b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.H @@ -125,6 +125,21 @@ public: //- Return true if the property exists bool foundProperty(const word& entryName) const; + //- Set dictionary, return true if set + bool getDict + ( + const word& entryName, + dictionary& dict + ) const; + + //- Set dictionary from named object, return true if set + bool getObjectDict + ( + const word& objectName, + const word& entryName, + dictionary& dict + ) const; + //- Retrieve generic property template Type getProperty @@ -133,9 +148,9 @@ public: const Type& defaultValue = Type(Zero) ) const; - //- Retrieve generic property + //- Set generic property, return true if set template - void getProperty(const word& entryName, Type& value) const; + bool getProperty(const word& entryName, Type& value) const; //- Add generic property template @@ -150,9 +165,9 @@ public: const Type& defaultValue = Type(Zero) ) const; - //- Retrieve generic property from named object + //- Set generic property from named object, return true if set template - void getObjectProperty + bool getObjectProperty ( const word& objectName, const word& entryName, @@ -205,9 +220,9 @@ public: const Type& defaultValue = Type(Zero) ) const; - //- Retrieve result from named object + //- Set result from named object, return true if set template - void getObjectResult + bool getObjectResult ( const word& objectName, const word& entryName, diff --git a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObjectTemplates.C b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObjectTemplates.C index 35184d3eca..cf8efceac8 100644 --- a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObjectTemplates.C +++ b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObjectTemplates.C @@ -41,13 +41,13 @@ Type Foam::functionObjects::stateFunctionObject::getProperty template -void Foam::functionObjects::stateFunctionObject::getProperty +bool Foam::functionObjects::stateFunctionObject::getProperty ( const word& entryName, Type& value ) const { - getObjectProperty(name(), entryName, value); + return getObjectProperty(name(), entryName, value); } @@ -77,7 +77,7 @@ Type Foam::functionObjects::stateFunctionObject::getObjectProperty template -void Foam::functionObjects::stateFunctionObject::getObjectProperty +bool Foam::functionObjects::stateFunctionObject::getObjectProperty ( const word& objectName, const word& entryName, @@ -89,18 +89,10 @@ void Foam::functionObjects::stateFunctionObject::getObjectProperty if (stateDict.found(objectName)) { const dictionary& baseDict = stateDict.subDict(objectName); - if (baseDict.found(entryName)) - { - if (baseDict.isDict(entryName)) - { - value = baseDict.subDict(entryName); - } - else - { - baseDict.lookup(entryName) >> value; - } - } + return baseDict.readIfPresent(entryName, value); } + + return false; } @@ -192,13 +184,13 @@ Type Foam::functionObjects::stateFunctionObject::getObjectResult ) const { Type result = defaultValue; - getObjectResult(objectName, entryName, result); + (void)getObjectResult(objectName, entryName, result); return result; } template -void Foam::functionObjects::stateFunctionObject::getObjectResult +bool Foam::functionObjects::stateFunctionObject::getObjectResult ( const word& objectName, const word& entryName, @@ -222,10 +214,12 @@ void Foam::functionObjects::stateFunctionObject::getObjectResult const dictionary& resultTypeDict = objectDict.subDict(dictTypeName); - resultTypeDict.readIfPresent(entryName, value); + return resultTypeDict.readIfPresent(entryName, value); } } } + + return false; }