#7400 StimPlanModel: Cache calculated results.

This commit is contained in:
Kristian Bendiksen
2021-02-24 11:49:21 +01:00
committed by Magne Sjaastad
parent 762e36ae9d
commit 35525eeedf
3 changed files with 52 additions and 4 deletions

View File

@@ -77,18 +77,56 @@ bool RimStimPlanModelCalculator::extractCurveData( RiaDefines::CurveProperty cur
std::vector<double>& tvDepthValues,
double& rkbDiff ) const
{
for ( const auto& calculator : m_resultCalculators )
ResultKey key = std::make_pair( curveProperty, timeStep );
auto data = m_resultCache.find( key );
if ( data != m_resultCache.end() )
{
if ( calculator->isMatching( curveProperty ) )
// Cache hit: reuse previous result
auto [cachedValues, cachedMeasuredDepthValues, cachedTvDepthValues, cachedRkbDiff] = data->second;
values = cachedValues;
measuredDepthValues = cachedMeasuredDepthValues;
tvDepthValues = cachedTvDepthValues;
rkbDiff = cachedRkbDiff;
return true;
}
else
{
// Cache miss: try to calculate the request data
for ( const auto& calculator : m_resultCalculators )
{
return calculator
->calculate( curveProperty, m_stimPlanModel, timeStep, values, measuredDepthValues, tvDepthValues, rkbDiff );
if ( calculator->isMatching( curveProperty ) )
{
bool isOk = calculator->calculate( curveProperty,
m_stimPlanModel,
timeStep,
values,
measuredDepthValues,
tvDepthValues,
rkbDiff );
if ( isOk )
{
// Populate cache when calculation succeeds
m_resultCache[key] = std::make_tuple( values, measuredDepthValues, tvDepthValues, rkbDiff );
}
return isOk;
}
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStimPlanModelCalculator::clearCache()
{
m_resultCache.clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------