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-2024 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 {
39 }
40 }
41 
42 
43 // * * * * * * * * * * * * * * * Private Members * * * * * * * * * * * * * * //
44 
45 void Foam::functionObjects::timeControl::readControls(const dictionary& dict)
46 {
47  dict.readIfPresent("startTime", time().userUnits(), startTime_);
48  dict.readIfPresent("endTime", time().userUnits(), endTime_);
49 }
50 
51 
52 bool Foam::functionObjects::timeControl::active() const
53 {
54  return
55  time_.value() >= startTime_
56  && time_.value() <= endTime_;
57 }
58 
59 
60 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
61 
63 (
64  const word& name,
65  const Time& t,
66  const dictionary& dict
67 )
68 :
69  functionObject(name, t),
70  time_(t),
71  startTime_(-vGreat),
72  endTime_(vGreat),
73  executeControl_(t, dict, "execute"),
74  writeControl_(t, dict, "write"),
75  foPtr_(functionObject::New(name, t, dict))
76 {
77  readControls(dict);
78  writeControl_.read(dict);
79  executeControl_.read(dict);
80 }
81 
82 
83 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
84 
86 {
87  return foPtr_->fields();
88 }
89 
90 
92 {
93  return foPtr_->executeAtStart();
94 }
95 
96 
98 {
99  if
100  (
101  active()
102  && (
103  postProcess
104  || executeControl_.execute()
105  || (executeAtStart() && time_.timeIndex() == time_.startTimeIndex())
106  )
107  )
108  {
109  foPtr_->execute();
110  }
111 
112  return true;
113 }
114 
115 
117 {
118  if
119  (
120  active()
121  && (
122  postProcess
123  || writeControl_.execute()
124  || (executeAtStart() && time_.timeIndex() == time_.startTimeIndex())
125  )
126  )
127  {
128  foPtr_->write();
129  }
130 
131  return true;
132 }
133 
134 
136 {
137  if (active() && (executeControl_.execute() || writeControl_.execute()))
138  {
139  foPtr_->end();
140  }
141 
142  return true;
143 }
144 
145 
147 {
148  return min
149  (
150  executeControl_.timeToNextAction(),
151  writeControl_.timeToNextAction()
152  );
153 }
154 
155 
157 {
158  writeControl_.read(dict);
159  executeControl_.read(dict);
160 
161  readControls(dict);
162 
163  if (active())
164  {
165  foPtr_->read(dict);
166  }
167 
168  return true;
169 }
170 
171 
173 {
174  if (active())
175  {
176  foPtr_->movePoints(mesh);
177  }
178 }
179 
180 
182 (
183  const polyTopoChangeMap& map
184 )
185 {
186  if (active())
187  {
188  foPtr_->topoChange(map);
189  }
190 }
191 
192 
194 (
195  const polyMeshMap& map
196 )
197 {
198  if (active())
199  {
200  foPtr_->mapMesh(map);
201  }
202 }
203 
204 
206 (
207  const polyDistributionMap& map
208 )
209 {
210  if (active())
211  {
212  foPtr_->distribute(map);
213  }
214 }
215 
216 
217 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Abstract base-class for Time/database functionObjects.
General time control for functionObjects.
const Time & time() const
Return time database.
virtual wordList fields() const
Return the list of fields required.
timeControl(const word &name, const Time &, const dictionary &)
Construct from components.
virtual bool executeAtStart() const
Return true if the functionObject should be executed.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
virtual void movePoints(const polyMesh &mesh)
Update topology using the given map.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual scalar timeToNextAction()
Return the time to the next execute or write.
virtual bool execute()
Called at each ++ or += of the time-loop.
virtual void topoChange(const polyTopoChangeMap &map)
Update topology using the given map.
virtual bool write()
Called at each ++ or += of the time-loop.
virtual bool end()
Called when Time::run() determines that the time-loop exits.
virtual bool read(const dictionary &)
Read and set the function object if its data have changed.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
void read(const dictionary &)
Read from dictionary.
Definition: timeControl.C:82
A class for handling words, derived from string.
Definition: word.H:62
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
Namespace for OpenFOAM.
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
dictionary dict