diff --git a/etc/caseDicts/postProcessing/numerical/time b/etc/caseDicts/postProcessing/numerical/time new file mode 100644 index 0000000000..0e519a5d65 --- /dev/null +++ b/etc/caseDicts/postProcessing/numerical/time @@ -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; + +// ************************************************************************* // diff --git a/src/functionObjects/utilities/Make/files b/src/functionObjects/utilities/Make/files index 870ee734ce..94c6bab14f 100644 --- a/src/functionObjects/utilities/Make/files +++ b/src/functionObjects/utilities/Make/files @@ -7,5 +7,6 @@ abort/abort.C removeRegisteredObject/removeRegisteredObject.C writeDictionary/writeDictionary.C writeObjects/writeObjects.C +time/timeFunctionObject.C LIB = $(FOAM_LIBBIN)/libutilityFunctionObjects diff --git a/src/functionObjects/utilities/time/timeFunctionObject.C b/src/functionObjects/utilities/time/timeFunctionObject.C new file mode 100644 index 0000000000..d61db9b4fd --- /dev/null +++ b/src/functionObjects/utilities/time/timeFunctionObject.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#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; +} + + +// ************************************************************************* // diff --git a/src/functionObjects/utilities/time/timeFunctionObject.H b/src/functionObjects/utilities/time/timeFunctionObject.H new file mode 100644 index 0000000000..903292095d --- /dev/null +++ b/src/functionObjects/utilities/time/timeFunctionObject.H @@ -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 . + +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 + +// ************************************************************************* //