ENH: added timeFunctionObject virtual class in inheritance hierarchy

- simply a functionObject with an additional Time reference, which is
  a combination frequently used by concrete functionObjects
This commit is contained in:
Mark Olesen 2019-01-25 08:56:21 +01:00
parent 8433ddee0e
commit ad7f29466a
27 changed files with 225 additions and 178 deletions

View File

@ -284,14 +284,17 @@ $(dll)/dynamicCode/dynamicCode.C
$(dll)/dynamicCode/dynamicCodeContext.C
$(dll)/codedBase/codedBase.C
db/functionObjects/functionObject/functionObject.C
db/functionObjects/functionObjectList/functionObjectList.C
db/functionObjects/stateFunctionObject/stateFunctionObject.C
db/functionObjects/writeFile/writeFile.C
db/functionObjects/logFiles/logFiles.C
db/functionObjects/timeControl/timeControl.C
db/functionObjects/timeControl/timeControlFunctionObject.C
db/functionObjects/regionFunctionObject/regionFunctionObject.C
funcObjs = db/functionObjects
$(funcObjs)/functionObject/functionObject.C
$(funcObjs)/functionObjectList/functionObjectList.C
$(funcObjs)/stateFunctionObject/stateFunctionObject.C
$(funcObjs)/timeFunctionObject/timeFunctionObject.C
$(funcObjs)/writeFile/writeFile.C
$(funcObjs)/logFiles/logFiles.C
$(funcObjs)/timeControl/timeControl.C
$(funcObjs)/timeControl/timeControlFunctionObject.C
$(funcObjs)/regionFunctionObject/regionFunctionObject.C
Time = db/Time
$(Time)/TimePaths.C

View File

@ -102,12 +102,6 @@ Foam::functionObjects::logFiles::logFiles
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::logFiles::~logFiles()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::wordList& Foam::functionObjects::logFiles::names() const

View File

@ -51,7 +51,7 @@ namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class logFiles Declaration
Class functionObjects::logFiles Declaration
\*---------------------------------------------------------------------------*/
class logFiles
@ -116,7 +116,7 @@ public:
//- Destructor
virtual ~logFiles();
virtual ~logFiles() = default;
// Member Functions

View File

@ -48,14 +48,14 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
// Forward declarations
class objectRegistry;
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class regionFunctionObject Declaration
Class functionObjects::regionFunctionObject Declaration
\*---------------------------------------------------------------------------*/
class regionFunctionObject
@ -65,7 +65,7 @@ class regionFunctionObject
protected:
// Protected member data
// Protected Member Data
//- Reference to the region objectRegistry
const objectRegistry& obr_;
@ -76,7 +76,7 @@ protected:
const objectRegistry& subObr_;
// Protected member functions
// Protected Member Functions
//- Selector for alternative sub-registry,
// when the keyword %subRegion is present in the dictionary
@ -148,10 +148,6 @@ protected:
bool clearObject(const word& fieldName);
private:
// Private Member Functions
//- No copy construct
regionFunctionObject(const regionFunctionObject&) = delete;

View File

@ -52,14 +52,7 @@ Foam::functionObjects::stateFunctionObject::stateFunctionObject
const Time& runTime
)
:
functionObject(name),
time_(runTime)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::stateFunctionObject::~stateFunctionObject()
timeFunctionObject(name, runTime)
{}

View File

@ -3,7 +3,7 @@
\\ / 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.
\\/ M anipulation | Copyright (C) 2015-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -22,7 +22,7 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::functionObjectState
Foam::functionObjects::stateFunctionObject
Description
Base class for function objects, adding functionality to read/write state
@ -46,7 +46,7 @@ SourceFiles
#ifndef functionObjects_stateFunctionObject_H
#define functionObjects_stateFunctionObject_H
#include "functionObject.H"
#include "timeFunctionObject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -59,12 +59,12 @@ namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class stateFunctionObject Declaration
Class functionObjects::stateFunctionObject Declaration
\*---------------------------------------------------------------------------*/
class stateFunctionObject
:
public functionObject
public functionObjects::timeFunctionObject
{
private:
@ -75,24 +75,9 @@ private:
static const word resultsName_;
// Private Member Functions
//- No copy construct
stateFunctionObject(const stateFunctionObject&) = delete;
//- No copy assignment
void operator=(const stateFunctionObject&) = delete;
protected:
// Protected Member Data
//- Reference to the time database
const Time& time_;
// Protacted Member Functions
// Protected Member Functions
//- Return a const reference to the state dictionary
const IOdictionary& stateDict() const;
@ -101,6 +86,12 @@ protected:
IOdictionary& stateDict();
//- No copy construct
stateFunctionObject(const stateFunctionObject&) = delete;
//- No copy assignment
void operator=(const stateFunctionObject&) = delete;
public:
@ -111,7 +102,7 @@ public:
//- Destructor
~stateFunctionObject();
virtual ~stateFunctionObject() = default;
// Member Functions

View File

@ -66,12 +66,6 @@ Foam::timeControl::timeControl
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::timeControl::~timeControl()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::timeControl::entriesPresent
@ -82,12 +76,7 @@ bool Foam::timeControl::entriesPresent
{
const word controlName(prefix + "Control");
if (dict.found(controlName))
{
return true;
}
return false;
return dict.found(controlName);
}

View File

@ -116,7 +116,7 @@ public:
//- Destructor
~timeControl();
~timeControl() = default;
// Member Functions

View File

@ -442,12 +442,11 @@ void Foam::functionObjects::timeControl::calcDeltaTCoeff
Foam::functionObjects::timeControl::timeControl
(
const word& name,
const Time& t,
const Time& runTime,
const dictionary& dict
)
:
functionObject(name),
time_(t),
timeFunctionObject(name, runTime),
dict_(dict),
controlMode_(controlMode::TIME),
timeStart_(-VGREAT),
@ -455,9 +454,9 @@ Foam::functionObjects::timeControl::timeControl
triggerStart_(labelMax),
triggerEnd_(labelMax),
nStepsToStartTimeChange_(labelMax),
executeControl_(t, dict, "execute"),
writeControl_(t, dict, "write"),
foPtr_(functionObject::New(name, t, dict_)),
executeControl_(runTime, dict, "execute"),
writeControl_(runTime, dict, "write"),
foPtr_(functionObject::New(name, runTime, dict_)),
executeTimeIndex_(-1),
deltaT0_(0),
seriesDTCoeff_(GREAT)

View File

@ -56,7 +56,7 @@ SourceFiles
#ifndef functionObjects_timeControl_H
#define functionObjects_timeControl_H
#include "functionObject.H"
#include "timeFunctionObject.H"
#include "dictionary.H"
#include "timeControl.H"
@ -68,12 +68,12 @@ namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class timeControl Declaration
Class functionObjects::timeControl Declaration
\*---------------------------------------------------------------------------*/
class timeControl
:
public functionObject
public functionObjects::timeFunctionObject
{
public:
@ -96,9 +96,6 @@ private:
// Private data
//- Reference to the time database
const Time& time_;
//- Input dictionary
dictionary dict_;
@ -198,8 +195,8 @@ public:
timeControl
(
const word& name,
const Time&,
const dictionary&
const Time& runTime,
const dictionary& dict
);
@ -207,9 +204,6 @@ public:
// Access
//- Return time database
inline const Time& time() const;
//- Return the input dictionary
inline const dictionary& dict() const;

View File

@ -25,12 +25,6 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::Time& Foam::functionObjects::timeControl::time() const
{
return time_;
}
inline const Foam::dictionary& Foam::functionObjects::timeControl::dict() const
{
return dict_;

View File

@ -0,0 +1,42 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
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 "timeFunctionObject.H"
#include "Time.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::timeFunctionObject::timeFunctionObject
(
const word& name,
const Time& runTime
)
:
functionObject(name),
time_(runTime)
{}
// ************************************************************************* //

View File

@ -0,0 +1,108 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
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::timeFunctionObject
Description
Virtual base class for function objects with a reference to Time.
See also
Foam::functionObject
SourceFiles
timeFunctionObject.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_timeFunctionObject_H
#define functionObjects_timeFunctionObject_H
#include "functionObject.H"
#include "Time.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class functionObjects::timeFunctionObject Declaration
\*---------------------------------------------------------------------------*/
class timeFunctionObject
:
public functionObject
{
protected:
// Protected Member Data
//- Reference to the time database
const Time& time_;
// Protected Member Functions
//- No copy construct
timeFunctionObject(const timeFunctionObject&) = delete;
//- No copy assignment
void operator=(const timeFunctionObject&) = delete;
public:
// Constructors
//- Construct from components
timeFunctionObject(const word& name, const Time& runTime);
//- Destructor
virtual ~timeFunctionObject() = default;
// Member Functions
//- Return time database
const Time& time() const
{
return time_;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -51,7 +51,7 @@ namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class writeFile Declaration
Class functionObjects::writeFile Declaration
\*---------------------------------------------------------------------------*/
class writeFile
@ -121,10 +121,6 @@ protected:
Omanip<int> valueWidth(const label offset = 0) const;
private:
// Private Member Functions
//- No copy construct
writeFile(const writeFile&) = delete;

View File

@ -508,9 +508,8 @@ Foam::functionObjects::externalCoupled::externalCoupled
const dictionary& dict
)
:
functionObject(name),
timeFunctionObject(name, runTime),
externalFileCoupler(),
time_(runTime),
calcFrequency_(-1),
lastTrigger_(-1),
initialisedCoupling_(false)

View File

@ -146,7 +146,7 @@ SourceFiles
#ifndef functionObjects_externalCoupled_H
#define functionObjects_externalCoupled_H
#include "functionObject.H"
#include "timeFunctionObject.H"
#include "externalFileCoupler.H"
#include "DynamicList.H"
#include "wordReList.H"
@ -173,7 +173,7 @@ namespace functionObjects
class externalCoupled
:
public functionObject,
public functionObjects::timeFunctionObject,
public externalFileCoupler
{
public:
@ -193,10 +193,7 @@ private:
//- State end names (NB, only selectable values itemized)
static const Enum<stateEnd> stateEndNames_;
// Private data
//- Reference to the time database
const Time& time_;
// Private Member Data
//- Calculation frequency
label calcFrequency_;

View File

@ -138,8 +138,7 @@ Foam::functionObjects::abort::abort
const dictionary& dict
)
:
functionObject(name),
time_(runTime),
timeFunctionObject(name, runTime),
file_(),
defaultAction_(Time::stopAtControls::saUnknown),
triggered_(false)

View File

@ -86,7 +86,7 @@ SourceFiles
#ifndef functionObjects_abort_H
#define functionObjects_abort_H
#include "functionObject.H"
#include "timeFunctionObject.H"
#include "Time.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -102,13 +102,10 @@ namespace functionObjects
class abort
:
public functionObject
public functionObjects::timeFunctionObject
{
// Private Data
//- Reference to the Time
const Time& time_;
//- The fully-qualified name of the trigger file
fileName file_;

View File

@ -124,13 +124,12 @@ Foam::functionObjects::codedFunctionObject::codeDict() const
Foam::functionObjects::codedFunctionObject::codedFunctionObject
(
const word& name,
const Time& time,
const Time& runTime,
const dictionary& dict
)
:
functionObject(name),
timeFunctionObject(name, runTime),
codedBase(),
time_(time),
dict_(dict)
{
read(dict_);
@ -140,12 +139,6 @@ Foam::functionObjects::codedFunctionObject::codedFunctionObject
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::codedFunctionObject::~codedFunctionObject()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::functionObject&

View File

@ -75,7 +75,7 @@ SourceFiles
#ifndef functionObjects_codedFunctionObject_H
#define functionObjects_codedFunctionObject_H
#include "functionObject.H"
#include "timeFunctionObject.H"
#include "codedBase.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -91,16 +91,13 @@ namespace functionObjects
class codedFunctionObject
:
public functionObject,
public functionObjects::timeFunctionObject,
public codedBase
{
protected:
// Protected data
//- Reference to the time database
const Time& time_;
//- Input dictionary
dictionary dict_;
@ -153,13 +150,13 @@ public:
codedFunctionObject
(
const word& name,
const Time& time,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~codedFunctionObject();
virtual ~codedFunctionObject() = default;
// Member Functions

View File

@ -53,28 +53,14 @@ Foam::functionObjects::setTimeStepFunctionObject::setTimeStepFunctionObject
const dictionary& dict
)
:
functionObject(name),
time_(runTime)
timeFunctionObject(name, runTime)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::setTimeStepFunctionObject::~setTimeStepFunctionObject()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::Time&
Foam::functionObjects::setTimeStepFunctionObject::time() const
{
return time_;
}
bool Foam::functionObjects::setTimeStepFunctionObject::adjustTimeStep()
{
// Wanted timestep

View File

@ -69,7 +69,7 @@ SourceFiles
#ifndef functionObjects_setTimeStepFunctionObject_H
#define functionObjects_setTimeStepFunctionObject_H
#include "functionObject.H"
#include "timeFunctionObject.H"
#include "Function1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -80,23 +80,20 @@ namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class setTimeStepFunctionObject Declaration
Class functionObjects::setTimeStepFunctionObject Declaration
\*---------------------------------------------------------------------------*/
class setTimeStepFunctionObject
:
public functionObject
public functionObjects::timeFunctionObject
{
// Private data
//- Reference to the time database
const Time& time_;
// Private Member Data
//- Time step function/table
autoPtr<Function1<scalar>> timeStepPtr_;
// Private member functions
// Private Member Functions
//- No copy construct
setTimeStepFunctionObject(const setTimeStepFunctionObject&) = delete;
@ -123,14 +120,11 @@ public:
// Destructor
virtual ~setTimeStepFunctionObject();
virtual ~setTimeStepFunctionObject() = default;
// Member Functions
//- Return time database
const Time& time() const;
//- Called at the end of Time::adjustDeltaT() if adjustTime is true
virtual bool adjustTimeStep();

View File

@ -89,8 +89,7 @@ Foam::functionObjects::timeActivatedFileUpdate::timeActivatedFileUpdate
const dictionary& dict
)
:
functionObject(name),
time_(runTime),
timeFunctionObject(name, runTime),
fileToUpdate_("unknown-fileToUpdate"),
timeVsFile_(),
lastIndex_(-1),
@ -100,12 +99,6 @@ Foam::functionObjects::timeActivatedFileUpdate::timeActivatedFileUpdate
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::timeActivatedFileUpdate::~timeActivatedFileUpdate()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::timeActivatedFileUpdate::read

View File

@ -69,7 +69,7 @@ SourceFiles
#ifndef functionObjects_timeActivatedFileUpdate_H
#define functionObjects_timeActivatedFileUpdate_H
#include "functionObject.H"
#include "timeFunctionObject.H"
#include "Tuple2.H"
#include "Switch.H"
@ -85,17 +85,14 @@ namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class timeActivatedFileUpdate Declaration
Class functionObjects::timeActivatedFileUpdate Declaration
\*---------------------------------------------------------------------------*/
class timeActivatedFileUpdate
:
public functionObject
public functionObjects::timeFunctionObject
{
// Private data
//- Reference to Time
const Time& time_;
// Private Member Data
//- Name of file to update
fileName fileToUpdate_;
@ -140,7 +137,7 @@ public:
//- Destructor
virtual ~timeActivatedFileUpdate();
virtual ~timeActivatedFileUpdate() = default;
// Member Functions

View File

@ -122,8 +122,7 @@ Foam::functionObjects::vtkWrite::vtkWrite
const dictionary& dict
)
:
functionObject(name),
time_(runTime),
timeFunctionObject(name, runTime),
outputDir_(),
printf_(),
writeOpts_(vtk::formatType::INLINE_BASE64),

View File

@ -132,7 +132,7 @@ SourceFiles
#ifndef functionObjects_vtkWrite_H
#define functionObjects_vtkWrite_H
#include "functionObject.H"
#include "timeFunctionObject.H"
#include "foamVtkInternalWriter.H"
#include "foamVtkPatchWriter.H"
#include "foamVtkSeriesWriter.H"
@ -152,13 +152,10 @@ namespace functionObjects
class vtkWrite
:
public functionObject
public functionObjects::timeFunctionObject
{
// Private Data
//- Reference to the time database
const Time& time_;
//- The output directory
fileName outputDir_;

View File

@ -99,7 +99,7 @@ namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class writeObjects Declaration
Class functionObjects::writeObjects Declaration
\*---------------------------------------------------------------------------*/
class writeObjects
@ -125,7 +125,7 @@ private:
// Private data
//- Reference to Db
//- Reference to registry
const objectRegistry& obr_;
//- To only write objects of defined writeOption