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-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::subCycle
28
29Description
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
41namespace Foam
42{
43
44/*---------------------------------------------------------------------------*\
45 Class subCycleField Declaration
46\*---------------------------------------------------------------------------*/
47
48template<class GeometricField>
49class 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
63
64 GeometricField& gf00_;
65
66 //- Copy of the "real" old-old-time value of the field
68
69
70public:
71
72 // Constructors
73
74 //- Construct field and number of sub-cycles
76 :
77 gf_(gf),
78 gf0_(gf.oldTime()),
79 gf00_(gf.oldTime().oldTime())
80 {
81 {
82 gf_0_ = GeometricField::New(gf0_.name() + "_", gf0_);
83 gf_00_ = GeometricField::New(gf00_.name() + "_", gf00_);
84 }
85 }
86
87
88 //- Destructor
90 {
91 if (gf_0_.valid())
92 {
93 // Reset the old-time field
94 gf0_ = gf_0_;
95
96 gf00_ = gf_00_;
97
98 // Correct the time index of the field to correspond to the global time
99 gf_.timeIndex() = gf_.time().timeIndex();
100 }
101 }
102
103
104 //- Correct the time index of the field to correspond to
105 // the sub-cycling time.
106 //
107 // The time index is incremented to protect the old-time value from
108 // being updated at the beginning of the time-loop in the case of
109 // outer iteration
110 void updateTimeIndex()
111 {
112 gf_.timeIndex() = gf_.time().timeIndex() + 1;
113 gf0_.timeIndex() = gf0_.time().timeIndex() + 1;
114 gf00_.timeIndex() = gf00_.time().timeIndex() + 1;
115 }
116};
117
118
119/*---------------------------------------------------------------------------*\
120 Class subCycle Declaration
121\*---------------------------------------------------------------------------*/
122
123template<class GeometricField>
124class subCycle
125:
126 public subCycleField<GeometricField>,
127 public subCycleTime
128{
129 // Private Member Functions
130
131 //- No copy construct
132 subCycle(const subCycle<GeometricField>&) = delete;
133
134 //- No copy assignment
135 void operator=(const subCycle<GeometricField>&) = delete;
136
137
138public:
139
140 // Constructors
141
142 //- Construct field and number of sub-cycles
143 subCycle(GeometricField& gf, const label nCycles)
144 :
146 subCycleTime(const_cast<Time&>(gf.time()), nCycles)
147 {
148 // Update the field time index to correspond to the sub-cycle time
149 this->updateTimeIndex();
150 }
151
152
153 //- Destructor
154 // End the subCycleTime, which restores the time state
155 ~subCycle()
156 {
157 endSubCycle();
158 }
159};
160
161
162// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163
164} // End namespace Foam
165
166// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167
168#endif
169
170// ************************************************************************* //
Generic GeometricField class.
label timeIndex() const
Return the time index of the field.
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
const Time & time() const
Return Time associated with the objectRegistry.
Definition: IOobject.C:506
label timeIndex() const noexcept
Return current time index.
Definition: TimeStateI.H:37
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
void updateTimeIndex()
Correct the time index of the field to correspond to.
Definition: subCycle.H:109
~subCycleField()
Destructor.
Definition: subCycle.H:88
subCycleField(GeometricField &gf)
Construct field and number of sub-cycles.
Definition: subCycle.H:74
A class for managing sub-cycling times.
Definition: subCycleTime.H:51
void endSubCycle()
End the sub-cycling and reset the time-state.
Definition: subCycleTime.C:68
Perform a subCycleTime on a field.
Definition: subCycle.H:127
subCycle(GeometricField &gf, const label nCycles)
Construct field and number of sub-cycles.
Definition: subCycle.H:142
~subCycle()
Destructor.
Definition: subCycle.H:154
A class for managing temporary objects.
Definition: tmp.H:65
bool valid() const noexcept
Identical to good(), or bool operator.
Definition: tmp.H:292
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()
Namespace for OpenFOAM.