Grid Calculator: compute results for all time steps

This commit is contained in:
Kristian Bendiksen
2022-05-04 09:13:56 +02:00
parent 144138904d
commit 8ea4e933aa
3 changed files with 92 additions and 104 deletions

View File

@@ -59,21 +59,27 @@ bool RimGridCalculation::calculate()
auto porosityModel = RiaDefines::PorosityModelType::MATRIX_MODEL; auto porosityModel = RiaDefines::PorosityModelType::MATRIX_MODEL;
RimEclipseCase* eclipseCase = nullptr; RimEclipseCase* eclipseCase = findEclipseCaseFromVariables();
std::vector<std::vector<double>> values; if ( !eclipseCase )
{
RiaLogging::errorInMessageBox( nullptr,
"Expression Parser",
QString( "No case found for calculation : %1" ).arg( leftHandSideVariableName ) );
return false;
}
const size_t timeStepCount = eclipseCase->results( porosityModel )->maxTimeStepCount();
std::vector<std::vector<std::vector<double>>> values;
for ( size_t i = 0; i < m_variables.size(); i++ ) for ( size_t i = 0; i < m_variables.size(); i++ )
{ {
RimGridCalculationVariable* v = dynamic_cast<RimGridCalculationVariable*>( m_variables[i] ); RimGridCalculationVariable* v = dynamic_cast<RimGridCalculationVariable*>( m_variables[i] );
// Use the first defined eclipse case from for output
if ( !eclipseCase ) eclipseCase = v->eclipseCase();
if ( !v->eclipseCase() ) if ( !v->eclipseCase() )
{ {
RiaLogging::errorInMessageBox( nullptr, RiaLogging::errorInMessageBox( nullptr,
"Expression Parser", "Expression Parser",
QString( "No case defined for variable : %1" ).arg( v->name() ) ); QString( "No case defined for variable : %1" ).arg( v->name() ) );
return false; return false;
} }
@@ -82,11 +88,11 @@ bool RimGridCalculation::calculate()
RiaLogging::errorInMessageBox( nullptr, RiaLogging::errorInMessageBox( nullptr,
"Expression Parser", "Expression Parser",
QString( "No result variable defined for variable : %1" ).arg( v->name() ) ); QString( "No result variable defined for variable : %1" ).arg( v->name() ) );
return false; return false;
} }
RigEclipseResultAddress resAddr( v->resultCategoryType(), v->resultVariable() ); auto resultCategoryType = v->resultCategoryType();
RigEclipseResultAddress resAddr( resultCategoryType, v->resultVariable() );
if ( !eclipseCase->results( porosityModel )->ensureKnownResultLoaded( resAddr ) ) if ( !eclipseCase->results( porosityModel )->ensureKnownResultLoaded( resAddr ) )
{ {
RiaLogging::errorInMessageBox( nullptr, RiaLogging::errorInMessageBox( nullptr,
@@ -95,59 +101,79 @@ bool RimGridCalculation::calculate()
return false; return false;
} }
int timeStep = v->timeStep();
std::vector<std::vector<double>> inputValues = eclipseCase->results( porosityModel )->cellScalarResults( resAddr ); std::vector<std::vector<double>> inputValues = eclipseCase->results( porosityModel )->cellScalarResults( resAddr );
if ( resultCategoryType == RiaDefines::ResultCatType::STATIC_NATIVE )
values.push_back( inputValues[0] );
}
ExpressionParser parser;
for ( size_t i = 0; i < m_variables.size(); i++ )
{
RimGridCalculationVariable* v = dynamic_cast<RimGridCalculationVariable*>( m_variables[i] );
parser.assignVector( v->name(), values[i] );
}
std::vector<double> resultValues;
resultValues.resize( values[0].size() );
parser.assignVector( leftHandSideVariableName, resultValues );
QString errorText;
bool evaluatedOk = parser.expandIfStatementsAndEvaluate( m_expression, &errorText );
if ( evaluatedOk )
{
m_timesteps.v().clear();
m_calculatedValues.v().clear();
RigEclipseResultAddress resAddr( RiaDefines::ResultCatType::GENERATED, leftHandSideVariableName );
if ( !eclipseCase->results( porosityModel )->ensureKnownResultLoaded( resAddr ) )
{ {
eclipseCase->results( porosityModel )->createResultEntry( resAddr, true ); // Use static data for all time steps
inputValues.resize( timeStepCount );
for ( size_t tsId = 1; tsId < timeStepCount; tsId++ )
{
inputValues[tsId] = inputValues[0];
}
}
else if ( timeStep != RimGridCalculationVariable::allTimeStepsValue() )
{
// Use data from a specific time step for this variable for all result time steps
for ( size_t tsId = 0; tsId < timeStepCount; tsId++ )
{
if ( static_cast<int>( tsId ) != timeStep )
{
inputValues[tsId] = inputValues[timeStep];
}
}
} }
eclipseCase->results( porosityModel )->clearScalarResult( resAddr ); values.push_back( inputValues );
std::vector<std::vector<double>>* scalarResultFrames =
eclipseCase->results( porosityModel )->modifiableCellScalarResultTimesteps( resAddr );
size_t timeStepCount = eclipseCase->results( porosityModel )->maxTimeStepCount();
scalarResultFrames->resize( timeStepCount );
size_t tsId = 0;
scalarResultFrames->at( tsId ) = resultValues;
m_isDirty = false;
} }
else
RigEclipseResultAddress resAddr( RiaDefines::ResultCatType::GENERATED, leftHandSideVariableName );
if ( !eclipseCase->results( porosityModel )->ensureKnownResultLoaded( resAddr ) )
{ {
QString s = "The following error message was received from the parser library : \n\n"; eclipseCase->results( porosityModel )->createResultEntry( resAddr, true );
s += errorText;
RiaLogging::errorInMessageBox( nullptr, "Expression Parser", s );
} }
return evaluatedOk; eclipseCase->results( porosityModel )->clearScalarResult( resAddr );
std::vector<std::vector<double>>* scalarResultFrames =
eclipseCase->results( porosityModel )->modifiableCellScalarResultTimesteps( resAddr );
scalarResultFrames->resize( timeStepCount );
for ( size_t tsId = 0; tsId < timeStepCount; tsId++ )
{
ExpressionParser parser;
for ( size_t i = 0; i < m_variables.size(); i++ )
{
RimGridCalculationVariable* v = dynamic_cast<RimGridCalculationVariable*>( m_variables[i] );
parser.assignVector( v->name(), values[i][tsId] );
}
std::vector<double> resultValues;
resultValues.resize( values[0][tsId].size() );
parser.assignVector( leftHandSideVariableName, resultValues );
QString errorText;
bool evaluatedOk = parser.expandIfStatementsAndEvaluate( m_expression, &errorText );
if ( evaluatedOk )
{
scalarResultFrames->at( tsId ) = resultValues;
m_isDirty = false;
}
else
{
QString s = "The following error message was received from the parser library : \n\n";
s += errorText;
RiaLogging::errorInMessageBox( nullptr, "Expression Parser", s );
return false;
}
}
return true;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@@ -40,56 +40,7 @@ RimGridCalculationVariable::RimGridCalculationVariable()
CAF_PDM_InitFieldNoDefault( &m_resultType, "ResultType", "Type" ); CAF_PDM_InitFieldNoDefault( &m_resultType, "ResultType", "Type" );
CAF_PDM_InitField( &m_resultVariable, "ResultVariable", RiaResultNames::undefinedResultName(), "Variable" ); CAF_PDM_InitField( &m_resultVariable, "ResultVariable", RiaResultNames::undefinedResultName(), "Variable" );
CAF_PDM_InitFieldNoDefault( &m_eclipseCase, "EclipseGridCase", "Grid Case" ); CAF_PDM_InitFieldNoDefault( &m_eclipseCase, "EclipseGridCase", "Grid Case" );
CAF_PDM_InitField( &m_timeStep, "TimeStep", 0, "Time Step" ); CAF_PDM_InitField( &m_timeStep, "TimeStep", allTimeStepsValue(), "Time Step" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridCalculationVariable::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
const QVariant& newValue )
{
// if ( changedField == &m_button )
// {
// bool updateContainingEditor = false;
// {
// RiuGridVectorSelectionDialog dlg( nullptr );
// dlg.hideEnsembles();
// readDataFromApplicationStore( &dlg );
// if ( dlg.exec() == QDialog::Accepted )
// {
// std::vector<RiaGridCurveDefinition> curveSelection = dlg.curveSelection();
// if ( curveSelection.size() > 0 )
// {
// m_case = curveSelection[0].summaryCase();
// m_summaryAddress->setAddress( curveSelection[0].summaryAddress() );
// writeDataToApplicationStore();
// updateContainingEditor = true;
// }
// }
// }
// if ( updateContainingEditor )
// {
// RimGridCalculation* rimCalculation = nullptr;
// this->firstAncestorOrThisOfTypeAsserted( rimCalculation );
// // RimCalculation is pointed to by RicGridCurveCalculator in a PtrField
// // Update editors connected to RicGridCurveCalculator
// std::vector<caf::PdmObjectHandle*> referringObjects;
// rimCalculation->objectsWithReferringPtrFields( referringObjects );
// for ( auto o : referringObjects )
// {
// o->uiCapability()->updateConnectedEditors();
// }
// }
// }
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -159,6 +110,8 @@ QList<caf::PdmOptionItemInfo>
} }
else if ( fieldNeedingOptions == &m_timeStep ) else if ( fieldNeedingOptions == &m_timeStep )
{ {
options.push_back( caf::PdmOptionItemInfo( "All timesteps", allTimeStepsValue() ) );
RimTools::timeStepsForCase( m_eclipseCase(), &options ); RimTools::timeStepsForCase( m_eclipseCase(), &options );
} }
@@ -218,3 +171,11 @@ int RimGridCalculationVariable::timeStep() const
{ {
return m_timeStep; return m_timeStep;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RimGridCalculationVariable::allTimeStepsValue()
{
return -1;
}

View File

@@ -49,8 +49,9 @@ public:
QString resultVariable() const; QString resultVariable() const;
int timeStep() const; int timeStep() const;
static int allTimeStepsValue();
private: private:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override; void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions, QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,