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-2018 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  dict_.readIfPresent("timeStart", timeStart_);
47  dict_.readIfPresent("timeEnd", timeEnd_);
48  dict_.readIfPresent("nStepsToStartTimeChange", nStepsToStartTimeChange_);
49 }
50 
51 
52 bool Foam::functionObjects::timeControl::active() const
53 {
54  return
55  time_.value() >= timeStart_
56  && time_.value() <= timeEnd_;
57 }
58 
59 
60 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
61 
62 Foam::functionObjects::timeControl::timeControl
63 (
64  const word& name,
65  const Time& t,
66  const dictionary& dict
67 )
68 :
69  functionObject(name),
70  time_(t),
71  dict_(dict),
72  timeStart_(-vGreat),
73  timeEnd_(vGreat),
74  nStepsToStartTimeChange_
75  (
76  dict.lookupOrDefault("nStepsToStartTimeChange", 3)
77  ),
78  executeControl_(t, dict, "execute"),
79  writeControl_(t, dict, "write"),
80  foPtr_(functionObject::New(name, t, dict_))
81 {
82  readControls();
83 }
84 
85 
86 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
87 
89 {
90  if (active() && (postProcess || executeControl_.execute()))
91  {
92  foPtr_->execute();
93  }
94 
95  return true;
96 }
97 
98 
100 {
101  if (active() && (postProcess || writeControl_.execute()))
102  {
103  foPtr_->write();
104  }
105 
106  return true;
107 }
108 
109 
111 {
112  if (active() && (executeControl_.execute() || writeControl_.execute()))
113  {
114  foPtr_->end();
115  }
116 
117  return true;
118 }
119 
120 
121 
123 {
124  if
125  (
126  active()
127  && writeControl_.control() == Foam::timeControl::ocAdjustableRunTime
128  )
129  {
130  const label writeTimeIndex = writeControl_.executionIndex();
131  const scalar writeInterval = writeControl_.interval();
132 
133  return
134  max
135  (
136  0.0,
137  (writeTimeIndex + 1)*writeInterval
138  - (time_.value() - time_.startTime().value())
139  );
140  }
141 
142  return vGreat;
143 }
144 
145 
147 (
148  const dictionary& dict
149 )
150 {
151  if (dict != dict_)
152  {
153  dict_ = dict;
154 
155  writeControl_.read(dict);
156  executeControl_.read(dict);
157  readControls();
158 
159  return true;
160  }
161  else
162  {
163  return false;
164  }
165 }
166 
167 
169 (
170  const mapPolyMesh& mpm
171 )
172 {
173  if (active())
174  {
175  foPtr_->updateMesh(mpm);
176  }
177 }
178 
179 
181 (
182  const polyMesh& mesh
183 )
184 {
185  if (active())
186  {
187  foPtr_->movePoints(mesh);
188  }
189 }
190 
191 
192 // ************************************************************************* //
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:137
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.
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.
Adjust time step for execution.
Definition: timeControl.H:59
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
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.