averageCondition.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) 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 "averageCondition.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace functionObjects
36 {
37 namespace runTimeControls
38 {
41 }
42 }
43 }
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
48 (
49  const word& name,
50  const objectRegistry& obr,
51  const dictionary& dict,
52  stateFunctionObject& state
53 )
54 :
55  runTimeCondition(name, obr, dict, state),
56  valueAverageBase(name, obr_, dict, state, false),
57  nIterStartUp_(dict.getOrDefault<label>("nIterStartUp", 10)),
58  iter_(-1)
59 {
61 
62  readState(conditionDict);
63 
65 }
66 
67 
68 // * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
69 
71 {
72  if (!active_)
73  {
74  return true;
75  }
76 
77  bool running = iter_ > nIterStartUp_;
78 
79  ++iter_;
80 
81  dictionary& conditionDict = this->conditionDict();
82 
83 
84  Info<< incrIndent;
85  running = valueAverageBase::calculate(conditionDict) && running;
86  Info<< decrIndent;
87 
88  return running;
89 }
90 
91 
93 {
94  dictionary& conditionDict = this->conditionDict();
95 
96  valueAverageBase::writeState(conditionDict);
97 
98  conditionDict.set("iter", iter_);
99 }
100 
101 
103 {
104  valueAverageBase::resetState(this->conditionDict());
105 
106  iter_ = 0;
107 }
108 
109 
110 // ************************************************************************* //
dictionary dict
virtual void writeState(dictionary &dict)
Write state to dictionary for restarts.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual bool calculate(dictionary &dict)
Calculate the averages.
Macros for easy insertion into run-time selection tables.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
virtual void readState(dictionary &dict)
Read state from dictionary.
A class for handling words, derived from Foam::string.
Definition: word.H:63
Average run time condition - satisfied when average does not change by more than a given value...
defineTypeNameAndDebug(averageCondition, 0)
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:511
averageCondition(const word &name, const objectRegistry &obr, const dictionary &dict, stateFunctionObject &state)
Constructor.
addToRunTimeSelectionTable(runTimeCondition, averageCondition, dictionary)
messageStream Info
Information stream (stdout output on master, null elsewhere)
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition: dictionary.C:765
Registry of regIOobjects.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:502
virtual void resetState(dictionary &dict)
Reset state.
const dictionary & conditionDict() const
Return const access to the conditions dictionary.
Namespace for OpenFOAM.