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 -------------------------------------------------------------------------------
10 License
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 
26 Class
27  Foam::loopControl
28 
29 Description
30  A class for managing arbitrary loops with the ability to invoke
31  function object execution.
32 
33 Usage
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 
71 SeeAlso
72  fvSolution
73 
74 SourceFiles
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 
88 namespace Foam
89 {
90 
91 /*---------------------------------------------------------------------------*\
92  Class loopControl Declaration
93 \*---------------------------------------------------------------------------*/
94 
95 class 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 
117 protected:
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 
143 public:
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  );
170 
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  );
183 
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
219 Ostream& operator<<(Ostream& os, const loopControl& ctrl);
220 
221 
222 } // End namespace Foam
223 
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 
226 #endif
227 
228 // ************************************************************************* //
Foam::loopControl::onLoop_
wordRes onLoop_
Function object names to fire during the loop (at executeInterval)
Definition: loopControl.H:176
runTime
engineTime & runTime
Definition: createEngineTime.H:13
wordRes.H
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::loopControl::onConverged_
wordRes onConverged_
Function object names to fire on convergence.
Definition: loopControl.H:179
dictName
const word dictName("blockMeshDict")
Foam::loopControl
A class for managing arbitrary loops with the ability to invoke function object execution.
Definition: loopControl.H:140
Foam::loopControl::~loopControl
~loopControl()
Destructor.
Definition: loopControl.C:215
Foam::loopControl::convergenceDict_
dictionary convergenceDict_
Dictionary for checking convergence (all regions)
Definition: loopControl.H:173
Foam::loopControl::loop
bool loop()
Definition: loopControl.C:223
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::loopControl::onEnd_
wordRes onEnd_
Definition: loopControl.H:183
Foam::subLoopTime::nCycles
label nCycles() const
The total number of cycles.
Definition: subLoopTime.H:100
Foam::loopControl::name
const word & name() const
Name of the loop control.
Definition: loopControl.H:237
Foam::loopControl::interval
label interval() const
The interval to execute onLoop function-objects.
Definition: loopControl.H:243
Foam::subLoopTime
A class for managing sub-loops referencing Time.
Definition: subLoopTime.H:53
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::loopControl::converged_
bool converged_
Convergence tests passed.
Definition: loopControl.H:186
Foam::loopControl::name_
word name_
Name of the loop control (the lookup dictionary name).
Definition: loopControl.H:167
subLoopTime.H
dictionary.H
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::loopControl::interval_
label interval_
The interval to execute onLoop function-objects.
Definition: loopControl.H:170