subLoopTime.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) 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 \*---------------------------------------------------------------------------*/
27 
28 #include "subLoopTime.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 Foam::subLoopTime::subLoopTime(Time& runTime, const label nCycles)
33 :
34  time_(runTime),
35  index_(0),
36  total_(nCycles)
37 {}
38 
39 
40 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
41 
43 {
44  stop();
45 }
46 
47 
48 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
49 
51 {
52  return (index_ < total_);
53 }
54 
55 
57 {
58  // If called manually, ensure status() will return false
59  index_ = total_ + 1;
60 }
61 
62 
64 {
65  const bool active = (index_ < total_); // as per status()
66 
67  if (active)
68  {
69  operator++();
70  }
71  else if (index_)
72  {
73  // Not active, the loop condition has now exiting on the last subloop
74  }
75 
76  return active;
77 }
78 
79 
81 {
82  ++index_;
83  return *this;
84 }
85 
86 
87 // ************************************************************************* //
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::operator++
subLoopTime & operator++()
Prefix increment.
Definition: subLoopTime.C:80
Foam::subLoopTime::stop
void stop()
Force terminate the loop.
Definition: subLoopTime.C:56
Foam::subLoopTime
A class for managing sub-loops referencing Time.
Definition: subLoopTime.H:53
subLoopTime.H
Foam::subLoopTime::status
bool status() const
Return true if looping is active.
Definition: subLoopTime.C:50
Foam::subLoopTime::loop
bool loop()
True if looping is active, increments the index.
Definition: subLoopTime.C:63