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 const IntensiveQuantities* cachedIntensiveQuantities(unsigned globalIdx, unsigned timeIdx) const
{ {
if (!enableIntensiveQuantityCache_ || if (!enableIntensiveQuantityCache_ || !intensiveQuantityCacheUpToDate_[timeIdx][globalIdx]) {
!intensiveQuantityCacheUpToDate_[timeIdx][globalIdx]) return nullptr;
return 0; }
if (timeIdx > 0 && enableStorageCache_) // With the storage cache enabled, usually only the
// with the storage cache enabled, only the intensive quantities for the most // intensive quantities for the most recent time step are
// recent time step are cached! // cached. However, this may be false for some Problem
return 0; // 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]; return &intensiveQuantityCache_[timeIdx][globalIdx];
} }
@ -818,10 +822,13 @@ public:
if (!storeIntensiveQuantities()) if (!storeIntensiveQuantities())
return; return;
if (enableStorageCache()) { if (enableStorageCache() && simulator_.problem().recycleFirstIterationStorage()) {
// if the storage term is cached, the intensive quantities of the previous // 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 // time steps do not need to be accessed, and we can thus spare ourselves to
// copy the objects for the intensive quantities. // 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; return;
} }