#3958 First shot on time difference implementation

This commit is contained in:
Jacob Støren 2019-01-30 16:46:16 +01:00
parent 1d60bd9843
commit 61e9a2a696
5 changed files with 198 additions and 61 deletions

View File

@ -53,6 +53,7 @@
#include <QDebug>
#include <QList>
#include "RimTools.h"
namespace caf
{
@ -90,6 +91,13 @@ RimEclipseResultDefinition::RimEclipseResultDefinition()
CAF_PDM_InitFieldNoDefault(&m_flowSolution, "FlowDiagSolution", "Solution", "", "", "");
m_flowSolution.uiCapability()->setUiHidden(true);
CAF_PDM_InitField(&m_isTimeLapseResult, "IsTimeLapseResult", false, "TimeLapseResult", "", "", "");
m_isTimeLapseResult.uiCapability()->setUiHidden(true);
CAF_PDM_InitField(&m_timeLapseBaseTimestep, "TimeLapseBaseTimeStep", 0, "Base Time Step", "", "", "");
m_timeLapseBaseTimestep.uiCapability()->setUiHidden(true);
// One single tracer list has been split into injectors and producers.
// The old list is defined as injectors and we'll have to move any producers in old projects.
CAF_PDM_InitFieldNoDefault(&m_selectedTracers_OBSOLETE, "SelectedTracers", "Tracers", "", "", "");
@ -120,6 +128,12 @@ RimEclipseResultDefinition::RimEclipseResultDefinition()
m_resultVariableUiField.xmlCapability()->disableIO();
m_resultVariableUiField.uiCapability()->setUiEditorTypeName(caf::PdmUiListEditor::uiEditorTypeName());
CAF_PDM_InitField(&m_isTimeLapseResultUiField, "IsTimeLapseResultUI", false, "Enable Relative Result", "", "Use the difference with respect to a specific time step as the result variable to plot", "");
m_isTimeLapseResultUiField.xmlCapability()->disableIO();
CAF_PDM_InitField(&m_timeLapseBaseTimestepUiField, "TimeLapseBaseTimeStepUI", 0, "Base Time Step", "", "", "");
m_timeLapseBaseTimestepUiField.xmlCapability()->disableIO();
CAF_PDM_InitFieldNoDefault(&m_flowSolutionUiField, "MFlowDiagSolution", "Solution", "", "", "");
m_flowSolutionUiField.xmlCapability()->disableIO();
@ -242,6 +256,8 @@ void RimEclipseResultDefinition::fieldChangedByUi(const caf::PdmFieldHandle* cha
m_porosityModel = m_porosityModelUiField;
m_resultType = m_resultTypeUiField;
m_resultVariable = m_resultVariableUiField;
m_isTimeLapseResult = m_isTimeLapseResultUiField;
m_timeLapseBaseTimestep = m_timeLapseBaseTimestepUiField;
if (m_resultTypeUiField() == RiaDefines::FLOW_DIAGNOSTICS)
{
@ -256,6 +272,16 @@ void RimEclipseResultDefinition::fieldChangedByUi(const caf::PdmFieldHandle* cha
loadDataAndUpdate();
}
if (&m_isTimeLapseResultUiField == changedField)
{
if (m_isTimeLapseResultUiField() && m_timeLapseBaseTimestep() == RigFemResultAddress::NO_TIME_LAPSE)
{
m_timeLapseBaseTimestepUiField = 0;
}
m_resultVariableUiField = "";
}
if (&m_flowTracerSelectionMode == changedField)
{
loadDataAndUpdate();
@ -616,6 +642,21 @@ QList<caf::PdmOptionItemInfo> RimEclipseResultDefinition::calculateValueOptions(
{
options = calcOptionsForVariableUiFieldStandard();
}
else if (fieldNeedingOptions == &m_timeLapseBaseTimestepUiField)
{
std::vector<QDateTime> stepDates;
const RigCaseCellResultsData* gridCellResults = this->currentGridCellResults();
if(gridCellResults)
{
stepDates = gridCellResults->timeStepDates();
}
for (size_t stepIdx = 0; stepIdx < stepDates.size(); ++stepIdx)
{
options.push_back(caf::PdmOptionItemInfo(stepDates[stepIdx].toString(RimTools::dateFormatString()),
static_cast<int>(stepIdx)));
}
}
}
@ -634,7 +675,10 @@ RigEclipseResultAddress RimEclipseResultDefinition::eclipseResultAddress() const
const RigCaseCellResultsData* gridCellResults = this->currentGridCellResults();
if (gridCellResults )
{
return RigEclipseResultAddress(m_resultType(), m_resultVariable());
if (m_isTimeLapseResult())
return RigEclipseResultAddress(m_resultType(), m_resultVariable(), m_timeLapseBaseTimestep());
else
return RigEclipseResultAddress(m_resultType(), m_resultVariable());
}
else
{
@ -748,7 +792,14 @@ QString RimEclipseResultDefinition::resultVariableUiName() const
return flowDiagResUiText(false, 32);
}
return m_resultVariable();
if (m_isTimeLapseResult() && resultType() == RiaDefines::DYNAMIC_NATIVE)
{
return m_resultVariable() + "_D" + QString::number(m_timeLapseBaseTimestep());
}
else
{
return m_resultVariable();
}
}
//--------------------------------------------------------------------------------------------------
@ -761,7 +812,14 @@ QString RimEclipseResultDefinition::resultVariableUiShortName() const
return flowDiagResUiText(true, 24);
}
return m_resultVariable();
if (m_isTimeLapseResult() && resultType() == RiaDefines::DYNAMIC_NATIVE)
{
return m_resultVariable() + "_D" + QString::number(m_timeLapseBaseTimestep());
}
else
{
return m_resultVariable();
}
}
//--------------------------------------------------------------------------------------------------
@ -783,7 +841,12 @@ void RimEclipseResultDefinition::loadResult()
RigCaseCellResultsData* gridCellResults = this->currentGridCellResults();
if (gridCellResults)
{
gridCellResults->ensureKnownResultLoaded(RigEclipseResultAddress(m_resultType(), m_resultVariable));
if (m_isTimeLapseResult())
{
gridCellResults->createResultEntry(this->eclipseResultAddress(), false);
}
gridCellResults->ensureKnownResultLoaded(this->eclipseResultAddress());
}
}
@ -822,7 +885,7 @@ bool RimEclipseResultDefinition::hasResult() const
{
const RigCaseCellResultsData* gridCellResults = this->currentGridCellResults();
return gridCellResults->hasResultEntry(RigEclipseResultAddress(m_resultType(), m_resultVariable()));
return gridCellResults->hasResultEntry(this->eclipseResultAddress());
}
return false;
@ -881,6 +944,8 @@ void RimEclipseResultDefinition::initAfterRead()
m_porosityModelUiField = m_porosityModel;
m_resultTypeUiField = m_resultType;
m_resultVariableUiField = m_resultVariable;
m_isTimeLapseResultUiField = m_isTimeLapseResult;
m_timeLapseBaseTimestepUiField = m_timeLapseBaseTimestep;
m_flowSolutionUiField = m_flowSolution();
m_selectedInjectorTracersUiField = m_selectedInjectorTracers;
@ -1068,6 +1133,7 @@ void RimEclipseResultDefinition::defineUiOrdering(QString uiConfigName, caf::Pdm
uiOrdering.add(&m_porosityModelUiField);
}
if ( m_resultTypeUiField() == RiaDefines::FLOW_DIAGNOSTICS )
{
uiOrdering.add(&m_flowSolutionUiField);
@ -1110,6 +1176,14 @@ void RimEclipseResultDefinition::defineUiOrdering(QString uiConfigName, caf::Pdm
uiOrdering.add(&m_resultVariableUiField);
}
if ( m_resultTypeUiField() == RiaDefines::DYNAMIC_NATIVE )
{
caf::PdmUiGroup * timeLapseGr = uiOrdering.addNewGroup("Relative Result Options");
timeLapseGr->add(&m_isTimeLapseResultUiField);
if ( m_isTimeLapseResultUiField() )
timeLapseGr->add(&m_timeLapseBaseTimestepUiField);
}
uiOrdering.skipRemainingFields(true);
}
@ -1257,6 +1331,21 @@ QString RimEclipseResultDefinition::flowDiagResUiText(bool shortLabel, int maxTr
return uiText;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimEclipseResultDefinition::convertToTimeDiffUiVarName(const QString& resultName)
{
if (m_isTimeLapseResultUiField() && m_resultTypeUiField() == RiaDefines::DYNAMIC_NATIVE)
{
return resultName + "_D" + QString::number(m_timeLapseBaseTimestepUiField());
}
else
{
return resultName;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -1272,6 +1361,7 @@ QList<caf::PdmOptionItemInfo> RimEclipseResultDefinition::calcOptionsForVariable
QStringList cellFaceResultNames;
RigCaseCellResultsData* results = this->currentGridCellResults();
foreach(QString s, getResultNamesForCurrentUiResultType())
{
if (s == RiaDefines::completionTypeResultName() && results->timeStepDates().empty()) continue;
@ -1292,7 +1382,7 @@ QList<caf::PdmOptionItemInfo> RimEclipseResultDefinition::calcOptionsForVariable
// Cell Center result names
foreach(QString s, cellCenterResultNames)
{
optionList.push_back(caf::PdmOptionItemInfo(s, s));
optionList.push_back(caf::PdmOptionItemInfo(convertToTimeDiffUiVarName(s), s));
}
// Ternary Result
@ -1319,11 +1409,11 @@ QList<caf::PdmOptionItemInfo> RimEclipseResultDefinition::calcOptionsForVariable
{
if (showDerivedResultsFirstInList)
{
optionList.push_front(caf::PdmOptionItemInfo(s, s));
optionList.push_front(caf::PdmOptionItemInfo(convertToTimeDiffUiVarName(s), s));
}
else
{
optionList.push_back(caf::PdmOptionItemInfo(s, s));
optionList.push_back(caf::PdmOptionItemInfo(convertToTimeDiffUiVarName(s), s));
}
}
@ -1535,7 +1625,7 @@ void RimEclipseResultDefinition::removePerCellFaceOptionItems(QList<caf::PdmOpti
std::vector<int> indicesToRemove;
for (int i = 0; i < optionItems.size(); i++)
{
QString text = optionItems[i].optionUiText();
QString text = optionItems[i].value().toString();
if (RiaDefines::isPerCellFaceResult(text))
{

View File

@ -131,6 +131,8 @@ protected:
caf::PdmField< caf::AppEnum< RiaDefines::ResultCatType > > m_resultType;
caf::PdmField< caf::AppEnum< RiaDefines::PorosityModelType > > m_porosityModel;
caf::PdmField<QString> m_resultVariable;
caf::PdmField<bool> m_isTimeLapseResult;
caf::PdmField<int> m_timeLapseBaseTimestep;
caf::PdmPtrField<RimFlowDiagSolution*> m_flowSolution;
caf::PdmField<std::vector<QString> > m_selectedInjectorTracers;
@ -146,6 +148,8 @@ protected:
caf::PdmField< caf::AppEnum< RiaDefines::ResultCatType > > m_resultTypeUiField;
caf::PdmField< caf::AppEnum< RiaDefines::PorosityModelType > > m_porosityModelUiField;
caf::PdmField<QString> m_resultVariableUiField;
caf::PdmField<bool> m_isTimeLapseResultUiField;
caf::PdmField<int> m_timeLapseBaseTimestepUiField;
caf::PdmField< caf::AppEnum< FlowTracerSelectionType > > m_flowTracerSelectionMode;
caf::PdmPtrField<RimFlowDiagSolution*> m_flowSolutionUiField;
@ -175,6 +179,7 @@ private:
QString flowDiagResUiText(bool shortLabel, int maxTracerStringLength = std::numeric_limits<int>::max()) const;
QString convertToTimeDiffUiVarName(const QString& resultName);
QList<caf::PdmOptionItemInfo> calcOptionsForVariableUiFieldStandard();
QList<caf::PdmOptionItemInfo> calcOptionsForSelectedTracerField(bool injector);

View File

@ -400,11 +400,11 @@ size_t RigCaseCellResultsData::findOrCreateScalarResultIndex(const RigEclipseRes
//--------------------------------------------------------------------------------------------------
QStringList RigCaseCellResultsData::resultNames(RiaDefines::ResultCatType resType) const
{
QStringList varList;
QStringList varList;
std::vector<RigEclipseResultInfo>::const_iterator it;
for (it = m_resultInfos.begin(); it != m_resultInfos.end(); ++it)
{
if (it->resultType() == resType)
if (it->resultType() == resType && !it->eclipseResultAddress().isTimeLapse())
{
varList.push_back(it->resultName());
}
@ -572,18 +572,18 @@ void RigCaseCellResultsData::setTimeStepInfos(const RigEclipseResultAddress& res
//--------------------------------------------------------------------------------------------------
size_t RigCaseCellResultsData::maxTimeStepCount(RigEclipseResultAddress* resultAddressWithMostTimeSteps) const
{
size_t maxTsCount = 0;
size_t maxTsCount = 0;
RigEclipseResultAddress scalarResultIndexWithMaxTsCount;
for (size_t i = 0; i < m_resultInfos.size(); i++)
{
if (m_resultInfos[i].timeStepInfos().size() > maxTsCount)
{
maxTsCount = m_resultInfos[i].timeStepInfos().size();
maxTsCount = m_resultInfos[i].timeStepInfos().size();
if (resultAddressWithMostTimeSteps)
{
*resultAddressWithMostTimeSteps = m_resultInfos[i].toAddress();
*resultAddressWithMostTimeSteps = m_resultInfos[i].eclipseResultAddress();
}
}
}
@ -968,7 +968,7 @@ std::vector<RigEclipseResultAddress> RigCaseCellResultsData::existingResults() c
std::vector<RigEclipseResultAddress> addresses;
for (const auto & ri: m_resultInfos)
{
addresses.emplace_back(ri.toAddress());
addresses.emplace_back(ri.eclipseResultAddress());
}
return addresses;
@ -982,6 +982,46 @@ const RigEclipseResultInfo* RigCaseCellResultsData::resultInfo(const RigEclipseR
return &(m_resultInfos[findScalarResultIndexFromAddress(resVarAddr)]);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RigCaseCellResultsData::ensureKnownResultLoaded(const RigEclipseResultAddress& resultAddress)
{
size_t resultIndex = findOrLoadKnownScalarResult(resultAddress);
return (resultIndex != cvf::UNDEFINED_SIZE_T);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RigCaseCellResultsData::hasResultEntry(const RigEclipseResultAddress& resultAddress) const
{
size_t resultIndex = findScalarResultIndexFromAddress(resultAddress);
return (resultIndex != cvf::UNDEFINED_SIZE_T);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigCaseCellResultsData::createResultEntry(const RigEclipseResultAddress& resultAddress, bool needsToBeStored)
{
findOrCreateScalarResultIndex(resultAddress, needsToBeStored);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigCaseCellResultsData::ensureKnownResultLoadedForTimeStep(const RigEclipseResultAddress& resultAddress,
size_t timeStepIndex)
{
CAF_ASSERT(resultAddress.m_resultCatType != RiaDefines::UNDEFINED);
findOrLoadKnownScalarResultForTimeStep(resultAddress,
timeStepIndex);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -1031,7 +1071,7 @@ size_t RigCaseCellResultsData::findOrLoadKnownScalarResult(const RigEclipseResul
return scalarResultIndex;
}
size_t scalarResultIndex = this->findScalarResultIndexFromAddress(resVarAddr);
@ -1040,6 +1080,48 @@ size_t RigCaseCellResultsData::findOrLoadKnownScalarResult(const RigEclipseResul
RiaDefines::ResultCatType type = resVarAddr.m_resultCatType;
QString resultName = resVarAddr.m_resultName;
if (resVarAddr.isTimeLapse())
{
RigEclipseResultAddress noneTimeLapseAddress(resVarAddr);
noneTimeLapseAddress.m_timeLapseBaseFrameIdx = RigEclipseResultAddress::NO_TIME_LAPSE;
size_t sourceResultIdx = this->findOrLoadKnownScalarResult(noneTimeLapseAddress);
if (sourceResultIdx != cvf::UNDEFINED_SIZE_T)
{
std::vector< std::vector<double> > & srcFrames = m_cellScalarResults[sourceResultIdx];
std::vector< std::vector<double> > & dstFrames = m_cellScalarResults[scalarResultIndex];
size_t baseFrameIdx = resVarAddr.m_timeLapseBaseFrameIdx;
size_t frameCount = srcFrames.size();
if (!(baseFrameIdx < frameCount ))
{
dstFrames.clear();
return scalarResultIndex;
}
std::vector<double>& srcBaseVals = srcFrames[baseFrameIdx];
dstFrames.resize(frameCount);
for (size_t fIdx = 0; fIdx < frameCount; ++fIdx)
{
std::vector<double>& srcVals = srcFrames[fIdx];
std::vector<double>& dstVals = dstFrames[fIdx];
dstVals.resize(srcVals.size(), std::numeric_limits<double>::infinity());
size_t valCount = srcVals.size();
//#pragma omp parallel for
for (long vIdx = 0; vIdx < static_cast<long>(valCount); ++vIdx)
{
dstVals[vIdx] = srcVals[vIdx] - srcBaseVals[vIdx];
}
}
}
return scalarResultIndex;
}
// Load dependency data sets
@ -1260,46 +1342,6 @@ size_t RigCaseCellResultsData::findOrLoadKnownScalarResult(const RigEclipseResul
return scalarResultIndex;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RigCaseCellResultsData::ensureKnownResultLoaded(const RigEclipseResultAddress& resultAddress)
{
size_t resultIndex = findOrLoadKnownScalarResult(resultAddress);
return (resultIndex != cvf::UNDEFINED_SIZE_T);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RigCaseCellResultsData::hasResultEntry(const RigEclipseResultAddress& resultAddress) const
{
size_t resultIndex = findScalarResultIndexFromAddress(resultAddress);
return (resultIndex != cvf::UNDEFINED_SIZE_T);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigCaseCellResultsData::createResultEntry(const RigEclipseResultAddress& resultAddress, bool needsToBeStored)
{
findOrCreateScalarResultIndex(resultAddress, needsToBeStored);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigCaseCellResultsData::ensureKnownResultLoadedForTimeStep(const RigEclipseResultAddress& resultAddress,
size_t timeStepIndex)
{
CAF_ASSERT(resultAddress.m_resultCatType != RiaDefines::UNDEFINED);
findOrLoadKnownScalarResultForTimeStep(resultAddress,
timeStepIndex);
}
//--------------------------------------------------------------------------------------------------
/// This method is intended to be used for multicase cross statistical calculations, when
@ -2845,7 +2887,7 @@ size_t RigCaseCellResultsData::findScalarResultIndexFromAddress(const RigEclipse
std::vector<RigEclipseResultInfo>::const_iterator it;
for (it = m_resultInfos.begin(); it != m_resultInfos.end(); ++it)
{
if (it->toAddress() == resVarAddr)
if (it->eclipseResultAddress() == resVarAddr)
{
return it->gridScalarResultIndex();
}
@ -2882,7 +2924,7 @@ void RigCaseCellResultsData::copyResultsMetaDataFromMainCase(RigEclipseCaseData*
for ( size_t resIdx = 0; resIdx < resultInfos.size(); resIdx++ )
{
RigEclipseResultAddress resVarAddr = resultInfos[resIdx].toAddress();
RigEclipseResultAddress resVarAddr = resultInfos[resIdx].eclipseResultAddress();
bool needsToBeStored = resultInfos[resIdx].needsToBeStored();
bool mustBeCalculated = resultInfos[resIdx].mustBeCalculated();

View File

@ -118,11 +118,11 @@ public:
void freeAllocatedResultsData();
void eraseAllSourSimData();
bool updateResultName(RiaDefines::ResultCatType resultType, QString& oldName, const QString& newName);
QStringList resultNames(RiaDefines::ResultCatType type) const;
QString makeResultNameUnique(const QString& resultNameProposal) const;
std::vector<RigEclipseResultAddress> existingResults() const;
const RigEclipseResultInfo* resultInfo(const RigEclipseResultAddress& resVarAddr) const;
bool updateResultName(RiaDefines::ResultCatType resultType, QString& oldName, const QString& newName);
QString makeResultNameUnique(const QString& resultNameProposal) const;
void ensureKnownResultLoadedForTimeStep(const RigEclipseResultAddress& resultAddress, size_t timeStepIndex);
bool ensureKnownResultLoaded(const RigEclipseResultAddress& resultAddress);

View File

@ -66,7 +66,7 @@ public:
bool operator<(const RigEclipseResultInfo& rhs) const;
RigEclipseResultAddress toAddress() const { return m_resultAddress;}
const RigEclipseResultAddress& eclipseResultAddress() const { return m_resultAddress;}
private:
friend class RigCaseCellResultsData;