2022-04-22 12:18:34 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2022 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.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "RimGridCalculation.h"
|
|
|
|
|
|
2022-05-02 14:25:45 +02:00
|
|
|
#include "RiaDefines.h"
|
2023-11-07 14:04:53 +01:00
|
|
|
#include "RiaGuiApplication.h"
|
2022-06-03 11:52:26 +02:00
|
|
|
#include "RiaLogging.h"
|
|
|
|
|
#include "RiaPorosityModel.h"
|
2026-05-06 12:00:10 +02:00
|
|
|
#include "RiaQStringFormatter.h"
|
2024-04-19 15:09:15 +02:00
|
|
|
#include "RiaRegressionTestRunner.h"
|
2026-05-06 11:50:40 +02:00
|
|
|
#include "RiuMessageDialog.h"
|
2022-06-03 11:52:26 +02:00
|
|
|
|
2022-11-24 10:44:03 +01:00
|
|
|
#include "RigActiveCellInfo.h"
|
2023-12-06 09:49:40 +01:00
|
|
|
#include "RigCaseCellResultsData.h"
|
|
|
|
|
#include "RigEclipseCaseData.h"
|
|
|
|
|
#include "RigEclipseResultAddress.h"
|
|
|
|
|
#include "RigGridManager.h"
|
|
|
|
|
#include "RigMainGrid.h"
|
|
|
|
|
#include "RigResultAccessor.h"
|
|
|
|
|
#include "RigResultAccessorFactory.h"
|
|
|
|
|
#include "RigStatisticsMath.h"
|
2026-07-15 11:03:31 +02:00
|
|
|
#include "RigStatisticsTools.h"
|
2023-12-06 09:49:40 +01:00
|
|
|
|
2024-01-19 08:26:31 +01:00
|
|
|
#include "RimCaseCollection.h"
|
2026-07-15 15:10:19 +02:00
|
|
|
#include "RimCellFilter.h"
|
|
|
|
|
#include "RimCellFilterTools.h"
|
|
|
|
|
#include "RimDataFilterCollection.h"
|
2022-04-22 12:18:34 +02:00
|
|
|
#include "RimEclipseCase.h"
|
2024-01-19 08:26:31 +01:00
|
|
|
#include "RimEclipseCaseCollection.h"
|
2024-12-16 12:44:29 +01:00
|
|
|
#include "RimEclipseCaseEnsemble.h"
|
2023-11-07 14:04:53 +01:00
|
|
|
#include "RimEclipseCaseTools.h"
|
2022-05-02 14:25:45 +02:00
|
|
|
#include "RimEclipseCellColors.h"
|
2024-01-16 13:39:26 +01:00
|
|
|
#include "RimEclipseResultAddress.h"
|
2023-11-07 14:04:53 +01:00
|
|
|
#include "RimEclipseStatisticsCase.h"
|
2022-05-02 14:25:45 +02:00
|
|
|
#include "RimEclipseView.h"
|
2023-12-06 09:49:40 +01:00
|
|
|
#include "RimGridCalculationCollection.h"
|
2022-06-03 11:52:26 +02:00
|
|
|
#include "RimGridCalculationVariable.h"
|
2024-01-19 08:26:31 +01:00
|
|
|
#include "RimIdenticalGridCaseGroup.h"
|
|
|
|
|
#include "RimOilField.h"
|
2022-11-17 15:51:01 +01:00
|
|
|
#include "RimProject.h"
|
2022-05-02 14:25:45 +02:00
|
|
|
#include "RimReloadCaseTools.h"
|
2026-07-15 15:40:38 +02:00
|
|
|
#include "RimReservoirGridEnsemble.h"
|
2024-01-16 13:39:26 +01:00
|
|
|
#include "RimResultSelectionUi.h"
|
2022-11-17 15:51:01 +01:00
|
|
|
#include "RimTools.h"
|
2022-04-22 12:18:34 +02:00
|
|
|
|
2022-05-02 09:18:48 +02:00
|
|
|
#include "expressionparser/ExpressionParser.h"
|
|
|
|
|
|
2024-01-16 13:39:26 +01:00
|
|
|
#include "cafPdmUiPropertyViewDialog.h"
|
2023-12-06 09:38:39 +01:00
|
|
|
#include "cafPdmUiTreeSelectionEditor.h"
|
|
|
|
|
|
2023-12-05 11:51:57 +01:00
|
|
|
#include <QCheckBox>
|
2023-11-07 14:04:53 +01:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
2026-09-14 14:02:18 +02:00
|
|
|
#include <set>
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
class CloseCasesOpenedForCalculation
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit CloseCasesOpenedForCalculation( const std::vector<RimEclipseCase*>& cases )
|
|
|
|
|
{
|
|
|
|
|
for ( auto* eclipseCase : cases )
|
|
|
|
|
{
|
|
|
|
|
if ( eclipseCase && !eclipseCase->isReservoirCaseOpen() ) m_casesToClose.insert( eclipseCase );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~CloseCasesOpenedForCalculation()
|
|
|
|
|
{
|
|
|
|
|
for ( auto* eclipseCase : m_casesToClose )
|
|
|
|
|
{
|
|
|
|
|
if ( eclipseCase->isReservoirCaseOpen() && eclipseCase->reservoirViews().empty() && eclipseCase->contourMapViews().empty() )
|
|
|
|
|
{
|
|
|
|
|
eclipseCase->closeReservoirCase();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::set<RimEclipseCase*> m_casesToClose;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::vector<RimEclipseCase*> sourceAndDestinationCases( const RimGridCalculation& calculation,
|
|
|
|
|
const std::vector<RimEclipseCase*>& destinationCases )
|
|
|
|
|
{
|
|
|
|
|
auto cases = calculation.inputCases();
|
|
|
|
|
cases.insert( cases.end(), destinationCases.begin(), destinationCases.end() );
|
|
|
|
|
return cases;
|
|
|
|
|
}
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2022-04-22 12:18:34 +02:00
|
|
|
CAF_PDM_SOURCE_INIT( RimGridCalculation, "RimGridCalculation" );
|
|
|
|
|
|
2022-11-17 15:51:01 +01:00
|
|
|
namespace caf
|
|
|
|
|
{
|
|
|
|
|
template <>
|
|
|
|
|
void caf::AppEnum<RimGridCalculation::DefaultValueType>::setUp()
|
|
|
|
|
{
|
|
|
|
|
addItem( RimGridCalculation::DefaultValueType::POSITIVE_INFINITY, "POSITIVE_INFINITY", "Infinity" );
|
|
|
|
|
addItem( RimGridCalculation::DefaultValueType::FROM_PROPERTY, "FROM_PROPERTY", "Property Value" );
|
|
|
|
|
addItem( RimGridCalculation::DefaultValueType::USER_DEFINED, "USER_DEFINED", "User Defined Custom Value" );
|
|
|
|
|
setDefault( RimGridCalculation::DefaultValueType::POSITIVE_INFINITY );
|
|
|
|
|
}
|
2024-01-19 08:26:31 +01:00
|
|
|
template <>
|
|
|
|
|
void caf::AppEnum<RimGridCalculation::AdditionalCasesType>::setUp()
|
|
|
|
|
{
|
|
|
|
|
addItem( RimGridCalculation::AdditionalCasesType::NONE, "NONE", "None" );
|
|
|
|
|
addItem( RimGridCalculation::AdditionalCasesType::GRID_CASE_GROUP, "GRID_CASE_GROUP", "Case Group" );
|
2024-12-16 12:44:29 +01:00
|
|
|
addItem( RimGridCalculation::AdditionalCasesType::ENSEMBLE, "ENSEMBLE", "Ensemble" );
|
2026-09-13 09:20:58 +02:00
|
|
|
addItem( RimGridCalculation::AdditionalCasesType::ALL_CASES, "ALL_CASES", "All Cases" );
|
2024-01-19 08:26:31 +01:00
|
|
|
setDefault( RimGridCalculation::AdditionalCasesType::NONE );
|
|
|
|
|
}
|
2026-07-15 15:10:19 +02:00
|
|
|
template <>
|
|
|
|
|
void caf::AppEnum<RimGridCalculation::FilterType>::setUp()
|
|
|
|
|
{
|
|
|
|
|
addItem( RimGridCalculation::FilterType::NO_FILTER, "NO_FILTER", "None" );
|
|
|
|
|
addItem( RimGridCalculation::FilterType::CELL_FILTER_VIEW, "CELL_FILTER_VIEW", "Cell Filter View" );
|
|
|
|
|
addItem( RimGridCalculation::FilterType::DATA_FILTER, "DATA_FILTER", "Data Filter" );
|
|
|
|
|
setDefault( RimGridCalculation::FilterType::NO_FILTER );
|
|
|
|
|
}
|
2022-11-17 15:51:01 +01:00
|
|
|
}; // namespace caf
|
|
|
|
|
|
2022-04-22 12:18:34 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimGridCalculation::RimGridCalculation()
|
|
|
|
|
{
|
|
|
|
|
CAF_PDM_InitObject( "RimGridCalculation", ":/octave.png", "Calculation", "" );
|
2026-07-15 15:10:19 +02:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_filterType, "FilterType", "Filter Type" );
|
2022-11-17 15:51:01 +01:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_cellFilterView, "VisibleCellView", "Filter by 3d View Visibility" );
|
2026-07-15 15:10:19 +02:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_dataFilter, "DataFilter", "Data Filter" );
|
2022-11-17 15:51:01 +01:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_defaultValueType, "DefaultValueType", "Non-visible Cell Value" );
|
|
|
|
|
CAF_PDM_InitField( &m_defaultValue, "DefaultValue", 0.0, "Custom Value" );
|
2026-09-14 14:05:25 +02:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_destinationEnsemble, "DestinationEnsemble", "Destination Ensemble" );
|
2022-11-17 15:51:01 +01:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_destinationCase, "DestinationCase", "Destination Case" );
|
2024-01-19 08:26:31 +01:00
|
|
|
|
|
|
|
|
CAF_PDM_InitField( &m_applyToAllCases_OBSOLETE, "AllDestinationCase", false, "Apply to All Cases" );
|
|
|
|
|
m_applyToAllCases_OBSOLETE.xmlCapability()->setIOWritable( false );
|
|
|
|
|
|
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_additionalCasesType, "AdditionalCasesType", "Apply To Additional Cases" );
|
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_additionalCaseGroup, "AdditionalCaseGroup", "Case Group" );
|
2024-12-16 12:44:29 +01:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_additionalEnsemble, "AdditionalEnsemble", "Ensemble" );
|
2024-01-16 13:39:26 +01:00
|
|
|
|
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_nonVisibleResultAddress, "NonVisibleResultAddress", "" );
|
|
|
|
|
m_nonVisibleResultAddress = new RimEclipseResultAddress;
|
|
|
|
|
|
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_nonVisibleResultText, "NonVisibleResultText", "" );
|
|
|
|
|
m_nonVisibleResultText.registerGetMethod( this, &RimGridCalculation::nonVisibleResultAddressText );
|
|
|
|
|
m_nonVisibleResultText.uiCapability()->setUiReadOnly( true );
|
2023-12-06 09:38:39 +01:00
|
|
|
|
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_selectedTimeSteps, "SelectedTimeSteps", "Time Step Selection" );
|
|
|
|
|
m_selectedTimeSteps.uiCapability()->setUiEditorTypeName( caf::PdmUiTreeSelectionEditor::uiEditorTypeName() );
|
2022-04-22 12:18:34 +02:00
|
|
|
}
|
|
|
|
|
|
2023-11-07 14:04:53 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
bool RimGridCalculation::preCalculate() const
|
|
|
|
|
{
|
2024-04-19 15:09:15 +02:00
|
|
|
if ( !RiaRegressionTestRunner::instance()->isRunningRegressionTests() && RiaGuiApplication::isRunning() &&
|
|
|
|
|
m_additionalCasesType() != RimGridCalculation::AdditionalCasesType::NONE )
|
2023-11-07 14:04:53 +01:00
|
|
|
{
|
2023-12-05 11:51:57 +01:00
|
|
|
const QString cacheKey = "GridCalculatorMessage";
|
2023-11-07 14:04:53 +01:00
|
|
|
|
2023-12-05 11:51:57 +01:00
|
|
|
auto cacheValue = RiaApplication::instance()->cacheDataObject( cacheKey );
|
|
|
|
|
if ( cacheValue.isValid() && cacheValue.canConvert<bool>() )
|
|
|
|
|
{
|
|
|
|
|
return cacheValue.toBool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QCheckBox* cb = new QCheckBox( "Don't show this question again" );
|
|
|
|
|
|
|
|
|
|
QMessageBox msgbox;
|
|
|
|
|
msgbox.setWindowTitle( "Grid Property Calculator" );
|
|
|
|
|
msgbox.setText( "Calculation will be executed on all grid model cases.\nDo you want to continue?\n" );
|
|
|
|
|
msgbox.setIcon( QMessageBox::Icon::Question );
|
|
|
|
|
msgbox.addButton( QMessageBox::Yes );
|
|
|
|
|
msgbox.addButton( QMessageBox::No );
|
|
|
|
|
msgbox.setDefaultButton( QMessageBox::Yes );
|
|
|
|
|
msgbox.setCheckBox( cb );
|
|
|
|
|
|
|
|
|
|
auto reply = msgbox.exec();
|
|
|
|
|
|
|
|
|
|
bool returnValue = ( reply == QMessageBox::Yes );
|
|
|
|
|
|
|
|
|
|
if ( cb->isChecked() && returnValue )
|
|
|
|
|
{
|
|
|
|
|
RiaApplication::instance()->setCacheDataObject( cacheKey, returnValue );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return returnValue;
|
2023-11-07 14:04:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 12:18:34 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2022-11-17 15:51:01 +01:00
|
|
|
RimGridCalculationVariable* RimGridCalculation::createVariable()
|
2022-04-22 12:18:34 +02:00
|
|
|
{
|
2022-11-17 15:51:01 +01:00
|
|
|
auto variable = new RimGridCalculationVariable;
|
|
|
|
|
|
|
|
|
|
variable->eclipseResultChanged.connect( this, &RimGridCalculation::onVariableUpdated );
|
|
|
|
|
|
|
|
|
|
return variable;
|
2022-04-22 12:18:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
bool RimGridCalculation::calculate()
|
|
|
|
|
{
|
2026-09-14 14:02:18 +02:00
|
|
|
CloseCasesOpenedForCalculation closeCasesWhenFinished( sourceAndDestinationCases( *this, outputEclipseCases() ) );
|
|
|
|
|
|
2026-07-15 15:10:19 +02:00
|
|
|
const bool useCellFilterView = ( m_filterType() == FilterType::CELL_FILTER_VIEW ) && m_cellFilterView() != nullptr;
|
|
|
|
|
const bool useDataFilter = ( m_filterType() == FilterType::DATA_FILTER );
|
|
|
|
|
|
|
|
|
|
if ( useDataFilter && m_dataFilter() == nullptr )
|
|
|
|
|
{
|
|
|
|
|
RiuMessageDialog::showError( nullptr, "Grid Property Calculator", "The filter type is 'Data Filter', but no data filter is selected." );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-19 15:09:15 +02:00
|
|
|
// Equal grid size is required if there is more than one grid case in the expression. If a cell filter view is active, the visibility is
|
2026-07-15 15:10:19 +02:00
|
|
|
// based on one view and reused for all other grid models, and requires equal grid size. A data filter is evaluated per case.
|
2026-09-14 14:05:25 +02:00
|
|
|
const bool calculateForEnsemble = m_destinationEnsemble() || m_additionalCasesType == AdditionalCasesType::ENSEMBLE;
|
|
|
|
|
bool checkIfGridSizeIsEqual = ( !allSourceCasesAreEqualToDestinationCase() || useCellFilterView ) && !calculateForEnsemble;
|
2024-04-19 15:09:15 +02:00
|
|
|
|
2026-08-21 14:13:57 +02:00
|
|
|
// Grid dimensions are required to validate the calculation, and a source case is not necessarily opened. This is the case for a
|
|
|
|
|
// statistics case with no computed statistics.
|
|
|
|
|
for ( auto inputCase : inputCases() )
|
|
|
|
|
{
|
|
|
|
|
if ( inputCase && !inputCase->eclipseCaseData() ) inputCase->ensureReservoirCaseIsOpen();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-10 08:06:46 +01:00
|
|
|
for ( auto calculationCase : outputEclipseCases() )
|
|
|
|
|
{
|
|
|
|
|
if ( !calculationCase ) continue;
|
|
|
|
|
|
2024-04-19 15:09:15 +02:00
|
|
|
if ( !calculationCase->eclipseCaseData() )
|
|
|
|
|
{
|
2024-12-16 12:44:29 +01:00
|
|
|
if ( m_additionalCasesType == AdditionalCasesType::ENSEMBLE )
|
|
|
|
|
{
|
|
|
|
|
calculationCase->ensureReservoirCaseIsOpen();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
QString msg = QString( "No data available for case %1, aborting calculation" ).arg( calculationCase->caseUserDescription() );
|
2026-05-06 11:50:40 +02:00
|
|
|
RiuMessageDialog::showError( nullptr, "Grid Property Calculator", msg );
|
2024-12-16 12:44:29 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2024-04-19 15:09:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !calculationCase->eclipseCaseData()->activeCellInfo( RiaDefines::PorosityModelType::MATRIX_MODEL ) )
|
|
|
|
|
{
|
|
|
|
|
QString msg =
|
|
|
|
|
QString( "No active cell data available for case %1, aborting calculation" ).arg( calculationCase->caseUserDescription() );
|
2026-05-06 11:50:40 +02:00
|
|
|
RiuMessageDialog::showError( nullptr, "Grid Property Calculator", msg );
|
2024-04-19 15:09:15 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( checkIfGridSizeIsEqual )
|
2023-11-10 08:06:46 +01:00
|
|
|
{
|
2024-04-19 15:09:15 +02:00
|
|
|
for ( auto inputCase : inputCases() )
|
2023-11-10 08:06:46 +01:00
|
|
|
{
|
2024-04-19 15:09:15 +02:00
|
|
|
if ( !calculationCase->isGridSizeEqualTo( inputCase ) )
|
|
|
|
|
{
|
|
|
|
|
QString msg = "Detected IJK mismatch between input cases and destination case. All grid "
|
|
|
|
|
"cases must have identical IJK sizes.";
|
2026-05-06 11:50:40 +02:00
|
|
|
RiuMessageDialog::showError( nullptr, "Grid Property Calculator", msg );
|
2024-04-19 15:09:15 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2023-11-10 08:06:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-16 13:39:26 +01:00
|
|
|
if ( m_defaultValueType() == DefaultValueType::FROM_PROPERTY )
|
|
|
|
|
{
|
|
|
|
|
bool isDataSourceAvailable = false;
|
|
|
|
|
|
|
|
|
|
if ( m_nonVisibleResultAddress->eclipseCase() )
|
|
|
|
|
{
|
|
|
|
|
auto data = m_nonVisibleResultAddress->eclipseCase()->results( RiaDefines::PorosityModelType::MATRIX_MODEL );
|
|
|
|
|
if ( data && data->hasResultEntry(
|
|
|
|
|
RigEclipseResultAddress( m_nonVisibleResultAddress->resultType(), m_nonVisibleResultAddress->resultName() ) ) )
|
|
|
|
|
{
|
|
|
|
|
isDataSourceAvailable = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !isDataSourceAvailable )
|
|
|
|
|
{
|
|
|
|
|
QString msg = "No data available for result defined in 'Non-visible Cell Value'";
|
|
|
|
|
|
2026-05-06 11:50:40 +02:00
|
|
|
RiuMessageDialog::showError( nullptr, "Grid Property Calculator", msg );
|
2024-01-16 13:39:26 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-15 16:30:43 +02:00
|
|
|
// The visible cells of the view, including the effect of property filters evaluated on the view's
|
|
|
|
|
// case. Cells inside the filters that are inactive in the view's case are not part of the mask; use
|
|
|
|
|
// the data filter type to evaluate filters per calculation case.
|
2026-07-15 13:21:04 +02:00
|
|
|
cvf::ref<cvf::UByteArray> inputValueVisibilityFilter;
|
2026-07-15 15:10:19 +02:00
|
|
|
if ( useCellFilterView )
|
2023-12-04 16:12:53 +01:00
|
|
|
{
|
2026-07-15 16:30:43 +02:00
|
|
|
inputValueVisibilityFilter = m_cellFilterView()->currentTotalCellVisibility();
|
2023-12-04 16:12:53 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-06 09:49:40 +01:00
|
|
|
std::optional<std::vector<size_t>> timeSteps = std::nullopt;
|
|
|
|
|
|
|
|
|
|
if ( !m_selectedTimeSteps().empty() )
|
|
|
|
|
{
|
|
|
|
|
std::vector<size_t> tmp;
|
|
|
|
|
for ( auto t : m_selectedTimeSteps() )
|
|
|
|
|
{
|
|
|
|
|
tmp.push_back( static_cast<size_t>( t ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
timeSteps = tmp;
|
|
|
|
|
}
|
2023-12-04 16:12:53 +01:00
|
|
|
|
2023-12-06 09:49:40 +01:00
|
|
|
bool evaluateDependentCalculations = true;
|
2026-07-15 13:21:04 +02:00
|
|
|
return calculateForCases( outputEclipseCases(), inputValueVisibilityFilter.p(), timeSteps, evaluateDependentCalculations );
|
2022-04-22 12:18:34 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-02 14:25:45 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-11-07 14:04:53 +01:00
|
|
|
std::vector<RimEclipseCase*> RimGridCalculation::outputEclipseCases() const
|
2022-11-17 15:51:01 +01:00
|
|
|
{
|
2024-01-19 08:26:31 +01:00
|
|
|
if ( m_additionalCasesType() == RimGridCalculation::AdditionalCasesType::ALL_CASES )
|
2023-11-07 14:04:53 +01:00
|
|
|
{
|
|
|
|
|
// Find all Eclipse cases suitable for grid calculations. This includes all single grid cases and source cases in a grid case group.
|
|
|
|
|
// Exclude the statistics cases, as it is not possible to use them in a grid calculations.
|
2024-09-23 11:51:32 +02:00
|
|
|
return RimEclipseCaseTools::nativeEclipseGridCases();
|
2023-11-07 14:04:53 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-19 08:26:31 +01:00
|
|
|
if ( m_additionalCasesType() == RimGridCalculation::AdditionalCasesType::GRID_CASE_GROUP )
|
|
|
|
|
{
|
2024-01-22 16:57:22 +01:00
|
|
|
if ( m_additionalCaseGroup() && m_additionalCaseGroup()->caseCollection() )
|
|
|
|
|
return m_additionalCaseGroup()->caseCollection()->reservoirs.childrenByType();
|
2024-01-19 08:26:31 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-16 12:44:29 +01:00
|
|
|
if ( m_additionalCasesType() == RimGridCalculation::AdditionalCasesType::ENSEMBLE )
|
|
|
|
|
{
|
|
|
|
|
if ( m_additionalEnsemble() ) return m_additionalEnsemble()->cases();
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-14 14:05:25 +02:00
|
|
|
if ( m_destinationEnsemble() ) return m_destinationEnsemble()->cases();
|
|
|
|
|
|
2023-11-07 14:04:53 +01:00
|
|
|
return { m_destinationCase };
|
2022-11-17 15:51:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::vector<RimEclipseCase*> RimGridCalculation::inputCases() const
|
|
|
|
|
{
|
|
|
|
|
std::vector<RimEclipseCase*> cases;
|
|
|
|
|
|
|
|
|
|
for ( const auto& variable : m_variables )
|
|
|
|
|
{
|
|
|
|
|
auto* v = dynamic_cast<RimGridCalculationVariable*>( variable.p() );
|
|
|
|
|
|
|
|
|
|
if ( v->eclipseCase() ) cases.push_back( v->eclipseCase() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cases;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimGridCalculation::DefaultValueConfig RimGridCalculation::defaultValueConfiguration() const
|
2022-05-02 14:25:45 +02:00
|
|
|
{
|
2022-11-17 15:51:01 +01:00
|
|
|
if ( m_defaultValueType() == RimGridCalculation::DefaultValueType::USER_DEFINED )
|
|
|
|
|
return std::make_pair( m_defaultValueType(), m_defaultValue() );
|
|
|
|
|
|
|
|
|
|
return std::make_pair( m_defaultValueType(), HUGE_VAL );
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-16 13:39:26 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
QString RimGridCalculation::nonVisibleResultAddressText() const
|
|
|
|
|
{
|
|
|
|
|
QString txt;
|
|
|
|
|
|
|
|
|
|
if ( m_nonVisibleResultAddress->eclipseCase() ) txt += m_nonVisibleResultAddress->eclipseCase()->caseUserDescription() + " : ";
|
|
|
|
|
|
|
|
|
|
txt += m_nonVisibleResultAddress->resultName();
|
|
|
|
|
|
|
|
|
|
return txt;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-17 15:51:01 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimGridCalculation::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
|
|
|
|
{
|
|
|
|
|
RimUserDefinedCalculation::defineUiOrdering( uiConfigName, uiOrdering );
|
|
|
|
|
|
2026-09-14 14:05:25 +02:00
|
|
|
uiOrdering.add( &m_destinationEnsemble );
|
2022-11-17 15:51:01 +01:00
|
|
|
uiOrdering.add( &m_destinationCase );
|
2026-09-14 14:05:25 +02:00
|
|
|
m_destinationCase.uiCapability()->setUiHidden( m_destinationEnsemble() != nullptr );
|
2022-11-17 15:51:01 +01:00
|
|
|
|
2024-01-19 08:26:31 +01:00
|
|
|
uiOrdering.add( &m_additionalCasesType );
|
|
|
|
|
uiOrdering.add( &m_additionalCaseGroup );
|
|
|
|
|
m_additionalCaseGroup.uiCapability()->setUiHidden( m_additionalCasesType() != RimGridCalculation::AdditionalCasesType::GRID_CASE_GROUP );
|
2023-11-07 14:04:53 +01:00
|
|
|
|
2024-12-16 12:44:29 +01:00
|
|
|
uiOrdering.add( &m_additionalEnsemble );
|
|
|
|
|
m_additionalEnsemble.uiCapability()->setUiHidden( m_additionalCasesType() != RimGridCalculation::AdditionalCasesType::ENSEMBLE );
|
|
|
|
|
|
2022-11-17 15:51:01 +01:00
|
|
|
caf::PdmUiGroup* filterGroup = uiOrdering.addNewGroup( "Cell Filter" );
|
|
|
|
|
filterGroup->setCollapsedByDefault();
|
2026-07-15 15:10:19 +02:00
|
|
|
filterGroup->add( &m_filterType );
|
2022-11-17 15:51:01 +01:00
|
|
|
|
2026-07-15 15:10:19 +02:00
|
|
|
if ( m_filterType() == FilterType::CELL_FILTER_VIEW ) filterGroup->add( &m_cellFilterView );
|
|
|
|
|
if ( m_filterType() == FilterType::DATA_FILTER ) filterGroup->add( &m_dataFilter );
|
|
|
|
|
|
|
|
|
|
const bool hasFilter = ( m_filterType() == FilterType::CELL_FILTER_VIEW && m_cellFilterView() != nullptr ) ||
|
|
|
|
|
( m_filterType() == FilterType::DATA_FILTER && m_dataFilter() != nullptr );
|
|
|
|
|
if ( hasFilter )
|
2022-05-02 14:25:45 +02:00
|
|
|
{
|
2022-11-17 15:51:01 +01:00
|
|
|
filterGroup->add( &m_defaultValueType );
|
2022-05-09 09:32:09 +02:00
|
|
|
|
2022-11-17 15:51:01 +01:00
|
|
|
if ( m_defaultValueType() == RimGridCalculation::DefaultValueType::FROM_PROPERTY )
|
2024-01-16 13:39:26 +01:00
|
|
|
{
|
|
|
|
|
filterGroup->add( &m_nonVisibleResultText );
|
2026-01-24 17:08:38 +01:00
|
|
|
filterGroup->addNewButton( "Edit", [this]() { onEditNonVisibleResultAddressButtonPressed(); }, { .newRow = false } );
|
2024-01-16 13:39:26 +01:00
|
|
|
}
|
2022-11-17 15:51:01 +01:00
|
|
|
else if ( m_defaultValueType() == RimGridCalculation::DefaultValueType::USER_DEFINED )
|
|
|
|
|
filterGroup->add( &m_defaultValue );
|
2022-05-02 14:25:45 +02:00
|
|
|
}
|
|
|
|
|
|
2023-12-06 09:38:39 +01:00
|
|
|
caf::PdmUiGroup* timeStepGroup = uiOrdering.addNewGroup( "Time Step Filter" );
|
|
|
|
|
timeStepGroup->setCollapsedByDefault();
|
|
|
|
|
timeStepGroup->add( &m_selectedTimeSteps );
|
|
|
|
|
|
2022-11-17 15:51:01 +01:00
|
|
|
uiOrdering.skipRemainingFields();
|
2022-05-02 14:25:45 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-03 11:52:26 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2022-11-17 15:51:01 +01:00
|
|
|
QList<caf::PdmOptionItemInfo> RimGridCalculation::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions )
|
2022-06-03 11:52:26 +02:00
|
|
|
{
|
2022-11-17 15:51:01 +01:00
|
|
|
QList<caf::PdmOptionItemInfo> options;
|
|
|
|
|
|
|
|
|
|
if ( fieldNeedingOptions == &m_cellFilterView )
|
|
|
|
|
{
|
|
|
|
|
options.push_back( caf::PdmOptionItemInfo( "Disabled", nullptr ) );
|
|
|
|
|
|
|
|
|
|
RimEclipseCase* firstEclipseCase = nullptr;
|
2024-01-08 15:22:45 +01:00
|
|
|
if ( !inputCases().empty() )
|
|
|
|
|
{
|
|
|
|
|
firstEclipseCase = inputCases().front();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-01-19 08:26:31 +01:00
|
|
|
// If no input cases are defined, use the destination case to determine the grid size. This will enable use of expressions
|
|
|
|
|
// with no input cases like "calculation := 1.0"
|
2026-09-14 14:05:25 +02:00
|
|
|
firstEclipseCase = destinationCase();
|
2024-01-08 15:22:45 +01:00
|
|
|
}
|
2022-11-17 15:51:01 +01:00
|
|
|
|
|
|
|
|
if ( firstEclipseCase )
|
|
|
|
|
{
|
2024-04-03 14:53:20 +02:00
|
|
|
std::vector<Rim3dView*> views = RimProject::current()->allViews();
|
2022-11-17 15:51:01 +01:00
|
|
|
for ( auto* view : views )
|
|
|
|
|
{
|
|
|
|
|
auto eclipseView = dynamic_cast<RimEclipseView*>( view );
|
|
|
|
|
if ( !eclipseView ) continue;
|
|
|
|
|
if ( !firstEclipseCase->isGridSizeEqualTo( eclipseView->eclipseCase() ) ) continue;
|
|
|
|
|
|
|
|
|
|
options.push_back( caf::PdmOptionItemInfo( view->autoName(), view, false, view->uiIconProvider() ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-15 15:10:19 +02:00
|
|
|
else if ( fieldNeedingOptions == &m_dataFilter )
|
|
|
|
|
{
|
|
|
|
|
options.push_back( caf::PdmOptionItemInfo( "None", nullptr ) );
|
|
|
|
|
|
2026-09-14 14:05:25 +02:00
|
|
|
if ( auto* destination = destinationCase() )
|
2026-07-15 15:10:19 +02:00
|
|
|
{
|
2026-09-14 14:05:25 +02:00
|
|
|
if ( auto dataFilterCollection = destination->dataFilterCollection() )
|
2026-07-15 15:10:19 +02:00
|
|
|
{
|
2026-07-15 15:40:38 +02:00
|
|
|
for ( RimCellFilter* filter : dataFilterCollection->filters() )
|
|
|
|
|
{
|
|
|
|
|
if ( !filter ) continue;
|
|
|
|
|
options.push_back( caf::PdmOptionItemInfo( filter->fullName(), filter, false, filter->uiIconProvider() ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Also offer the data filters of the grid ensemble the destination case belongs to, if any
|
2026-09-14 14:05:25 +02:00
|
|
|
if ( auto gridEnsemble = destination->firstAncestorOfType<RimReservoirGridEnsemble>() )
|
2026-07-15 15:40:38 +02:00
|
|
|
{
|
|
|
|
|
if ( auto dataFilterCollection = gridEnsemble->dataFilterCollection() )
|
|
|
|
|
{
|
|
|
|
|
for ( RimCellFilter* filter : dataFilterCollection->filters() )
|
|
|
|
|
{
|
|
|
|
|
if ( !filter ) continue;
|
|
|
|
|
options.push_back( caf::PdmOptionItemInfo( QString( "%1 : %2" ).arg( gridEnsemble->name(), filter->fullName() ),
|
|
|
|
|
filter,
|
|
|
|
|
false,
|
|
|
|
|
filter->uiIconProvider() ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-15 15:10:19 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-09-14 14:05:25 +02:00
|
|
|
else if ( fieldNeedingOptions == &m_destinationEnsemble )
|
|
|
|
|
{
|
|
|
|
|
options.push_back( caf::PdmOptionItemInfo( "None", nullptr ) );
|
|
|
|
|
|
|
|
|
|
RimProject* project = RimProject::current();
|
|
|
|
|
if ( project->activeOilField() && project->activeOilField()->analysisModels() )
|
|
|
|
|
{
|
|
|
|
|
for ( auto* ensemble : project->activeOilField()->analysisModels()->reservoirGridEnsembles.childrenByType() )
|
|
|
|
|
{
|
|
|
|
|
options.push_back( caf::PdmOptionItemInfo( ensemble->name(), ensemble, false, ensemble->uiIconProvider() ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-17 15:51:01 +01:00
|
|
|
else if ( fieldNeedingOptions == &m_destinationCase )
|
2022-06-03 11:52:26 +02:00
|
|
|
{
|
2023-11-07 14:04:53 +01:00
|
|
|
RimEclipseCase* firstInputCase = nullptr;
|
|
|
|
|
|
|
|
|
|
if ( !inputCases().empty() )
|
2022-11-17 15:51:01 +01:00
|
|
|
{
|
2023-11-07 14:04:53 +01:00
|
|
|
firstInputCase = inputCases()[0];
|
2022-11-17 15:51:01 +01:00
|
|
|
}
|
|
|
|
|
|
2024-09-23 11:51:32 +02:00
|
|
|
for ( auto eclipseCase : RimEclipseCaseTools::nativeEclipseGridCases() )
|
2023-11-07 14:04:53 +01:00
|
|
|
{
|
|
|
|
|
if ( !eclipseCase ) continue;
|
|
|
|
|
if ( firstInputCase && !firstInputCase->isGridSizeEqualTo( eclipseCase ) ) continue;
|
2022-11-17 15:51:01 +01:00
|
|
|
|
2023-11-07 14:04:53 +01:00
|
|
|
options.push_back( caf::PdmOptionItemInfo( eclipseCase->caseUserDescription(), eclipseCase, false, eclipseCase->uiIconProvider() ) );
|
2022-11-17 15:51:01 +01:00
|
|
|
}
|
2022-06-03 11:52:26 +02:00
|
|
|
|
2022-11-17 15:51:01 +01:00
|
|
|
options.push_front( caf::PdmOptionItemInfo( "None", nullptr ) );
|
2022-06-03 11:52:26 +02:00
|
|
|
}
|
2023-12-06 09:38:39 +01:00
|
|
|
else if ( &m_selectedTimeSteps == fieldNeedingOptions )
|
|
|
|
|
{
|
|
|
|
|
RimEclipseCase* firstEclipseCase = nullptr;
|
|
|
|
|
if ( !inputCases().empty() ) firstEclipseCase = inputCases().front();
|
|
|
|
|
|
|
|
|
|
if ( firstEclipseCase )
|
|
|
|
|
{
|
|
|
|
|
const auto timeStepStrings = firstEclipseCase->timeStepStrings();
|
|
|
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
for ( const auto& text : timeStepStrings )
|
|
|
|
|
{
|
|
|
|
|
options.push_back( caf::PdmOptionItemInfo( text, index++ ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-19 08:26:31 +01:00
|
|
|
else if ( &m_additionalCaseGroup == fieldNeedingOptions )
|
|
|
|
|
{
|
|
|
|
|
options.push_back( caf::PdmOptionItemInfo( "None", nullptr ) );
|
|
|
|
|
|
|
|
|
|
RimProject* proj = RimProject::current();
|
|
|
|
|
if ( proj->activeOilField() && proj->activeOilField()->analysisModels() )
|
|
|
|
|
{
|
|
|
|
|
auto analysisModels = proj->activeOilField()->analysisModels();
|
|
|
|
|
for ( RimIdenticalGridCaseGroup* cg : analysisModels->caseGroups() )
|
|
|
|
|
{
|
|
|
|
|
options.push_back( caf::PdmOptionItemInfo( cg->name(), cg, false, cg->uiIconProvider() ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-16 12:44:29 +01:00
|
|
|
else if ( &m_additionalEnsemble == fieldNeedingOptions )
|
|
|
|
|
{
|
|
|
|
|
options.push_back( caf::PdmOptionItemInfo( "None", nullptr ) );
|
|
|
|
|
|
|
|
|
|
RimProject* proj = RimProject::current();
|
|
|
|
|
if ( proj->activeOilField() && proj->activeOilField()->analysisModels() )
|
|
|
|
|
{
|
|
|
|
|
auto analysisModels = proj->activeOilField()->analysisModels();
|
|
|
|
|
for ( RimEclipseCaseEnsemble* e : analysisModels->caseEnsembles() )
|
|
|
|
|
{
|
|
|
|
|
options.push_back( caf::PdmOptionItemInfo( e->name(), e, false, e->uiIconProvider() ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-06 09:38:39 +01:00
|
|
|
|
2022-11-17 15:51:01 +01:00
|
|
|
return options;
|
2022-06-03 11:52:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2022-11-17 15:51:01 +01:00
|
|
|
void RimGridCalculation::initAfterRead()
|
2022-06-03 11:52:26 +02:00
|
|
|
{
|
2022-11-17 15:51:01 +01:00
|
|
|
for ( auto& variable : m_variables )
|
2022-06-03 11:52:26 +02:00
|
|
|
{
|
2022-11-17 15:51:01 +01:00
|
|
|
auto gridVar = dynamic_cast<RimGridCalculationVariable*>( variable.p() );
|
|
|
|
|
if ( gridVar )
|
|
|
|
|
{
|
|
|
|
|
gridVar->eclipseResultChanged.connect( this, &RimGridCalculation::onVariableUpdated );
|
2022-06-03 11:52:26 +02:00
|
|
|
|
2026-09-14 14:05:25 +02:00
|
|
|
if ( !m_destinationEnsemble() && m_destinationCase == nullptr ) m_destinationCase = gridVar->eclipseCase();
|
2022-11-17 15:51:01 +01:00
|
|
|
}
|
2022-06-03 11:52:26 +02:00
|
|
|
}
|
2024-01-19 08:26:31 +01:00
|
|
|
|
|
|
|
|
if ( m_applyToAllCases_OBSOLETE ) m_additionalCasesType = RimGridCalculation::AdditionalCasesType::ALL_CASES;
|
2026-07-15 15:10:19 +02:00
|
|
|
|
|
|
|
|
// Projects from before the filter type field was introduced only have the cell filter view. The view
|
|
|
|
|
// pointer is cleared when the filter type is changed away from CELL_FILTER_VIEW, so a set view pointer
|
|
|
|
|
// implies the cell filter view mode.
|
|
|
|
|
if ( m_cellFilterView() != nullptr ) m_filterType = FilterType::CELL_FILTER_VIEW;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimGridCalculation::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
|
|
|
|
|
{
|
|
|
|
|
RimUserDefinedCalculation::fieldChangedByUi( changedField, oldValue, newValue );
|
|
|
|
|
|
|
|
|
|
if ( changedField == &m_filterType )
|
|
|
|
|
{
|
|
|
|
|
if ( m_filterType() != FilterType::CELL_FILTER_VIEW ) m_cellFilterView = nullptr;
|
|
|
|
|
if ( m_filterType() != FilterType::DATA_FILTER ) m_dataFilter = nullptr;
|
2026-09-14 14:05:25 +02:00
|
|
|
}
|
2026-07-15 15:10:19 +02:00
|
|
|
|
2026-09-14 14:05:25 +02:00
|
|
|
if ( changedField == &m_filterType || changedField == &m_destinationEnsemble )
|
|
|
|
|
{
|
2026-07-15 15:10:19 +02:00
|
|
|
updateConnectedEditors();
|
|
|
|
|
}
|
2022-11-17 15:51:01 +01:00
|
|
|
}
|
2022-06-03 11:52:26 +02:00
|
|
|
|
2024-01-16 13:39:26 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2026-01-24 17:08:38 +01:00
|
|
|
void RimGridCalculation::onEditNonVisibleResultAddressButtonPressed()
|
2024-01-16 13:39:26 +01:00
|
|
|
{
|
2026-01-24 17:08:38 +01:00
|
|
|
auto eclipseCase = m_nonVisibleResultAddress->eclipseCase();
|
2026-09-14 14:05:25 +02:00
|
|
|
if ( !eclipseCase ) eclipseCase = destinationCase();
|
2024-01-16 13:39:26 +01:00
|
|
|
|
2026-01-24 17:08:38 +01:00
|
|
|
RimResultSelectionUi selectionUi;
|
|
|
|
|
selectionUi.setEclipseResultAddress( eclipseCase, m_nonVisibleResultAddress->resultType(), m_nonVisibleResultAddress->resultName() );
|
2024-01-16 13:39:26 +01:00
|
|
|
|
2026-01-24 17:08:38 +01:00
|
|
|
caf::PdmUiPropertyViewDialog propertyDialog( nullptr, &selectionUi, "Select Result", "" );
|
|
|
|
|
if ( propertyDialog.exec() == QDialog::Accepted )
|
2024-01-16 13:39:26 +01:00
|
|
|
{
|
2026-01-24 17:08:38 +01:00
|
|
|
m_nonVisibleResultAddress->setEclipseCase( selectionUi.eclipseCase() );
|
|
|
|
|
m_nonVisibleResultAddress->setResultType( selectionUi.resultType() );
|
|
|
|
|
m_nonVisibleResultAddress->setResultName( selectionUi.resultVariable() );
|
2024-01-16 13:39:26 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-17 15:51:01 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimGridCalculation::onVariableUpdated( const SignalEmitter* emitter )
|
|
|
|
|
{
|
2023-11-10 08:15:43 +01:00
|
|
|
if ( auto variable = dynamic_cast<const RimGridCalculationVariable*>( emitter ) )
|
2022-11-17 15:51:01 +01:00
|
|
|
{
|
2023-11-10 08:15:43 +01:00
|
|
|
if ( auto variableCase = variable->eclipseCase() )
|
2022-11-17 15:51:01 +01:00
|
|
|
{
|
2026-08-21 14:13:57 +02:00
|
|
|
// A statistics case can be used as source, but never as destination. A calculated result stored in a statistics case is
|
|
|
|
|
// interpreted as computed statistics, and will block recomputation of the statistics.
|
|
|
|
|
const bool canBeDestinationCase = dynamic_cast<RimEclipseStatisticsCase*>( variableCase ) == nullptr;
|
|
|
|
|
|
2026-09-14 14:05:25 +02:00
|
|
|
if ( canBeDestinationCase && !m_destinationEnsemble() &&
|
|
|
|
|
( !m_destinationCase || !m_destinationCase->isGridSizeEqualTo( variableCase ) ) )
|
2023-11-10 08:15:43 +01:00
|
|
|
{
|
|
|
|
|
m_destinationCase = variableCase;
|
|
|
|
|
}
|
2022-11-17 15:51:01 +01:00
|
|
|
}
|
|
|
|
|
}
|
2023-11-10 08:15:43 +01:00
|
|
|
|
|
|
|
|
updateConnectedEditors();
|
|
|
|
|
|
|
|
|
|
variableUpdated.send();
|
2022-06-03 11:52:26 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-14 14:05:25 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimEclipseCase* RimGridCalculation::destinationCase() const
|
|
|
|
|
{
|
|
|
|
|
if ( m_destinationEnsemble() ) return m_destinationEnsemble()->mainCase();
|
|
|
|
|
|
|
|
|
|
return m_destinationCase();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-07 14:04:53 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
bool RimGridCalculation::allSourceCasesAreEqualToDestinationCase() const
|
|
|
|
|
{
|
2026-09-14 14:05:25 +02:00
|
|
|
auto* destination = destinationCase();
|
|
|
|
|
if ( destination == nullptr ) return false;
|
2023-11-07 14:04:53 +01:00
|
|
|
|
|
|
|
|
for ( const auto& variable : m_variables )
|
|
|
|
|
{
|
|
|
|
|
auto gridVar = dynamic_cast<RimGridCalculationVariable*>( variable.p() );
|
|
|
|
|
if ( gridVar )
|
|
|
|
|
{
|
2026-09-14 14:05:25 +02:00
|
|
|
if ( gridVar->eclipseCase() != destination ) return false;
|
2023-11-07 14:04:53 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-22 10:22:17 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RigEclipseResultAddress RimGridCalculation::outputAddress() const
|
|
|
|
|
{
|
|
|
|
|
QString leftHandSideVariableName = RimGridCalculation::findLeftHandSide( m_expression );
|
|
|
|
|
RigEclipseResultAddress resAddr( RiaDefines::ResultCatType::GENERATED, leftHandSideVariableName );
|
|
|
|
|
return resAddr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-03 11:52:26 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2024-04-19 15:09:15 +02:00
|
|
|
std::vector<double> RimGridCalculation::getActiveCellValuesForVariable( RimGridCalculationVariable* variable,
|
|
|
|
|
size_t tsId,
|
|
|
|
|
RiaDefines::PorosityModelType porosityModel,
|
|
|
|
|
RimEclipseCase* sourceCase,
|
|
|
|
|
RimEclipseCase* destinationCase ) const
|
2022-06-03 11:52:26 +02:00
|
|
|
{
|
2024-01-16 13:39:26 +01:00
|
|
|
if ( !sourceCase || !destinationCase ) return {};
|
2022-06-03 11:52:26 +02:00
|
|
|
|
2024-01-16 13:39:26 +01:00
|
|
|
int timeStep = variable->timeStep();
|
2023-11-29 09:15:04 +01:00
|
|
|
auto resultCategoryType = variable->resultCategoryType();
|
2022-06-03 11:52:26 +02:00
|
|
|
|
|
|
|
|
// General case is to use the data from the given time step
|
|
|
|
|
size_t timeStepToUse = tsId;
|
|
|
|
|
|
|
|
|
|
if ( resultCategoryType == RiaDefines::ResultCatType::STATIC_NATIVE )
|
|
|
|
|
{
|
|
|
|
|
// Use the first time step for static data for all time steps
|
|
|
|
|
timeStepToUse = 0;
|
|
|
|
|
}
|
|
|
|
|
else if ( timeStep != RimGridCalculationVariable::allTimeStepsValue() )
|
|
|
|
|
{
|
|
|
|
|
// Use data from a specific time step for this variable for all result time steps
|
|
|
|
|
timeStepToUse = timeStep;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-19 15:09:15 +02:00
|
|
|
return getActiveCellValues( variable->resultVariable(), resultCategoryType, timeStepToUse, porosityModel, sourceCase, destinationCase );
|
2024-01-16 13:39:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2024-04-19 15:09:15 +02:00
|
|
|
/// Return values for active cells, both for dynamic and static results. Use the active cell info from the destination case, and read data
|
|
|
|
|
/// from the source case.
|
2024-01-16 13:39:26 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2024-04-19 15:09:15 +02:00
|
|
|
std::vector<double> RimGridCalculation::getActiveCellValues( const QString& resultName,
|
|
|
|
|
const RiaDefines::ResultCatType resultCategoryType,
|
|
|
|
|
size_t tsId,
|
|
|
|
|
RiaDefines::PorosityModelType porosityModel,
|
|
|
|
|
RimEclipseCase* sourceCase,
|
|
|
|
|
RimEclipseCase* destinationCase ) const
|
2024-01-16 13:39:26 +01:00
|
|
|
{
|
|
|
|
|
if ( !sourceCase || !destinationCase ) return {};
|
|
|
|
|
|
2026-08-21 14:13:57 +02:00
|
|
|
// A statistics case is not necessarily opened when used as source for a calculation
|
|
|
|
|
if ( !sourceCase->eclipseCaseData() && !sourceCase->ensureReservoirCaseIsOpen() ) return {};
|
|
|
|
|
|
2024-01-16 13:39:26 +01:00
|
|
|
size_t timeStepToUse = tsId;
|
|
|
|
|
if ( resultCategoryType == RiaDefines::ResultCatType::STATIC_NATIVE )
|
|
|
|
|
{
|
|
|
|
|
// Use the first time step for static data for all time steps
|
|
|
|
|
timeStepToUse = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RigEclipseResultAddress resAddr( resultCategoryType, resultName );
|
2022-06-03 11:52:26 +02:00
|
|
|
|
2026-08-21 14:13:57 +02:00
|
|
|
auto eclipseCaseData = sourceCase->eclipseCaseData();
|
|
|
|
|
if ( !eclipseCaseData ) return {};
|
|
|
|
|
|
2023-11-07 14:04:53 +01:00
|
|
|
auto rigCaseCellResultsData = eclipseCaseData->results( porosityModel );
|
2024-04-19 15:09:15 +02:00
|
|
|
if ( rigCaseCellResultsData->findOrLoadKnownScalarResultForTimeStep( resAddr, timeStepToUse ) == cvf::UNDEFINED_SIZE_T ) return {};
|
2023-11-07 14:04:53 +01:00
|
|
|
|
2024-01-19 08:26:31 +01:00
|
|
|
// Active cell info must always be retrieved from the destination case, as the returned vector must be of the same size as
|
|
|
|
|
// number of active cells in the destination case. Active cells can be different between source and destination case.
|
2023-11-29 09:15:04 +01:00
|
|
|
auto activeCellInfoDestination = destinationCase->eclipseCaseData()->activeCellInfo( porosityModel );
|
2024-04-19 15:09:15 +02:00
|
|
|
if ( !activeCellInfoDestination ) return {};
|
|
|
|
|
|
|
|
|
|
auto activeReservoirCells = activeCellInfoDestination->activeReservoirCellIndices();
|
|
|
|
|
if ( activeReservoirCells.empty() ) return {};
|
2022-06-03 11:52:26 +02:00
|
|
|
|
2023-11-29 09:15:04 +01:00
|
|
|
std::vector<double> values( activeCellInfoDestination->activeReservoirCellIndices().size() );
|
2022-11-24 10:44:03 +01:00
|
|
|
|
2024-01-18 14:09:07 +01:00
|
|
|
size_t gridIndex = 0;
|
|
|
|
|
auto resultAccessor =
|
|
|
|
|
RigResultAccessorFactory::createFromResultAddress( eclipseCaseData, gridIndex, porosityModel, timeStepToUse, resAddr );
|
2026-08-09 07:53:03 +02:00
|
|
|
if ( resultAccessor.isNull() ) return {};
|
2022-06-03 11:52:26 +02:00
|
|
|
|
|
|
|
|
#pragma omp parallel for
|
2023-11-29 09:15:04 +01:00
|
|
|
for ( int i = 0; i < static_cast<int>( activeReservoirCells.size() ); i++ )
|
|
|
|
|
{
|
2025-10-03 11:06:36 +02:00
|
|
|
values[i] = resultAccessor->cellScalarGlobIdx( activeReservoirCells[i].value() );
|
2022-06-03 11:52:26 +02:00
|
|
|
}
|
|
|
|
|
|
2024-03-05 12:10:02 +01:00
|
|
|
if ( m_releaseMemoryAfterDataIsExtracted )
|
|
|
|
|
{
|
|
|
|
|
auto categoriesToExclude = { RiaDefines::ResultCatType::GENERATED };
|
2024-01-18 14:09:07 +01:00
|
|
|
|
2024-03-05 12:10:02 +01:00
|
|
|
sourceCase->results( RiaDefines::PorosityModelType::MATRIX_MODEL )->freeAllocatedResultsData( categoriesToExclude, timeStepToUse );
|
|
|
|
|
sourceCase->results( RiaDefines::PorosityModelType::FRACTURE_MODEL )->freeAllocatedResultsData( categoriesToExclude, timeStepToUse );
|
|
|
|
|
}
|
2024-01-18 14:09:07 +01:00
|
|
|
|
2023-11-29 09:15:04 +01:00
|
|
|
return values;
|
2022-06-03 11:52:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2024-04-19 15:09:15 +02:00
|
|
|
void RimGridCalculation::replaceFilteredValuesWithVector( const std::vector<double>& inputValues,
|
|
|
|
|
cvf::ref<cvf::UByteArray> visibility,
|
|
|
|
|
std::vector<double>& resultValues,
|
|
|
|
|
RigActiveCellInfo* activeCellInfo )
|
2022-11-24 10:44:03 +01:00
|
|
|
|
2022-06-03 11:52:26 +02:00
|
|
|
{
|
2024-04-19 15:09:15 +02:00
|
|
|
auto activeReservoirCellIndices = activeCellInfo->activeReservoirCellIndices();
|
|
|
|
|
int numActiveCells = static_cast<int>( activeReservoirCellIndices.size() );
|
|
|
|
|
|
|
|
|
|
CAF_ASSERT( numActiveCells == (int)resultValues.size() );
|
|
|
|
|
CAF_ASSERT( numActiveCells == (int)inputValues.size() );
|
2022-11-24 10:44:03 +01:00
|
|
|
|
2022-06-03 11:52:26 +02:00
|
|
|
#pragma omp parallel for
|
2024-04-19 15:09:15 +02:00
|
|
|
for ( int i = 0; i < numActiveCells; i++ )
|
2022-06-03 11:52:26 +02:00
|
|
|
{
|
2024-04-19 15:09:15 +02:00
|
|
|
const auto reservoirCellIndex = activeReservoirCellIndices[i];
|
2025-10-03 11:06:36 +02:00
|
|
|
if ( !visibility->val( reservoirCellIndex.value() ) )
|
2022-06-03 11:52:26 +02:00
|
|
|
{
|
2024-04-19 15:09:15 +02:00
|
|
|
resultValues[i] = inputValues[i];
|
2022-06-03 11:52:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2026-07-15 11:51:50 +02:00
|
|
|
/// Replace values for non-visible cells with the given default value. Returns the number of replaced
|
|
|
|
|
/// values.
|
2022-06-03 11:52:26 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2026-07-15 11:51:50 +02:00
|
|
|
size_t RimGridCalculation::replaceFilteredValuesWithDefaultValue( double defaultValue,
|
|
|
|
|
cvf::ref<cvf::UByteArray> visibility,
|
|
|
|
|
std::vector<double>& resultValues,
|
|
|
|
|
RigActiveCellInfo* activeCellInfo )
|
2022-11-24 10:44:03 +01:00
|
|
|
|
2022-06-03 11:52:26 +02:00
|
|
|
{
|
2024-04-19 15:09:15 +02:00
|
|
|
auto activeReservoirCellIndices = activeCellInfo->activeReservoirCellIndices();
|
|
|
|
|
int numActiveCells = static_cast<int>( activeReservoirCellIndices.size() );
|
|
|
|
|
|
|
|
|
|
CAF_ASSERT( numActiveCells == (int)resultValues.size() );
|
2022-11-24 10:44:03 +01:00
|
|
|
|
2026-07-15 11:51:50 +02:00
|
|
|
size_t replacedCount = 0;
|
|
|
|
|
|
|
|
|
|
#pragma omp parallel for reduction( + : replacedCount )
|
2024-04-19 15:09:15 +02:00
|
|
|
for ( int i = 0; i < numActiveCells; i++ )
|
2022-06-03 11:52:26 +02:00
|
|
|
{
|
2024-04-19 15:09:15 +02:00
|
|
|
const auto reservoirCellIndex = activeReservoirCellIndices[i];
|
2025-10-03 11:06:36 +02:00
|
|
|
if ( !visibility->val( reservoirCellIndex.value() ) )
|
2022-06-03 11:52:26 +02:00
|
|
|
{
|
2024-04-19 15:09:15 +02:00
|
|
|
resultValues[i] = defaultValue;
|
2026-07-15 11:51:50 +02:00
|
|
|
replacedCount++;
|
2022-06-03 11:52:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-07-15 11:51:50 +02:00
|
|
|
|
|
|
|
|
return replacedCount;
|
2022-06-03 11:52:26 +02:00
|
|
|
}
|
|
|
|
|
|
2026-07-15 11:03:31 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
/// Replace undefined values (infinity and NaN) with the given default value. Returns the number of
|
|
|
|
|
/// replaced values.
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
size_t RimGridCalculation::replaceInvalidValuesWithDefaultValue( double defaultValue, std::vector<double>& values )
|
|
|
|
|
{
|
|
|
|
|
size_t replacedCount = 0;
|
|
|
|
|
|
|
|
|
|
#pragma omp parallel for reduction( + : replacedCount )
|
|
|
|
|
for ( int i = 0; i < static_cast<int>( values.size() ); i++ )
|
|
|
|
|
{
|
|
|
|
|
if ( RigStatisticsTools::isInvalidNumber( values[i] ) )
|
|
|
|
|
{
|
|
|
|
|
values[i] = defaultValue;
|
|
|
|
|
replacedCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return replacedCount;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-03 11:52:26 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2026-07-15 13:21:04 +02:00
|
|
|
void RimGridCalculation::filterResults( cvf::UByteArray* visibility,
|
2022-11-17 15:51:01 +01:00
|
|
|
const std::vector<std::vector<double>>& values,
|
2024-01-16 13:39:26 +01:00
|
|
|
size_t timeStep,
|
2022-11-17 15:51:01 +01:00
|
|
|
RimGridCalculation::DefaultValueType defaultValueType,
|
|
|
|
|
double defaultValue,
|
2022-11-24 10:44:03 +01:00
|
|
|
std::vector<double>& resultValues,
|
|
|
|
|
RiaDefines::PorosityModelType porosityModel,
|
|
|
|
|
RimEclipseCase* outputEclipseCase ) const
|
|
|
|
|
|
2022-06-03 11:52:26 +02:00
|
|
|
{
|
2024-04-19 15:09:15 +02:00
|
|
|
auto activeCellInfo = outputEclipseCase->eclipseCaseData()->activeCellInfo( porosityModel );
|
|
|
|
|
|
2022-11-17 15:51:01 +01:00
|
|
|
if ( defaultValueType == RimGridCalculation::DefaultValueType::FROM_PROPERTY )
|
2022-06-03 11:52:26 +02:00
|
|
|
{
|
2024-04-19 15:09:15 +02:00
|
|
|
auto nonVisibleValues = getActiveCellValues( m_nonVisibleResultAddress->resultName(),
|
|
|
|
|
m_nonVisibleResultAddress->resultType(),
|
|
|
|
|
timeStep,
|
|
|
|
|
porosityModel,
|
|
|
|
|
outputEclipseCase,
|
|
|
|
|
outputEclipseCase );
|
2024-01-16 13:39:26 +01:00
|
|
|
|
|
|
|
|
if ( !nonVisibleValues.empty() )
|
|
|
|
|
{
|
2024-04-19 15:09:15 +02:00
|
|
|
replaceFilteredValuesWithVector( nonVisibleValues, visibility, resultValues, activeCellInfo );
|
2024-01-16 13:39:26 +01:00
|
|
|
}
|
2022-11-17 15:51:01 +01:00
|
|
|
else
|
|
|
|
|
{
|
2024-01-16 10:21:41 +01:00
|
|
|
QString errorMessage =
|
|
|
|
|
"Grid Property Calculator: Invalid input data for default result property, no data assigned to non-visible cells.";
|
2026-05-06 12:00:10 +02:00
|
|
|
RiaLogging::error( errorMessage.toStdString() );
|
2022-11-17 15:51:01 +01:00
|
|
|
}
|
2022-06-03 11:52:26 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-11-17 15:51:01 +01:00
|
|
|
double valueToUse = defaultValue;
|
|
|
|
|
if ( defaultValueType == RimGridCalculation::DefaultValueType::POSITIVE_INFINITY ) valueToUse = HUGE_VAL;
|
|
|
|
|
|
2024-04-19 15:09:15 +02:00
|
|
|
replaceFilteredValuesWithDefaultValue( valueToUse, visibility, resultValues, activeCellInfo );
|
2022-06-03 11:52:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 12:18:34 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimGridCalculation::updateDependentObjects()
|
|
|
|
|
{
|
2023-11-07 14:04:53 +01:00
|
|
|
for ( RimEclipseCase* eclipseCase : outputEclipseCases() )
|
2022-05-02 14:25:45 +02:00
|
|
|
{
|
2023-11-07 14:04:53 +01:00
|
|
|
if ( eclipseCase )
|
|
|
|
|
{
|
|
|
|
|
RimReloadCaseTools::updateAll3dViews( eclipseCase );
|
|
|
|
|
}
|
2022-05-02 14:25:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimGridCalculation::removeDependentObjects()
|
|
|
|
|
{
|
|
|
|
|
QString leftHandSideVariableName = RimGridCalculation::findLeftHandSide( m_expression );
|
|
|
|
|
|
|
|
|
|
auto porosityModel = RiaDefines::PorosityModelType::MATRIX_MODEL;
|
|
|
|
|
|
|
|
|
|
RigEclipseResultAddress resAddr( RiaDefines::ResultCatType::GENERATED, leftHandSideVariableName );
|
|
|
|
|
|
2023-11-07 14:04:53 +01:00
|
|
|
for ( RimEclipseCase* eclipseCase : outputEclipseCases() )
|
2022-05-02 14:25:45 +02:00
|
|
|
{
|
2023-11-07 14:04:53 +01:00
|
|
|
if ( eclipseCase )
|
2022-05-02 14:25:45 +02:00
|
|
|
{
|
2023-11-07 14:04:53 +01:00
|
|
|
// Select "None" result if the result that is being removed were displayed in a view.
|
|
|
|
|
for ( auto v : eclipseCase->reservoirViews() )
|
2022-05-02 14:25:45 +02:00
|
|
|
{
|
2023-11-07 14:04:53 +01:00
|
|
|
if ( v->cellResult()->resultType() == resAddr.resultCatType() && v->cellResult()->resultVariable() == resAddr.resultName() )
|
|
|
|
|
{
|
|
|
|
|
v->cellResult()->setResultType( RiaDefines::ResultCatType::GENERATED );
|
|
|
|
|
v->cellResult()->setResultVariable( "None" );
|
|
|
|
|
}
|
2022-05-02 14:25:45 +02:00
|
|
|
}
|
|
|
|
|
|
2023-11-07 14:04:53 +01:00
|
|
|
eclipseCase->results( porosityModel )->clearScalarResult( resAddr );
|
|
|
|
|
eclipseCase->results( porosityModel )->setRemovedTagOnGeneratedResult( resAddr );
|
2022-05-02 14:25:45 +02:00
|
|
|
|
2023-11-07 14:04:53 +01:00
|
|
|
RimReloadCaseTools::updateAll3dViews( eclipseCase );
|
|
|
|
|
}
|
2022-05-02 14:25:45 +02:00
|
|
|
}
|
2022-04-22 12:18:34 +02:00
|
|
|
}
|
2022-06-03 11:52:26 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-11-10 10:38:37 +01:00
|
|
|
bool RimGridCalculation::calculateForCases( const std::vector<RimEclipseCase*>& calculationCases,
|
2023-11-27 15:26:33 +01:00
|
|
|
cvf::UByteArray* inputValueVisibilityFilter,
|
2023-12-06 09:49:40 +01:00
|
|
|
std::optional<std::vector<size_t>> timeSteps,
|
|
|
|
|
bool evaluateDependentCalculations )
|
2023-11-07 19:23:12 +01:00
|
|
|
{
|
2026-09-14 14:02:18 +02:00
|
|
|
CloseCasesOpenedForCalculation closeCasesWhenFinished( sourceAndDestinationCases( *this, calculationCases ) );
|
|
|
|
|
|
2023-11-07 19:23:12 +01:00
|
|
|
if ( calculationCases.empty() ) return true;
|
|
|
|
|
|
2023-12-06 09:49:40 +01:00
|
|
|
if ( evaluateDependentCalculations ) findAndEvaluateDependentCalculations( calculationCases, inputValueVisibilityFilter, timeSteps );
|
|
|
|
|
|
2023-11-07 19:23:12 +01:00
|
|
|
QString leftHandSideVariableName = RimGridCalculation::findLeftHandSide( m_expression );
|
|
|
|
|
|
|
|
|
|
auto [isOk, errorMessage] = validateVariables();
|
|
|
|
|
if ( !isOk )
|
|
|
|
|
{
|
2026-05-06 11:50:40 +02:00
|
|
|
RiuMessageDialog::showError( nullptr, "Grid Property Calculator", errorMessage );
|
2023-11-07 19:23:12 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-27 15:27:36 +01:00
|
|
|
const bool isMultipleCasesPresent = calculationCases.size() > 1;
|
|
|
|
|
const bool hasAggregationExpression = m_expression().contains( "sum" ) || m_expression().contains( "avg" ) ||
|
|
|
|
|
m_expression().contains( "min" ) || m_expression().contains( "max" ) ||
|
|
|
|
|
m_expression().contains( "count" );
|
2023-11-07 19:23:12 +01:00
|
|
|
|
2024-03-05 12:10:02 +01:00
|
|
|
// If multiple cases are present, release memory after data is extracted to avoid memory issues.
|
|
|
|
|
m_releaseMemoryAfterDataIsExtracted = isMultipleCasesPresent;
|
|
|
|
|
|
2023-11-07 19:23:12 +01:00
|
|
|
if ( isMultipleCasesPresent )
|
|
|
|
|
{
|
2023-11-27 15:27:36 +01:00
|
|
|
QString txt = "Starting calculation '" + description() + "' for " + QString::number( calculationCases.size() ) + " cases.";
|
2026-05-06 12:00:10 +02:00
|
|
|
RiaLogging::info( txt.toStdString() );
|
2023-11-27 15:27:36 +01:00
|
|
|
|
|
|
|
|
if ( hasAggregationExpression )
|
|
|
|
|
{
|
2026-05-06 12:00:10 +02:00
|
|
|
RiaLogging::info( std::format( " Detected aggregated value in expression '{}'.", m_expression() ) );
|
|
|
|
|
RiaLogging::info( " Aggregated value per realization is displayed in one column per time step." );
|
2023-11-27 15:27:36 +01:00
|
|
|
}
|
2023-11-07 19:23:12 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-01 14:53:24 +01:00
|
|
|
std::vector<std::vector<double>> allAggregatedValues;
|
|
|
|
|
|
2023-11-07 19:23:12 +01:00
|
|
|
bool anyErrorsDetected = false;
|
|
|
|
|
for ( RimEclipseCase* calculationCase : calculationCases )
|
|
|
|
|
{
|
|
|
|
|
if ( !calculationCase )
|
|
|
|
|
{
|
2026-05-06 11:50:40 +02:00
|
|
|
RiuMessageDialog::showError( nullptr,
|
|
|
|
|
"Grid Property Calculator",
|
|
|
|
|
QString( "No case found for calculation : %1" ).arg( leftHandSideVariableName ) );
|
2023-11-07 19:23:12 +01:00
|
|
|
anyErrorsDetected = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto porosityModel = RiaDefines::PorosityModelType::MATRIX_MODEL;
|
|
|
|
|
|
|
|
|
|
RigEclipseResultAddress resAddr( RiaDefines::ResultCatType::GENERATED, leftHandSideVariableName );
|
|
|
|
|
|
|
|
|
|
if ( !calculationCase->results( porosityModel )->ensureKnownResultLoaded( resAddr ) )
|
|
|
|
|
{
|
|
|
|
|
bool needsToBeStored = false;
|
|
|
|
|
calculationCase->results( porosityModel )->createResultEntry( resAddr, needsToBeStored );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
calculationCase->results( porosityModel )->clearScalarResult( resAddr );
|
|
|
|
|
|
|
|
|
|
// If an input grid is present, max time step count is zero. Make sure the time step count for the calculation is
|
|
|
|
|
// always 1 or more.
|
|
|
|
|
const size_t timeStepCount = std::max( size_t( 1 ), calculationCase->results( porosityModel )->maxTimeStepCount() );
|
|
|
|
|
|
2023-12-06 09:38:39 +01:00
|
|
|
if ( calculationCase == calculationCases.front() && hasAggregationExpression )
|
|
|
|
|
{
|
|
|
|
|
// Print time header
|
|
|
|
|
|
|
|
|
|
auto timeStepStrings = calculationCase->timeStepStrings();
|
|
|
|
|
|
|
|
|
|
QString timeHeader;
|
|
|
|
|
for ( size_t tsId = 0; tsId < timeStepCount; tsId++ )
|
|
|
|
|
{
|
|
|
|
|
// Skip time steps that are not in the list of time steps to calculate
|
|
|
|
|
if ( timeSteps && std::find( timeSteps->begin(), timeSteps->end(), tsId ) == timeSteps->end() ) continue;
|
|
|
|
|
|
|
|
|
|
timeHeader += "\t";
|
|
|
|
|
auto index = static_cast<int>( tsId );
|
|
|
|
|
|
|
|
|
|
if ( index < timeStepStrings.size() )
|
|
|
|
|
{
|
|
|
|
|
timeHeader += timeStepStrings.at( static_cast<int>( tsId ) );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
timeHeader += "Undefined";
|
|
|
|
|
}
|
2026-05-06 12:00:10 +02:00
|
|
|
RiaLogging::info( timeHeader.toStdString() );
|
2023-12-06 09:38:39 +01:00
|
|
|
}
|
|
|
|
|
|
2023-11-07 19:23:12 +01:00
|
|
|
std::vector<std::vector<double>>* scalarResultFrames =
|
|
|
|
|
calculationCase->results( porosityModel )->modifiableCellScalarResultTimesteps( resAddr );
|
|
|
|
|
scalarResultFrames->resize( timeStepCount );
|
|
|
|
|
|
2023-12-01 14:53:24 +01:00
|
|
|
std::vector<double> aggregatedValuesOneTimeStep;
|
2026-07-15 11:03:31 +02:00
|
|
|
std::vector<size_t> invalidValueCountPerVariable( m_variables.size(), 0 );
|
2023-11-27 15:27:36 +01:00
|
|
|
|
2023-11-07 19:23:12 +01:00
|
|
|
for ( size_t tsId = 0; tsId < timeStepCount; tsId++ )
|
|
|
|
|
{
|
|
|
|
|
// Skip time steps that are not in the list of time steps to calculate
|
|
|
|
|
if ( timeSteps && std::find( timeSteps->begin(), timeSteps->end(), tsId ) == timeSteps->end() ) continue;
|
|
|
|
|
|
2026-07-15 15:10:19 +02:00
|
|
|
// A data filter is evaluated per calculation case and time step, using the case's own active
|
|
|
|
|
// cells and result values. The visibility filter provided by the caller is used as-is.
|
|
|
|
|
cvf::ref<cvf::UByteArray> dataFilterVisibility;
|
|
|
|
|
cvf::UByteArray* visibilityFilter = inputValueVisibilityFilter;
|
|
|
|
|
if ( m_filterType() == FilterType::DATA_FILTER && m_dataFilter() )
|
|
|
|
|
{
|
|
|
|
|
dataFilterVisibility = RimCellFilterTools::computeReservoirCellVisibility( m_dataFilter(), calculationCase, tsId );
|
|
|
|
|
visibilityFilter = dataFilterVisibility.p();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 09:15:04 +01:00
|
|
|
std::vector<std::vector<double>> dataForAllVariables;
|
2023-11-07 19:23:12 +01:00
|
|
|
for ( size_t i = 0; i < m_variables.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
RimGridCalculationVariable* v = dynamic_cast<RimGridCalculationVariable*>( m_variables[i] );
|
|
|
|
|
CAF_ASSERT( v != nullptr );
|
2023-11-27 15:26:33 +01:00
|
|
|
|
2026-09-14 14:05:25 +02:00
|
|
|
bool useDataFromSourceCase = ( v->eclipseCase() == destinationCase() ) || m_destinationEnsemble() ||
|
2024-12-16 12:44:29 +01:00
|
|
|
m_additionalCasesType == AdditionalCasesType::ENSEMBLE;
|
|
|
|
|
auto sourceCase = useDataFromSourceCase ? calculationCase : v->eclipseCase();
|
2023-11-29 09:15:04 +01:00
|
|
|
|
2024-04-19 15:09:15 +02:00
|
|
|
auto dataForVariable = getActiveCellValuesForVariable( v, tsId, porosityModel, sourceCase, calculationCase );
|
2023-12-06 09:49:40 +01:00
|
|
|
if ( dataForVariable.empty() )
|
|
|
|
|
{
|
2026-05-06 12:00:10 +02:00
|
|
|
RiaLogging::error( std::format( " No data found for variable '{}'.", v->name() ) );
|
2023-12-06 09:49:40 +01:00
|
|
|
}
|
2026-07-15 11:03:31 +02:00
|
|
|
else if ( hasAggregationExpression )
|
2023-11-27 15:26:33 +01:00
|
|
|
{
|
2026-07-15 11:51:50 +02:00
|
|
|
const double defaultValue = 0.0;
|
|
|
|
|
size_t nonVisibleCount = 0;
|
2026-07-15 15:10:19 +02:00
|
|
|
if ( visibilityFilter )
|
2026-07-15 11:03:31 +02:00
|
|
|
{
|
|
|
|
|
auto activeCellInfo = calculationCase->eclipseCaseData()->activeCellInfo( porosityModel );
|
2026-07-15 11:51:50 +02:00
|
|
|
nonVisibleCount =
|
2026-07-15 15:10:19 +02:00
|
|
|
replaceFilteredValuesWithDefaultValue( defaultValue, visibilityFilter, dataForVariable, activeCellInfo );
|
2026-07-15 11:03:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Aggregation functions include all values in the vector. Replace undefined values with the
|
|
|
|
|
// default value to avoid contaminating aggregated values like sum() with infinity. Undefined
|
|
|
|
|
// values are ignored by other statistics computations, like the histogram in the 3d view.
|
2026-07-15 11:51:50 +02:00
|
|
|
const size_t invalidCount = replaceInvalidValuesWithDefaultValue( defaultValue, dataForVariable );
|
|
|
|
|
invalidValueCountPerVariable[i] += invalidCount;
|
|
|
|
|
|
|
|
|
|
RiaLogging::debug( std::format( " Case '{}', time step {}: variable '{}': {} of {} values used in aggregation "
|
|
|
|
|
"({} non-visible and {} undefined values replaced with 0.0)",
|
|
|
|
|
calculationCase->caseUserDescription().toStdString(),
|
|
|
|
|
tsId,
|
|
|
|
|
v->name().toStdString(),
|
|
|
|
|
dataForVariable.size() - nonVisibleCount - invalidCount,
|
|
|
|
|
dataForVariable.size(),
|
|
|
|
|
nonVisibleCount,
|
|
|
|
|
invalidCount ) );
|
2023-11-27 15:26:33 +01:00
|
|
|
}
|
|
|
|
|
|
2023-11-29 09:15:04 +01:00
|
|
|
dataForAllVariables.push_back( dataForVariable );
|
2023-11-07 19:23:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExpressionParser parser;
|
|
|
|
|
for ( size_t i = 0; i < m_variables.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
RimGridCalculationVariable* v = dynamic_cast<RimGridCalculationVariable*>( m_variables[i] );
|
|
|
|
|
CAF_ASSERT( v != nullptr );
|
2023-11-29 09:15:04 +01:00
|
|
|
parser.assignVector( v->name(), dataForAllVariables[i] );
|
2023-11-07 19:23:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<double> resultValues;
|
2024-04-19 15:09:15 +02:00
|
|
|
if ( calculationCase && calculationCase->eclipseCaseData() )
|
2024-01-08 15:22:45 +01:00
|
|
|
{
|
|
|
|
|
// Find number of active cells in the destination case.
|
2024-04-19 15:09:15 +02:00
|
|
|
auto activeCellInfoDestination = calculationCase->eclipseCaseData()->activeCellInfo( porosityModel );
|
2024-01-08 15:22:45 +01:00
|
|
|
if ( activeCellInfoDestination )
|
|
|
|
|
{
|
|
|
|
|
resultValues.resize( activeCellInfoDestination->reservoirActiveCellCount() );
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-07 19:23:12 +01:00
|
|
|
parser.assignVector( leftHandSideVariableName, resultValues );
|
|
|
|
|
|
2026-02-23 11:19:16 +01:00
|
|
|
auto evaluateResult = parser.expandIfStatementsAndEvaluate( m_expression );
|
2023-11-07 19:23:12 +01:00
|
|
|
|
2026-02-23 11:19:16 +01:00
|
|
|
if ( evaluateResult )
|
2023-11-07 19:23:12 +01:00
|
|
|
{
|
2023-11-27 15:27:36 +01:00
|
|
|
if ( hasAggregationExpression )
|
|
|
|
|
{
|
|
|
|
|
auto it =
|
|
|
|
|
std::find_if( resultValues.begin(), resultValues.end(), []( double v ) { return ( !std::isnan( v ) && v != 0.0 ); } );
|
|
|
|
|
if ( it != resultValues.end() )
|
|
|
|
|
{
|
2023-12-01 14:53:24 +01:00
|
|
|
aggregatedValuesOneTimeStep.push_back( *it );
|
2023-11-27 15:27:36 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-12-01 14:53:24 +01:00
|
|
|
aggregatedValuesOneTimeStep.push_back( 0.0 );
|
2023-11-27 15:27:36 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-15 15:10:19 +02:00
|
|
|
if ( visibilityFilter && !resultValues.empty() )
|
2023-11-07 19:23:12 +01:00
|
|
|
{
|
2026-07-15 15:10:19 +02:00
|
|
|
filterResults( visibilityFilter,
|
2023-11-29 09:15:04 +01:00
|
|
|
dataForAllVariables,
|
2024-01-16 13:39:26 +01:00
|
|
|
tsId,
|
2023-11-29 09:15:04 +01:00
|
|
|
m_defaultValueType(),
|
|
|
|
|
m_defaultValue(),
|
|
|
|
|
resultValues,
|
|
|
|
|
porosityModel,
|
|
|
|
|
calculationCase );
|
2023-11-07 19:23:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scalarResultFrames->at( tsId ) = resultValues;
|
|
|
|
|
|
|
|
|
|
m_isDirty = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
QString s = "The following error message was received from the parser library : \n\n";
|
2026-02-23 11:19:16 +01:00
|
|
|
s += evaluateResult.error();
|
2023-11-07 19:23:12 +01:00
|
|
|
|
2026-05-06 11:50:40 +02:00
|
|
|
RiuMessageDialog::showError( nullptr, "Grid Property Calculator", s );
|
2023-11-07 19:23:12 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
calculationCase->updateResultAddressCollection();
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-15 11:03:31 +02:00
|
|
|
for ( size_t i = 0; i < m_variables.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
if ( invalidValueCountPerVariable[i] > 0 )
|
|
|
|
|
{
|
|
|
|
|
RiaLogging::warning( std::format( " Variable '{}': {} undefined input values were replaced with 0.0 for case '{}'. The "
|
|
|
|
|
"input result may be missing data for some cells or time steps.",
|
|
|
|
|
m_variables[i]->name().toStdString(),
|
|
|
|
|
invalidValueCountPerVariable[i],
|
|
|
|
|
calculationCase->caseUserDescription().toStdString() ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-06 09:49:40 +01:00
|
|
|
if ( hasAggregationExpression )
|
2023-11-07 19:23:12 +01:00
|
|
|
{
|
|
|
|
|
QString txt = " " + calculationCase->caseUserDescription();
|
2023-11-27 15:27:36 +01:00
|
|
|
|
2023-12-01 14:53:24 +01:00
|
|
|
for ( auto v : aggregatedValuesOneTimeStep )
|
2023-11-27 15:27:36 +01:00
|
|
|
{
|
|
|
|
|
txt += "\t" + QString::number( v );
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-01 14:53:24 +01:00
|
|
|
allAggregatedValues.push_back( aggregatedValuesOneTimeStep );
|
|
|
|
|
|
2026-05-06 12:00:10 +02:00
|
|
|
RiaLogging::info( txt.toStdString() );
|
2023-11-07 19:23:12 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( isMultipleCasesPresent )
|
|
|
|
|
{
|
2023-12-01 14:53:24 +01:00
|
|
|
auto [anyError, statisticsText] = createStatisticsText( allAggregatedValues );
|
|
|
|
|
if ( anyError )
|
|
|
|
|
{
|
|
|
|
|
anyErrorsDetected = true;
|
|
|
|
|
}
|
|
|
|
|
else if ( !statisticsText.empty() )
|
|
|
|
|
{
|
|
|
|
|
RiaLogging::info( " Statistics" );
|
|
|
|
|
for ( const auto& txt : statisticsText )
|
|
|
|
|
{
|
2026-05-06 12:00:10 +02:00
|
|
|
RiaLogging::info( txt.toStdString() );
|
2023-12-01 14:53:24 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-27 15:27:36 +01:00
|
|
|
QString txt = "Completed calculation '" + description() + "' for " + QString::number( calculationCases.size() ) + " cases.";
|
2026-05-06 12:00:10 +02:00
|
|
|
RiaLogging::info( txt.toStdString() );
|
2023-11-07 19:23:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return !anyErrorsDetected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-12-06 09:49:40 +01:00
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimGridCalculation::findAndEvaluateDependentCalculations( const std::vector<RimEclipseCase*>& calculationCases,
|
|
|
|
|
cvf::UByteArray* inputValueVisibilityFilter,
|
|
|
|
|
std::optional<std::vector<size_t>> timeSteps )
|
|
|
|
|
{
|
|
|
|
|
auto proj = RimProject::current();
|
|
|
|
|
auto calcColl = proj->gridCalculationCollection();
|
|
|
|
|
|
|
|
|
|
auto dependentCalculations = calcColl->dependentCalculations( this );
|
|
|
|
|
for ( auto dependentCalc : dependentCalculations )
|
|
|
|
|
{
|
|
|
|
|
if ( dependentCalc == this ) continue;
|
|
|
|
|
|
2024-01-19 08:26:31 +01:00
|
|
|
// Propagate the settings for this calculation to the dependent calculation. This will allow changes on top level
|
|
|
|
|
// calculation to be propagated to dependent calculations automatically. Do not trigger
|
|
|
|
|
// findAndEvaluateDependentCalculations() recursively, as all dependent calculations are traversed in this function.
|
2023-12-06 09:49:40 +01:00
|
|
|
|
|
|
|
|
bool evaluateDependentCalculations = false;
|
|
|
|
|
dependentCalc->calculateForCases( calculationCases, inputValueVisibilityFilter, timeSteps, evaluateDependentCalculations );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-11-07 19:23:12 +01:00
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-11-10 09:16:06 +01:00
|
|
|
void RimGridCalculation::assignEclipseCaseForNullPointers( RimEclipseCase* eclipseCase )
|
|
|
|
|
{
|
2026-09-14 14:05:25 +02:00
|
|
|
if ( destinationCase() == nullptr )
|
2023-11-10 09:16:06 +01:00
|
|
|
{
|
|
|
|
|
m_destinationCase = eclipseCase;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for ( auto v : m_variables )
|
|
|
|
|
{
|
|
|
|
|
if ( auto gridVar = dynamic_cast<RimGridCalculationVariable*>( v.p() ) )
|
|
|
|
|
{
|
|
|
|
|
if ( gridVar->eclipseCase() == nullptr )
|
|
|
|
|
{
|
|
|
|
|
gridVar->setEclipseCase( eclipseCase );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2022-06-03 11:52:26 +02:00
|
|
|
std::pair<bool, QString> RimGridCalculation::validateVariables()
|
|
|
|
|
{
|
|
|
|
|
auto porosityModel = RiaDefines::PorosityModelType::MATRIX_MODEL;
|
|
|
|
|
|
|
|
|
|
for ( size_t i = 0; i < m_variables.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
RimGridCalculationVariable* v = dynamic_cast<RimGridCalculationVariable*>( m_variables[i] );
|
|
|
|
|
CAF_ASSERT( v != nullptr );
|
|
|
|
|
|
|
|
|
|
if ( !v->eclipseCase() )
|
|
|
|
|
{
|
|
|
|
|
QString errorMessage = QString( "No case defined for variable : %1" ).arg( v->name() );
|
|
|
|
|
return std::make_pair( false, errorMessage );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( v->resultVariable().isEmpty() )
|
|
|
|
|
{
|
|
|
|
|
QString errorMessage = QString( "No result variable defined for variable : %1" ).arg( v->name() );
|
|
|
|
|
return std::make_pair( false, errorMessage );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto resultCategoryType = v->resultCategoryType();
|
|
|
|
|
RigEclipseResultAddress resAddr( resultCategoryType, v->resultVariable() );
|
|
|
|
|
if ( !v->eclipseCase()->results( porosityModel )->ensureKnownResultLoaded( resAddr ) )
|
|
|
|
|
{
|
|
|
|
|
QString errorMessage = QString( "Unable to load result for variable : %1" ).arg( v->name() );
|
|
|
|
|
return std::make_pair( false, errorMessage );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return std::make_pair( true, "" );
|
|
|
|
|
}
|
2022-06-10 11:55:41 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-02-26 10:48:40 +01:00
|
|
|
void RimGridCalculation::onChildrenUpdated( caf::PdmChildArrayFieldHandle* childArray, std::vector<caf::PdmObjectHandle*>& updatedObjects )
|
2022-06-10 11:55:41 +02:00
|
|
|
{
|
|
|
|
|
if ( childArray == &m_variables )
|
|
|
|
|
{
|
|
|
|
|
// Update the editors of all the variables if a variable changes.
|
|
|
|
|
// This makes the read-only state of the filter parameters consistent:
|
|
|
|
|
// only one filter is allowed at a time.
|
|
|
|
|
for ( auto v : m_variables )
|
|
|
|
|
{
|
|
|
|
|
v->updateConnectedEditors();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-01 14:53:24 +01:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::pair<bool, QStringList> RimGridCalculation::createStatisticsText( const std::vector<std::vector<double>>& values )
|
|
|
|
|
{
|
|
|
|
|
bool anyErrorsDetected = false;
|
|
|
|
|
QStringList statisticsText;
|
|
|
|
|
|
|
|
|
|
if ( values.empty() ) return { anyErrorsDetected, statisticsText };
|
|
|
|
|
|
|
|
|
|
size_t size = values.front().size();
|
|
|
|
|
for ( const auto& aggregatedVector : values )
|
|
|
|
|
{
|
|
|
|
|
if ( aggregatedVector.size() != size )
|
|
|
|
|
{
|
|
|
|
|
QString msg = "Detected mismatch in number of time steps for aggregated values. All grid "
|
|
|
|
|
"cases must have identical number of time steps.";
|
2026-05-06 12:00:10 +02:00
|
|
|
RiaLogging::error( msg.toStdString() );
|
2023-12-01 14:53:24 +01:00
|
|
|
anyErrorsDetected = true;
|
|
|
|
|
return { anyErrorsDetected, statisticsText };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<double> minValues;
|
|
|
|
|
std::vector<double> p90Values;
|
|
|
|
|
std::vector<double> p50Values;
|
|
|
|
|
std::vector<double> avgValues;
|
|
|
|
|
std::vector<double> p10Values;
|
|
|
|
|
std::vector<double> maxValues;
|
|
|
|
|
|
|
|
|
|
for ( size_t timeIdx = 0; timeIdx < values.front().size(); timeIdx++ )
|
|
|
|
|
{
|
|
|
|
|
std::vector<double> valuesForTimeStep;
|
|
|
|
|
|
|
|
|
|
for ( auto v : values )
|
|
|
|
|
{
|
|
|
|
|
valuesForTimeStep.push_back( v[timeIdx] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Required to have minimum 8 values to calculate statistics
|
|
|
|
|
if ( valuesForTimeStep.size() < 8 ) continue;
|
|
|
|
|
|
|
|
|
|
double p90 = std::numeric_limits<double>::infinity();
|
|
|
|
|
double p50 = std::numeric_limits<double>::infinity();
|
|
|
|
|
double avg = std::numeric_limits<double>::infinity();
|
|
|
|
|
double p10 = std::numeric_limits<double>::infinity();
|
|
|
|
|
|
|
|
|
|
auto [min, max] = std::minmax_element( valuesForTimeStep.begin(), valuesForTimeStep.end() );
|
|
|
|
|
|
|
|
|
|
RigStatisticsMath::calculateStatisticsCurves( valuesForTimeStep, &p10, &p50, &p90, &avg, RigStatisticsMath::PercentileStyle::SWITCHED );
|
|
|
|
|
|
|
|
|
|
minValues.push_back( *min );
|
|
|
|
|
p90Values.push_back( p90 );
|
|
|
|
|
p50Values.push_back( p50 );
|
|
|
|
|
avgValues.push_back( avg );
|
|
|
|
|
p10Values.push_back( p10 );
|
|
|
|
|
maxValues.push_back( *max );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !minValues.empty() )
|
|
|
|
|
{
|
|
|
|
|
QString minTxt = " Minimum";
|
|
|
|
|
QString p90Txt = " P90 ";
|
|
|
|
|
QString p50Txt = " P50 ";
|
|
|
|
|
QString avgTxt = " Mean ";
|
|
|
|
|
QString p10Txt = " P10 ";
|
|
|
|
|
QString maxTxt = " Maximum";
|
|
|
|
|
|
|
|
|
|
for ( size_t timeIdx = 0; timeIdx < p10Values.size(); timeIdx++ )
|
|
|
|
|
{
|
|
|
|
|
minTxt += "\t" + QString::number( minValues[timeIdx] );
|
|
|
|
|
p90Txt += "\t" + QString::number( p90Values[timeIdx] );
|
|
|
|
|
p50Txt += "\t" + QString::number( p50Values[timeIdx] );
|
|
|
|
|
avgTxt += "\t" + QString::number( avgValues[timeIdx] );
|
|
|
|
|
p10Txt += "\t" + QString::number( p10Values[timeIdx] );
|
|
|
|
|
maxTxt += "\t" + QString::number( maxValues[timeIdx] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
statisticsText.push_back( minTxt );
|
|
|
|
|
statisticsText.push_back( p90Txt );
|
|
|
|
|
statisticsText.push_back( p50Txt );
|
|
|
|
|
statisticsText.push_back( avgTxt );
|
|
|
|
|
statisticsText.push_back( p10Txt );
|
|
|
|
|
statisticsText.push_back( maxTxt );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { anyErrorsDetected, statisticsText };
|
|
|
|
|
}
|