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 | Copyright (C) 2013 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 
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  defineTypeNameAndDebug(setTimeStepFunctionObject, 0);
34 
36  (
37  functionObject,
38  setTimeStepFunctionObject,
39  dictionary
40  );
41 }
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
46 Foam::setTimeStepFunctionObject::setTimeStepFunctionObject
47 (
48  const word& name,
49  const Time& runTime,
50  const dictionary& dict
51 )
52 :
53  functionObject(name),
54  time_(runTime),
55  enabled_(true)
56 {
57  read(dict);
58 }
59 
60 
61 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
62 
64 {
65  enabled_ = true;
66 }
67 
68 
70 {
71  enabled_ = false;
72 }
73 
74 
76 {
77  return true;
78 }
79 
80 
81 bool Foam::setTimeStepFunctionObject::execute(const bool forceWrite)
82 {
83  return true;
84 }
85 
86 
88 {
89  return true;
90 }
91 
92 
94 {
95  return true;
96 }
97 
98 
100 {
101  if (enabled())
102  {
103  // Wanted timestep
104  scalar newDeltaT = timeStepPtr_().value(time_.timeOutputValue());
105 
106  const_cast<Time&>(time()).setDeltaT(newDeltaT, false);
107 
108  return true;
109  }
110  else
111  {
112  return false;
113  }
114 }
115 
116 
118 {
119  enabled_ = dict.lookupOrDefault("enabled", true);
120 
121  if (enabled_)
122  {
123  timeStepPtr_ = DataEntry<scalar>::New("deltaT", dict);
124 
125  // Check that time has adjustTimeStep
126  const dictionary& controlDict = time_.controlDict();
127 
128  Switch adjust;
129  if
130  (
131  !controlDict.readIfPresent<Switch>("adjustTimeStep", adjust)
132  || !adjust
133  )
134  {
135  FatalIOErrorIn("setTimeStep::read(const dictionary&)", dict)
136  << "Need to have 'adjustTimeStep' true to enable external"
137  << " timestep control" << exit(FatalIOError);
138  }
139  }
140  return true;
141 }
142 
143 
145 {}
146 
147 
149 {}
150 
151 
152 // ************************************************************************* //
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Abstract base-class for Time/database function objects.
virtual bool read(const dictionary &)
Read and set the function object if its data have changed.
A class for handling words, derived from string.
Definition: word.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none.
Definition: Switch.H:60
dynamicFvMesh & mesh
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual void movePoints(const polyMesh &mesh)
Update for changes of mesh.
Namespace for OpenFOAM.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
IOerror FatalIOError
virtual bool execute(const bool forceWrite)
Called at each ++ or += of the time-loop.
virtual bool end()
Called when Time::run() determines that the time-loop exits.
Macros for easy insertion into run-time selection tables.
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
virtual bool timeSet()
Called when time was set at the end of the Time::operator++.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
virtual void on()
Switch the function object on.
runTime controlDict().lookup("adjustTimeStep") >> adjustTimeStep
virtual void off()
Switch the function object off.
static autoPtr< DataEntry< Type > > New(const word &entryName, const dictionary &dict)
Selector.
Definition: DataEntryNew.C:32
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
bool read(const char *, int32_t &)
Definition: int32IO.C:87
virtual bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:325
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
virtual bool start()
Called at the start of the time-loop.
defineTypeNameAndDebug(combustionModel, 0)