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-2021 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(const dictionary& dict)
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  startTime_(-vGreat),
80  endTime_(vGreat),
81  nStepsToStartTimeChange_
82  (
83  dict.lookupOrDefault("nStepsToStartTimeChange", 3)
84  ),
85  executeControl_(t, dict, "execute"),
86  writeControl_(t, dict, "write"),
87  foPtr_(functionObject::New(name, t, dict))
88 {
89  writeControl_.read(dict);
90  executeControl_.read(dict);
91 
92  readControls(dict);
93 }
94 
95 
96 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
97 
99 {
100  return foPtr_->executeAtStart();
101 }
102 
103 
105 {
106  if
107  (
108  active()
109  && (
110  postProcess
111  || executeControl_.execute()
112  || (executeAtStart() && time_.timeIndex() == time_.startTimeIndex())
113  )
114  )
115  {
116  foPtr_->execute();
117  }
118 
119  return true;
120 }
121 
122 
124 {
125  if
126  (
127  active()
128  && (
129  postProcess
130  || writeControl_.execute()
131  || (executeAtStart() && time_.timeIndex() == time_.startTimeIndex())
132  )
133  )
134  {
135  foPtr_->write();
136  }
137 
138  return true;
139 }
140 
141 
143 {
144  if (active() && (executeControl_.execute() || writeControl_.execute()))
145  {
146  foPtr_->end();
147  }
148 
149  return true;
150 }
151 
152 
153 
155 {
156  if
157  (
158  active()
159  && writeControl_.control() ==
161  )
162  {
163  const label writeTimeIndex = writeControl_.executionIndex();
164  const scalar writeInterval = writeControl_.interval();
165 
166  return
167  max
168  (
169  0.0,
170  (writeTimeIndex + 1)*writeInterval
171  - (time_.value() - time_.beginTime().value())
172  );
173  }
174 
175  return vGreat;
176 }
177 
178 
180 {
181  writeControl_.read(dict);
182  executeControl_.read(dict);
183 
184  readControls(dict);
185 
186  if (active())
187  {
188  foPtr_->read(dict);
189  }
190 
191  return true;
192 }
193 
194 
196 {
197  if (active())
198  {
199  foPtr_->updateMesh(mpm);
200  }
201 }
202 
203 
205 {
206  if (active())
207  {
208  foPtr_->movePoints(mesh);
209  }
210 }
211 
212 
213 // ************************************************************************* //
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:156
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.
dynamicFvMesh & mesh
A class for handling words, derived from string.
Definition: word.H:59
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
virtual bool read(const dictionary &)
Read and set the functionObject if its data have changed.
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.