maxDurationCondition.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2018-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
30#include "Time.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
36namespace functionObjects
37{
38namespace runTimeControls
39{
42 (
46 );
47}
48}
49}
50
51
52// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53
54Foam::functionObjects::runTimeControls::maxDurationCondition::
55maxDurationCondition
56(
57 const word& name,
58 const objectRegistry& obr,
59 const dictionary& dict,
61)
62:
63 runTimeCondition(name, obr, dict, state),
64 duration_(dict.get<scalar>("duration")),
65 startTime_(-1),
66 initialised_(false),
67 resetOnRestart_(dict.getOrDefault("resetOnRestart", false))
68{
69 if
70 (
72 && conditionDict().readIfPresent("startTime", startTime_))
73 {
74 initialised_ = true;
75 }
76}
77
78
79// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
80
82{
83 if (!active_)
84 {
85 return true;
86 }
87
88 if (!initialised_)
89 {
90 startTime_ = obr_.time().value();
91 initialised_ = true;
92 }
93
94 scalar delta = obr_.time().value() - startTime_;
95 delta = obr_.time().timeToUserTime(delta);
96
97 Log << " " << type() << ": " << name_ << nl
98 << " Completed " << delta << " out of " << duration_ << nl;
99
100 return delta >= duration_;
101}
102
103
105{
106 if (initialised_)
107 {
108 conditionDict().set("startTime", startTime_);
109 }
110}
111
112
114{
115 initialised_ = false;
116}
117
118
119// ************************************************************************* //
scalar delta
#define Log
Definition: PDRblock.C:35
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Switch resetOnRestart_
Reset on restart (ignores any state information)
scalar startTime_
Time when the condition is activated.
const dictionary & conditionDict() const
Return const access to the conditions dictionary.
Base class for function objects, adding functionality to read/write state information (data required ...
Registry of regIOobjects.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
Namespace for OpenFOAM.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
propsDict readIfPresent("fields", acceptFields)