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 -------------------------------------------------------------------------------
10 License
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 
28 #include "maxDurationCondition.H"
30 #include "Time.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionObjects
37 {
38 namespace runTimeControls
39 {
40  defineTypeNameAndDebug(maxDurationCondition, 0);
42  (
43  runTimeCondition,
44  maxDurationCondition,
45  dictionary
46  );
47 }
48 }
49 }
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
56 (
57  const word& name,
58  const objectRegistry& obr,
59  const dictionary& dict,
60  stateFunctionObject& state
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 {
107  {
108  conditionDict().set("startTime", startTime_);
109  }
110 }
111 
112 
114 {
115  initialised_ = false;
116 }
117 
118 
119 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
scalar delta
dictionary dict
static bool initialised_(false)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
scalar startTime_
Time when the condition is activated.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Macros for easy insertion into run-time selection tables.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
Switch resetOnRestart_
Reset on restart (ignores any state information)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
defineTypeNameAndDebug(averageCondition, 0)
addToRunTimeSelectionTable(runTimeCondition, averageCondition, dictionary)
meshDefDict readIfPresent("polyMeshPatches", polyPatchNames)
#define Log
Definition: PDRblock.C:28
Base class for function objects, adding functionality to read/write state information (data required ...
Registry of regIOobjects.
const dictionary & conditionDict() const
Return const access to the conditions dictionary.
maxDurationCondition(const word &name, const objectRegistry &obr, const dictionary &dict, stateFunctionObject &state)
Constructor.
Namespace for OpenFOAM.