timeControlFunctionObject.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2019 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 
27 #include "polyMesh.H"
28 #include "mapPolyMesh.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace functionObjects
36 {
37  defineTypeNameAndDebug(timeControl, 0);
38 }
39 }
40 
41 
42 // * * * * * * * * * * * * * * * Private Members * * * * * * * * * * * * * * //
43 
44 void Foam::functionObjects::timeControl::readControls()
45 {
46  if (!dict_.readIfPresent("startTime", startTime_))
47  {
48  dict_.readIfPresent("timeStart", startTime_);
49  }
50 
51  if (!dict_.readIfPresent("endTime", endTime_))
52  {
53  dict_.readIfPresent("timeEnd", endTime_);
54  }
55 
56  dict_.readIfPresent("nStepsToStartTimeChange", nStepsToStartTimeChange_);
57 }
58 
59 
60 bool Foam::functionObjects::timeControl::active() const
61 {
62  return
63  time_.value() >= startTime_
64  && time_.value() <= endTime_;
65 }
66 
67 
68 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
69 
71 (
72  const word& name,
73  const Time& t,
74  const dictionary& dict
75 )
76 :
77  functionObject(name),
78  time_(t),
79  dict_(dict),
80  startTime_(-vGreat),
81  endTime_(vGreat),
82  nStepsToStartTimeChange_
83  (
84  dict.lookupOrDefault("nStepsToStartTimeChange", 3)
85  ),
86  executeControl_(t, dict, "execute"),
87  writeControl_(t, dict, "write"),
88  foPtr_(functionObject::New(name, t, dict_))
89 {
90  readControls();
91 }
92 
93 
94 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
95 
97 {
98  return foPtr_->executeAtStart();
99 }
100 
101 
103 {
104  if
105  (
106  active()
107  && (
108  postProcess
109  || executeControl_.execute()
110  || (executeAtStart() && time_.timeIndex() == time_.startTimeIndex())
111  )
112  )
113  {
114  foPtr_->execute();
115  }
116 
117  return true;
118 }
119 
120 
122 {
123  if
124  (
125  active()
126  && (
127  postProcess
128  || writeControl_.execute()
129  || (executeAtStart() && time_.timeIndex() == time_.startTimeIndex())
130  )
131  )
132  {
133  foPtr_->write();
134  }
135 
136  return true;
137 }
138 
139 
141 {
142  if (active() && (executeControl_.execute() || writeControl_.execute()))
143  {
144  foPtr_->end();
145  }
146 
147  return true;
148 }
149 
150 
151 
153 {
154  if
155  (
156  active()
157  && writeControl_.control() ==
159  )
160  {
161  const label writeTimeIndex = writeControl_.executionIndex();
162  const scalar writeInterval = writeControl_.interval();
163 
164  return
165  max
166  (
167  0.0,
168  (writeTimeIndex + 1)*writeInterval
169  - (time_.value() - time_.startTime().value())
170  );
171  }
172 
173  return vGreat;
174 }
175 
176 
178 (
179  const dictionary& dict
180 )
181 {
182  if (dict != dict_)
183  {
184  dict_ = dict;
185 
186  writeControl_.read(dict);
187  executeControl_.read(dict);
188  readControls();
189 
190  return true;
191  }
192  else
193  {
194  return false;
195  }
196 }
197 
198 
200 (
201  const mapPolyMesh& mpm
202 )
203 {
204  if (active())
205  {
206  foPtr_->updateMesh(mpm);
207  }
208 }
209 
210 
212 (
213  const polyMesh& mesh
214 )
215 {
216  if (active())
217  {
218  foPtr_->movePoints(mesh);
219  }
220 }
221 
222 
223 // ************************************************************************* //
dictionary dict
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
virtual bool executeAtStart() const
Return true if the functionObject should be executed.
virtual bool execute()
Called at each ++ or += of the time-loop.
Abstract base-class for Time/database functionObjects.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Macros for easy insertion into run-time selection tables.
virtual bool write()
Called at each ++ or += of the time-loop.
A class for handling words, derived from string.
Definition: word.H:59
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
virtual scalar timeToNextWrite()
Return the time to the next write.
defineTypeNameAndDebug(Qdot, 0)
virtual void movePoints(const polyMesh &mesh)
Update for changes of mesh.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
static autoPtr< functionObject > New(const word &name, const Time &, const dictionary &)
Select from dictionary, based on its "type" entry.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
virtual bool read(const dictionary &)
Read and set the function object if its data have changed.
virtual bool end()
Called when Time::run() determines that the time-loop exits.
Namespace for OpenFOAM.
timeControl(const word &name, const Time &, const dictionary &)
Construct from components.