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  tmp<GeometricField> gf_0_;
63 
64  GeometricField& gf00_;
65 
66  //- Copy of the "real" old-old-time value of the field
67  tmp<GeometricField> gf_00_;
68 
69 
70 public:
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 
123 template<class GeometricField>
124 class 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 
138 public:
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 // ************************************************************************* //
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:154
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
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:142
Foam::subCycleTime
A class for managing sub-cycling times.
Definition: subCycleTime.H:50
Foam::GeometricField::New
static tmp< GeometricField< Type, PatchField, GeoMesh > > New(const word &name, const Mesh &mesh, const dimensionSet &ds, const word &patchFieldType=PatchField< Type >::calculatedType())
Return tmp field from name, mesh, dimensions and patch type.
Definition: GeometricFieldNew.C:34
Foam::subCycleTime::endSubCycle
void endSubCycle()
End the sub-cycling and reset the time-state.
Definition: subCycleTime.C:68
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:74
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:109
Foam::tmp::valid
bool valid() const noexcept
Identical to good(), or bool operator.
Definition: tmp.H:292
Foam::subCycleField::~subCycleField
~subCycleField()
Destructor.
Definition: subCycle.H:88
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::subCycle
Perform a subCycleTime on a field.
Definition: subCycle.H:123