timeFunctionObject: New functionObject which writes run, CPU and clock time
and optionally the CPU and clock times per time step.
Example of function object specification:
time
{
type time;
libs ("libutilityFunctionObjects.so");
writeControl timeStep;
writeInterval 1;
perTimeStep no;
}
Adding
#includeFunc time
to the functions list in the controlDict of the motorBike tutorial generates
0 1.190000e+00 1
1 1.640000e+00 1
2 1.940000e+00 2
Enabling the optional writing of the CPU and clock time per time step is
straight forward:
#includeFunc time(perTimeStep=yes)
This commit is contained in:
22
etc/caseDicts/postProcessing/numerical/time
Normal file
22
etc/caseDicts/postProcessing/numerical/time
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/*--------------------------------*- C++ -*----------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Web: www.OpenFOAM.org
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Description
|
||||||
|
Writes run time, CPU time and clock time
|
||||||
|
and optionally the CPU and clock times per time step
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
type time;
|
||||||
|
libs ("libutilityFunctionObjects.so");
|
||||||
|
|
||||||
|
writeControl timeStep;
|
||||||
|
writeInterval 1;
|
||||||
|
|
||||||
|
perTimeStep no;
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -7,5 +7,6 @@ abort/abort.C
|
|||||||
removeRegisteredObject/removeRegisteredObject.C
|
removeRegisteredObject/removeRegisteredObject.C
|
||||||
writeDictionary/writeDictionary.C
|
writeDictionary/writeDictionary.C
|
||||||
writeObjects/writeObjects.C
|
writeObjects/writeObjects.C
|
||||||
|
time/timeFunctionObject.C
|
||||||
|
|
||||||
LIB = $(FOAM_LIBBIN)/libutilityFunctionObjects
|
LIB = $(FOAM_LIBBIN)/libutilityFunctionObjects
|
||||||
|
|||||||
143
src/functionObjects/utilities/time/timeFunctionObject.C
Normal file
143
src/functionObjects/utilities/time/timeFunctionObject.C
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "timeFunctionObject.H"
|
||||||
|
#include "Time.H"
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace functionObjects
|
||||||
|
{
|
||||||
|
defineTypeNameAndDebug(time, 0);
|
||||||
|
|
||||||
|
addToRunTimeSelectionTable
|
||||||
|
(
|
||||||
|
functionObject,
|
||||||
|
time,
|
||||||
|
dictionary
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::functionObjects::time::time
|
||||||
|
(
|
||||||
|
const word& name,
|
||||||
|
const Time& runTime,
|
||||||
|
const dictionary& dict
|
||||||
|
)
|
||||||
|
:
|
||||||
|
regionFunctionObject(name, runTime, dict),
|
||||||
|
logFiles(obr_, name),
|
||||||
|
perTimeStep_(false),
|
||||||
|
cpuTime0_(time_.elapsedCpuTime()),
|
||||||
|
clockTime0_(time_.elapsedClockTime())
|
||||||
|
{
|
||||||
|
read(dict);
|
||||||
|
resetName(typeName);
|
||||||
|
write();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::functionObjects::time::~time()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
bool Foam::functionObjects::time::read(const dictionary& dict)
|
||||||
|
{
|
||||||
|
functionObject::read(dict);
|
||||||
|
|
||||||
|
dict.readIfPresent("perTimeStep", perTimeStep_);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::functionObjects::time::writeFileHeader(const label i)
|
||||||
|
{
|
||||||
|
if (Pstream::master())
|
||||||
|
{
|
||||||
|
writeHeader(file(), "time");
|
||||||
|
writeCommented(file(), "Time");
|
||||||
|
writeTabbed(file(), "cpu");
|
||||||
|
writeTabbed(file(), "clock");
|
||||||
|
|
||||||
|
if (perTimeStep_)
|
||||||
|
{
|
||||||
|
writeTabbed(file(), "cpu/step");
|
||||||
|
writeTabbed(file(), "clock/step");
|
||||||
|
}
|
||||||
|
|
||||||
|
file() << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::functionObjects::time::execute()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::functionObjects::time::write()
|
||||||
|
{
|
||||||
|
logFiles::write();
|
||||||
|
|
||||||
|
if (Pstream::master())
|
||||||
|
{
|
||||||
|
writeTime(file());
|
||||||
|
|
||||||
|
const scalar cpuTime(time_.elapsedCpuTime());
|
||||||
|
const scalar clockTime(time_.elapsedClockTime());
|
||||||
|
|
||||||
|
file() << tab << time_.elapsedCpuTime();
|
||||||
|
file() << tab << time_.elapsedClockTime();
|
||||||
|
|
||||||
|
if (perTimeStep_)
|
||||||
|
{
|
||||||
|
file() << tab << time_.elapsedCpuTime() - cpuTime0_;
|
||||||
|
file() << tab << time_.elapsedClockTime() - clockTime0_;
|
||||||
|
}
|
||||||
|
|
||||||
|
file() << endl;
|
||||||
|
|
||||||
|
cpuTime0_ = cpuTime;
|
||||||
|
clockTime0_ = clockTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
153
src/functionObjects/utilities/time/timeFunctionObject.H
Normal file
153
src/functionObjects/utilities/time/timeFunctionObject.H
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::functionObjects::time
|
||||||
|
|
||||||
|
Group
|
||||||
|
grpUtilitiesFunctionObjects
|
||||||
|
|
||||||
|
Description
|
||||||
|
Writes run time, CPU time and clock time
|
||||||
|
and optionally the CPU and clock times per time step.
|
||||||
|
|
||||||
|
Example of function object specification:
|
||||||
|
\verbatim
|
||||||
|
time
|
||||||
|
{
|
||||||
|
type time;
|
||||||
|
|
||||||
|
libs ("libutilityFunctionObjects.so");
|
||||||
|
|
||||||
|
writeControl timeStep;
|
||||||
|
writeInterval 1;
|
||||||
|
|
||||||
|
perTimeStep no;
|
||||||
|
}
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
See also
|
||||||
|
Foam::functionObject
|
||||||
|
Foam::regionFunctionObject
|
||||||
|
Foam::functionObjects::logFiles
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
time.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef timeFunctionObject_H
|
||||||
|
#define timeFunctionObject_H
|
||||||
|
|
||||||
|
#include "regionFunctionObject.H"
|
||||||
|
#include "logFiles.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace functionObjects
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class time Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class time
|
||||||
|
:
|
||||||
|
public regionFunctionObject,
|
||||||
|
public logFiles
|
||||||
|
{
|
||||||
|
// Private member data
|
||||||
|
|
||||||
|
//- Switch to write CPU and clock times per time-step
|
||||||
|
Switch perTimeStep_;
|
||||||
|
|
||||||
|
//- Previous time-step CPU time
|
||||||
|
scalar cpuTime0_;
|
||||||
|
|
||||||
|
//- Previous time-step clock time
|
||||||
|
scalar clockTime0_;
|
||||||
|
|
||||||
|
|
||||||
|
// Private member functions
|
||||||
|
|
||||||
|
//- Disallow default bitwise copy construct
|
||||||
|
time(const time&);
|
||||||
|
|
||||||
|
//- Disallow default bitwise assignment
|
||||||
|
void operator=(const time&);
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Protected Member Functions
|
||||||
|
|
||||||
|
//- Output file header information
|
||||||
|
virtual void writeFileHeader(const label i);
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Runtime type information
|
||||||
|
TypeName("time");
|
||||||
|
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct from Time and dictionary
|
||||||
|
time
|
||||||
|
(
|
||||||
|
const word& name,
|
||||||
|
const Time& runTime,
|
||||||
|
const dictionary& dict
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//- Destructor
|
||||||
|
virtual ~time();
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Read the controls
|
||||||
|
virtual bool read(const dictionary&);
|
||||||
|
|
||||||
|
//- Execute, currently does nothing
|
||||||
|
virtual bool execute();
|
||||||
|
|
||||||
|
//- Write the time
|
||||||
|
virtual bool write();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace functionObjects
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
Reference in New Issue
Block a user