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-2020 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  (
71  !resetOnRestart_
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_;
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 
113 // ************************************************************************* //
Foam::functionObjects::runTimeControls::defineTypeNameAndDebug
defineTypeNameAndDebug(averageCondition, 0)
Log
#define Log
Definition: PDRblock.C:35
Foam::functionObjects::runTimeControls::runTimeCondition
Base class for run time conditions.
Definition: runTimeCondition.H:61
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::functionObjects::runTimeControls::runTimeCondition::active_
bool active_
On/off switch.
Definition: runTimeCondition.H:78
Foam::TimeState::timeToUserTime
virtual scalar timeToUserTime(const scalar t) const
Convert the real-time (s) into user-time (e.g. CA deg)
Definition: TimeState.C:55
Foam::functionObjects::runTimeControls::addToRunTimeSelectionTable
addToRunTimeSelectionTable(runTimeCondition, averageCondition, dictionary)
Foam::functionObjects::stateFunctionObject
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: stateFunctionObject.H:69
Foam::functionObjects::runTimeControls::maxDurationCondition::startTime_
scalar startTime_
Time when the condition is activated.
Definition: maxDurationCondition.H:67
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:434
Foam::functionObjects::runTimeControls::maxDurationCondition::apply
virtual bool apply()
Apply the condition.
Definition: maxDurationCondition.C:81
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::functionObjects::runTimeControls::maxDurationCondition::write
virtual void write()
Write.
Definition: maxDurationCondition.C:104
Foam::functionObjects::runTimeControls::runTimeCondition::obr_
const objectRegistry & obr_
Reference to the object registry.
Definition: runTimeCondition.H:72
Foam::functionObjects::runTimeControls::maxDurationCondition::maxDurationCondition
maxDurationCondition(const word &name, const objectRegistry &obr, const dictionary &dict, stateFunctionObject &state)
Constructor.
Definition: maxDurationCondition.C:56
delta
scalar delta
Definition: LISASMDCalcMethod2.H:8
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Time.H
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::functionObjects::runTimeControls::maxDurationCondition::duration_
scalar duration_
Duration.
Definition: maxDurationCondition.H:64
maxDurationCondition.H
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::functionObjects::runTimeControls::runTimeCondition::name_
word name_
Condition name.
Definition: runTimeCondition.H:69
Foam::objectRegistry::time
const Time & time() const noexcept
Return time registry.
Definition: objectRegistry.H:178
Foam::functionObjects::runTimeControls::maxDurationCondition::initialised_
bool initialised_
Initialisation flag.
Definition: maxDurationCondition.H:70