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-2026 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 Member Functions * * * * * * * * * * * //
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  // If we are *not* executing at the start then we need to explicitly call
70  // the controls' execute methods to ensure that internal state is correctly
71  // advanced past the initial time instant. If we *are* executing at the
72  // start then we don't need to do this as it will happen naturally as part
73  // of the function object's execute and write hooks.
74  if (!foPtr_->executeAtStart())
75  {
76  executeControl_.execute();
77  writeControl_.execute();
78  }
79 }
80 
81 
82 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
83 
85 {
86  return foPtr_->fields();
87 }
88 
89 
91 {
92  return foPtr_->executeAtStart();
93 }
94 
95 
97 {
98  if (executeControl_.active() && (postProcess || executeControl_.execute()))
99  {
100  foPtr_->execute();
101  }
102 
103  return true;
104 }
105 
106 
108 {
109  if (writeControl_.active() && (postProcess || writeControl_.execute()))
110  {
111  foPtr_->write();
112  }
113 
114  return true;
115 }
116 
117 
119 {
120  if (executeControl_.execute() || writeControl_.execute())
121  {
122  foPtr_->end();
123  }
124 
125  return true;
126 }
127 
128 
130 {
131  return min
132  (
133  executeControl_.timeToNextAction(),
134  writeControl_.timeToNextAction()
135  );
136 }
137 
138 
140 {
141  writeControl_.read(dict);
142  executeControl_.read(dict);
143 
144  if (active())
145  {
146  foPtr_->read(dict);
147  }
148 
149  return true;
150 }
151 
152 
154 {
155  foPtr_->movePoints(mesh);
156 }
157 
158 
160 (
161  const polyTopoChangeMap& map
162 )
163 {
164  foPtr_->topoChange(map);
165 }
166 
167 
169 (
170  const polyMeshMap& map
171 )
172 {
173  foPtr_->mapMesh(map);
174 }
175 
176 
178 (
179  const polyDistributionMap& map
180 )
181 {
182  foPtr_->distribute(map);
183 }
184 
185 
186 // ************************************************************************* //
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:78
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
void read(const dictionary &)
Read from dictionary.
Definition: timeControl.C:86
bool active() const
Returns true the time is within the start to end period.
Definition: timeControl.C:254
bool execute()
Flag to indicate whether to execute.
Definition: timeControl.C:263
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
Namespace for OpenFOAM.
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
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