setTimeStepFunctionObject.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) 2013-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionObjects
37 {
38  defineTypeNameAndDebug(setTimeStepFunctionObject, 0);
39 
41  (
42  functionObject,
43  setTimeStepFunctionObject,
44  dictionary
45  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
52 Foam::functionObjects::setTimeStepFunctionObject::setTimeStepFunctionObject
53 (
54  const word& name,
55  const Time& runTime,
56  const dictionary& dict
57 )
58 :
60 {
61  read(dict);
62 }
63 
64 
65 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
66 
68 {
69  // Wanted timestep
70  scalar newDeltaT = timeStepPtr_().value(time_.timeOutputValue());
71 
72  static label index = -1;
73 
74  if (time_.timeIndex() != index)
75  {
76  // Store current time so we don't get infinite recursion (since
77  // setDeltaT calls adjustTimeStep() again)
78  index = time_.timeIndex();
79 
80  // Set time, allow deltaT to be adjusted for writeInterval purposes
81  const_cast<Time&>(time_).setDeltaT(newDeltaT, false);
82  }
83 
84  return true;
85 }
86 
87 
89 (
90  const dictionary& dict
91 )
92 {
94 
95  timeStepPtr_ = Function1<scalar>::New("deltaT", dict, &time_);
96 
97  // Ensure that adjustTimeStep is active
98  if (!time_.controlDict().getOrDefault("adjustTimeStep", false))
99  {
101  << "Need to set 'adjustTimeStep' true to allow timestep control"
102  << nl
103  << exit(FatalIOError);
104  }
105 
106  return true;
107 }
108 
109 
111 {
112  return true;
113 }
114 
115 
117 {
118  return true;
119 }
120 
121 
122 // ************************************************************************* //
Foam::TimeState::timeOutputValue
scalar timeOutputValue() const
Return current time value.
Definition: TimeStateI.H:31
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::functionObjects::timeFunctionObject::time_
const Time & time_
Reference to the time database.
Definition: timeFunctionObject.H:65
Foam::functionObjects::setTimeStepFunctionObject::read
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
Definition: setTimeStepFunctionObject.C:89
Foam::functionObjects::timeFunctionObject
Virtual base class for function objects with a reference to Time.
Definition: timeFunctionObject.H:56
Foam::FatalIOError
IOerror FatalIOError
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: propellerInfo.H:291
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
Foam::TimeState::timeIndex
label timeIndex() const noexcept
Return current time index.
Definition: TimeStateI.H:37
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::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
setTimeStepFunctionObject.H
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::functionObjects::setTimeStepFunctionObject::write
virtual bool write()
Write does nothing.
Definition: setTimeStepFunctionObject.C:116
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
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::functionObjects::setTimeStepFunctionObject::execute
virtual bool execute()
Execute does nothing.
Definition: setTimeStepFunctionObject.C:110
Foam::functionObjects::setTimeStepFunctionObject::adjustTimeStep
virtual bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
Definition: setTimeStepFunctionObject.C:67