timeFunctionObject.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2018-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
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 
26 #include "timeFunctionObject.H"
27 #include "Time.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace functionObjects
35 {
36  defineTypeNameAndDebug(time, 0);
37 
39  (
40  functionObject,
41  time,
42  dictionary
43  );
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
51 (
52  const word& name,
53  const Time& runTime,
54  const dictionary& dict
55 )
56 :
57  regionFunctionObject(name, runTime, dict),
58  logFiles(obr_, name),
59  perTimeStep_(false),
60  cpuTime0_(time_.elapsedCpuTime()),
61  clockTime0_(time_.elapsedClockTime())
62 {
63  read(dict);
64 }
65 
66 
67 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
68 
70 {}
71 
72 
73 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
74 
76 {
78 
79  dict.readIfPresent("perTimeStep", perTimeStep_);
80 
81  resetName(typeName);
82 
83  return true;
84 }
85 
86 
88 {
89  if (Pstream::master())
90  {
91  writeHeader(file(), "time");
92  writeCommented(file(), "Time");
93  writeTabbed(file(), "cpu");
94  writeTabbed(file(), "clock");
95 
96  if (perTimeStep_)
97  {
98  writeTabbed(file(), "cpu/step");
99  writeTabbed(file(), "clock/step");
100  }
101 
102  file() << endl;
103  }
104 }
105 
106 
108 {
109  return true;
110 }
111 
112 
114 {
115  logFiles::write();
116 
117  if (Pstream::master())
118  {
119  writeTime(file());
120 
121  const scalar cpuTime(time_.elapsedCpuTime());
122  const scalar clockTime(time_.elapsedClockTime());
123 
124  file() << tab << time_.elapsedCpuTime();
125  file() << tab << time_.elapsedClockTime();
126 
127  if (perTimeStep_)
128  {
129  file() << tab << time_.elapsedCpuTime() - cpuTime0_;
130  file() << tab << time_.elapsedClockTime() - clockTime0_;
131  }
132 
133  file() << endl;
134 
135  cpuTime0_ = cpuTime;
136  clockTime0_ = clockTime;
137  }
138 
139  return true;
140 }
141 
142 
143 // ************************************************************************* //
Specialisation of Foam::functionObject for a region and providing a reference to the region Foam::obj...
virtual bool write()
Write function.
Definition: logFiles.C:167
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
virtual void writeFileHeader(const label i)
Output file header information.
static const char tab
Definition: Ostream.H:259
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
virtual ~time()
Destructor.
Macros for easy insertion into run-time selection tables.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
void writeHeader(std::ostream &, const bool isBinary, const std::string &title)
Write header.
A class for handling words, derived from string.
Definition: word.H:59
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
virtual bool read(const dictionary &)
Read and set the functionObject if its data have changed.
time(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
virtual bool write()
Write the time.
defineTypeNameAndDebug(Qdot, 0)
Starts timing CPU usage and return elapsed time from start.
Definition: cpuTime.H:52
virtual bool execute()
Execute, currently does nothing.
Namespace for OpenFOAM.
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:57
Starts timing (using rtc) and returns elapsed time from start. Better resolution (2uSec instead of ~2...
Definition: clockTime.H:49
virtual bool read(const dictionary &)
Read the controls.