mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3318 Plot editor performance. Several performance fixes
This commit is contained in:
@@ -43,12 +43,12 @@ RifEclipseSummaryAddress::RifEclipseSummaryAddress(SummaryVarCategory category,
|
||||
m_aquiferNumber(-1),
|
||||
m_isErrorResult(false)
|
||||
{
|
||||
std::tuple<int, int, int> ijkTuple;
|
||||
std::pair<int, int> reg2regPair;
|
||||
std::tuple<int32_t, int32_t, int32_t> ijkTuple;
|
||||
std::pair<int16_t, int16_t> reg2regPair;
|
||||
switch (category)
|
||||
{
|
||||
case SUMMARY_REGION:
|
||||
m_regionNumber = RiaStdStringTools::toInt(identifiers[INPUT_REGION_NUMBER]);
|
||||
m_regionNumber = RiaStdStringTools::toInt16(identifiers[INPUT_REGION_NUMBER]);
|
||||
break;
|
||||
case SUMMARY_REGION_2_REGION:
|
||||
reg2regPair = regionToRegionPairFromUiText(identifiers[INPUT_REGION_2_REGION]);
|
||||
@@ -783,14 +783,14 @@ std::string RifEclipseSummaryAddress::formatUiTextRegionToRegion() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<int, int> RifEclipseSummaryAddress::regionToRegionPairFromUiText(const std::string &s)
|
||||
std::pair<int16_t, int16_t> RifEclipseSummaryAddress::regionToRegionPairFromUiText(const std::string &s)
|
||||
{
|
||||
QStringList r2r = QString().fromStdString(s).trimmed().split(QRegExp("[-]"));
|
||||
|
||||
if (r2r.size() != 2) return std::make_pair(-1, -1);
|
||||
if (r2r.size() != 2) return std::make_pair((int16_t)-1, (int16_t)-1);
|
||||
|
||||
return std::make_pair(RiaStdStringTools::toInt(r2r[0].trimmed().toStdString()),
|
||||
RiaStdStringTools::toInt(r2r[1].trimmed().toStdString()));
|
||||
return std::make_pair(RiaStdStringTools::toInt16(r2r[0].trimmed().toStdString()),
|
||||
RiaStdStringTools::toInt16(r2r[1].trimmed().toStdString()));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -890,7 +890,6 @@ bool operator!=(const RifEclipseSummaryAddress& first, const RifEclipseSummaryAd
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool operator<(const RifEclipseSummaryAddress& first, const RifEclipseSummaryAddress& second)
|
||||
{
|
||||
if(first.category() != second.category()) return first.category() < second.category();
|
||||
if(first.quantityName() != second.quantityName()) return first.quantityName() < second.quantityName();
|
||||
|
||||
switch(first.category())
|
||||
|
||||
@@ -39,7 +39,7 @@ class RifEclipseSummaryAddress
|
||||
public:
|
||||
|
||||
// Based on list in ecl_smspec.c and list of types taken from Eclipse Reference Manual ecl_rm_2011.1.pdf
|
||||
enum SummaryVarCategory
|
||||
enum SummaryVarCategory : int8_t
|
||||
{
|
||||
SUMMARY_INVALID,
|
||||
SUMMARY_FIELD,
|
||||
@@ -91,16 +91,16 @@ public:
|
||||
|
||||
RifEclipseSummaryAddress(SummaryVarCategory category,
|
||||
const std::string& quantityName,
|
||||
int regionNumber,
|
||||
int regionNumber2,
|
||||
int16_t regionNumber,
|
||||
int16_t regionNumber2,
|
||||
const std::string& wellGroupName,
|
||||
const std::string& wellName,
|
||||
int wellSegmentNumber,
|
||||
int16_t wellSegmentNumber,
|
||||
const std::string& lgrName,
|
||||
int cellI,
|
||||
int cellJ,
|
||||
int cellK,
|
||||
int aquiferNumber,
|
||||
int32_t cellI,
|
||||
int32_t cellJ,
|
||||
int32_t cellK,
|
||||
int16_t aquiferNumber,
|
||||
bool isErrorResult):
|
||||
m_variableCategory(category),
|
||||
m_quantityName(quantityName),
|
||||
@@ -172,34 +172,33 @@ public:
|
||||
void setQuantityName(const std::string& quantity) { m_quantityName = quantity; }
|
||||
void setWellName(const std::string& wellName) { m_wellName = wellName; }
|
||||
void setWellGroupName(const std::string& wellGroupName) { m_wellGroupName = wellGroupName; }
|
||||
void setRegion(int region) { m_regionNumber = region; }
|
||||
void setAquiferNumber(int aquiferNumber) { m_aquiferNumber = aquiferNumber; }
|
||||
void setRegion(int region) { m_regionNumber = (int16_t)region; }
|
||||
void setAquiferNumber(int aquiferNumber) { m_aquiferNumber = (int16_t)aquiferNumber; }
|
||||
|
||||
void setAsErrorResult() { m_isErrorResult = true; }
|
||||
bool isErrorResult() const { return m_isErrorResult; }
|
||||
bool hasAccumulatedData() const;
|
||||
|
||||
private:
|
||||
bool isValidEclipseCategory() const;
|
||||
static std::string baseQuantityName(const std::string& quantityName);
|
||||
std::string formatUiTextIJK() const;
|
||||
static std::tuple<int, int, int> ijkTupleFromUiText(const std::string &s);
|
||||
std::string formatUiTextRegionToRegion() const;
|
||||
std::pair<int, int> regionToRegionPairFromUiText(const std::string &s);
|
||||
bool isValidEclipseCategory() const;
|
||||
static std::string baseQuantityName(const std::string& quantityName);
|
||||
std::string formatUiTextIJK() const;
|
||||
static std::tuple<int32_t, int32_t, int32_t> ijkTupleFromUiText(const std::string &s);
|
||||
std::string formatUiTextRegionToRegion() const;
|
||||
std::pair<int16_t, int16_t> regionToRegionPairFromUiText(const std::string &s);
|
||||
|
||||
SummaryVarCategory m_variableCategory;
|
||||
std::string m_quantityName;
|
||||
int m_regionNumber;
|
||||
int m_regionNumber2;
|
||||
std::string m_wellGroupName;
|
||||
std::string m_wellName;
|
||||
int m_wellSegmentNumber;
|
||||
std::string m_lgrName;
|
||||
int m_cellI;
|
||||
int m_cellJ;
|
||||
int m_cellK;
|
||||
int m_aquiferNumber;
|
||||
|
||||
int32_t m_cellI;
|
||||
int32_t m_cellJ;
|
||||
int32_t m_cellK;
|
||||
int16_t m_regionNumber;
|
||||
int16_t m_regionNumber2;
|
||||
int16_t m_wellSegmentNumber;
|
||||
int16_t m_aquiferNumber;
|
||||
SummaryVarCategory m_variableCategory;
|
||||
bool m_isErrorResult;
|
||||
};
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ RifReaderEclipseSummary::RifReaderEclipseSummary()
|
||||
: m_ecl_sum(nullptr),
|
||||
m_ecl_SmSpec(nullptr)
|
||||
{
|
||||
|
||||
m_valuesCache.reset(new ValuesCache());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -384,7 +384,12 @@ bool RifReaderEclipseSummary::values(const RifEclipseSummaryAddress& resultAddre
|
||||
values->clear();
|
||||
values->reserve(timeStepCount());
|
||||
|
||||
if (m_ecl_SmSpec)
|
||||
const std::vector<double>& cachedValues = m_valuesCache->getValues(resultAddress);
|
||||
if (!cachedValues.empty())
|
||||
{
|
||||
values->insert(values->begin(), cachedValues.begin(), cachedValues.end());
|
||||
}
|
||||
else if (m_ecl_SmSpec)
|
||||
{
|
||||
const smspec_node_type* ertSumVarNode = ecl_smspec_iget_node(m_ecl_SmSpec, variableIndex);
|
||||
int paramsIndex = smspec_node_get_params_index(ertSumVarNode);
|
||||
@@ -398,6 +403,8 @@ bool RifReaderEclipseSummary::values(const RifEclipseSummaryAddress& resultAddre
|
||||
values->push_back(double_vector_iget(dataValues, i));
|
||||
}
|
||||
free(dataValues);
|
||||
|
||||
m_valuesCache->insertValues(resultAddress, *values);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,6 +526,22 @@ std::string RifReaderEclipseSummary::unitName(const RifEclipseSummaryAddress& re
|
||||
return smspec_node_get_unit(ertSumVarNode);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifReaderEclipseSummary::markForCachePurge(const RifEclipseSummaryAddress& address)
|
||||
{
|
||||
m_valuesCache->markAddressForPurge(address);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifReaderEclipseSummary::purgeCache()
|
||||
{
|
||||
ValuesCache::purge();
|
||||
}
|
||||
|
||||
#if 0
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@@ -534,3 +557,76 @@ void RifReaderEclipseSummary::populateVectorFromStringList(stringlist_type* stri
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<double> RifReaderEclipseSummary::ValuesCache::EMPTY_VECTOR;
|
||||
std::set<RifReaderEclipseSummary::ValuesCache*> RifReaderEclipseSummary::ValuesCache::m_instances;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifReaderEclipseSummary::ValuesCache::ValuesCache()
|
||||
{
|
||||
// Register instance
|
||||
m_instances.insert(this);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifReaderEclipseSummary::ValuesCache::~ValuesCache()
|
||||
{
|
||||
// Deregister instance
|
||||
m_instances.erase(this);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifReaderEclipseSummary::ValuesCache::insertValues(const RifEclipseSummaryAddress& address, const std::vector<double>& values)
|
||||
{
|
||||
m_cachedValues[address] = values;
|
||||
m_purgeList.erase(address);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<double>& RifReaderEclipseSummary::ValuesCache::getValues(const RifEclipseSummaryAddress& address) const
|
||||
{
|
||||
if (m_cachedValues.find(address) != m_cachedValues.end())
|
||||
{
|
||||
return m_cachedValues.at(address);
|
||||
}
|
||||
return EMPTY_VECTOR;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifReaderEclipseSummary::ValuesCache::markAddressForPurge(const RifEclipseSummaryAddress& address)
|
||||
{
|
||||
m_purgeList.insert(address);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifReaderEclipseSummary::ValuesCache::purge()
|
||||
{
|
||||
for (auto instance : m_instances) instance->purgeData();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifReaderEclipseSummary::ValuesCache::purgeData()
|
||||
{
|
||||
for (const auto purgeAddr : m_purgeList)
|
||||
{
|
||||
m_cachedValues.erase(purgeAddr);
|
||||
}
|
||||
m_purgeList.clear();
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <memory>
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
@@ -68,6 +70,9 @@ public:
|
||||
|
||||
QStringList warnings() const { return m_warnings; }
|
||||
|
||||
virtual void markForCachePurge(const RifEclipseSummaryAddress& address) override;
|
||||
static void purgeCache();
|
||||
|
||||
private:
|
||||
int timeStepCount() const;
|
||||
int indexFromAddress(const RifEclipseSummaryAddress& resultAddress) const;
|
||||
@@ -86,5 +91,33 @@ private:
|
||||
std::map<RifEclipseSummaryAddress, int> m_resultAddressToErtNodeIdx;
|
||||
|
||||
QStringList m_warnings;
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//==================================================================================================
|
||||
class ValuesCache
|
||||
{
|
||||
static const std::vector<double> EMPTY_VECTOR;
|
||||
|
||||
public:
|
||||
ValuesCache();
|
||||
~ValuesCache();
|
||||
|
||||
void insertValues(const RifEclipseSummaryAddress& address, const std::vector<double>& values);
|
||||
const std::vector<double>& getValues(const RifEclipseSummaryAddress& address) const;
|
||||
void markAddressForPurge(const RifEclipseSummaryAddress& address);
|
||||
static void purge();
|
||||
|
||||
private:
|
||||
void purgeData();
|
||||
|
||||
std::map<const RifEclipseSummaryAddress, std::vector<double>> m_cachedValues;
|
||||
std::set<RifEclipseSummaryAddress> m_purgeList;
|
||||
|
||||
static std::set<ValuesCache*> m_instances;
|
||||
};
|
||||
|
||||
std::unique_ptr<ValuesCache> m_valuesCache;
|
||||
};
|
||||
|
||||
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
// TODO: Move this to a tools class with static members
|
||||
static std::vector<QDateTime> fromTimeT(const std::vector<time_t>& timeSteps);
|
||||
|
||||
virtual void markForCachePurge(const RifEclipseSummaryAddress& address) {}
|
||||
|
||||
protected:
|
||||
std::set<RifEclipseSummaryAddress> m_allResultAddresses; // Result and error addresses
|
||||
std::set<RifEclipseSummaryAddress> m_allErrorAddresses; // Error addresses
|
||||
|
||||
Reference in New Issue
Block a user