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-2015 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 
47 (
48  const word& name,
49  const Time& runTime,
50  const dictionary& dict
51 )
52 :
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_.readIfPresent("enabled", dict);
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  {
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 // ************************************************************************* //
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:60
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::setTimeStepFunctionObject::end
virtual bool end()
Called when Time::run() determines that the time-loop exits.
Definition: setTimeStepFunctionObject.C:87
Foam::setTimeStepFunctionObject::execute
virtual bool execute(const bool forceWrite)
Called at each ++ or += of the time-loop.
Definition: setTimeStepFunctionObject.C:81
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::setTimeStepFunctionObject::start
virtual bool start()
Called at the start of the time-loop.
Definition: setTimeStepFunctionObject.C:75
Foam::DataEntry::New
static autoPtr< DataEntry< Type > > New(const word &entryName, const dictionary &dict)
Selector.
Definition: DataEntryNew.C:32
Foam::setTimeStepFunctionObject::setTimeStepFunctionObject
setTimeStepFunctionObject(const setTimeStepFunctionObject &)
Disallow default bitwise copy construct.
Foam::setTimeStepFunctionObject::enabled_
Switch enabled_
Switch for the execution - defaults to 'yes/on'.
Definition: setTimeStepFunctionObject.H:104
Foam::FatalIOError
IOerror FatalIOError
Foam::setTimeStepFunctionObject::on
virtual void on()
Switch the function object on.
Definition: setTimeStepFunctionObject.C:63
Foam::setTimeStepFunctionObject::read
virtual bool read(const dictionary &)
Read and set the function object if its data have changed.
Definition: setTimeStepFunctionObject.C:117
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::functionObject
Abstract base-class for Time/database function objects.
Definition: functionObject.H:58
Foam::setTimeStepFunctionObject::adjustTimeStep
virtual bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
Definition: setTimeStepFunctionObject.C:99
controlDict
runTime controlDict().lookup("adjustTimeStep") >> adjustTimeStep
Foam::setTimeStepFunctionObject::updateMesh
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
Definition: setTimeStepFunctionObject.C:144
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
setTimeStepFunctionObject.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::setTimeStepFunctionObject::movePoints
virtual void movePoints(const polyMesh &mesh)
Update for changes of mesh.
Definition: setTimeStepFunctionObject.C:148
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::setTimeStepFunctionObject::off
virtual void off()
Switch the function object off.
Definition: setTimeStepFunctionObject.C:69
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:330
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::setTimeStepFunctionObject::timeSet
virtual bool timeSet()
Called when time was set at the end of the Time::operator++.
Definition: setTimeStepFunctionObject.C:93
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47