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 -------------------------------------------------------------------------------
11 License
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 
30 namespace Foam
31 {
32 namespace functionObjects
33 {
34  defineTypeNameAndDebug(timeInfo, 0);
35 
37  (
38  functionObject,
39  timeInfo,
40  dictionary
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);
80  writeFileHeader(file());
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 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::functionObjects::timeFunctionObject
Virtual base class for function objects with a reference to Time.
Definition: timeFunctionObject.H:56
Foam::functionObjects::timeInfo::writeFileHeader
virtual void writeFileHeader(Ostream &os)
Output file header information.
Definition: timeInfo.C:48
timeInfo.H
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Am I the master process.
Definition: UPstream.H:457
Foam::functionObjects::timeInfo::timeInfo
timeInfo(const timeInfo &)=delete
No copy construct.
Foam::functionObjects::writeFile::read
virtual bool read(const dictionary &dict)
Read.
Definition: writeFile.C:213
Foam::functionObject::read
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
Definition: functionObject.C:163
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::functionObjects::timeInfo::read
virtual bool read(const dictionary &dict)
Read the controls.
Definition: timeInfo.C:86
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::timeInfo::execute
virtual bool execute()
Execute, does nothing.
Definition: timeInfo.C:96
Foam::functionObjects::writeFile::writeCommented
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:272
Foam::tab
constexpr char tab
Definition: Ostream.H:403
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::functionObjects::writeFile
Base class for writing single files from the function objects.
Definition: writeFile.H:119
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::functionObjects::writeFile::writeTabbed
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:288
Foam::functionObjects::timeInfo::write
virtual bool write()
Write the timeInfo.
Definition: timeInfo.C:102