timeInfo.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 OpenFOAM Foundation
9 Copyright (C) 2019-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
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 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 for more details.
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23\*---------------------------------------------------------------------------*/
24
25#include "timeInfo.H"
27
28// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29
30namespace Foam
31{
32namespace functionObjects
33{
35
37 (
41 );
42}
43}
44
45
46// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
47
49{
50 writeCommented(os, "Time");
51 writeTabbed(os, "cpuTime");
52 writeTabbed(os, "clockTime");
53
54 if (perTimeStep_)
55 {
56 writeTabbed(os, "cpu/step");
57 writeTabbed(os, "clock/step");
58 }
59
60 os << nl;
61}
62
63
64// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
65
67(
68 const word& name,
69 const Time& runTime,
70 const dictionary& dict
71)
72:
74 writeFile(time_, name, typeName, dict),
75 cpuTime0_(Zero),
76 clockTime0_(Zero),
77 perTimeStep_(false)
78{
79 read(dict);
81}
82
83
84// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
85
87{
90
91 perTimeStep_ = dict.getOrDefault("perTimeStep", false);
92 return true;
93}
94
95
97{
98 return true;
99}
100
101
103{
104 if (Pstream::master())
105 {
106 writeCurrentTime(file());
107
108 const scalar cpuTimeNow(time_.elapsedCpuTime());
109 const scalar clockTimeNow(time_.elapsedClockTime());
110
111 file()
112 << tab << cpuTimeNow
113 << tab << clockTimeNow;
114
115 if (perTimeStep_)
116 {
117 file()
118 << tab << (cpuTimeNow - cpuTime0_)
119 << tab << (clockTimeNow - clockTime0_);
120
121 cpuTime0_ = cpuTimeNow;
122 clockTime0_ = clockTimeNow;
123 }
124
125 file() << nl;
126 }
127
128 return true;
129}
130
131
132// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual bool read()
Re-read model coefficients if they have changed.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Abstract base-class for Time/database function objects.
Virtual base class for function objects with a reference to Time.
Writes the run time (time-step), cpuTime and clockTime - optionally with cpuTime and clockTime change...
Definition: timeInfo.H:109
virtual bool read(const dictionary &dict)
Read the controls.
Definition: timeInfo.C:86
virtual void writeFileHeader(Ostream &os)
Output file header information.
Definition: timeInfo.C:48
virtual bool execute()
Execute, does nothing.
Definition: timeInfo.C:96
virtual bool write()
Write the timeInfo.
Definition: timeInfo.C:102
Base class for writing single files from the function objects.
Definition: writeFile.H:120
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:285
virtual OFstream & file()
Return access to the file (if only 1)
Definition: writeFile.C:233
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:269
splitCell * master() const
Definition: splitCell.H:113
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
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
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
constexpr char tab
The tab '\t' character(0x09)
Definition: Ostream.H:52
dictionary dict