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 -------------------------------------------------------------------------------
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::subLoopTime
28 
29 Description
30  A class for managing sub-loops referencing Time.
31 
32 SourceFiles
33  subLoopTime.C
34 
35 SeeAlso
36  subCycleTime
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef subLoopTime_H
41 #define subLoopTime_H
42 
43 #include "Time.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class subLoopTime Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class 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 
65 protected:
66 
67  // Protected data
68 
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 
78 public:
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
89  ~subLoopTime();
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 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::subLoopTime::~subLoopTime
~subLoopTime()
Destructor.
Definition: subLoopTime.C:42
Foam::subLoopTime::time_
Time & time_
Definition: subLoopTime.H:68
Foam::subLoopTime::operator++
subLoopTime & operator++()
Prefix increment.
Definition: subLoopTime.C:80
Foam::subLoopTime::stop
void stop()
Force terminate the loop.
Definition: subLoopTime.C:56
Foam::subLoopTime::nCycles
label nCycles() const
The total number of cycles.
Definition: subLoopTime.H:100
Foam::subLoopTime
A class for managing sub-loops referencing Time.
Definition: subLoopTime.H:53
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::subLoopTime::index_
label index_
The current sub-cycle index.
Definition: subLoopTime.H:71
Time.H
Foam::subLoopTime::index
label index() const
The current cycle index.
Definition: subLoopTime.H:94
Foam::subLoopTime::status
bool status() const
Return true if looping is active.
Definition: subLoopTime.C:50
Foam::subLoopTime::total_
label total_
The total number of cycles in the sub-cycle.
Definition: subLoopTime.H:74
Foam::subLoopTime::loop
bool loop()
True if looping is active, increments the index.
Definition: subLoopTime.C:63