#3958 Refactoring: Replaced result info based lookups with result address.

Replaced access of resultInfo as vector with single access based on address.
Moved RigEclipseResultAddress to a separate new file.
This commit is contained in:
Jacob Støren 2019-01-22 15:22:45 +01:00
parent accc0768a1
commit 5a01fdb88e
9 changed files with 173 additions and 89 deletions

View File

@ -81,10 +81,10 @@ void RiaMemoryCleanup::clearSelectedResultsFromMemory()
RigCaseCellResultsData* caseData = eclipseCase->results(RiaDefines::MATRIX_MODEL);
if (caseData)
{
std::vector<RigEclipseResultInfo> resultsToDelete = selectedEclipseResults();
for (const RigEclipseResultInfo& resultInfo : resultsToDelete)
std::vector<RigEclipseResultAddress> resultsToDelete = selectedEclipseResults();
for (const RigEclipseResultAddress& resultAddr : resultsToDelete)
{
caseData->clearScalarResult(resultInfo);
caseData->clearScalarResult(resultAddr);
}
}
}
@ -129,9 +129,9 @@ std::vector<RigFemResultAddress> RiaMemoryCleanup::selectedGeoMechResults() cons
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RigEclipseResultInfo> RiaMemoryCleanup::selectedEclipseResults() const
std::vector<RigEclipseResultAddress> RiaMemoryCleanup::selectedEclipseResults() const
{
std::vector<RigEclipseResultInfo> results;
std::vector<RigEclipseResultAddress> results;
if (dynamic_cast<const RimEclipseCase*>(m_case()))
{
for (size_t index : m_resultsToDelete())
@ -170,20 +170,23 @@ std::set<RigFemResultAddress> RiaMemoryCleanup::findGeoMechCaseResultsInUse() co
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::set<RigEclipseResultInfo> RiaMemoryCleanup::findEclipseResultsInUse() const
std::set<RigEclipseResultAddress> RiaMemoryCleanup::findEclipseResultsInUse() const
{
std::set<RigEclipseResultInfo> resultsInUse;
std::set<RigEclipseResultAddress> resultsInUse;
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(m_case());
if (eclipseCase)
{
RigCaseCellResultsData* caseData = eclipseCase->results(RiaDefines::MATRIX_MODEL);
std::vector<RimEclipseResultDefinition*> eclipseResultDefs;
eclipseCase->descendantsIncludingThisOfType(eclipseResultDefs);
for (RimEclipseResultDefinition* resultDef : eclipseResultDefs)
{
RigEclipseResultInfo resultInfo(resultDef->resultType(), resultDef->resultVariable());
resultsInUse.insert(resultInfo);
RigEclipseResultAddress resultAddr(caseData->findScalarResultIndex(resultDef->resultType(), resultDef->resultVariable()));
resultsInUse.insert(resultAddr);
}
}
return resultsInUse;
}
@ -237,20 +240,23 @@ QList<caf::PdmOptionItemInfo> RiaMemoryCleanup::calculateValueOptions(const caf:
RimGeoMechCase* geoMechCase = dynamic_cast<RimGeoMechCase*>(m_case());
if (eclipseCase)
{
std::set<RigEclipseResultInfo> resultsInUse = findEclipseResultsInUse();
std::set<RigEclipseResultAddress> resultsInUse = findEclipseResultsInUse();
RigCaseCellResultsData* caseData = eclipseCase->results(RiaDefines::MATRIX_MODEL);
if (caseData)
{
m_eclipseResultAddresses = caseData->infoForEachResultIndex();
m_eclipseResultAddresses = caseData->existingResults();
for (size_t i = 0; i < m_eclipseResultAddresses.size(); ++i)
{
const RigEclipseResultInfo& result = m_eclipseResultAddresses[i];
if (caseData->isResultLoaded(result))
const RigEclipseResultAddress& resultAddr = m_eclipseResultAddresses[i];
if (caseData->isResultLoaded(resultAddr))
{
bool inUse = resultsInUse.count(result);
QString posText = caf::AppEnum<RiaDefines::ResultCatType>::uiTextFromIndex(result.resultType());
QString resultsText = QString("%1, %2").arg(posText).arg(result.resultName());
bool inUse = resultsInUse.count(resultAddr);
const RigEclipseResultInfo* resInfo = caseData->resultInfo(resultAddr);
QString posText = caf::AppEnum<RiaDefines::ResultCatType>::uiTextFromIndex(resInfo->resultType());
QString resultsText = QString("%1, %2").arg(posText).arg(resInfo->resultName());
if (inUse)
{
resultsText += QString(" [used in view]");

View File

@ -20,6 +20,7 @@
#include "RigFemResultAddress.h"
#include "RigEclipseResultInfo.h"
#include "RigEclipseResultAddress.h"
#include "cafPdmField.h"
#include "cafPdmChildArrayField.h"
@ -42,9 +43,9 @@ protected:
void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
private:
std::vector<RigFemResultAddress> selectedGeoMechResults() const;
std::vector<RigEclipseResultInfo> selectedEclipseResults() const;
std::vector<RigEclipseResultAddress> selectedEclipseResults() const;
std::set<RigFemResultAddress> findGeoMechCaseResultsInUse() const;
std::set<RigEclipseResultInfo> findEclipseResultsInUse() const;
std::set<RigEclipseResultAddress> findEclipseResultsInUse() const;
QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions,
bool* useOptionsOnly) override;
@ -54,6 +55,6 @@ private:
caf::PdmPtrField<RimCase*> m_case;
caf::PdmField<std::vector<size_t>> m_resultsToDelete;
std::vector<RigFemResultAddress> m_geomResultAddresses;
std::vector<RigEclipseResultInfo> m_eclipseResultAddresses;
std::vector<RigEclipseResultAddress> m_eclipseResultAddresses;
caf::PdmField<bool> m_performDelete;
};

View File

@ -665,8 +665,8 @@ void RimEclipseStatisticsCase::updatePercentileUiVisibility()
bool RimEclipseStatisticsCase::hasComputedStatistics() const
{
if ( eclipseCaseData()
&& ( eclipseCaseData()->results(RiaDefines::MATRIX_MODEL)->resultCount()
|| eclipseCaseData()->results(RiaDefines::FRACTURE_MODEL)->resultCount()))
&& ( eclipseCaseData()->results(RiaDefines::MATRIX_MODEL)->existingResults().size()
|| eclipseCaseData()->results(RiaDefines::FRACTURE_MODEL)->existingResults().size()))
{
return true;
}

View File

@ -91,19 +91,19 @@ void RimReservoirCellResultsStorage::setupBeforeSave()
if (!m_cellResults) return;
const std::vector<RigEclipseResultInfo>& resInfo = m_cellResults->infoForEachResultIndex();
const std::vector<RigEclipseResultAddress>& resAddrs = m_cellResults->existingResults();
bool hasResultsToStore = false;
for (size_t rIdx = 0; rIdx < resInfo.size(); ++rIdx)
for (size_t rIdx = 0; rIdx < resAddrs.size(); ++rIdx)
{
if (resInfo[rIdx].needsToBeStored())
if ( m_cellResults->resultInfo(resAddrs[rIdx])->needsToBeStored() )
{
hasResultsToStore = true;
break;
}
}
if(resInfo.size() && hasResultsToStore)
if(resAddrs.size() && hasResultsToStore)
{
QDir::root().mkpath(getCacheDirectoryPath());
@ -122,38 +122,39 @@ void RimReservoirCellResultsStorage::setupBeforeSave()
stream << (quint32)0xCEECAC4E; // magic number
stream << (quint32)1; // Version number. Increment if needing to extend the format in ways that can not be handled generically by the reader
caf::ProgressInfo progInfo(resInfo.size(), "Saving generated and imported properties");
caf::ProgressInfo progInfo(resAddrs.size(), "Saving generated and imported properties");
for (size_t rIdx = 0; rIdx < resInfo.size(); ++rIdx)
for (size_t rIdx = 0; rIdx < resAddrs.size(); ++rIdx)
{
// If there is no data, we do not store anything for the current result variable
// (Even not the metadata, of cause)
size_t timestepCount = m_cellResults->cellScalarResults(RigEclipseResultAddress(resInfo[rIdx].gridScalarResultIndex())).size();
size_t timestepCount = m_cellResults->cellScalarResults(resAddrs[rIdx]).size();
const RigEclipseResultInfo* resInfo = m_cellResults->resultInfo(resAddrs[rIdx]);
if (timestepCount && resInfo[rIdx].needsToBeStored())
if (timestepCount && resInfo->needsToBeStored())
{
progInfo.setProgressDescription(resInfo[rIdx].resultName());
progInfo.setProgressDescription(resInfo->resultName());
// Create and setup the cache information for this result
RimReservoirCellResultsStorageEntryInfo* cacheEntry = new RimReservoirCellResultsStorageEntryInfo;
m_resultCacheMetaData.push_back(cacheEntry);
cacheEntry->m_resultType = resInfo[rIdx].resultType();
cacheEntry->m_resultName = resInfo[rIdx].resultName();
cacheEntry->m_timeStepDates = resInfo[rIdx].dates();
cacheEntry->m_daysSinceSimulationStart = resInfo[rIdx].daysSinceSimulationStarts();
cacheEntry->m_resultType = resInfo->resultType();
cacheEntry->m_resultName = resInfo->resultName();
cacheEntry->m_timeStepDates = resInfo->dates();
cacheEntry->m_daysSinceSimulationStart = resInfo->daysSinceSimulationStarts();
// Take note of the file position for fast lookup later
cacheEntry->m_filePosition = cacheFile.pos();
// Write all the scalar values for each time step to the stream,
// starting with the number of values
for (size_t tsIdx = 0; tsIdx < resInfo[rIdx].dates().size() ; ++tsIdx)
for (size_t tsIdx = 0; tsIdx < resInfo->dates().size() ; ++tsIdx)
{
const std::vector<double>* data = nullptr;
if (tsIdx < timestepCount)
{
data = &(m_cellResults->cellScalarResults(RigEclipseResultAddress(resInfo[rIdx].gridScalarResultIndex()), tsIdx));
data = &(m_cellResults->cellScalarResults(resAddrs[rIdx], tsIdx));
}
if (data && data->size())

View File

@ -53,6 +53,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RigTesselatorTools.h
${CMAKE_CURRENT_LIST_DIR}/RigCellGeometryTools.h
${CMAKE_CURRENT_LIST_DIR}/RigWellPathIntersectionTools.h
${CMAKE_CURRENT_LIST_DIR}/RigEclipseResultInfo.h
${CMAKE_CURRENT_LIST_DIR}/RigEclipseResultAddress.h
${CMAKE_CURRENT_LIST_DIR}/RigTofAccumulatedPhaseFractionsCalculator.h
${CMAKE_CURRENT_LIST_DIR}/RigTransmissibilityEquations.h
${CMAKE_CURRENT_LIST_DIR}/RigNumberOfFloodedPoreVolumesCalculator.h

View File

@ -659,7 +659,18 @@ QString RigCaseCellResultsData::makeResultNameUnique(const QString& resultNamePr
void RigCaseCellResultsData::clearScalarResult(RiaDefines::ResultCatType type, const QString& resultName)
{
size_t scalarResultIndex = this->findScalarResultIndex(type, resultName);
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) return;
clearScalarResult(RigEclipseResultAddress(scalarResultIndex));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigCaseCellResultsData::clearScalarResult(const RigEclipseResultAddress& resultAddress)
{
if (!resultAddress.isValid()) return;
size_t scalarResultIndex = resultAddress.scalarResultIndex;
for (size_t tsIdx = 0; tsIdx < m_cellScalarResults[scalarResultIndex].size(); ++tsIdx)
{
@ -670,14 +681,6 @@ void RigCaseCellResultsData::clearScalarResult(RiaDefines::ResultCatType type, c
recalculateStatistics(RigEclipseResultAddress(scalarResultIndex));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigCaseCellResultsData::clearScalarResult(const RigEclipseResultInfo& resultInfo)
{
clearScalarResult(resultInfo.resultType(), resultInfo.resultName());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -708,9 +711,10 @@ void RigCaseCellResultsData::freeAllocatedResultsData()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RigCaseCellResultsData::isResultLoaded(const RigEclipseResultInfo& resultInfo) const
bool RigCaseCellResultsData::isResultLoaded(const RigEclipseResultAddress& resultAddr) const
{
size_t scalarResultIndex = this->findScalarResultIndex(resultInfo.resultType(), resultInfo.resultName());
size_t scalarResultIndex = resultAddr.scalarResultIndex;//this->findScalarResultIndex(resultAddr.resultType(), resultAddr.resultName());
CVF_TIGHT_ASSERT(scalarResultIndex != cvf::UNDEFINED_SIZE_T);
if (scalarResultIndex != cvf::UNDEFINED_SIZE_T)
{
@ -1014,6 +1018,28 @@ bool RigCaseCellResultsData::findTransmissibilityResults(size_t& tranX, size_t&
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RigEclipseResultAddress> RigCaseCellResultsData::existingResults() const
{
std::vector<RigEclipseResultAddress> addresses;
for (const auto & ri: m_resultInfos)
{
addresses.emplace_back(RigEclipseResultAddress(ri.gridScalarResultIndex()));
}
return addresses;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const RigEclipseResultInfo* RigCaseCellResultsData::resultInfo(const RigEclipseResultAddress& resVarAddr) const
{
return &(m_resultInfos[resVarAddr.scalarResultIndex]);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -29,6 +29,7 @@
#include <vector>
#include <cmath>
#include "RigEclipseResultAddress.h"
class RifReaderInterface;
@ -41,36 +42,6 @@ class RigEclipseCaseData;
class RimEclipseCase;
class RigEclipseResultAddress
{
public:
RigEclipseResultAddress()
: scalarResultIndex(-1)
, m_resultCatType(RiaDefines::UNDEFINED)
{}
explicit RigEclipseResultAddress(size_t ascalarResultIndex)
: scalarResultIndex(ascalarResultIndex)
, m_resultCatType(RiaDefines::UNDEFINED)
{}
explicit RigEclipseResultAddress(RiaDefines::ResultCatType type, const QString& resultName)
: scalarResultIndex(-1)
, m_resultCatType(type)
, m_resultName(resultName)
{}
bool isValid() const
{
return (scalarResultIndex != -1);
// Todo
}
size_t scalarResultIndex;
RiaDefines::ResultCatType m_resultCatType;
QString m_resultName;
};
//==================================================================================================
@ -133,16 +104,15 @@ public:
void computeCellVolumes();
void clearScalarResult(RiaDefines::ResultCatType type, const QString & resultName);
void clearScalarResult(const RigEclipseResultInfo& resultInfo);
void clearScalarResult(const RigEclipseResultAddress& resultAddress);
void clearAllResults();
void freeAllocatedResultsData();
bool isResultLoaded(const RigEclipseResultInfo& resultInfo) const;
bool isResultLoaded(const RigEclipseResultAddress& resultAddress) const;
void eraseAllSourSimData();
bool updateResultName(RiaDefines::ResultCatType resultType, QString& oldName, const QString& newName);
// Index based stuff to rewrite/hide -->
size_t resultCount() const;
size_t findOrLoadScalarResultForTimeStep(RiaDefines::ResultCatType type, const QString& resultName, size_t timeStepIndex);
size_t findOrLoadScalarResult(RiaDefines::ResultCatType type, const QString& resultName);
@ -169,7 +139,6 @@ public:
RiaDefines::PorosityModelType poroModel,
std::vector<RimEclipseCase*> destinationCases);
const std::vector<RigEclipseResultInfo>& infoForEachResultIndex();
size_t addStaticScalarResult(RiaDefines::ResultCatType type,
const QString& resultName,
@ -180,7 +149,14 @@ public:
// <---
std::vector<RigEclipseResultAddress> existingResults() const;
const RigEclipseResultInfo* resultInfo(const RigEclipseResultAddress& resVarAddr) const;
private:
const std::vector<RigEclipseResultInfo>& infoForEachResultIndex();
size_t resultCount() const;
bool mustBeCalculated(size_t scalarResultIndex) const;
void setMustBeCalculated(size_t scalarResultIndex);

View File

@ -0,0 +1,70 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RiaDefines.h"
#include <QString>
class RigEclipseResultAddress
{
public:
RigEclipseResultAddress()
: scalarResultIndex(-1)
, m_resultCatType(RiaDefines::UNDEFINED)
{}
explicit RigEclipseResultAddress(size_t ascalarResultIndex)
: scalarResultIndex(ascalarResultIndex)
, m_resultCatType(RiaDefines::UNDEFINED)
{}
explicit RigEclipseResultAddress(RiaDefines::ResultCatType type, const QString& resultName)
: scalarResultIndex(-1)
, m_resultCatType(type)
, m_resultName(resultName)
{}
bool isValid() const
{
return (scalarResultIndex != -1);
// Todo
}
bool operator< (const RigEclipseResultAddress& other ) const
{
// Todo
if (scalarResultIndex != other.scalarResultIndex)
{
return (scalarResultIndex < other.scalarResultIndex);
}
if (m_resultCatType != other.m_resultCatType)
{
return (m_resultCatType < other.m_resultCatType);
}
return (m_resultName < other.m_resultName);
}
size_t scalarResultIndex;
RiaDefines::ResultCatType m_resultCatType;
QString m_resultName;
};

View File

@ -56,23 +56,26 @@ public:
size_t gridScalarResultIndex = 0u);
RiaDefines::ResultCatType resultType() const;
void setResultType(RiaDefines::ResultCatType newType);
const QString& resultName() const;
void setResultName(const QString& name);
bool needsToBeStored() const;
bool mustBeCalculated() const;
void setMustBeCalculated(bool mustCalculate);
size_t gridScalarResultIndex() const;
const std::vector<RigEclipseTimeStepInfo>& timeStepInfos() const;
void setTimeStepInfos(const std::vector<RigEclipseTimeStepInfo>& timeSteps);
std::vector<QDateTime> dates() const;
std::vector<double> daysSinceSimulationStarts() const;
std::vector<int> reportNumbers() const;
bool operator<(const RigEclipseResultInfo& rhs) const;
private:
friend class RigCaseCellResultsData;
void setResultType(RiaDefines::ResultCatType newType);
void setResultName(const QString& name);
bool mustBeCalculated() const;
void setMustBeCalculated(bool mustCalculate);
size_t gridScalarResultIndex() const;
const std::vector<RigEclipseTimeStepInfo>& timeStepInfos() const;
void setTimeStepInfos(const std::vector<RigEclipseTimeStepInfo>& timeSteps);
RiaDefines::ResultCatType m_resultType;
bool m_needsToBeStored;
bool m_mustBeCalculated;