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  time_.subCycle(nCycles);
40 }
41 
42 
43 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
44 
46 {
47  endSubCycle();
48 }
49 
50 
51 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52 
54 {
55  return (index_ <= total_);
56 }
57 
58 
60 {
61  return (index_ > total_); // or !(status())
62 }
63 
64 
66 {
67  time_.endSubCycle();
68 
69  // If called manually, ensure status() will return false
70 
71  index_ = total_ + 1;
72 }
73 
74 
76 {
77  const bool active = status();
78 
79  if (active)
80  {
81  operator++();
82  }
83 
84  return active;
85 }
86 
87 
88 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
89 
91 {
92  ++time_;
93  ++index_;
94 
95  // Register index change with Time, in case someone wants this information
96  time_.subCycleIndex(index_);
97 
98  return *this;
99 }
100 
101 
103 {
104  return operator++();
105 }
106 
107 
108 // ************************************************************************* //
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:59
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:45
Foam::Time::subCycle
virtual TimeState subCycle(const label nSubCycles)
Set time to sub-cycle for the given number of steps.
Definition: Time.C:1091
Foam::subCycleTime::endSubCycle
void endSubCycle()
End the sub-cycling and reset the time-state.
Definition: subCycleTime.C:65
subCycleTime.H
Foam::subCycleTime::loop
bool loop()
True if looping is active, increments the index.
Definition: subCycleTime.C:75
Foam::subCycleTime::status
bool status() const
True if the sub-cycle is active.
Definition: subCycleTime.C:53
Foam::subCycleTime::operator++
subCycleTime & operator++()
Prefix increment.
Definition: subCycleTime.C:90