loopControl.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2017 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::loopControl
28
29Description
30 A class for managing arbitrary loops with the ability to invoke
31 function object execution.
32
33Usage
34 Examples of function object specification:
35 \verbatim
36 SIMPLE
37 {
38 energyCoupling
39 {
40 iterations 100;
41 onLoop ();
42 onConverged ( externalCoupled "loopThings.*" );
43
44 convergence
45 {
46 "h" 1e-3;
47 }
48 }
49 }
50 \endverbatim
51
52 Where the loop entries comprise:
53 \table
54 Property | Description | Required | Default
55 enabled | activate/deactivate loop | no | true
56 iteration | times to loop | no | 0
57 timeStart | begin time for loop activation | no | -VGREAT
58 timeEnd | end time of loop activation | no | VGREAT
59 interval | sub-interval to execute onLoop | no | 0
60 onLoop | function object names to call at executeInterval | no
61 onConverged | function object names to call when converged | no
62 onEnd | function object names to call when loop ends | no
63 convergence | dictionary of convergence values to check | no
64 \endtable
65
66 The function object names listed by \c onLoop, \c onConverged, \c onEnd
67 must implement an \c execute(int) method.
68 If the time controls \c timeStart or \c timeEnd are used for the loop,
69 these values are only inspected upon creation, not during execution.
70
71SeeAlso
72 fvSolution
73
74SourceFiles
75 loopControl.C
76
77\*---------------------------------------------------------------------------*/
78
79#ifndef loopControl_H
80#define loopControl_H
81
82#include "subLoopTime.H"
83#include "dictionary.H"
84#include "wordRes.H"
85
86// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
87
88namespace Foam
89{
90
91/*---------------------------------------------------------------------------*\
92 Class loopControl Declaration
93\*---------------------------------------------------------------------------*/
94
95class loopControl
96:
97 public subLoopTime
98{
99 // Private Member Functions
100
101 //- Reset
102 void clear();
103
104 //- Read settings from dictionary
105 void read(const dictionary& dict);
106
107 //- Execute specified function names
108 bool checkConverged() const;
109
110 //- No copy construct
111 loopControl(const loopControl&) = delete;
112
113 //- No copy assignment
114 void operator=(const loopControl&) = delete;
115
116
117protected:
118
119 // Protected data
120
121 //- Name of the loop control (the lookup dictionary name).
122 word name_;
123
124 //- The interval to execute onLoop function-objects
125 label interval_;
126
127 //- Dictionary for checking convergence (all regions)
128 dictionary convergenceDict_;
129
130 //- Function object names to fire during the loop (at executeInterval)
131 wordRes onLoop_;
132
133 //- Function object names to fire on convergence
134 wordRes onConverged_;
135
136 //- Function object names to fire when the loop exits without
137 //- convergence
138 wordRes onEnd_;
139
140 //- Convergence tests passed
141 bool converged_;
142
143public:
144
145 // Constructors
146
147 //- Construct from time with fixed number of cycles
148 // \param runTime the top-level time
149 // \param nCycles the number of times to loop
150 // \param loopName the name of the loop
152 (
153 Time& runTime,
154 const label nCycles,
155 const word& dictName = "loop"
156 );
157
158 //- Construct from fvSolution dictionary based on time and the name
159 //- of the controlling algorithm
160 // \param runTime the top-level time
161 // \param algorithmName the name of the fvSolution dictionary,
162 // typically PIMPLE or SIMPLE
163 // \param dictName the name of the control dictionary
165 (
166 Time& runTime,
167 const word& algorithmName,
168 const word& dictName = "loop"
169 );
171 //- Construct from fvSolution dictionary based on time and the name
172 //- of the controlling algorithm
173 // \param runTime the top-level time
174 // \param algorithmDict the fvSolution algorithm dictionary,
175 // typically PIMPLE or SIMPLE
176 // \param dictName the name of the control dictionary
178 (
180 const dictionary& algorithmDict,
181 const word& dictName = "loop"
182 );
184
185 //- Destructor
187
188
189 // Member Functions
190
191 //- Name of the loop control
192 inline const word& name() const
193 {
194 return name_;
195 }
196
197 //- The interval to execute onLoop function-objects
198 inline label interval() const
199 {
200 return interval_;
201 }
202
203 //- True if looping is active, increments the index and executes
204 //- the onLoop and onConverged functions.
205 // Example usage,
206 // \code
207 // while (control.loop())
208 // {
209 // solve;
210 // }
211 // \endcode
212 bool loop();
213};
214
215
216// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
217
218//- Write name and state (on/off, index/total) to Ostream
219Ostream& operator<<(Ostream& os, const loopControl& ctrl);
220
221
222} // End namespace Foam
223
224// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225
226#endif
227
228// ************************************************************************* //
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for managing arbitrary loops with the ability to invoke function object execution.
Definition: loopControl.H:143
~loopControl()
Destructor.
Definition: loopControl.C:212
word name_
Name of the loop control (the lookup dictionary name).
Definition: loopControl.H:167
const word & name() const
Name of the loop control.
Definition: loopControl.H:237
label interval() const
The interval to execute onLoop function-objects.
Definition: loopControl.H:243
label interval_
The interval to execute onLoop function-objects.
Definition: loopControl.H:170
wordRes onConverged_
Function object names to fire on convergence.
Definition: loopControl.H:179
dictionary convergenceDict_
Dictionary for checking convergence (all regions)
Definition: loopControl.H:173
wordRes onLoop_
Function object names to fire during the loop (at executeInterval)
Definition: loopControl.H:176
bool converged_
Convergence tests passed.
Definition: loopControl.H:186
A class for managing sub-loops referencing Time.
Definition: subLoopTime.H:54
label nCycles() const
The total number of cycles.
Definition: subLoopTime.H:100
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
const word dictName("faMeshDefinition")
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
dictionary dict