From f44899b4c548a692166395c8a1634b6258c566bc Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 18 Dec 2020 16:06:03 +0000 Subject: [PATCH] functionObjects::setWriteInterval: Added files --- .../setWriteIntervalFunctionObject.C | 101 +++++++++++++ .../setWriteIntervalFunctionObject.H | 141 ++++++++++++++++++ 2 files changed, 242 insertions(+) create mode 100644 src/functionObjects/utilities/setWriteInterval/setWriteIntervalFunctionObject.C create mode 100644 src/functionObjects/utilities/setWriteInterval/setWriteIntervalFunctionObject.H diff --git a/src/functionObjects/utilities/setWriteInterval/setWriteIntervalFunctionObject.C b/src/functionObjects/utilities/setWriteInterval/setWriteIntervalFunctionObject.C new file mode 100644 index 0000000000..a86f5f6a07 --- /dev/null +++ b/src/functionObjects/utilities/setWriteInterval/setWriteIntervalFunctionObject.C @@ -0,0 +1,101 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2020 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 "setWriteIntervalFunctionObject.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(setWriteIntervalFunctionObject, 0); + + addToRunTimeSelectionTable + ( + functionObject, + setWriteIntervalFunctionObject, + dictionary + ); +} +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::setWriteIntervalFunctionObject:: +setWriteIntervalFunctionObject +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + functionObject(name), + time_(runTime) +{ + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::setWriteIntervalFunctionObject:: +~setWriteIntervalFunctionObject() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::setWriteIntervalFunctionObject::read +( + const dictionary& dict +) +{ + writeIntervalPtr_ = Function1::New("writeInterval", dict); + + return true; +} + + +bool Foam::functionObjects::setWriteIntervalFunctionObject::execute() +{ + const_cast(time_).setWriteInterval + ( + writeIntervalPtr_().value(time_.timeOutputValue()) + ); + + return true; +} + + +bool Foam::functionObjects::setWriteIntervalFunctionObject::write() +{ + return true; +} + + +// ************************************************************************* // diff --git a/src/functionObjects/utilities/setWriteInterval/setWriteIntervalFunctionObject.H b/src/functionObjects/utilities/setWriteInterval/setWriteIntervalFunctionObject.H new file mode 100644 index 0000000000..76f5123d57 --- /dev/null +++ b/src/functionObjects/utilities/setWriteInterval/setWriteIntervalFunctionObject.H @@ -0,0 +1,141 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2020 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::setWriteIntervalFunctionObject + +Description + Updates the writeInterval as a Function1 of time. + + Examples of function object specification: + \verbatim + setWriteInterval + { + type setWriteInterval; + libs ("libutilityFunctionObjects.so"); + + writeInterval table + ( + (0 0.005) + (0.1 0.005) + (0.1001 0.01) + (0.2 0.01) + (0.2001 0.02) + ); + } + \endverbatim + will cause results to be written every 0.005s between 0 and 0.1s, every + 0.01s between 0.1 and 0.2s and every 0.02s thereafter. + +SourceFiles + setWriteIntervalFunctionObject.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_setWriteIntervalFunctionObject_H +#define functionObjects_setWriteIntervalFunctionObject_H + +#include "functionObject.H" +#include "Function1.H" +#include "Time.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class setWriteIntervalFunctionObject Declaration +\*---------------------------------------------------------------------------*/ + +class setWriteIntervalFunctionObject +: + public functionObject +{ + // Private Data + + //- Reference to the time database + const Time& time_; + + //- Time step function/table + autoPtr> writeIntervalPtr_; + + +public: + + //- Runtime type information + TypeName("setWriteInterval"); + + + // Constructors + + //- Construct from components + setWriteIntervalFunctionObject + ( + const word& name, + const Time& runTime, + const dictionary& dict + ); + + //- Disallow default bitwise copy construction + setWriteIntervalFunctionObject + ( + const setWriteIntervalFunctionObject& + ) = delete; + + + // Destructor + virtual ~setWriteIntervalFunctionObject(); + + + // Member Functions + + //- Read and reset the writeInterval Function1 + virtual bool read(const dictionary&); + + //- Reset the writeInterval from the Function1 of time + virtual bool execute(); + + //- Do nothing + virtual bool write(); + + + // Member Operators + + //- Disallow default bitwise assignment + void operator=(const setWriteIntervalFunctionObject&) = delete; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //