functionObjects::stopAtClockTime: New functionObject to stop the run when the specified clock time is exceeded

Description
    Stops the run when the specified clock time in second has been reached
    and optionally write results before stopping.

    The following actions are supported:
    - noWriteNow
    - writeNow
    - nextWrite (default)

    Examples of function object specification:
    \verbatim
    stop
    {
        type        stopAtClockTime;
        libs        ("libutilityFunctionObjects.so");
        stopTime    10;
        action      writeNow;
    }
    \endverbatim
    will stop the run at the next write after the file "stop" is created in the
    case directory.

Usage
    \table
        Property | Description              | Required | Default value
        type     | type name: stopAtClockTime | yes    |
        stopTime | Maximum elapsed time [s] | yes      |
        action   | Action executed          | no       | nextWrite
    \endtable
This commit is contained in:
Henry Weller
2020-07-17 11:13:46 +01:00
parent e1c41275ac
commit 5bfd3b2488
8 changed files with 268 additions and 19 deletions

View File

@ -5,6 +5,7 @@ setTimeStep/setTimeStepFunctionObject.C
systemCall/systemCall.C
stopAt/stopAt.C
stopAt/stopAtFile/stopAtFile.C
stopAt/stopAtClockTime/stopAtClockTime.C
removeRegisteredObject/removeRegisteredObject.C
writeDictionary/writeDictionary.C
writeObjects/writeObjects.C

View File

@ -69,9 +69,7 @@ Foam::functionObjects::stopAt::stopAt
time_(runTime),
action_(actionType::nextWrite),
stopped_(false)
{
read(dict);
}
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //

View File

@ -0,0 +1,89 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020 OpenFOAM Foundation
\\/ 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 "stopAtClockTime.H"
#include "Time.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(stopAtClockTime, 0);
addToRunTimeSelectionTable
(
functionObject,
stopAtClockTime,
dictionary
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::stopAtClockTime::condition() const
{
return time_.elapsedClockTime() > stopTime_;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::stopAtClockTime::stopAtClockTime
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
stopAt(name, runTime, dict),
stopTime_(0)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::stopAtClockTime::~stopAtClockTime()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::stopAtClockTime::read(const dictionary& dict)
{
stopAt::read(dict);
dict.lookup("stopTime") >> stopTime_;
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,140 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020 OpenFOAM Foundation
\\/ 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::stopAtClockTime
Description
Stops the run when the specified clock time in second has been reached
and optionally write results before stopping.
The following actions are supported:
- noWriteNow
- writeNow
- nextWrite (default)
Examples of function object specification:
\verbatim
stop
{
type stopAtClockTime;
libs ("libutilityFunctionObjects.so");
stopTime 10;
action writeNow;
}
\endverbatim
will stop the run at the next write after the file "stop" is created in the
case directory.
Usage
\table
Property | Description | Required | Default value
type | type name: stopAtClockTime | yes |
stopTime | Maximum elapsed time [s] | yes |
action | Action executed | no | nextWrite
\endtable
SourceFiles
stopAtClockTime.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_stopAtClockTime_H
#define functionObjects_stopAtClockTime_H
#include "stopAt.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class stopAtClockTime Declaration
\*---------------------------------------------------------------------------*/
class stopAtClockTime
:
public stopAt
{
// Private Data
//-
time_t stopTime_;
// Private Member Functions
//- Return true when the stop condition is achieved
virtual bool condition() const;
public:
//- Runtime type information
TypeName("stopAtClockTime");
// Constructors
//- Construct from Time and dictionary
stopAtClockTime
(
const word& name,
const Time& runTime,
const dictionary&
);
//- Disallow default bitwise copy construction
stopAtClockTime(const stopAtClockTime&) = delete;
//- Destructor
virtual ~stopAtClockTime();
// Member Functions
//- Read the dictionary settings
virtual bool read(const dictionary&);
// Member Operators
//- Disallow default bitwise assignment
void operator=(const stopAtClockTime&) = delete;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -64,9 +64,7 @@ void Foam::functionObjects::stopAtFile::removeFile() const
bool Foam::functionObjects::stopAtFile::condition() const
{
bool fileExists = isFile(stopAtFileFile_);
reduce(fileExists, orOp<bool>());
return fileExists;
return isFile(stopAtFileFile_);
}
@ -100,6 +98,8 @@ Foam::functionObjects::stopAtFile::~stopAtFile()
bool Foam::functionObjects::stopAtFile::read(const dictionary& dict)
{
stopAt::read(dict);
if (dict.readIfPresent("file", stopAtFileFile_))
{
stopAtFileFile_.expand();

View File

@ -25,23 +25,23 @@ Class
Foam::functionObjects::stopAtFile
Description
Stops the run when the specified file is created in the case directory.
Stops the run when the specified file is created in the case directory
and optionally write results before stopping.
The default name of the trigger file is \c $FOAM_CASE/<name> where \c
<name> is the name of the functionObject entry and the default action is \c
nextWrite.
<name> is the name of the functionObject entry.
Currently the following action types are supported:
- noWriteNow
- writeNow
- nextWrite
- nextWrite (default)
Examples of function object specification:
\verbatim
stop
{
type stopAtFile;
libs ("libutilityFunctionObjects.so");
type stopAtFile;
libs ("libutilityFunctionObjects.so");
}
\endverbatim
will stop the run at the next write after the file "stop" is created in the
@ -50,10 +50,10 @@ Description
\verbatim
stop
{
type stopAtFile;
libs ("libutilityFunctionObjects.so");
file "$FOAM_CASE/stop";
action writeNow;
type stopAtFile;
libs ("libutilityFunctionObjects.so");
file "$FOAM_CASE/stop";
action writeNow;
}
\endverbatim
will write the fields and stop the run when the file "stop" is created in