mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3061 Implement Memory Cleanup for eclipse data.
This commit is contained in:
@@ -19,10 +19,13 @@
|
|||||||
#include "RiaMemoryCleanup.h"
|
#include "RiaMemoryCleanup.h"
|
||||||
|
|
||||||
#include "RiaApplication.h"
|
#include "RiaApplication.h"
|
||||||
|
#include "RigCaseCellResultsData.h"
|
||||||
#include "RigFemPartResultsCollection.h"
|
#include "RigFemPartResultsCollection.h"
|
||||||
#include "RigFemResultAddress.h"
|
#include "RigFemResultAddress.h"
|
||||||
#include "RigGeoMechCaseData.h"
|
#include "RigGeoMechCaseData.h"
|
||||||
#include "Rim3dView.h"
|
#include "Rim3dView.h"
|
||||||
|
#include "RimEclipseCase.h"
|
||||||
|
#include "RimEclipseResultDefinition.h"
|
||||||
#include "RimGeoMechCase.h"
|
#include "RimGeoMechCase.h"
|
||||||
#include "RimGeoMechResultDefinition.h"
|
#include "RimGeoMechResultDefinition.h"
|
||||||
#include "RimProject.h"
|
#include "RimProject.h"
|
||||||
@@ -71,8 +74,21 @@ void RiaMemoryCleanup::setPropertiesFromView(Rim3dView* view)
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiaMemoryCleanup::clearSelectedResultsFromMemory()
|
void RiaMemoryCleanup::clearSelectedResultsFromMemory()
|
||||||
{
|
{
|
||||||
|
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(m_case());
|
||||||
RimGeoMechCase* geoMechCase = dynamic_cast<RimGeoMechCase*>(m_case());
|
RimGeoMechCase* geoMechCase = dynamic_cast<RimGeoMechCase*>(m_case());
|
||||||
if (geoMechCase)
|
if (eclipseCase)
|
||||||
|
{
|
||||||
|
RigCaseCellResultsData* caseData = eclipseCase->results(RiaDefines::MATRIX_MODEL);
|
||||||
|
if (caseData)
|
||||||
|
{
|
||||||
|
std::vector<RigEclipseResultInfo> resultsToDelete = selectedEclipseResults();
|
||||||
|
for (const RigEclipseResultInfo& resultInfo : resultsToDelete)
|
||||||
|
{
|
||||||
|
caseData->clearScalarResult(resultInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (geoMechCase)
|
||||||
{
|
{
|
||||||
RigGeoMechCaseData* data = geoMechCase->geoMechData();
|
RigGeoMechCaseData* data = geoMechCase->geoMechData();
|
||||||
if (data)
|
if (data)
|
||||||
@@ -89,6 +105,7 @@ void RiaMemoryCleanup::clearSelectedResultsFromMemory()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_resultsToDelete.v().clear();
|
m_resultsToDelete.v().clear();
|
||||||
|
m_eclipseResultAddresses.clear();
|
||||||
m_geomResultAddresses.clear();
|
m_geomResultAddresses.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,9 +115,30 @@ void RiaMemoryCleanup::clearSelectedResultsFromMemory()
|
|||||||
std::vector<RigFemResultAddress> RiaMemoryCleanup::selectedGeoMechResults() const
|
std::vector<RigFemResultAddress> RiaMemoryCleanup::selectedGeoMechResults() const
|
||||||
{
|
{
|
||||||
std::vector<RigFemResultAddress> results;
|
std::vector<RigFemResultAddress> results;
|
||||||
for (size_t index : m_resultsToDelete())
|
if (dynamic_cast<const RimGeoMechCase*>(m_case()))
|
||||||
{
|
{
|
||||||
results.push_back(m_geomResultAddresses[index]);
|
for (size_t index : m_resultsToDelete())
|
||||||
|
{
|
||||||
|
CVF_ASSERT(index < m_geomResultAddresses.size());
|
||||||
|
results.push_back(m_geomResultAddresses[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
std::vector<RigEclipseResultInfo> RiaMemoryCleanup::selectedEclipseResults() const
|
||||||
|
{
|
||||||
|
std::vector<RigEclipseResultInfo> results;
|
||||||
|
if (dynamic_cast<const RimEclipseCase*>(m_case()))
|
||||||
|
{
|
||||||
|
for (size_t index : m_resultsToDelete())
|
||||||
|
{
|
||||||
|
CVF_ASSERT(index < m_eclipseResultAddresses.size());
|
||||||
|
results.push_back(m_eclipseResultAddresses[index]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
@@ -129,6 +167,26 @@ std::set<RigFemResultAddress> RiaMemoryCleanup::findGeoMechCaseResultsInUse() co
|
|||||||
return resultsInUse;
|
return resultsInUse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
std::set<RigEclipseResultInfo> RiaMemoryCleanup::findEclipseResultsInUse() const
|
||||||
|
{
|
||||||
|
std::set<RigEclipseResultInfo> resultsInUse;
|
||||||
|
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(m_case());
|
||||||
|
if (eclipseCase)
|
||||||
|
{
|
||||||
|
std::vector<RimEclipseResultDefinition*> eclipseResultDefs;
|
||||||
|
eclipseCase->descendantsIncludingThisOfType(eclipseResultDefs);
|
||||||
|
for (RimEclipseResultDefinition* resultDef : eclipseResultDefs)
|
||||||
|
{
|
||||||
|
RigEclipseResultInfo resultInfo(resultDef->resultType(), resultDef->resultVariable());
|
||||||
|
resultsInUse.insert(resultInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultsInUse;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -170,8 +228,35 @@ QList<caf::PdmOptionItemInfo> RiaMemoryCleanup::calculateValueOptions(const caf:
|
|||||||
}
|
}
|
||||||
else if (fieldNeedingOptions == &m_resultsToDelete)
|
else if (fieldNeedingOptions == &m_resultsToDelete)
|
||||||
{
|
{
|
||||||
|
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(m_case());
|
||||||
RimGeoMechCase* geoMechCase = dynamic_cast<RimGeoMechCase*>(m_case());
|
RimGeoMechCase* geoMechCase = dynamic_cast<RimGeoMechCase*>(m_case());
|
||||||
if (geoMechCase)
|
if (eclipseCase)
|
||||||
|
{
|
||||||
|
std::set<RigEclipseResultInfo> resultsInUse = findEclipseResultsInUse();
|
||||||
|
RigCaseCellResultsData* caseData = eclipseCase->results(RiaDefines::MATRIX_MODEL);
|
||||||
|
if (caseData)
|
||||||
|
{
|
||||||
|
m_eclipseResultAddresses = caseData->infoForEachResultIndex();
|
||||||
|
|
||||||
|
for (size_t i = 0; i < m_eclipseResultAddresses.size(); ++i)
|
||||||
|
{
|
||||||
|
const RigEclipseResultInfo& result = m_eclipseResultAddresses[i];
|
||||||
|
if (caseData->isResultLoaded(result))
|
||||||
|
{
|
||||||
|
bool inUse = resultsInUse.count(result);
|
||||||
|
QString posText = caf::AppEnum<RiaDefines::ResultCatType>::uiTextFromIndex(result.resultType());
|
||||||
|
QString resultsText = QString("%1, %2").arg(posText).arg(result.resultName());
|
||||||
|
if (inUse)
|
||||||
|
{
|
||||||
|
resultsText += QString(" [used in view]");
|
||||||
|
}
|
||||||
|
options.push_back(caf::PdmOptionItemInfo(resultsText, (qulonglong)i, inUse));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (geoMechCase)
|
||||||
{
|
{
|
||||||
std::set<RigFemResultAddress> resultsInUse = findGeoMechCaseResultsInUse();
|
std::set<RigFemResultAddress> resultsInUse = findGeoMechCaseResultsInUse();
|
||||||
RigGeoMechCaseData* caseData = geoMechCase->geoMechData();
|
RigGeoMechCaseData* caseData = geoMechCase->geoMechData();
|
||||||
@@ -192,7 +277,7 @@ QList<caf::PdmOptionItemInfo> RiaMemoryCleanup::calculateValueOptions(const caf:
|
|||||||
}
|
}
|
||||||
if (inUse)
|
if (inUse)
|
||||||
{
|
{
|
||||||
resultsText += QString(" [shown in view]");
|
resultsText += QString(" [used in view]");
|
||||||
}
|
}
|
||||||
options.push_back(caf::PdmOptionItemInfo(resultsText, (qulonglong) i, inUse));
|
options.push_back(caf::PdmOptionItemInfo(resultsText, (qulonglong) i, inUse));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "RigFemResultAddress.h"
|
#include "RigFemResultAddress.h"
|
||||||
|
#include "RigEclipseResultInfo.h"
|
||||||
|
|
||||||
#include "cafPdmField.h"
|
#include "cafPdmField.h"
|
||||||
#include "cafPdmChildArrayField.h"
|
#include "cafPdmChildArrayField.h"
|
||||||
@@ -41,7 +42,9 @@ protected:
|
|||||||
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
|
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
|
||||||
private:
|
private:
|
||||||
std::vector<RigFemResultAddress> selectedGeoMechResults() const;
|
std::vector<RigFemResultAddress> selectedGeoMechResults() const;
|
||||||
|
std::vector<RigEclipseResultInfo> selectedEclipseResults() const;
|
||||||
std::set<RigFemResultAddress> findGeoMechCaseResultsInUse() const;
|
std::set<RigFemResultAddress> findGeoMechCaseResultsInUse() const;
|
||||||
|
std::set<RigEclipseResultInfo> findEclipseResultsInUse() const;
|
||||||
|
|
||||||
virtual QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions,
|
virtual QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions,
|
||||||
bool* useOptionsOnly) override;
|
bool* useOptionsOnly) override;
|
||||||
@@ -51,5 +54,6 @@ private:
|
|||||||
caf::PdmPtrField<RimCase*> m_case;
|
caf::PdmPtrField<RimCase*> m_case;
|
||||||
caf::PdmField<std::vector<size_t>> m_resultsToDelete;
|
caf::PdmField<std::vector<size_t>> m_resultsToDelete;
|
||||||
std::vector<RigFemResultAddress> m_geomResultAddresses;
|
std::vector<RigFemResultAddress> m_geomResultAddresses;
|
||||||
|
std::vector<RigEclipseResultInfo> m_eclipseResultAddresses;
|
||||||
caf::PdmField<bool> m_performDelete;
|
caf::PdmField<bool> m_performDelete;
|
||||||
};
|
};
|
||||||
@@ -632,11 +632,13 @@ void RigCaseCellResultsData::clearScalarResult(RiaDefines::ResultCatType type, c
|
|||||||
size_t scalarResultIndex = this->findScalarResultIndex(type, resultName);
|
size_t scalarResultIndex = this->findScalarResultIndex(type, resultName);
|
||||||
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) return;
|
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) return;
|
||||||
|
|
||||||
std::vector<std::vector<double>> empty;
|
for (size_t tsIdx = 0; tsIdx < m_cellScalarResults[scalarResultIndex].size(); ++tsIdx)
|
||||||
m_cellScalarResults[scalarResultIndex].swap(empty);
|
{
|
||||||
|
std::vector<double> empty;
|
||||||
|
m_cellScalarResults[scalarResultIndex][tsIdx].swap(empty);
|
||||||
|
}
|
||||||
|
|
||||||
recalculateStatistics(scalarResultIndex);
|
recalculateStatistics(scalarResultIndex);
|
||||||
|
|
||||||
//m_resultInfos[scalarResultIndex].type() = RiaDefines::REMOVED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -674,6 +676,20 @@ void RigCaseCellResultsData::freeAllocatedResultsData()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RigCaseCellResultsData::isResultLoaded(const RigEclipseResultInfo& resultInfo) const
|
||||||
|
{
|
||||||
|
size_t scalarResultIndex = this->findScalarResultIndex(resultInfo.resultType(), resultInfo.resultName());
|
||||||
|
CVF_TIGHT_ASSERT(scalarResultIndex != cvf::UNDEFINED_SIZE_T);
|
||||||
|
if (scalarResultIndex != cvf::UNDEFINED_SIZE_T)
|
||||||
|
{
|
||||||
|
return isDataPresent(scalarResultIndex);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
/// Make sure we have a result with given type and name, and make sure one "timestep" result vector
|
/// Make sure we have a result with given type and name, and make sure one "timestep" result vector
|
||||||
// for the static result values are allocated
|
// for the static result values are allocated
|
||||||
|
|||||||
@@ -110,6 +110,8 @@ public:
|
|||||||
void clearScalarResult(const RigEclipseResultInfo& resultInfo);
|
void clearScalarResult(const RigEclipseResultInfo& resultInfo);
|
||||||
void clearAllResults();
|
void clearAllResults();
|
||||||
void freeAllocatedResultsData();
|
void freeAllocatedResultsData();
|
||||||
|
bool isResultLoaded(const RigEclipseResultInfo& resultInfo) const;
|
||||||
|
|
||||||
|
|
||||||
// Access the results data
|
// Access the results data
|
||||||
|
|
||||||
|
|||||||
@@ -204,3 +204,19 @@ std::vector<int> RigEclipseResultInfo::reportNumbers() const
|
|||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
/// Ordering operator for set storage. Just the type and name are used to find unique addresses.
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RigEclipseResultInfo::operator<(const RigEclipseResultInfo& rhs) const
|
||||||
|
{
|
||||||
|
if (m_resultType != rhs.resultType())
|
||||||
|
{
|
||||||
|
return m_resultType < rhs.resultType();
|
||||||
|
}
|
||||||
|
if (m_resultName != rhs.resultName())
|
||||||
|
{
|
||||||
|
return m_resultName < rhs.resultName();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ public:
|
|||||||
std::vector<double> daysSinceSimulationStarts() const;
|
std::vector<double> daysSinceSimulationStarts() const;
|
||||||
std::vector<int> reportNumbers() const;
|
std::vector<int> reportNumbers() const;
|
||||||
|
|
||||||
|
bool operator<(const RigEclipseResultInfo& rhs) const;
|
||||||
private:
|
private:
|
||||||
RiaDefines::ResultCatType m_resultType;
|
RiaDefines::ResultCatType m_resultType;
|
||||||
bool m_needsToBeStored;
|
bool m_needsToBeStored;
|
||||||
|
|||||||
Reference in New Issue
Block a user