mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Refactored stateFunctionObject
- created new functionObjects::properties class derived from IOdictionary - replaces raw state IOdictionary owned by functionObjectList - state dictionary access/manipulators moved from stateFunctionObject - stateFunctionObject now acts as a light wrapper around functionObjecties::properties - updated dependent code
This commit is contained in:
committed by
Mark Olesen
parent
b19e767b8f
commit
aeef96251f
@ -354,6 +354,7 @@ $(dll)/codedBase/codedBase.C
|
|||||||
funcObjs = db/functionObjects
|
funcObjs = db/functionObjects
|
||||||
|
|
||||||
$(funcObjs)/functionObject/functionObject.C
|
$(funcObjs)/functionObject/functionObject.C
|
||||||
|
$(funcObjs)/functionObjectProperties/functionObjectProperties.C
|
||||||
$(funcObjs)/functionObjectList/functionObjectList.C
|
$(funcObjs)/functionObjectList/functionObjectList.C
|
||||||
$(funcObjs)/stateFunctionObject/stateFunctionObject.C
|
$(funcObjs)/stateFunctionObject/stateFunctionObject.C
|
||||||
$(funcObjs)/timeFunctionObject/timeFunctionObject.C
|
$(funcObjs)/timeFunctionObject/timeFunctionObject.C
|
||||||
|
|||||||
@ -97,13 +97,13 @@ namespace Foam
|
|||||||
|
|
||||||
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
|
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::functionObjectList::createStateDict() const
|
void Foam::functionObjectList::createPropertiesDict() const
|
||||||
{
|
{
|
||||||
// Cannot set the state dictionary on construction since Time has not
|
// Cannot set the properties dictionary on construction since Time has not
|
||||||
// been fully initialised
|
// been fully initialised
|
||||||
stateDictPtr_.reset
|
propsDictPtr_.reset
|
||||||
(
|
(
|
||||||
new IOdictionary
|
new functionObjects::properties
|
||||||
(
|
(
|
||||||
IOobject
|
IOobject
|
||||||
(
|
(
|
||||||
@ -412,7 +412,7 @@ Foam::functionObjectList::functionObjectList
|
|||||||
warnings_(),
|
warnings_(),
|
||||||
time_(runTime),
|
time_(runTime),
|
||||||
parentDict_(parentDict),
|
parentDict_(parentDict),
|
||||||
stateDictPtr_(nullptr),
|
propsDictPtr_(nullptr),
|
||||||
objectsRegistryPtr_(nullptr),
|
objectsRegistryPtr_(nullptr),
|
||||||
execution_(execution),
|
execution_(execution),
|
||||||
updated_(false)
|
updated_(false)
|
||||||
@ -509,37 +509,38 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New
|
|||||||
|
|
||||||
Foam::label Foam::functionObjectList::triggerIndex() const
|
Foam::label Foam::functionObjectList::triggerIndex() const
|
||||||
{
|
{
|
||||||
return stateDict().getOrDefault<label>("triggerIndex", labelMin);
|
return propsDict().getOrDefault<label>("triggerIndex", labelMin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::functionObjectList::resetState()
|
void Foam::functionObjectList::resetPropertiesDict()
|
||||||
{
|
{
|
||||||
// Reset (re-read) the state dictionary
|
// Reset (re-read) the properties dictionary
|
||||||
stateDictPtr_.reset(nullptr);
|
propsDictPtr_.reset(nullptr);
|
||||||
createStateDict();
|
createPropertiesDict();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::IOdictionary& Foam::functionObjectList::stateDict()
|
Foam::functionObjects::properties& Foam::functionObjectList::propsDict()
|
||||||
{
|
{
|
||||||
if (!stateDictPtr_)
|
if (!propsDictPtr_)
|
||||||
{
|
{
|
||||||
createStateDict();
|
createPropertiesDict();
|
||||||
}
|
}
|
||||||
|
|
||||||
return *stateDictPtr_;
|
return *propsDictPtr_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const Foam::IOdictionary& Foam::functionObjectList::stateDict() const
|
const Foam::functionObjects::properties&
|
||||||
|
Foam::functionObjectList::propsDict() const
|
||||||
{
|
{
|
||||||
if (!stateDictPtr_)
|
if (!propsDictPtr_)
|
||||||
{
|
{
|
||||||
createStateDict();
|
createPropertiesDict();
|
||||||
}
|
}
|
||||||
|
|
||||||
return *stateDictPtr_;
|
return *propsDictPtr_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -768,13 +769,13 @@ bool Foam::functionObjectList::execute()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force writing of state dictionary after function object execution
|
// Force writing of properties dictionary after function object execution
|
||||||
if (time_.writeTime())
|
if (time_.writeTime())
|
||||||
{
|
{
|
||||||
const auto oldPrecision = IOstream::precision_;
|
const auto oldPrecision = IOstream::precision_;
|
||||||
IOstream::precision_ = 16;
|
IOstream::precision_ = 16;
|
||||||
|
|
||||||
stateDictPtr_->writeObject
|
propsDictPtr_->writeObject
|
||||||
(
|
(
|
||||||
IOstreamOption(IOstream::ASCII, time_.writeCompression()),
|
IOstreamOption(IOstream::ASCII, time_.writeCompression()),
|
||||||
true
|
true
|
||||||
@ -930,9 +931,9 @@ bool Foam::functionObjectList::adjustTimeStep()
|
|||||||
|
|
||||||
bool Foam::functionObjectList::read()
|
bool Foam::functionObjectList::read()
|
||||||
{
|
{
|
||||||
if (!stateDictPtr_)
|
if (!propsDictPtr_)
|
||||||
{
|
{
|
||||||
createStateDict();
|
createPropertiesDict();
|
||||||
}
|
}
|
||||||
|
|
||||||
updated_ = execution_;
|
updated_ = execution_;
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2020 OpenCFD Ltd.
|
Copyright (C) 2015-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -87,6 +87,7 @@ SourceFiles
|
|||||||
#include "HashTable.H"
|
#include "HashTable.H"
|
||||||
#include "IOdictionary.H"
|
#include "IOdictionary.H"
|
||||||
#include "HashSet.H"
|
#include "HashSet.H"
|
||||||
|
#include "functionObjectProperties.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -145,7 +146,7 @@ class functionObjectList
|
|||||||
const dictionary& parentDict_;
|
const dictionary& parentDict_;
|
||||||
|
|
||||||
//- Function object properties - stores state information
|
//- Function object properties - stores state information
|
||||||
mutable autoPtr<IOdictionary> stateDictPtr_;
|
mutable autoPtr<functionObjects::properties> propsDictPtr_;
|
||||||
|
|
||||||
//- Function objects output registry
|
//- Function objects output registry
|
||||||
mutable autoPtr<objectRegistry> objectsRegistryPtr_;
|
mutable autoPtr<objectRegistry> objectsRegistryPtr_;
|
||||||
@ -165,8 +166,8 @@ class functionObjectList
|
|||||||
//- List of functions
|
//- List of functions
|
||||||
PtrList<functionObject>& functions() { return *this; }
|
PtrList<functionObject>& functions() { return *this; }
|
||||||
|
|
||||||
//- Create state dictionary - attached to Time.
|
//- Create properties dictionary - attached to Time.
|
||||||
void createStateDict() const;
|
void createPropertiesDict() const;
|
||||||
|
|
||||||
//- Create registry for output objects - attached to Time.
|
//- Create registry for output objects - attached to Time.
|
||||||
void createOutputRegistry() const;
|
void createOutputRegistry() const;
|
||||||
@ -262,19 +263,19 @@ public:
|
|||||||
//- Access to the functionObjects
|
//- Access to the functionObjects
|
||||||
using PtrList<functionObject>::operator[];
|
using PtrList<functionObject>::operator[];
|
||||||
|
|
||||||
//- Return the current trigger index (read from the stateDict)
|
//- Return the current trigger index (read from the propsDict)
|
||||||
label triggerIndex() const;
|
label triggerIndex() const;
|
||||||
|
|
||||||
//- Reset/read state dictionary for current time
|
//- Reset/read properties dictionary for current time
|
||||||
void resetState();
|
void resetPropertiesDict();
|
||||||
|
|
||||||
//- Write access to the state dictionary ("functionObjectProperties")
|
//- Write access to the properties dictionary
|
||||||
//- registered on Time
|
//- ("functionObjectProperties") registered on Time
|
||||||
IOdictionary& stateDict();
|
functionObjects::properties& propsDict();
|
||||||
|
|
||||||
//- Const access to the state dictionary ("functionObjectProperties")
|
//- Const access to the properties dictionary
|
||||||
//- registered on Time
|
//- ("functionObjectProperties") registered on Time
|
||||||
const IOdictionary& stateDict() const;
|
const Foam::functionObjects::properties& propsDict() const;
|
||||||
|
|
||||||
//- Write access to the output objects ("functionObjectObjects")
|
//- Write access to the output objects ("functionObjectObjects")
|
||||||
//- registered on Time
|
//- registered on Time
|
||||||
|
|||||||
@ -0,0 +1,308 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "functionObjectProperties.H"
|
||||||
|
#include "SHA1.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
const Foam::word Foam::functionObjects::properties::resultsName_ =
|
||||||
|
SHA1("results").str();
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::functionObjects::properties::properties
|
||||||
|
(
|
||||||
|
const IOobject& io
|
||||||
|
)
|
||||||
|
:
|
||||||
|
IOdictionary(io)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::wordList Foam::functionObjects::properties::objectNames() const
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
// - remove resultsName_ dict from results?
|
||||||
|
// - or put objects into their own subdictionary?
|
||||||
|
return sortedToc();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::functionObjects::properties::hasObjectDict
|
||||||
|
(
|
||||||
|
const word& objectName
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return found(objectName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::dictionary& Foam::functionObjects::properties::getObjectDict
|
||||||
|
(
|
||||||
|
const word& objectName
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (!found(objectName))
|
||||||
|
{
|
||||||
|
add(objectName, dictionary());
|
||||||
|
}
|
||||||
|
|
||||||
|
return subDict(objectName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::functionObjects::properties::setTrigger
|
||||||
|
(
|
||||||
|
const label triggeri
|
||||||
|
)
|
||||||
|
{
|
||||||
|
label oldTriggeri = getOrDefault<label>("triggerIndex", labelMin);
|
||||||
|
|
||||||
|
if (triggeri > oldTriggeri)
|
||||||
|
{
|
||||||
|
set("triggerIndex", triggeri);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::label Foam::functionObjects::properties::getTrigger() const
|
||||||
|
{
|
||||||
|
return getOrDefault<label>("triggerIndex", labelMin);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::functionObjects::properties::foundObjectProperty
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
if (found(objectName))
|
||||||
|
{
|
||||||
|
const dictionary& baseDict = subDict(objectName);
|
||||||
|
return baseDict.found(entryName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::functionObjects::properties::getObjectDict
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName,
|
||||||
|
dictionary& dict
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
if (found(objectName))
|
||||||
|
{
|
||||||
|
const dictionary& baseDict = subDict(objectName);
|
||||||
|
|
||||||
|
if (baseDict.found(entryName) && baseDict.isDict(entryName))
|
||||||
|
{
|
||||||
|
dict = baseDict.subDict(entryName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::functionObjects::properties::hasResultObject
|
||||||
|
(
|
||||||
|
const word& objectName
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
if (found(resultsName_))
|
||||||
|
{
|
||||||
|
return subDict(resultsName_).found(objectName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::wordList Foam::functionObjects::properties::objectResultNames() const
|
||||||
|
{
|
||||||
|
if (found(resultsName_))
|
||||||
|
{
|
||||||
|
return subDict(resultsName_).sortedToc();
|
||||||
|
}
|
||||||
|
|
||||||
|
return wordList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::functionObjects::properties::hasResultObjectEntry
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
if (found(resultsName_))
|
||||||
|
{
|
||||||
|
const dictionary& resultsDict = subDict(resultsName_);
|
||||||
|
|
||||||
|
if (resultsDict.found(objectName))
|
||||||
|
{
|
||||||
|
const dictionary& objectDict = resultsDict.subDict(objectName);
|
||||||
|
|
||||||
|
for (const entry& dEntry : objectDict)
|
||||||
|
{
|
||||||
|
const dictionary& dict = dEntry.dict();
|
||||||
|
|
||||||
|
if (dict.found(entryName))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::word Foam::functionObjects::properties::objectResultType
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
if (found(resultsName_))
|
||||||
|
{
|
||||||
|
const dictionary& resultsDict = subDict(resultsName_);
|
||||||
|
|
||||||
|
if (resultsDict.found(objectName))
|
||||||
|
{
|
||||||
|
const dictionary& objectDict = resultsDict.subDict(objectName);
|
||||||
|
|
||||||
|
for (const entry& dEntry : objectDict)
|
||||||
|
{
|
||||||
|
const dictionary& dict = dEntry.dict();
|
||||||
|
|
||||||
|
if (dict.found(entryName))
|
||||||
|
{
|
||||||
|
return dict.dictName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return word::null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::wordList Foam::functionObjects::properties::objectResultEntries
|
||||||
|
(
|
||||||
|
const word& objectName
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
DynamicList<word> result;
|
||||||
|
|
||||||
|
if (found(resultsName_))
|
||||||
|
{
|
||||||
|
const dictionary& resultsDict = subDict(resultsName_);
|
||||||
|
|
||||||
|
if (resultsDict.found(objectName))
|
||||||
|
{
|
||||||
|
const dictionary& objectDict = resultsDict.subDict(objectName);
|
||||||
|
|
||||||
|
for (const entry& dEntry : objectDict)
|
||||||
|
{
|
||||||
|
const dictionary& dict = dEntry.dict();
|
||||||
|
|
||||||
|
result.append(dict.toc());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wordList entries;
|
||||||
|
entries.transfer(result);
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::functionObjects::properties::writeResultEntries
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
Ostream& os
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
if (found(resultsName_))
|
||||||
|
{
|
||||||
|
const dictionary& resultsDict = subDict(resultsName_);
|
||||||
|
|
||||||
|
if (resultsDict.found(objectName))
|
||||||
|
{
|
||||||
|
const dictionary& objectDict = resultsDict.subDict(objectName);
|
||||||
|
|
||||||
|
for (const word& dataFormat : objectDict.sortedToc())
|
||||||
|
{
|
||||||
|
os << " Type: " << dataFormat << nl;
|
||||||
|
|
||||||
|
const dictionary& resultDict = objectDict.subDict(dataFormat);
|
||||||
|
|
||||||
|
for (const word& result : resultDict.sortedToc())
|
||||||
|
{
|
||||||
|
os << " " << result << nl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::functionObjects::properties::writeAllResultEntries
|
||||||
|
(
|
||||||
|
Ostream& os
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
if (found(resultsName_))
|
||||||
|
{
|
||||||
|
const dictionary& resultsDict = subDict(resultsName_);
|
||||||
|
|
||||||
|
for (const word& objectName : resultsDict.sortedToc())
|
||||||
|
{
|
||||||
|
os << "Object: " << objectName << endl;
|
||||||
|
|
||||||
|
writeResultEntries(objectName, os);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -0,0 +1,241 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::functionObjects::properties
|
||||||
|
|
||||||
|
Description
|
||||||
|
Storage for function object properties, derived from IOdictionary.
|
||||||
|
Provides functionality to read/write state information (data required for
|
||||||
|
smooth restart behaviour) and results to/from the state dictionary
|
||||||
|
|
||||||
|
Note: cannot be accessed until after construction of thefunction objects,
|
||||||
|
since the owner container functionObjectList is owned by time, and time owns
|
||||||
|
[this] i.e. need to wait for time to be fully constructed.
|
||||||
|
|
||||||
|
See also
|
||||||
|
Foam::functionObject
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
functionObjectProperties.C
|
||||||
|
functionObjectPropertiesTemplates.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef functionObjects_properties_H
|
||||||
|
#define functionObjects_properties_H
|
||||||
|
|
||||||
|
#include "IOdictionary.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace functionObjects
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class properties Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class properties
|
||||||
|
:
|
||||||
|
public IOdictionary
|
||||||
|
{
|
||||||
|
// Private Member Data
|
||||||
|
|
||||||
|
//- Name of the results dictionary
|
||||||
|
static const word resultsName_;
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Protected Member Functions
|
||||||
|
|
||||||
|
//- No copy construct
|
||||||
|
properties(const properties&) = delete;
|
||||||
|
|
||||||
|
//- No copy assignment
|
||||||
|
void operator=(const properties&) = delete;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct from components
|
||||||
|
explicit properties(const IOobject& io);
|
||||||
|
|
||||||
|
|
||||||
|
//- Destructor
|
||||||
|
virtual ~properties() = default;
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Return list of object names
|
||||||
|
wordList objectNames() const;
|
||||||
|
|
||||||
|
//- Return true if the object with objectName exists
|
||||||
|
bool hasObjectDict(const word& objectName) const;
|
||||||
|
|
||||||
|
//- Return access to the property dictionary
|
||||||
|
dictionary& propertyDict(const word& objectName);
|
||||||
|
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
|
||||||
|
//- Get dictionary for named object. Creates one if required
|
||||||
|
dictionary& getObjectDict(const word& objectName);
|
||||||
|
|
||||||
|
//- Return true if the property exists
|
||||||
|
bool foundObjectProperty
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Get the current trigger index
|
||||||
|
label getTrigger() const;
|
||||||
|
|
||||||
|
//- Set the current trigger index
|
||||||
|
bool setTrigger(const label triggeri);
|
||||||
|
|
||||||
|
//- Set dictionary from named object, return true if set
|
||||||
|
bool getObjectDict
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName,
|
||||||
|
dictionary& dict
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Retrieve generic property from named object
|
||||||
|
template<class Type>
|
||||||
|
Type getObjectProperty
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName,
|
||||||
|
const Type& defaultValue = Type(Zero)
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Set generic property from named object, return true if set
|
||||||
|
template<class Type>
|
||||||
|
bool getObjectProperty
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName,
|
||||||
|
Type& value
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Add generic property from named object
|
||||||
|
template<class Type>
|
||||||
|
void setObjectProperty
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName,
|
||||||
|
const Type& value
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// Results
|
||||||
|
|
||||||
|
//- Add result from named object
|
||||||
|
template<class Type>
|
||||||
|
void setObjectResult
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName,
|
||||||
|
const Type& value
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Retrieve result from named object
|
||||||
|
template<class Type>
|
||||||
|
Type getObjectResult
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName,
|
||||||
|
const Type& defaultValue = Type(Zero)
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Set result from named object, return true if set
|
||||||
|
template<class Type>
|
||||||
|
bool getObjectResult
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName,
|
||||||
|
Type& value
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Return true if the object with objectName exists in results
|
||||||
|
bool hasResultObject(const word& objectName) const;
|
||||||
|
|
||||||
|
//- Return list of objects with results
|
||||||
|
wordList objectResultNames() const;
|
||||||
|
|
||||||
|
//- Return true if the object with objectName exists and has
|
||||||
|
//- entryName in its results
|
||||||
|
bool hasResultObjectEntry
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Return the type of result
|
||||||
|
word objectResultType
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Return result entries for named object
|
||||||
|
wordList objectResultEntries(const word& objectName) const;
|
||||||
|
|
||||||
|
//- Write the results entries for all objects to stream
|
||||||
|
void writeResultEntries(Ostream& os) const;
|
||||||
|
|
||||||
|
//- Write the results entries for named object to stream
|
||||||
|
void writeResultEntries(const word& objectName, Ostream& os) const;
|
||||||
|
|
||||||
|
//- Write the results entries for all objects to stream
|
||||||
|
void writeAllResultEntries(Ostream& os) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace functionObjects
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#ifdef NoRepository
|
||||||
|
#include "functionObjectPropertiesTemplates.C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -0,0 +1,163 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "IOdictionary.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Type Foam::functionObjects::properties::getObjectProperty
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName,
|
||||||
|
const Type& defaultValue
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
Type result = defaultValue;
|
||||||
|
getObjectProperty(objectName, entryName, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
bool Foam::functionObjects::properties::getObjectProperty
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName,
|
||||||
|
Type& value
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
if (this->found(objectName))
|
||||||
|
{
|
||||||
|
const dictionary& baseDict = this->subDict(objectName);
|
||||||
|
return baseDict.readIfPresent(entryName, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
void Foam::functionObjects::properties::setObjectProperty
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName,
|
||||||
|
const Type& value
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (!this->found(objectName))
|
||||||
|
{
|
||||||
|
this->add(objectName, dictionary());
|
||||||
|
}
|
||||||
|
|
||||||
|
dictionary& baseDict = this->subDict(objectName);
|
||||||
|
baseDict.add(entryName, value, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
void Foam::functionObjects::properties::setObjectResult
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName,
|
||||||
|
const Type& value
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (!this->found(resultsName_))
|
||||||
|
{
|
||||||
|
this->add(resultsName_, dictionary());
|
||||||
|
}
|
||||||
|
|
||||||
|
dictionary& resultsDict = this->subDict(resultsName_);
|
||||||
|
|
||||||
|
if (!resultsDict.found(objectName))
|
||||||
|
{
|
||||||
|
resultsDict.add(objectName, dictionary());
|
||||||
|
}
|
||||||
|
|
||||||
|
dictionary& objectDict = resultsDict.subDict(objectName);
|
||||||
|
|
||||||
|
const word& dictTypeName = pTraits<Type>::typeName;
|
||||||
|
|
||||||
|
if (!objectDict.found(dictTypeName))
|
||||||
|
{
|
||||||
|
objectDict.add(dictTypeName, dictionary());
|
||||||
|
}
|
||||||
|
|
||||||
|
dictionary& resultTypeDict = objectDict.subDict(dictTypeName);
|
||||||
|
|
||||||
|
resultTypeDict.add(entryName, value, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Type Foam::functionObjects::properties::getObjectResult
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName,
|
||||||
|
const Type& defaultValue
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
Type result = defaultValue;
|
||||||
|
(void)getObjectResult(objectName, entryName, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
bool Foam::functionObjects::properties::getObjectResult
|
||||||
|
(
|
||||||
|
const word& objectName,
|
||||||
|
const word& entryName,
|
||||||
|
Type& value
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
if (this->found(resultsName_))
|
||||||
|
{
|
||||||
|
const dictionary& resultsDict = this->subDict(resultsName_);
|
||||||
|
|
||||||
|
if (resultsDict.found(objectName))
|
||||||
|
{
|
||||||
|
const dictionary& objectDict = resultsDict.subDict(objectName);
|
||||||
|
|
||||||
|
const word& dictTypeName = pTraits<Type>::typeName;
|
||||||
|
|
||||||
|
if (objectDict.found(dictTypeName))
|
||||||
|
{
|
||||||
|
const dictionary& resultTypeDict =
|
||||||
|
objectDict.subDict(dictTypeName);
|
||||||
|
|
||||||
|
return resultTypeDict.readIfPresent<Type>(entryName, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2015 OpenFOAM Foundation
|
Copyright (C) 2015 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2020 OpenCFD Ltd.
|
Copyright (C) 2015-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -37,16 +37,20 @@ const Foam::word Foam::functionObjects::stateFunctionObject::resultsName_ =
|
|||||||
|
|
||||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
const Foam::IOdictionary&
|
const Foam::functionObjects::properties&
|
||||||
Foam::functionObjects::stateFunctionObject::stateDict() const
|
Foam::functionObjects::stateFunctionObject::stateDict() const
|
||||||
{
|
{
|
||||||
return time_.functionObjects().stateDict();
|
return time_.functionObjects().propsDict();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::IOdictionary& Foam::functionObjects::stateFunctionObject::stateDict()
|
Foam::functionObjects::properties&
|
||||||
|
Foam::functionObjects::stateFunctionObject::stateDict()
|
||||||
{
|
{
|
||||||
return const_cast<IOdictionary&>(time_.functionObjects().stateDict());
|
return const_cast<functionObjects::properties&>
|
||||||
|
(
|
||||||
|
time_.functionObjects().propsDict()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -66,14 +70,7 @@ Foam::functionObjects::stateFunctionObject::stateFunctionObject
|
|||||||
|
|
||||||
Foam::dictionary& Foam::functionObjects::stateFunctionObject::propertyDict()
|
Foam::dictionary& Foam::functionObjects::stateFunctionObject::propertyDict()
|
||||||
{
|
{
|
||||||
IOdictionary& stateDict = this->stateDict();
|
return stateDict().getObjectDict(name());
|
||||||
|
|
||||||
if (!stateDict.found(name()))
|
|
||||||
{
|
|
||||||
stateDict.add(name(), dictionary());
|
|
||||||
}
|
|
||||||
|
|
||||||
return stateDict.subDict(name());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -82,26 +79,13 @@ bool Foam::functionObjects::stateFunctionObject::setTrigger
|
|||||||
const label triggeri
|
const label triggeri
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
IOdictionary& stateDict = this->stateDict();
|
return stateDict().setTrigger(triggeri);
|
||||||
|
|
||||||
label oldTriggeri =
|
|
||||||
stateDict.getOrDefault<label>("triggerIndex", labelMin);
|
|
||||||
|
|
||||||
if (triggeri > oldTriggeri)
|
|
||||||
{
|
|
||||||
stateDict.set("triggerIndex", triggeri);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::label Foam::functionObjects::stateFunctionObject::getTrigger() const
|
Foam::label Foam::functionObjects::stateFunctionObject::getTrigger() const
|
||||||
{
|
{
|
||||||
const IOdictionary& stateDict = this->stateDict();
|
return stateDict().getTrigger();
|
||||||
|
|
||||||
return stateDict.getOrDefault<label>("triggerIndex", labelMin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -110,15 +94,7 @@ bool Foam::functionObjects::stateFunctionObject::foundProperty
|
|||||||
const word& entryName
|
const word& entryName
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const IOdictionary& stateDict = this->stateDict();
|
return stateDict().foundObjectProperty(name(), entryName);
|
||||||
|
|
||||||
if (stateDict.found(name()))
|
|
||||||
{
|
|
||||||
const dictionary& baseDict = stateDict.subDict(name());
|
|
||||||
return baseDict.found(entryName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -128,7 +104,7 @@ bool Foam::functionObjects::stateFunctionObject::getDict
|
|||||||
dictionary& dict
|
dictionary& dict
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
return getObjectDict(name(), entryName, dict);
|
return stateDict().getObjectDict(name(), entryName, dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -139,19 +115,7 @@ bool Foam::functionObjects::stateFunctionObject::getObjectDict
|
|||||||
dictionary& dict
|
dictionary& dict
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const IOdictionary& stateDict = this->stateDict();
|
return stateDict().getObjectDict(objectName, entryName, dict);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -160,7 +124,7 @@ Foam::word Foam::functionObjects::stateFunctionObject::resultType
|
|||||||
const word& entryName
|
const word& entryName
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
return objectResultType(name(), entryName);
|
return stateDict().objectResultType(name(), entryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -170,79 +134,33 @@ Foam::word Foam::functionObjects::stateFunctionObject::objectResultType
|
|||||||
const word& entryName
|
const word& entryName
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
word result = word::null;
|
return stateDict().objectResultType(objectName, entryName);
|
||||||
const IOdictionary& stateDict = this->stateDict();
|
|
||||||
|
|
||||||
if (stateDict.found(resultsName_))
|
|
||||||
{
|
|
||||||
const dictionary& resultsDict = stateDict.subDict(resultsName_);
|
|
||||||
|
|
||||||
if (resultsDict.found(objectName))
|
|
||||||
{
|
|
||||||
const dictionary& objectDict = resultsDict.subDict(objectName);
|
|
||||||
|
|
||||||
for (const entry& dEntry : objectDict)
|
|
||||||
{
|
|
||||||
const dictionary& dict = dEntry.dict();
|
|
||||||
|
|
||||||
if (dict.found(entryName))
|
|
||||||
{
|
|
||||||
return dict.dictName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::List<Foam::word>
|
Foam::wordList
|
||||||
Foam::functionObjects::stateFunctionObject::objectResultEntries() const
|
Foam::functionObjects::stateFunctionObject::objectResultEntries() const
|
||||||
{
|
{
|
||||||
return objectResultEntries(name());
|
return stateDict().objectResultEntries(name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::List<Foam::word>
|
Foam::wordList
|
||||||
Foam::functionObjects::stateFunctionObject::objectResultEntries
|
Foam::functionObjects::stateFunctionObject::objectResultEntries
|
||||||
(
|
(
|
||||||
const word& objectName
|
const word& objectName
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
DynamicList<word> result(2);
|
return stateDict().objectResultEntries(objectName);
|
||||||
|
|
||||||
const IOdictionary& stateDict = this->stateDict();
|
|
||||||
|
|
||||||
if (stateDict.found(resultsName_))
|
|
||||||
{
|
|
||||||
const dictionary& resultsDict = stateDict.subDict(resultsName_);
|
|
||||||
|
|
||||||
if (resultsDict.found(objectName))
|
|
||||||
{
|
|
||||||
const dictionary& objectDict = resultsDict.subDict(objectName);
|
|
||||||
|
|
||||||
for (const entry& dEntry : objectDict)
|
|
||||||
{
|
|
||||||
const dictionary& dict = dEntry.dict();
|
|
||||||
|
|
||||||
result.append(dict.toc());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wordList entries;
|
|
||||||
entries.transfer(result);
|
|
||||||
|
|
||||||
return entries;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::functionObjects::stateFunctionObject::writeResultEntries
|
void Foam::functionObjects::stateFunctionObject::writeResultEntries
|
||||||
(
|
(
|
||||||
Ostream& os
|
Ostream& os
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
writeResultEntries(name(), os);
|
return stateDict().writeResultEntries(name(), os);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -252,29 +170,7 @@ void Foam::functionObjects::stateFunctionObject::writeResultEntries
|
|||||||
Ostream& os
|
Ostream& os
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const IOdictionary& stateDict = this->stateDict();
|
return stateDict().writeResultEntries(objectName, os);
|
||||||
|
|
||||||
if (stateDict.found(resultsName_))
|
|
||||||
{
|
|
||||||
const dictionary& resultsDict = stateDict.subDict(resultsName_);
|
|
||||||
|
|
||||||
if (resultsDict.found(objectName))
|
|
||||||
{
|
|
||||||
const dictionary& objectDict = resultsDict.subDict(objectName);
|
|
||||||
|
|
||||||
for (const word& dataFormat : objectDict.sortedToc())
|
|
||||||
{
|
|
||||||
os << " Type: " << dataFormat << nl;
|
|
||||||
|
|
||||||
const dictionary& resultDict = objectDict.subDict(dataFormat);
|
|
||||||
|
|
||||||
for (const word& result : resultDict.sortedToc())
|
|
||||||
{
|
|
||||||
os << " " << result << nl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -283,21 +179,7 @@ void Foam::functionObjects::stateFunctionObject::writeAllResultEntries
|
|||||||
Ostream& os
|
Ostream& os
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const IOdictionary& stateDict = this->stateDict();
|
return stateDict().writeAllResultEntries(os);
|
||||||
|
|
||||||
if (stateDict.found(resultsName_))
|
|
||||||
{
|
|
||||||
const dictionary& resultsDict = stateDict.subDict(resultsName_);
|
|
||||||
|
|
||||||
const wordList allObjectNames = resultsDict.sortedToc();
|
|
||||||
|
|
||||||
for (const word& objectName : allObjectNames)
|
|
||||||
{
|
|
||||||
os << "Object: " << objectName << endl;
|
|
||||||
|
|
||||||
writeResultEntries(objectName, os);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2015 OpenFOAM Foundation
|
Copyright (C) 2015 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
Copyright (C) 2015-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -50,12 +50,14 @@ SourceFiles
|
|||||||
#define functionObjects_stateFunctionObject_H
|
#define functionObjects_stateFunctionObject_H
|
||||||
|
|
||||||
#include "timeFunctionObject.H"
|
#include "timeFunctionObject.H"
|
||||||
|
#include "functionObjectProperties.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Forward Declarations
|
||||||
class IOdictionary;
|
class IOdictionary;
|
||||||
|
|
||||||
namespace functionObjects
|
namespace functionObjects
|
||||||
@ -80,10 +82,10 @@ protected:
|
|||||||
// Protected Member Functions
|
// Protected Member Functions
|
||||||
|
|
||||||
//- Return a const reference to the state dictionary
|
//- Return a const reference to the state dictionary
|
||||||
const IOdictionary& stateDict() const;
|
const functionObjects::properties& stateDict() const;
|
||||||
|
|
||||||
//- Return non-const access to the state dictionary
|
//- Return non-const access to the state dictionary
|
||||||
IOdictionary& stateDict();
|
functionObjects::properties& stateDict();
|
||||||
|
|
||||||
|
|
||||||
//- No copy construct
|
//- No copy construct
|
||||||
@ -237,10 +239,10 @@ public:
|
|||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Retrieve the result entries
|
//- Retrieve the result entries
|
||||||
List<word> objectResultEntries() const;
|
wordList objectResultEntries() const;
|
||||||
|
|
||||||
//- Return result entries for named object
|
//- Return result entries for named object
|
||||||
List<word> objectResultEntries(const word& objectName) const;
|
wordList objectResultEntries(const word& objectName) const;
|
||||||
|
|
||||||
//- Write the results entries for all objects to stream
|
//- Write the results entries for all objects to stream
|
||||||
void writeResultEntries(Ostream& os) const;
|
void writeResultEntries(Ostream& os) const;
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2015 OpenFOAM Foundation
|
Copyright (C) 2015 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2016 OpenCFD Ltd.
|
Copyright (C) 2015-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -87,15 +87,7 @@ bool Foam::functionObjects::stateFunctionObject::getObjectProperty
|
|||||||
Type& value
|
Type& value
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const IOdictionary& stateDict = this->stateDict();
|
return stateDict().getObjectProperty(objectName, entryName, value);
|
||||||
|
|
||||||
if (stateDict.found(objectName))
|
|
||||||
{
|
|
||||||
const dictionary& baseDict = stateDict.subDict(objectName);
|
|
||||||
return baseDict.readIfPresent(entryName, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -107,15 +99,7 @@ void Foam::functionObjects::stateFunctionObject::setObjectProperty
|
|||||||
const Type& value
|
const Type& value
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
IOdictionary& stateDict = this->stateDict();
|
stateDict().setObjectProperty(objectName, entryName, value);
|
||||||
|
|
||||||
if (!stateDict.found(objectName))
|
|
||||||
{
|
|
||||||
stateDict.add(objectName, dictionary());
|
|
||||||
}
|
|
||||||
|
|
||||||
dictionary& baseDict = stateDict.subDict(objectName);
|
|
||||||
baseDict.add(entryName, value, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -138,32 +122,7 @@ void Foam::functionObjects::stateFunctionObject::setObjectResult
|
|||||||
const Type& value
|
const Type& value
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
IOdictionary& stateDict = this->stateDict();
|
stateDict().setObjectResult(objectName, entryName, value);
|
||||||
|
|
||||||
if (!stateDict.found(resultsName_))
|
|
||||||
{
|
|
||||||
stateDict.add(resultsName_, dictionary());
|
|
||||||
}
|
|
||||||
|
|
||||||
dictionary& resultsDict = stateDict.subDict(resultsName_);
|
|
||||||
|
|
||||||
if (!resultsDict.found(objectName))
|
|
||||||
{
|
|
||||||
resultsDict.add(name(), dictionary());
|
|
||||||
}
|
|
||||||
|
|
||||||
dictionary& objectDict = resultsDict.subDict(objectName);
|
|
||||||
|
|
||||||
const word& dictTypeName = pTraits<Type>::typeName;
|
|
||||||
|
|
||||||
if (!objectDict.found(dictTypeName))
|
|
||||||
{
|
|
||||||
objectDict.add(dictTypeName, dictionary());
|
|
||||||
}
|
|
||||||
|
|
||||||
dictionary& resultTypeDict = objectDict.subDict(dictTypeName);
|
|
||||||
|
|
||||||
resultTypeDict.add(entryName, value, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -200,29 +159,7 @@ bool Foam::functionObjects::stateFunctionObject::getObjectResult
|
|||||||
Type& value
|
Type& value
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const IOdictionary& stateDict = this->stateDict();
|
return stateDict().getObjectResult(objectName, entryName, value);
|
||||||
|
|
||||||
if (stateDict.found(resultsName_))
|
|
||||||
{
|
|
||||||
const dictionary& resultsDict = stateDict.subDict(resultsName_);
|
|
||||||
|
|
||||||
if (resultsDict.found(objectName))
|
|
||||||
{
|
|
||||||
const dictionary& objectDict = resultsDict.subDict(objectName);
|
|
||||||
|
|
||||||
const word& dictTypeName = pTraits<Type>::typeName;
|
|
||||||
|
|
||||||
if (objectDict.found(dictTypeName))
|
|
||||||
{
|
|
||||||
const dictionary& resultTypeDict =
|
|
||||||
objectDict.subDict(dictTypeName);
|
|
||||||
|
|
||||||
return resultTypeDict.readIfPresent<Type>(entryName, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user