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-2022 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 "polyTopoChangeMap.H"
29 #include "polyMeshMap.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionObjects
37 {
38  defineTypeNameAndDebug(timeControl, 0);
39 }
40 }
41 
42 
43 // * * * * * * * * * * * * * * * Private Members * * * * * * * * * * * * * * //
44 
45 void Foam::functionObjects::timeControl::readControls(const dictionary& dict)
46 {
47  if (!dict.readIfPresent("startTime", startTime_))
48  {
49  dict.readIfPresent("timeStart", startTime_);
50  }
51 
52  if (!dict.readIfPresent("endTime", endTime_))
53  {
54  dict.readIfPresent("timeEnd", endTime_);
55  }
56 
57  dict.readIfPresent("nStepsToStartTimeChange", nStepsToStartTimeChange_);
58 }
59 
60 
61 bool Foam::functionObjects::timeControl::active() const
62 {
63  return
64  time_.value() >= startTime_
65  && time_.value() <= endTime_;
66 }
67 
68 
69 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
70 
72 (
73  const word& name,
74  const Time& t,
75  const dictionary& dict
76 )
77 :
78  functionObject(name),
79  time_(t),
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  writeControl_.read(dict);
91  executeControl_.read(dict);
92 
93  readControls(dict);
94 }
95 
96 
97 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 
100 {
101  return foPtr_->fields();
102 }
103 
104 
106 {
107  return foPtr_->executeAtStart();
108 }
109 
110 
112 {
113  if
114  (
115  active()
116  && (
117  postProcess
118  || executeControl_.execute()
119  || (executeAtStart() && time_.timeIndex() == time_.startTimeIndex())
120  )
121  )
122  {
123  foPtr_->execute();
124  }
125 
126  return true;
127 }
128 
129 
131 {
132  if
133  (
134  active()
135  && (
136  postProcess
137  || writeControl_.execute()
138  || (executeAtStart() && time_.timeIndex() == time_.startTimeIndex())
139  )
140  )
141  {
142  foPtr_->write();
143  }
144 
145  return true;
146 }
147 
148 
150 {
151  if (active() && (executeControl_.execute() || writeControl_.execute()))
152  {
153  foPtr_->end();
154  }
155 
156  return true;
157 }
158 
159 
161 {
162  if
163  (
164  active()
165  && writeControl_.control() ==
167  )
168  {
169  const label writeTimeIndex = writeControl_.executionIndex();
170  const scalar writeInterval = writeControl_.interval();
171 
172  return
173  max
174  (
175  0.0,
176  (writeTimeIndex + 1)*writeInterval
177  - (time_.value() - time_.beginTime().value())
178  );
179  }
180 
181  return vGreat;
182 }
183 
184 
186 {
187  writeControl_.read(dict);
188  executeControl_.read(dict);
189 
190  readControls(dict);
191 
192  if (active())
193  {
194  foPtr_->read(dict);
195  }
196 
197  return true;
198 }
199 
200 
202 {
203  if (active())
204  {
205  foPtr_->movePoints(mesh);
206  }
207 }
208 
209 
211 (
212  const polyTopoChangeMap& map
213 )
214 {
215  if (active())
216  {
217  foPtr_->topoChange(map);
218  }
219 }
220 
221 
223 (
224  const polyMeshMap& map
225 )
226 {
227  if (active())
228  {
229  foPtr_->mapMesh(map);
230  }
231 }
232 
233 
234 // ************************************************************************* //
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
virtual wordList fields() const
Return the list of fields required.
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.
fvMesh & mesh
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
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
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
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 topology using the given map.
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:76
virtual void topoChange(const polyTopoChangeMap &map)
Update topology using the given map.
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:50
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.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Namespace for OpenFOAM.
timeControl(const word &name, const Time &, const dictionary &)
Construct from components.