subCycleTime.C
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) 2011 OpenFOAM Foundation
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 \*---------------------------------------------------------------------------*/
27 
28 #include "subCycleTime.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
33 :
34  time_(runTime),
35  index_(0),
36  total_(nCycles)
37 {
38  // Could avoid 0 or 1 nCycles here on construction
39  if (nCycles > 1)
40  {
41  time_.subCycle(nCycles);
42  }
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
47 
49 {
50  endSubCycle();
51 }
52 
53 
54 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
55 
57 {
58  return (index_ <= total_);
59 }
60 
61 
63 {
64  return (index_ > total_); // or !(status())
65 }
66 
67 
69 {
70  if (total_ > 1)
71  {
72  time_.endSubCycle();
73  }
74 
75  // If called manually, ensure status() will return false
76 
77  index_ = total_ + 1;
78 }
79 
80 
82 {
83  const bool active = status();
84 
85  if (active)
86  {
87  operator++();
88  }
89 
90  return active;
91 }
92 
93 
94 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
95 
97 {
98  if (total_ > 1)
99  {
100  time_++;
101  }
102 
103  index_++;
104 
105  // Register index change with Time, in case someone wants this information
106  time_.subCycleIndex(index_);
107 
108  return *this;
109 }
110 
111 
113 {
114  return operator++();
115 }
116 
117 
118 // ************************************************************************* //
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::subCycleTime::end
bool end() const
Return true if the number of sub-cycles has been reached.
Definition: subCycleTime.C:62
Foam::subCycleTime
A class for managing sub-cycling times.
Definition: subCycleTime.H:50
Foam::subCycleTime::subCycleTime
subCycleTime(Time &runTime, const label nCycle)
Construct referencing the original time and number of sub-cycles.
Definition: subCycleTime.C:32
Foam::subCycleTime::~subCycleTime
~subCycleTime()
Destructor.
Definition: subCycleTime.C:48
Foam::Time::subCycle
virtual TimeState subCycle(const label nSubCycles)
Set time to sub-cycle for the given number of steps.
Definition: Time.C:1088
Foam::subCycleTime::endSubCycle
void endSubCycle()
End the sub-cycling and reset the time-state.
Definition: subCycleTime.C:68
subCycleTime.H
Foam::subCycleTime::loop
bool loop()
True if looping is active, increments the index.
Definition: subCycleTime.C:81
Foam::subCycleTime::status
bool status() const
True if the sub-cycle is active.
Definition: subCycleTime.C:56
Foam::subCycleTime::operator++
subCycleTime & operator++()
Prefix increment.
Definition: subCycleTime.C:96