subLoopTime.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::subLoopTime
28
29Description
30 A class for managing sub-loops referencing Time.
31
32SourceFiles
33 subLoopTime.C
34
35SeeAlso
36 subCycleTime
37
38\*---------------------------------------------------------------------------*/
39
40#ifndef subLoopTime_H
41#define subLoopTime_H
42
43#include "Time.H"
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
49
50/*---------------------------------------------------------------------------*\
51 Class subLoopTime Declaration
52\*---------------------------------------------------------------------------*/
54class subLoopTime
55{
56 // Private Member Functions
57
58 //- No copy construct
59 subLoopTime(const subLoopTime&) = delete;
60
61 //- No copy assignment
62 void operator=(const subLoopTime&) = delete;
63
64
65protected:
66
67 // Protected data
69 Time& time_;
70
71 //- The current sub-cycle index
72 label index_;
73
74 //- The total number of cycles in the sub-cycle
75 label total_;
76
77
78public:
79
80 // Constructors
81
82 //- Construct from time with fixed number of cycles
83 // \param runTime the top-level time
84 // \param nCycles the number of times to loop
85 subLoopTime(Time& runTime, const label nCycles);
86
87
88 //- Destructor
90
91
92 // Member Functions
93
94 //- The current cycle index
95 inline label index() const
96 {
97 return index_;
98 }
99
100 //- The total number of cycles
101 inline label nCycles() const
102 {
103 return total_;
104 }
105
106 //- Return true if looping is active
107 bool status() const;
108
109 //- Force terminate the loop
110 void stop();
111
112 //- True if looping is active, increments the index.
113 // Example usage,
114 // \code
115 // while (control.loop())
116 // {
117 // solve;
118 // }
119 // \endcode
120 bool loop();
121
122
123 // Member Operators
124
125 //- Prefix increment
127
128};
129
130
131// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
132
133} // End namespace Foam
134
135// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136
137#endif
138
139// ************************************************************************* //
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
A class for managing sub-loops referencing Time.
Definition: subLoopTime.H:54
label nCycles() const
The total number of cycles.
Definition: subLoopTime.H:100
label index() const
The current cycle index.
Definition: subLoopTime.H:94
subLoopTime & operator++()
Prefix increment.
Definition: subLoopTime.C:80
void stop()
Force terminate the loop.
Definition: subLoopTime.C:56
label index_
The current sub-cycle index.
Definition: subLoopTime.H:71
~subLoopTime()
Destructor.
Definition: subLoopTime.C:42
bool status() const
Return true if looping is active.
Definition: subLoopTime.C:50
bool loop()
True if looping is active, increments the index.
Definition: subLoopTime.C:63
label total_
The total number of cycles in the sub-cycle.
Definition: subLoopTime.H:74
engineTime & runTime
Namespace for OpenFOAM.