mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
subCycle: Updated handling of the old-time field and timeIndex to support outer-iterations
This commit is contained in:
@ -51,8 +51,13 @@ class subCycleField
|
||||
//- Reference to the field being sub-cycled
|
||||
GeometricField& gf_;
|
||||
|
||||
//- Reference to the field old-time field being sub-cycled
|
||||
// Needed to avoid calls to oldTime() which may cause
|
||||
// unexpected updates of the old-time field
|
||||
GeometricField& gf0_;
|
||||
|
||||
//- Copy of the "real" old-time value of the field
|
||||
GeometricField gf0_;
|
||||
GeometricField gf_0_;
|
||||
|
||||
|
||||
public:
|
||||
@ -63,19 +68,33 @@ public:
|
||||
subCycleField(GeometricField& gf)
|
||||
:
|
||||
gf_(gf),
|
||||
gf0_(gf.oldTime())
|
||||
gf0_(gf.oldTime()),
|
||||
gf_0_(gf0_.name() + "_", gf0_)
|
||||
{}
|
||||
|
||||
|
||||
//- Destructor
|
||||
~subCycleField()
|
||||
{
|
||||
// Reset the old-time field
|
||||
gf0_ = gf_0_;
|
||||
|
||||
// Correct the time index of the field to correspond to the global time
|
||||
gf_.timeIndex() = gf_.time().timeIndex();
|
||||
gf0_.timeIndex() = gf_.time().timeIndex();
|
||||
}
|
||||
|
||||
// Reset the old-time field value
|
||||
gf_.oldTime() = gf0_;
|
||||
gf_.oldTime().timeIndex() = gf0_.timeIndex();
|
||||
|
||||
//- Correct the time index of the field to correspond to
|
||||
// the sub-cycling time.
|
||||
//
|
||||
// The time index is incremented to protect the old-time value from
|
||||
// being updated at the beginning of the time-loop in the case of
|
||||
// outer iteration
|
||||
void updateTimeIndex()
|
||||
{
|
||||
gf_.timeIndex() = gf_.time().timeIndex() + 1;
|
||||
gf0_.timeIndex() = gf_.time().timeIndex() + 1;
|
||||
}
|
||||
};
|
||||
|
||||
@ -106,16 +125,18 @@ public:
|
||||
//- Construct field and number of sub-cycles
|
||||
subCycle(GeometricField& gf, const label nSubCycles)
|
||||
:
|
||||
|
||||
subCycleField<GeometricField>(gf),
|
||||
subCycleTime(const_cast<Time&>(gf.time()), nSubCycles)
|
||||
{}
|
||||
{
|
||||
// Update the field time index to correspond to the sub-cycle time
|
||||
this->updateTimeIndex();
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
// End the subCycleTime, which restores the time state
|
||||
~subCycle()
|
||||
{
|
||||
// End the subCycleTime, which restores the time state
|
||||
endSubCycle();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user