mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-20 21:43:20 -06:00
#7400 StimPlanModel: Cache calculated results.
This commit is contained in:
parent
762e36ae9d
commit
35525eeedf
@ -379,6 +379,7 @@ void RimStimPlanModel::fieldChangedByUi( const caf::PdmFieldHandle* changedField
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
m_calculator->clearCache();
|
||||||
updateViewsAndPlots();
|
updateViewsAndPlots();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1692,6 +1693,8 @@ RimStimPlanModelTemplate* RimStimPlanModel::stimPlanModelTemplate() const
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RimStimPlanModel::stimPlanModelTemplateChanged( const caf::SignalEmitter* emitter )
|
void RimStimPlanModel::stimPlanModelTemplateChanged( const caf::SignalEmitter* emitter )
|
||||||
{
|
{
|
||||||
|
m_calculator->clearCache();
|
||||||
|
|
||||||
if ( m_stimPlanModelTemplate() )
|
if ( m_stimPlanModelTemplate() )
|
||||||
{
|
{
|
||||||
m_eclipseCase = m_stimPlanModelTemplate()->dynamicEclipseCase();
|
m_eclipseCase = m_stimPlanModelTemplate()->dynamicEclipseCase();
|
||||||
|
@ -77,18 +77,56 @@ bool RimStimPlanModelCalculator::extractCurveData( RiaDefines::CurveProperty cur
|
|||||||
std::vector<double>& tvDepthValues,
|
std::vector<double>& tvDepthValues,
|
||||||
double& rkbDiff ) const
|
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
|
if ( calculator->isMatching( curveProperty ) )
|
||||||
->calculate( curveProperty, m_stimPlanModel, timeStep, values, measuredDepthValues, tvDepthValues, rkbDiff );
|
{
|
||||||
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RimStimPlanModelCalculator::clearCache()
|
||||||
|
{
|
||||||
|
m_resultCache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "RimStimPlanModelPropertyCalculator.h"
|
#include "RimStimPlanModelPropertyCalculator.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -66,6 +67,8 @@ public:
|
|||||||
|
|
||||||
void calculateTemperature( std::vector<double>& temperatures ) const;
|
void calculateTemperature( std::vector<double>& temperatures ) const;
|
||||||
|
|
||||||
|
void clearCache();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<double> findCurveAndComputeLayeredAverage( RiaDefines::CurveProperty curveProperty ) const;
|
std::vector<double> findCurveAndComputeLayeredAverage( RiaDefines::CurveProperty curveProperty ) const;
|
||||||
std::vector<double> findCurveXValuesByProperty( RiaDefines::CurveProperty curveProperty ) const;
|
std::vector<double> findCurveXValuesByProperty( RiaDefines::CurveProperty curveProperty ) const;
|
||||||
@ -93,4 +96,8 @@ protected:
|
|||||||
private:
|
private:
|
||||||
RimStimPlanModel* m_stimPlanModel;
|
RimStimPlanModel* m_stimPlanModel;
|
||||||
std::vector<std::unique_ptr<RimStimPlanModelPropertyCalculator>> m_resultCalculators;
|
std::vector<std::unique_ptr<RimStimPlanModelPropertyCalculator>> m_resultCalculators;
|
||||||
|
|
||||||
|
typedef std::pair<RiaDefines::CurveProperty, int> ResultKey;
|
||||||
|
typedef std::tuple<std::vector<double>, std::vector<double>, std::vector<double>, double> ResultData;
|
||||||
|
mutable std::map<ResultKey, ResultData> m_resultCache;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user