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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2012 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 Class
27  Foam::subCycle
28 
29 Description
30  Perform a subCycleTime on a field
31 
32 \*---------------------------------------------------------------------------*/
33 
34 #ifndef subCycle_H
35 #define subCycle_H
36 
37 #include "subCycleTime.H"
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43 
44 /*---------------------------------------------------------------------------*\
45  Class subCycleField Declaration
46 \*---------------------------------------------------------------------------*/
47 
48 template<class GeometricField>
49 class subCycleField
50 {
51  // Private data
52 
53  //- Reference to the field being sub-cycled
54  GeometricField& gf_;
55 
56  //- Reference to the field old-time field being sub-cycled
57  // Needed to avoid calls to oldTime() which may cause
58  // unexpected updates of the old-time field
59  GeometricField& gf0_;
60 
61  //- Copy of the "real" old-time value of the field
62  GeometricField gf_0_;
63 
64 
65 public:
66 
67  // Constructors
68 
69  //- Construct field and number of sub-cycles
71  :
72  gf_(gf),
73  gf0_(gf.oldTime()),
74  gf_0_(gf0_.name() + "_", gf0_)
75  {}
76 
77 
78  //- Destructor
80  {
81  // Reset the old-time field
82  gf0_ = gf_0_;
83 
84  // Correct the time index of the field to correspond to the global time
85  gf_.timeIndex() = gf_.time().timeIndex();
86  gf0_.timeIndex() = gf_.time().timeIndex();
87  }
88 
89 
90  //- Correct the time index of the field to correspond to
91  // the sub-cycling time.
92  //
93  // The time index is incremented to protect the old-time value from
94  // being updated at the beginning of the time-loop in the case of
95  // outer iteration
96  void updateTimeIndex()
97  {
98  gf_.timeIndex() = gf_.time().timeIndex() + 1;
99  gf0_.timeIndex() = gf_.time().timeIndex() + 1;
100  }
101 };
102 
103 
104 /*---------------------------------------------------------------------------*\
105  Class subCycle Declaration
106 \*---------------------------------------------------------------------------*/
107 
108 template<class GeometricField>
109 class subCycle
110 :
111  public subCycleField<GeometricField>,
112  public subCycleTime
113 {
114  // Private Member Functions
115 
116  //- No copy construct
117  subCycle(const subCycle<GeometricField>&) = delete;
118 
119  //- No copy assignment
120  void operator=(const subCycle<GeometricField>&) = delete;
121 
122 
123 public:
124 
125  // Constructors
126 
127  //- Construct field and number of sub-cycles
128  subCycle(GeometricField& gf, const label nCycles)
129  :
131  subCycleTime(const_cast<Time&>(gf.time()), nCycles)
132  {
133  // Update the field time index to correspond to the sub-cycle time
134  this->updateTimeIndex();
135  }
136 
137 
138  //- Destructor
139  // End the subCycleTime, which restores the time state
140  ~subCycle()
141  {
142  endSubCycle();
143  }
144 };
145 
146 
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 
149 } // End namespace Foam
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 #endif
154 
155 // ************************************************************************* //
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::subCycle::~subCycle
~subCycle()
Destructor.
Definition: subCycle.H:139
oldTime
Info<< "Creating field kinetic energy K\n"<< endl;volScalarField K("K", 0.5 *magSqr(U));if(U.nOldTimes()){ volVectorField *Uold=&U.oldTime();volScalarField *Kold=&K.oldTime();*Kold==0.5 *magSqr(*Uold);while(Uold->nOldTimes()) { Uold=&Uold-> oldTime()
Definition: createK.H:12
Foam::subCycle::subCycle
subCycle(GeometricField &gf, const label nCycles)
Construct field and number of sub-cycles.
Definition: subCycle.H:127
Foam::subCycleTime
A class for managing sub-cycling times.
Definition: subCycleTime.H:50
Foam::subCycleTime::endSubCycle
void endSubCycle()
End the sub-cycling and reset the time-state.
Definition: subCycleTime.C:65
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
subCycleTime.H
Foam::subCycleField
Definition: subCycle.H:48
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::subCycleField::subCycleField
subCycleField(GeometricField &gf)
Construct field and number of sub-cycles.
Definition: subCycle.H:69
Foam::GeometricField::timeIndex
label timeIndex() const
Return the time index of the field.
Definition: GeometricFieldI.H:70
Foam::subCycleField::updateTimeIndex
void updateTimeIndex()
Correct the time index of the field to correspond to.
Definition: subCycle.H:95
Foam::subCycleField::~subCycleField
~subCycleField()
Destructor.
Definition: subCycle.H:78
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::subCycle
Perform a subCycleTime on a field.
Definition: subCycle.H:108