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  if (active() && (postProcess || executeControl_.execute()))
99  {
100  foPtr_->execute();
101  }
102 
103  return true;
104 }
105 
106 
108 {
109  if (active() && (postProcess || writeControl_.execute()))
110  {
111  foPtr_->write();
112  }
113 
114  return true;
115 }
116 
117 
119 {
120  if (active() && (executeControl_.execute() || writeControl_.execute()))
121  {
122  foPtr_->end();
123  }
124 
125  return true;
126 }
127 
128 
129 
131 {
132  if
133  (
134  active()
135  && writeControl_.control() ==
137  )
138  {
139  const label writeTimeIndex = writeControl_.executionIndex();
140  const scalar writeInterval = writeControl_.interval();
141 
142  return
143  max
144  (
145  0.0,
146  (writeTimeIndex + 1)*writeInterval
147  - (time_.value() - time_.startTime().value())
148  );
149  }
150 
151  return vGreat;
152 }
153 
154 
156 (
157  const dictionary& dict
158 )
159 {
160  if (dict != dict_)
161  {
162  dict_ = dict;
163 
164  writeControl_.read(dict);
165  executeControl_.read(dict);
166  readControls();
167 
168  return true;
169  }
170  else
171  {
172  return false;
173  }
174 }
175 
176 
178 (
179  const mapPolyMesh& mpm
180 )
181 {
182  if (active())
183  {
184  foPtr_->updateMesh(mpm);
185  }
186 }
187 
188 
190 (
191  const polyMesh& mesh
192 )
193 {
194  if (active())
195  {
196  foPtr_->movePoints(mesh);
197  }
198 }
199 
200 
201 // ************************************************************************* //
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 execute()
Called at each ++ or += of the time-loop.
Abstract base-class for Time/database function objects.
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.