Account for the recycleFirstIteration() false possibility.

This commit is contained in:
Atgeirr Flø Rasmussen 2023-05-22 17:39:15 +02:00
parent 2628472f7a
commit 65739e15d6

View File

@ -723,14 +723,18 @@ public:
*/
const IntensiveQuantities* cachedIntensiveQuantities(unsigned globalIdx, unsigned timeIdx) const
{
if (!enableIntensiveQuantityCache_ ||
!intensiveQuantityCacheUpToDate_[timeIdx][globalIdx])
return 0;
if (!enableIntensiveQuantityCache_ || !intensiveQuantityCacheUpToDate_[timeIdx][globalIdx]) {
return nullptr;
}
if (timeIdx > 0 && enableStorageCache_)
// with the storage cache enabled, only the intensive quantities for the most
// recent time step are cached!
return 0;
// With the storage cache enabled, usually only the
// intensive quantities for the most recent time step are
// cached. However, this may be false for some Problem
// variants, so we should check if the cache exists for
// the timeIdx in question.
if (timeIdx > 0 && enableStorageCache_ && intensiveQuantityCache_[timeIdx].empty()) {
return nullptr;
}
return &intensiveQuantityCache_[timeIdx][globalIdx];
}
@ -818,10 +822,13 @@ public:
if (!storeIntensiveQuantities())
return;
if (enableStorageCache()) {
// if the storage term is cached, the intensive quantities of the previous
if (enableStorageCache() && simulator_.problem().recycleFirstIterationStorage()) {
// If the storage term is cached, the intensive quantities of the previous
// time steps do not need to be accessed, and we can thus spare ourselves to
// copy the objects for the intensive quantities.
// However, if the storage term at the start of the timestep cannot be deduced
// from the primary variables, we must calculate it from the old intensive
// quantities, and need to shift them.
return;
}