diff --git a/etc/caseDicts/postProcessing/control/stopAtClockTime b/etc/caseDicts/postProcessing/control/stopAtClockTime new file mode 100644 index 0000000000..3deafeeb88 --- /dev/null +++ b/etc/caseDicts/postProcessing/control/stopAtClockTime @@ -0,0 +1,20 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: dev + \\/ M anipulation | +------------------------------------------------------------------------------- +Description + Stops the run when the specified clock time in second has been reached + and optionally write results before stopping. + +\*---------------------------------------------------------------------------*/ + +type stopAtClockTime; +libs ("libutilityFunctionObjects.so"); + +stopTime ; +action nextWrite; + +// ************************************************************************* // diff --git a/etc/caseDicts/postProcessing/control/stopAtFile b/etc/caseDicts/postProcessing/control/stopAtFile index fcd51670f2..ac3bcb5e4c 100644 --- a/etc/caseDicts/postProcessing/control/stopAtFile +++ b/etc/caseDicts/postProcessing/control/stopAtFile @@ -10,9 +10,10 @@ Description \*---------------------------------------------------------------------------*/ -type stopAtFile; -libs ("libutilityFunctionObjects.so"); +type stopAtFile; +libs ("libutilityFunctionObjects.so"); -file "$FOAM_CASE/stop"; +file "$FOAM_CASE/stop"; +action nextWrite; // ************************************************************************* // diff --git a/src/functionObjects/utilities/Make/files b/src/functionObjects/utilities/Make/files index dba261b06e..19c8063eb1 100644 --- a/src/functionObjects/utilities/Make/files +++ b/src/functionObjects/utilities/Make/files @@ -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 diff --git a/src/functionObjects/utilities/stopAt/stopAt.C b/src/functionObjects/utilities/stopAt/stopAt.C index ea38444657..b9b279ae73 100644 --- a/src/functionObjects/utilities/stopAt/stopAt.C +++ b/src/functionObjects/utilities/stopAt/stopAt.C @@ -69,9 +69,7 @@ Foam::functionObjects::stopAt::stopAt time_(runTime), action_(actionType::nextWrite), stopped_(false) -{ - read(dict); -} +{} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // diff --git a/src/functionObjects/utilities/stopAt/stopAtClockTime/stopAtClockTime.C b/src/functionObjects/utilities/stopAt/stopAtClockTime/stopAtClockTime.C new file mode 100644 index 0000000000..3b990cd9ce --- /dev/null +++ b/src/functionObjects/utilities/stopAt/stopAtClockTime/stopAtClockTime.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#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; +} + + +// ************************************************************************* // diff --git a/src/functionObjects/utilities/stopAt/stopAtClockTime/stopAtClockTime.H b/src/functionObjects/utilities/stopAt/stopAtClockTime/stopAtClockTime.H new file mode 100644 index 0000000000..de71919588 --- /dev/null +++ b/src/functionObjects/utilities/stopAt/stopAtClockTime/stopAtClockTime.H @@ -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 . + +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 + +// ************************************************************************* // diff --git a/src/functionObjects/utilities/stopAt/stopAtFile/stopAtFile.C b/src/functionObjects/utilities/stopAt/stopAtFile/stopAtFile.C index d37f0edb64..c7634b4731 100644 --- a/src/functionObjects/utilities/stopAt/stopAtFile/stopAtFile.C +++ b/src/functionObjects/utilities/stopAt/stopAtFile/stopAtFile.C @@ -64,9 +64,7 @@ void Foam::functionObjects::stopAtFile::removeFile() const bool Foam::functionObjects::stopAtFile::condition() const { - bool fileExists = isFile(stopAtFileFile_); - reduce(fileExists, orOp()); - 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(); diff --git a/src/functionObjects/utilities/stopAt/stopAtFile/stopAtFile.H b/src/functionObjects/utilities/stopAt/stopAtFile/stopAtFile.H index 303b9c018b..9e71224052 100644 --- a/src/functionObjects/utilities/stopAt/stopAtFile/stopAtFile.H +++ b/src/functionObjects/utilities/stopAt/stopAtFile/stopAtFile.H @@ -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/ where \c - is the name of the functionObject entry and the default action is \c - nextWrite. + 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