subCycle.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 | Copyright (C) 2011-2012 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::subCycle
26 
27 Description
28  Perform a subCycleTime on a field
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #ifndef subCycle_H
33 #define subCycle_H
34 
35 #include "subCycleTime.H"
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 
42 /*---------------------------------------------------------------------------*\
43  Class subCycleField Declaration
44 \*---------------------------------------------------------------------------*/
45 
46 template<class GeometricField>
47 class subCycleField
48 {
49  // Private data
50 
51  //- Reference to the field being sub-cycled
52  GeometricField& gf_;
53 
54  //- Reference to the field old-time field being sub-cycled
55  // Needed to avoid calls to oldTime() which may cause
56  // unexpected updates of the old-time field
57  GeometricField& gf0_;
58 
59  //- Copy of the "real" old-time value of the field
60  GeometricField gf_0_;
61 
62 
63 public:
64 
65  // Constructors
66 
67  //- Construct field and number of sub-cycles
69  :
70  gf_(gf),
71  gf0_(gf.oldTime()),
72  gf_0_(gf0_.name() + "_", gf0_)
73  {}
74 
75 
76  //- Destructor
78  {
79  // Reset the old-time field
80  gf0_ = gf_0_;
81 
82  // Correct the time index of the field to correspond to the global time
83  gf_.timeIndex() = gf_.time().timeIndex();
84  gf0_.timeIndex() = gf_.time().timeIndex();
85  }
86 
87 
88  //- Correct the time index of the field to correspond to
89  // the sub-cycling time.
90  //
91  // The time index is incremented to protect the old-time value from
92  // being updated at the beginning of the time-loop in the case of
93  // outer iteration
94  void updateTimeIndex()
95  {
96  gf_.timeIndex() = gf_.time().timeIndex() + 1;
97  gf0_.timeIndex() = gf_.time().timeIndex() + 1;
98  }
99 };
100 
101 
102 /*---------------------------------------------------------------------------*\
103  Class subCycle Declaration
104 \*---------------------------------------------------------------------------*/
105 
106 template<class GeometricField>
107 class subCycle
108 :
109  public subCycleField<GeometricField>,
110  public subCycleTime
111 {
112  // Private Member Functions
113 
114  //- Disallow default bitwise copy construct
116 
117  //- Disallow default bitwise assignment
118  void operator=(const subCycle<GeometricField>&);
119 
120 
121 public:
122 
123  // Constructors
124 
125  //- Construct field and number of sub-cycles
126  subCycle(GeometricField& gf, const label nSubCycles)
127  :
129  subCycleTime(const_cast<Time&>(gf.time()), nSubCycles)
130  {
131  // Update the field time index to correspond to the sub-cycle time
132  this->updateTimeIndex();
133  }
134 
135 
136  //- Destructor
137  // End the subCycleTime, which restores the time state
138  ~subCycle()
139  {
140  endSubCycle();
141  }
142 };
143 
144 
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
146 
147 } // End namespace Foam
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 #endif
152 
153 // ************************************************************************* //
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:35
rho oldTime()
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
~subCycleField()
Destructor.
Definition: subCycle.H:76
Generic GeometricField class.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
const Time & time() const
Return time.
Definition: IOobject.C:227
label timeIndex() const
Return the time index of the field.
Perform a subCycleTime on a field.
Definition: subCycle.H:106
subCycleField(GeometricField &gf)
Construct field and number of sub-cycles.
Definition: subCycle.H:67
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
void updateTimeIndex()
Correct the time index of the field to correspond to.
Definition: subCycle.H:93
A class for managing sub-cycling times.
Definition: subCycleTime.H:48
Namespace for OpenFOAM.