Loading...
Searching...
No Matches
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"
28// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
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 }
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{
81}
82
83
84// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
85
87{
90
91 perTimeStep_ = dict.getOrDefault("perTimeStep", false);
92 return true;
93}
94
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:59
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition UPstream.H:1714
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Abstract base-class for Time/database function objects.
const word & name() const noexcept
Return the name of this functionObject.
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
Virtual base class for function objects with a reference to Time.
const Time & time_
Reference to the time database.
timeFunctionObject(const timeFunctionObject &)=delete
No copy construct.
Writes the run time (time-step), cpuTime and clockTime - optionally with cpuTime and clockTime change...
Definition timeInfo.H:112
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
Definition timeInfo.C:79
virtual void writeFileHeader(Ostream &os)
Output file header information.
Definition timeInfo.C:41
virtual bool execute()
Execute the function-object operations (no-op).
Definition timeInfo.C:89
timeInfo(const timeInfo &)=delete
No copy construct.
virtual bool write()
Write the function-object results.
Definition timeInfo.C:95
Base class for writing single files from the function objects.
Definition writeFile.H:113
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition writeFile.C:334
writeFile(const objectRegistry &obr, const fileName &prefix, const word &name="undefined", const bool writeToFile=true, const string &ext=".dat")
Construct from objectRegistry, prefix, fileName.
Definition writeFile.C:200
virtual bool read(const dictionary &dict)
Read.
Definition writeFile.C:240
virtual OFstream & file()
Return access to the file (if only 1).
Definition writeFile.C:270
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition writeFile.C:318
virtual void writeCurrentTime(Ostream &os) const
Write the current time to stream.
Definition writeFile.C:354
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
constexpr char tab
The tab '\t' character(0x09).
Definition Ostream.H:49
dictionary dict