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-2023 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  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, t),
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  return min
163  (
164  executeControl_.timeToNextAction(),
165  writeControl_.timeToNextAction()
166  );
167 }
168 
169 
171 {
172  writeControl_.read(dict);
173  executeControl_.read(dict);
174 
175  readControls(dict);
176 
177  if (active())
178  {
179  foPtr_->read(dict);
180  }
181 
182  return true;
183 }
184 
185 
187 {
188  if (active())
189  {
190  foPtr_->movePoints(mesh);
191  }
192 }
193 
194 
196 (
197  const polyTopoChangeMap& map
198 )
199 {
200  if (active())
201  {
202  foPtr_->topoChange(map);
203  }
204 }
205 
206 
208 (
209  const polyMeshMap& map
210 )
211 {
212  if (active())
213  {
214  foPtr_->mapMesh(map);
215  }
216 }
217 
218 
220 (
221  const polyDistributionMap& map
222 )
223 {
224  if (active())
225  {
226  foPtr_->distribute(map);
227  }
228 }
229 
230 
231 // ************************************************************************* //
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:160
Abstract base-class for Time/database functionObjects.
General time control for functionObjects.
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.
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)
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
dictionary dict