mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-12-28 03:37:59 +00:00
COMP: Multiple changes - first clean build after latest merge - UNTESTED
This commit is contained in:
@ -0,0 +1,180 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 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 "stateFunctionObject.H"
|
||||
#include "Time.H"
|
||||
|
||||
const Foam::word Foam::functionObjects::stateFunctionObject::resultsName_ =
|
||||
"results";
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
const Foam::IOdictionary&
|
||||
Foam::functionObjects::stateFunctionObject::stateDict() const
|
||||
{
|
||||
return time_.functionObjects().stateDict();
|
||||
}
|
||||
|
||||
|
||||
Foam::IOdictionary& Foam::functionObjects::stateFunctionObject::stateDict()
|
||||
{
|
||||
return const_cast<IOdictionary&>(time_.functionObjects().stateDict());
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::stateFunctionObject::stateFunctionObject
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime
|
||||
)
|
||||
:
|
||||
functionObject(name),
|
||||
time_(runTime)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::stateFunctionObject::~stateFunctionObject()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::dictionary& Foam::functionObjects::stateFunctionObject::propertyDict()
|
||||
{
|
||||
IOdictionary& stateDict = this->stateDict();
|
||||
|
||||
if (!stateDict.found(name()))
|
||||
{
|
||||
stateDict.add(name(), dictionary());
|
||||
}
|
||||
|
||||
return stateDict.subDict(name());
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::stateFunctionObject::foundProperty
|
||||
(
|
||||
const word& entryName
|
||||
) const
|
||||
{
|
||||
const IOdictionary& stateDict = this->stateDict();
|
||||
|
||||
if (stateDict.found(name()))
|
||||
{
|
||||
const dictionary& baseDict = stateDict.subDict(name());
|
||||
return baseDict.found(entryName);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Foam::word Foam::functionObjects::stateFunctionObject::resultType
|
||||
(
|
||||
const word& entryName
|
||||
) const
|
||||
{
|
||||
return objectResultType(name(), entryName);
|
||||
}
|
||||
|
||||
|
||||
Foam::word Foam::functionObjects::stateFunctionObject::objectResultType
|
||||
(
|
||||
const word& objectName,
|
||||
const word& entryName
|
||||
) const
|
||||
{
|
||||
word result = word::null;
|
||||
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);
|
||||
|
||||
forAllConstIter(dictionary, objectDict, iter)
|
||||
{
|
||||
const dictionary& dict = iter().dict();
|
||||
|
||||
if (dict.found(entryName))
|
||||
{
|
||||
return dict.dictName();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Foam::List<Foam::word>
|
||||
Foam::functionObjects::stateFunctionObject::objectResultEntries() const
|
||||
{
|
||||
return objectResultEntries(name());
|
||||
}
|
||||
|
||||
|
||||
Foam::List<Foam::word> Foam::functionObjects::stateFunctionObject::
|
||||
objectResultEntries
|
||||
(
|
||||
const word& objectName
|
||||
) const
|
||||
{
|
||||
DynamicList<word> result(2);
|
||||
|
||||
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);
|
||||
|
||||
forAllConstIter(dictionary, objectDict, iter)
|
||||
{
|
||||
const dictionary& dict = iter().dict();
|
||||
result.append(dict.toc());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wordList entries;
|
||||
entries.transfer(result);
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,250 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 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::functionObjectState
|
||||
|
||||
Description
|
||||
Base class for function objects, adding functionality to read/write state
|
||||
information (data required for smooth restart behaviour) and results
|
||||
to/from the state dictionary
|
||||
|
||||
Note: cannot access the state dictionary until after construction of the
|
||||
function objects, since the owner container functionObjectList is owned
|
||||
by time, and time owns the state dictionary. I.e. need to wait for time
|
||||
to be fully consttucted.
|
||||
|
||||
See also
|
||||
Foam::functionObject
|
||||
|
||||
SourceFiles
|
||||
stateFunctionObject.C
|
||||
stateFunctionObjectTemplates.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_stateFunctionObject_H
|
||||
#define functionObjects_stateFunctionObject_H
|
||||
|
||||
#include "functionObject.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class IOdictionary;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class stateFunctionObject Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class stateFunctionObject
|
||||
:
|
||||
public functionObject
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
// Private member data
|
||||
|
||||
//- Name of the results dictionary
|
||||
static const word resultsName_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
stateFunctionObject(const stateFunctionObject&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const stateFunctionObject&) = delete;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Member Data
|
||||
|
||||
//- Reference to the time database
|
||||
const Time& time_;
|
||||
|
||||
|
||||
// Protacted Member Functions
|
||||
|
||||
//- Return a const reference to the state dictionary
|
||||
const IOdictionary& stateDict() const;
|
||||
|
||||
//- Return non-const access to the state dictionary
|
||||
IOdictionary& stateDict();
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
stateFunctionObject(const word& name, const Time& runTime);
|
||||
|
||||
|
||||
//- Destructor
|
||||
~stateFunctionObject();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return access to the property dictionary
|
||||
dictionary& propertyDict();
|
||||
|
||||
|
||||
// Properties
|
||||
|
||||
//- Return true if the property exists
|
||||
bool foundProperty(const word& entryName) const;
|
||||
|
||||
//- Retrieve generic property
|
||||
template<class Type>
|
||||
Type getProperty
|
||||
(
|
||||
const word& entryName,
|
||||
const Type& defaultValue = Type(Zero)
|
||||
) const;
|
||||
|
||||
//- Retrieve generic property
|
||||
template<class Type>
|
||||
void getProperty(const word& entryName, Type& value) const;
|
||||
|
||||
//- Add generic property
|
||||
template<class Type>
|
||||
void setProperty(const word& entryName, const Type& value);
|
||||
|
||||
//- Retrieve generic property from named object
|
||||
template<class Type>
|
||||
Type getObjectProperty
|
||||
(
|
||||
const word& objectName,
|
||||
const word& entryName,
|
||||
const Type& defaultValue = Type(Zero)
|
||||
) const;
|
||||
|
||||
//- Retrieve generic property from named object
|
||||
template<class Type>
|
||||
void 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
|
||||
template<class Type>
|
||||
void setResult
|
||||
(
|
||||
const word& entryName,
|
||||
const Type& value
|
||||
);
|
||||
|
||||
//- Add result from named object
|
||||
template<class Type>
|
||||
void setObjectResult
|
||||
(
|
||||
const word& objectName,
|
||||
const word& entryName,
|
||||
const Type& value
|
||||
);
|
||||
|
||||
//- Retrieve result
|
||||
template<class Type>
|
||||
Type getResult
|
||||
(
|
||||
const word& entryName,
|
||||
const Type& defaultValue = Type(Zero)
|
||||
) const;
|
||||
|
||||
//- Retrieve result from named object
|
||||
template<class Type>
|
||||
Type getObjectResult
|
||||
(
|
||||
const word& objectName,
|
||||
const word& entryName,
|
||||
const Type& defaultValue = Type(Zero)
|
||||
) const;
|
||||
|
||||
//- Retrieve result from named object
|
||||
template<class Type>
|
||||
void getObjectResult
|
||||
(
|
||||
const word& objectName,
|
||||
const word& entryName,
|
||||
Type& value
|
||||
) const;
|
||||
|
||||
//- Retrieve the result type
|
||||
word resultType(const word& entryName) const;
|
||||
|
||||
//- Return the type of result
|
||||
word objectResultType
|
||||
(
|
||||
const word& objectName,
|
||||
const word& entryName
|
||||
) const;
|
||||
|
||||
//- Retrieve the result entries
|
||||
List<word> objectResultEntries() const;
|
||||
|
||||
//- Return result entries for named object
|
||||
List<word> objectResultEntries(const word& objectName) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "stateFunctionObjectTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,232 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 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::stateFunctionObject::getProperty
|
||||
(
|
||||
const word& entryName,
|
||||
const Type& defaultValue
|
||||
) const
|
||||
{
|
||||
Type result = defaultValue;
|
||||
getProperty(entryName, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::stateFunctionObject::getProperty
|
||||
(
|
||||
const word& entryName,
|
||||
Type& value
|
||||
) const
|
||||
{
|
||||
getObjectProperty(name(), entryName, value);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::stateFunctionObject::setProperty
|
||||
(
|
||||
const word& entryName,
|
||||
const Type& value
|
||||
)
|
||||
{
|
||||
setObjectProperty(name(), entryName, value);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Type Foam::functionObjects::stateFunctionObject::getObjectProperty
|
||||
(
|
||||
const word& objectName,
|
||||
const word& entryName,
|
||||
const Type& defaultValue
|
||||
) const
|
||||
{
|
||||
Type result = defaultValue;
|
||||
getObjectProperty(objectName, entryName, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::stateFunctionObject::getObjectProperty
|
||||
(
|
||||
const word& objectName,
|
||||
const word& entryName,
|
||||
Type& value
|
||||
) const
|
||||
{
|
||||
const IOdictionary& stateDict = this->stateDict();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::stateFunctionObject::setObjectProperty
|
||||
(
|
||||
const word& objectName,
|
||||
const word& entryName,
|
||||
const Type& value
|
||||
)
|
||||
{
|
||||
IOdictionary& stateDict = this->stateDict();
|
||||
|
||||
if (!stateDict.found(objectName))
|
||||
{
|
||||
stateDict.add(objectName, dictionary());
|
||||
}
|
||||
|
||||
dictionary& baseDict = stateDict.subDict(objectName);
|
||||
baseDict.add(entryName, value, true);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::stateFunctionObject::setResult
|
||||
(
|
||||
const word& entryName,
|
||||
const Type& value
|
||||
)
|
||||
{
|
||||
setObjectResult(name(), entryName, value);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::stateFunctionObject::setObjectResult
|
||||
(
|
||||
const word& objectName,
|
||||
const word& entryName,
|
||||
const Type& value
|
||||
)
|
||||
{
|
||||
IOdictionary& stateDict = this->stateDict();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Type Foam::functionObjects::stateFunctionObject::getResult
|
||||
(
|
||||
const word& entryName,
|
||||
const Type& defaultValue
|
||||
) const
|
||||
{
|
||||
return getObjectResult(name(), entryName, defaultValue);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Type Foam::functionObjects::stateFunctionObject::getObjectResult
|
||||
(
|
||||
const word& objectName,
|
||||
const word& entryName,
|
||||
const Type& defaultValue
|
||||
) const
|
||||
{
|
||||
Type result = defaultValue;
|
||||
getObjectResult(objectName, entryName, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::stateFunctionObject::getObjectResult
|
||||
(
|
||||
const word& objectName,
|
||||
const word& entryName,
|
||||
Type& value
|
||||
) const
|
||||
{
|
||||
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);
|
||||
|
||||
const word& dictTypeName = pTraits<Type>::typeName;
|
||||
|
||||
if (objectDict.found(dictTypeName))
|
||||
{
|
||||
const dictionary& resultTypeDict =
|
||||
objectDict.subDict(dictTypeName);
|
||||
|
||||
resultTypeDict.readIfPresent<Type>(entryName, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user