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 bool Foam::functionObjects::timeControl::active() const
46 {
47  return executeControl_.active() || writeControl_.active();
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
54 (
55  const word& name,
56  const Time& t,
57  const dictionary& dict
58 )
59 :
60  functionObject(name, t),
61  time_(t),
62  executeControl_(t, dict, "execute"),
63  writeControl_(t, dict, "write"),
64  foPtr_(functionObject::New(name, t, dict))
65 {
66  writeControl_.read(dict);
67  executeControl_.read(dict);
68 }
69 
70 
71 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
72 
74 {
75  return foPtr_->fields();
76 }
77 
78 
80 {
81  return foPtr_->executeAtStart();
82 }
83 
84 
86 {
87  if
88  (
89  executeControl_.active()
90  && (
91  postProcess
92  || executeControl_.execute()
93  || (executeAtStart() && time_.timeIndex() == time_.startTimeIndex())
94  )
95  )
96  {
97  foPtr_->execute();
98  }
99 
100  return true;
101 }
102 
103 
105 {
106  if
107  (
108  writeControl_.active()
109  && (
110  postProcess
111  || writeControl_.execute()
112  || (executeAtStart() && time_.timeIndex() == time_.startTimeIndex())
113  )
114  )
115  {
116  foPtr_->write();
117  }
118 
119  return true;
120 }
121 
122 
124 {
125  if (executeControl_.execute() || writeControl_.execute())
126  {
127  foPtr_->end();
128  }
129 
130  return true;
131 }
132 
133 
135 {
136  return min
137  (
138  executeControl_.timeToNextAction(),
139  writeControl_.timeToNextAction()
140  );
141 }
142 
143 
145 {
146  writeControl_.read(dict);
147  executeControl_.read(dict);
148 
149  if (active())
150  {
151  foPtr_->read(dict);
152  }
153 
154  return true;
155 }
156 
157 
159 {
160  if (active())
161  {
162  foPtr_->movePoints(mesh);
163  }
164 }
165 
166 
168 (
169  const polyTopoChangeMap& map
170 )
171 {
172  if (active())
173  {
174  foPtr_->topoChange(map);
175  }
176 }
177 
178 
180 (
181  const polyMeshMap& map
182 )
183 {
184  if (active())
185  {
186  foPtr_->mapMesh(map);
187  }
188 }
189 
190 
192 (
193  const polyDistributionMap& map
194 )
195 {
196  if (active())
197  {
198  foPtr_->distribute(map);
199  }
200 }
201 
202 
203 // ************************************************************************* //
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
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:87
bool active() const
Returns true the time is within the start to end period.
Definition: timeControl.C:48
A class for handling words, derived from string.
Definition: word.H:62
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
Namespace for OpenFOAM.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
dictionary dict