2024-10-23 15:10:03 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2024- 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 "RimStatisticsContourMap.h"
|
|
|
|
|
|
|
|
|
|
#include "RiaLogging.h"
|
2025-01-14 21:52:54 +01:00
|
|
|
#include "RiaPreferencesGrid.h"
|
2024-11-06 14:25:25 +01:00
|
|
|
#include "RiaStatisticsTools.h"
|
2024-10-23 15:10:03 +02:00
|
|
|
|
2025-01-14 21:52:54 +01:00
|
|
|
#include "RicNewStatisticsContourMapViewFeature.h"
|
|
|
|
|
|
|
|
|
|
#include "RifReaderSettings.h"
|
|
|
|
|
|
2024-10-23 15:10:03 +02:00
|
|
|
#include "RigCaseCellResultsData.h"
|
2024-11-13 14:06:23 +01:00
|
|
|
#include "RigContourMapCalculator.h"
|
2024-11-06 14:25:25 +01:00
|
|
|
#include "RigContourMapGrid.h"
|
2024-10-23 15:10:03 +02:00
|
|
|
#include "RigEclipseCaseData.h"
|
2024-11-06 14:25:25 +01:00
|
|
|
#include "RigEclipseContourMapProjection.h"
|
|
|
|
|
#include "RigEclipseResultAddress.h"
|
|
|
|
|
#include "RigMainGrid.h"
|
|
|
|
|
#include "RigStatisticsMath.h"
|
2024-10-23 15:10:03 +02:00
|
|
|
|
2024-11-06 14:25:25 +01:00
|
|
|
#include "RimEclipseCase.h"
|
|
|
|
|
#include "RimEclipseCaseEnsemble.h"
|
|
|
|
|
#include "RimEclipseContourMapProjection.h"
|
2024-10-23 15:10:03 +02:00
|
|
|
#include "RimEclipseResultDefinition.h"
|
2024-11-06 14:25:25 +01:00
|
|
|
#include "RimProject.h"
|
2025-01-14 21:52:54 +01:00
|
|
|
#include "RimSimWellInViewCollection.h"
|
|
|
|
|
#include "RimStatisticsContourMapProjection.h"
|
|
|
|
|
#include "RimStatisticsContourMapView.h"
|
2024-11-13 11:21:35 +01:00
|
|
|
#include "RimTools.h"
|
2024-10-23 15:10:03 +02:00
|
|
|
|
2025-01-14 21:52:54 +01:00
|
|
|
#include "Riu3DMainWindowTools.h"
|
|
|
|
|
|
2024-11-13 14:06:23 +01:00
|
|
|
#include "cafCmdFeatureMenuBuilder.h"
|
2024-11-13 10:02:54 +01:00
|
|
|
#include "cafPdmUiDoubleSliderEditor.h"
|
2024-10-23 15:10:03 +02:00
|
|
|
#include "cafPdmUiPushButtonEditor.h"
|
2025-01-14 21:52:54 +01:00
|
|
|
#include "cafPdmUiTreeSelectionEditor.h"
|
2024-10-23 15:10:03 +02:00
|
|
|
#include "cafProgressInfo.h"
|
|
|
|
|
|
2024-11-06 14:25:25 +01:00
|
|
|
#include <limits>
|
|
|
|
|
|
2024-10-23 15:10:03 +02:00
|
|
|
CAF_PDM_SOURCE_INIT( RimStatisticsContourMap, "RimStatisticalContourMap" );
|
|
|
|
|
|
2024-11-13 14:06:23 +01:00
|
|
|
namespace caf
|
|
|
|
|
{
|
|
|
|
|
template <>
|
|
|
|
|
void caf::AppEnum<RimStatisticsContourMap::StatisticsType>::setUp()
|
|
|
|
|
{
|
|
|
|
|
addItem( RimStatisticsContourMap::StatisticsType::P10, "P10", "P10" );
|
|
|
|
|
addItem( RimStatisticsContourMap::StatisticsType::P50, "P50", "P50" );
|
|
|
|
|
addItem( RimStatisticsContourMap::StatisticsType::P90, "P90", "P90" );
|
|
|
|
|
addItem( RimStatisticsContourMap::StatisticsType::MEAN, "MEAN", "Mean" );
|
|
|
|
|
addItem( RimStatisticsContourMap::StatisticsType::MIN, "MIN", "Minimum" );
|
|
|
|
|
addItem( RimStatisticsContourMap::StatisticsType::MAX, "MAX", "Maximum" );
|
|
|
|
|
setDefault( RimStatisticsContourMap::StatisticsType::MEAN );
|
|
|
|
|
}
|
|
|
|
|
}; // namespace caf
|
|
|
|
|
|
2024-10-23 15:10:03 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimStatisticsContourMap::RimStatisticsContourMap()
|
|
|
|
|
{
|
2025-01-14 21:52:54 +01:00
|
|
|
CAF_PDM_InitObject( "Statistics Contour Map", ":/Histogram16x16.png" );
|
2024-10-23 15:10:03 +02:00
|
|
|
|
2025-01-15 20:44:20 +01:00
|
|
|
CAF_PDM_InitField( &m_boundingBoxExpPercent,
|
|
|
|
|
"BoundingBoxExpPercent",
|
|
|
|
|
5.0,
|
|
|
|
|
"Bounding Box Expansion (%)",
|
|
|
|
|
"",
|
|
|
|
|
"How much to increase the bounding box of the primary case to cover for any grid size differences across the "
|
|
|
|
|
"ensemble." );
|
2025-01-14 21:52:54 +01:00
|
|
|
m_boundingBoxExpPercent.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleSliderEditor::uiEditorTypeName() );
|
|
|
|
|
|
2025-01-15 20:44:20 +01:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_resolution, "Resolution", "Sampling Resolution" );
|
2024-11-13 10:02:54 +01:00
|
|
|
|
2024-11-13 11:21:35 +01:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_resultAggregation, "ResultAggregation", "Result Aggregation" );
|
|
|
|
|
|
2025-01-14 21:52:54 +01:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_selectedTimeSteps, "SelectedTimeSteps", "Time Step Selection" );
|
|
|
|
|
m_selectedTimeSteps.uiCapability()->setUiEditorTypeName( caf::PdmUiTreeSelectionEditor::uiEditorTypeName() );
|
2024-11-13 11:21:35 +01:00
|
|
|
|
2024-10-23 15:10:03 +02:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_resultDefinition, "ResultDefinition", "" );
|
|
|
|
|
m_resultDefinition.uiCapability()->setUiTreeChildrenHidden( true );
|
|
|
|
|
m_resultDefinition = new RimEclipseResultDefinition;
|
|
|
|
|
m_resultDefinition->findField( "MResultType" )->uiCapability()->setUiName( "Result" );
|
|
|
|
|
m_resultDefinition->setResultType( RiaDefines::ResultCatType::DYNAMIC_NATIVE );
|
|
|
|
|
m_resultDefinition->setResultVariable( "SOIL" );
|
|
|
|
|
|
2025-01-14 21:52:54 +01:00
|
|
|
CAF_PDM_InitField( &m_primaryCase,
|
|
|
|
|
"PrimaryCase",
|
|
|
|
|
RiaResultNames::undefinedResultName(),
|
|
|
|
|
"Primary Case",
|
|
|
|
|
"",
|
|
|
|
|
"Eclipse Case used for wells and faults shown in views, initializing available result list, timesteps, etc." );
|
|
|
|
|
|
2024-10-23 15:10:03 +02:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_computeStatisticsButton, "ComputeStatisticsButton", "" );
|
|
|
|
|
caf::PdmUiPushButtonEditor::configureEditorLabelLeft( &m_computeStatisticsButton );
|
|
|
|
|
m_computeStatisticsButton = false;
|
2025-01-14 21:52:54 +01:00
|
|
|
|
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_views, "ContourMapViews", "Contour Maps", ":/CrossSection16x16.png" );
|
|
|
|
|
|
|
|
|
|
setDeletable( true );
|
2024-10-23 15:10:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimStatisticsContourMap::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
|
|
|
|
{
|
2025-01-14 21:52:54 +01:00
|
|
|
if ( ( eclipseCase() == nullptr ) && ( ensemble()->cases().size() > 0 ) )
|
|
|
|
|
{
|
|
|
|
|
auto selCase = ensemble()->cases().front();
|
|
|
|
|
setEclipseCase( selCase );
|
|
|
|
|
m_primaryCase = selCase->caseUserDescription();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uiOrdering.add( nameField() );
|
|
|
|
|
|
|
|
|
|
auto genGrp = uiOrdering.addNewGroup( "General" );
|
|
|
|
|
|
|
|
|
|
genGrp->add( &m_resultAggregation );
|
2025-01-15 20:44:20 +01:00
|
|
|
genGrp->add( &m_resolution );
|
2025-01-14 21:52:54 +01:00
|
|
|
genGrp->add( &m_primaryCase );
|
|
|
|
|
genGrp->add( &m_boundingBoxExpPercent );
|
2024-11-13 10:02:54 +01:00
|
|
|
|
2025-01-14 21:52:54 +01:00
|
|
|
auto tsGroup = uiOrdering.addNewGroup( "Time Step Selection" );
|
|
|
|
|
tsGroup->setCollapsedByDefault();
|
|
|
|
|
tsGroup->add( &m_selectedTimeSteps );
|
|
|
|
|
|
|
|
|
|
if ( !isColumnResult() )
|
|
|
|
|
{
|
|
|
|
|
auto resultDefinitionGroup = uiOrdering.addNewGroup( "Result Definition" );
|
|
|
|
|
m_resultDefinition->uiOrdering( uiConfigName, *resultDefinitionGroup );
|
|
|
|
|
}
|
2024-10-23 15:10:03 +02:00
|
|
|
|
|
|
|
|
uiOrdering.add( &m_computeStatisticsButton );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimStatisticsContourMap::setEclipseCase( RimEclipseCase* eclipseCase )
|
|
|
|
|
{
|
|
|
|
|
m_resultDefinition->setEclipseCase( eclipseCase );
|
2025-01-14 21:52:54 +01:00
|
|
|
if ( eclipseCase ) m_primaryCase = eclipseCase->caseUserDescription();
|
|
|
|
|
|
|
|
|
|
for ( auto& view : m_views )
|
|
|
|
|
{
|
|
|
|
|
view->setEclipseCase( eclipseCase );
|
|
|
|
|
}
|
|
|
|
|
m_resultDefinition->updateConnectedEditors();
|
2024-10-23 15:10:03 +02:00
|
|
|
}
|
|
|
|
|
|
2024-11-13 14:06:23 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimEclipseCaseEnsemble* RimStatisticsContourMap::ensemble() const
|
|
|
|
|
{
|
|
|
|
|
return firstAncestorOrThisOfType<RimEclipseCaseEnsemble>();
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-23 15:10:03 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimStatisticsContourMap::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
|
|
|
|
|
{
|
|
|
|
|
if ( &m_computeStatisticsButton == changedField )
|
|
|
|
|
{
|
|
|
|
|
computeStatistics();
|
|
|
|
|
m_computeStatisticsButton = false;
|
2025-01-14 21:52:54 +01:00
|
|
|
|
|
|
|
|
if ( m_views.empty() )
|
|
|
|
|
{
|
|
|
|
|
auto view = RicNewStatisticsContourMapViewFeature::createAndAddView( this );
|
|
|
|
|
updateConnectedEditors();
|
|
|
|
|
Riu3DMainWindowTools::selectAsCurrentItem( view );
|
|
|
|
|
Riu3DMainWindowTools::setExpanded( this );
|
|
|
|
|
Riu3DMainWindowTools::setExpanded( view );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for ( auto& view : m_views )
|
|
|
|
|
{
|
|
|
|
|
auto proj = dynamic_cast<RimStatisticsContourMapProjection*>( view->contourMapProjection() );
|
|
|
|
|
if ( proj != nullptr )
|
|
|
|
|
proj->clearGridMappingAndRedraw();
|
|
|
|
|
else
|
|
|
|
|
view->scheduleCreateDisplayModelAndRedraw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ( &m_primaryCase == changedField )
|
|
|
|
|
{
|
|
|
|
|
switchToSelectedSourceCase();
|
|
|
|
|
|
|
|
|
|
// Update views
|
|
|
|
|
for ( auto& view : m_views )
|
|
|
|
|
{
|
|
|
|
|
view->wellCollection()->wells.deleteChildren();
|
|
|
|
|
view->updateDisplayModelForWellResults();
|
|
|
|
|
view->wellCollection()->updateConnectedEditors();
|
|
|
|
|
}
|
2024-10-23 15:10:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 21:52:54 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimEclipseCase* RimStatisticsContourMap::switchToSelectedSourceCase()
|
|
|
|
|
{
|
|
|
|
|
RimEclipseCase* sourceResultCase = ensemble()->findByDescription( m_primaryCase );
|
|
|
|
|
if ( sourceResultCase == nullptr )
|
|
|
|
|
{
|
|
|
|
|
setEclipseCase( nullptr );
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( sourceResultCase != eclipseCase() )
|
|
|
|
|
{
|
|
|
|
|
auto oldCase = eclipseCase();
|
|
|
|
|
sourceResultCase->ensureReservoirCaseIsOpen();
|
|
|
|
|
setEclipseCase( sourceResultCase );
|
|
|
|
|
|
|
|
|
|
if ( oldCase && !ensemble()->casesInViews().contains( oldCase ) )
|
|
|
|
|
{
|
|
|
|
|
oldCase->closeReservoirCase();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sourceResultCase;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 11:21:35 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
QList<caf::PdmOptionItemInfo> RimStatisticsContourMap::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions )
|
|
|
|
|
{
|
|
|
|
|
QList<caf::PdmOptionItemInfo> options;
|
|
|
|
|
|
2025-01-14 21:52:54 +01:00
|
|
|
if ( &m_selectedTimeSteps == fieldNeedingOptions )
|
|
|
|
|
{
|
|
|
|
|
if ( auto eCase = eclipseCase() )
|
|
|
|
|
{
|
|
|
|
|
const auto timeStepStrings = eCase->timeStepStrings();
|
|
|
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
for ( const auto& text : timeStepStrings )
|
|
|
|
|
{
|
|
|
|
|
options.push_back( caf::PdmOptionItemInfo( text, index++ ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return options;
|
|
|
|
|
}
|
|
|
|
|
else if ( &m_primaryCase == fieldNeedingOptions )
|
2024-11-13 11:21:35 +01:00
|
|
|
{
|
2025-01-14 21:52:54 +01:00
|
|
|
QStringList sourceCaseNames;
|
|
|
|
|
sourceCaseNames += RiaResultNames::undefinedResultName();
|
|
|
|
|
|
|
|
|
|
for ( auto eCase : ensemble()->cases() )
|
2024-11-13 11:21:35 +01:00
|
|
|
{
|
2025-01-14 21:52:54 +01:00
|
|
|
options.push_back( caf::PdmOptionItemInfo( eCase->caseUserDescription(), eCase->caseUserDescription() ) );
|
2024-11-13 11:21:35 +01:00
|
|
|
}
|
2025-01-14 21:52:54 +01:00
|
|
|
return options;
|
2024-11-13 11:21:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return options;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-23 15:10:03 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimStatisticsContourMap::defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute )
|
|
|
|
|
{
|
|
|
|
|
if ( &m_computeStatisticsButton == field )
|
|
|
|
|
{
|
|
|
|
|
if ( auto attrib = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*>( attribute ) )
|
|
|
|
|
{
|
|
|
|
|
attrib->m_buttonText = "Compute";
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-14 21:52:54 +01:00
|
|
|
else if ( &m_boundingBoxExpPercent == field )
|
|
|
|
|
{
|
|
|
|
|
if ( auto myAttr = dynamic_cast<caf::PdmUiDoubleSliderEditorAttribute*>( attribute ) )
|
|
|
|
|
{
|
|
|
|
|
myAttr->m_minimum = 0.0;
|
|
|
|
|
myAttr->m_maximum = 25.0;
|
2024-11-13 10:02:54 +01:00
|
|
|
myAttr->m_delaySliderUpdateUntilRelease = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-23 15:10:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimStatisticsContourMap::initAfterRead()
|
|
|
|
|
{
|
|
|
|
|
auto ensemble = firstAncestorOrThisOfType<RimEclipseCaseEnsemble>();
|
|
|
|
|
if ( !ensemble ) return;
|
|
|
|
|
|
2025-01-14 21:52:54 +01:00
|
|
|
switchToSelectedSourceCase();
|
2024-10-23 15:10:03 +02:00
|
|
|
|
2025-01-14 21:52:54 +01:00
|
|
|
for ( auto view : m_views )
|
|
|
|
|
{
|
|
|
|
|
view->loadDataAndUpdate();
|
|
|
|
|
}
|
2024-10-23 15:10:03 +02:00
|
|
|
}
|
2024-12-16 15:36:53 +01:00
|
|
|
|
2024-10-23 15:10:03 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2025-01-14 21:52:54 +01:00
|
|
|
void RimStatisticsContourMap::doStatisticsCalculation( std::map<size_t, std::vector<std::vector<double>>>& timestepResults )
|
2024-10-23 15:10:03 +02:00
|
|
|
{
|
2025-01-14 21:52:54 +01:00
|
|
|
m_timeResults.clear();
|
2024-11-06 14:25:25 +01:00
|
|
|
|
2025-01-14 21:52:54 +01:00
|
|
|
for ( const auto& [timeStep, res] : timestepResults )
|
2024-11-06 14:25:25 +01:00
|
|
|
{
|
2025-01-14 21:52:54 +01:00
|
|
|
if ( res.empty() ) continue;
|
2024-11-06 14:25:25 +01:00
|
|
|
|
2025-01-14 21:52:54 +01:00
|
|
|
int nCells = static_cast<int>( res[0].size() );
|
2024-11-06 14:25:25 +01:00
|
|
|
std::vector<double> p10Results( nCells, std::numeric_limits<double>::infinity() );
|
|
|
|
|
std::vector<double> p50Results( nCells, std::numeric_limits<double>::infinity() );
|
|
|
|
|
std::vector<double> p90Results( nCells, std::numeric_limits<double>::infinity() );
|
|
|
|
|
std::vector<double> meanResults( nCells, std::numeric_limits<double>::infinity() );
|
|
|
|
|
std::vector<double> minResults( nCells, std::numeric_limits<double>::infinity() );
|
|
|
|
|
std::vector<double> maxResults( nCells, std::numeric_limits<double>::infinity() );
|
|
|
|
|
|
2025-01-14 21:52:54 +01:00
|
|
|
const size_t numSamples = res.size();
|
|
|
|
|
|
|
|
|
|
// Clang version 16.0.6 does not handle OpenMP here, the compiler crashes.
|
|
|
|
|
#ifndef __clang__
|
2024-11-06 14:25:25 +01:00
|
|
|
#pragma omp parallel for
|
2025-01-14 21:52:54 +01:00
|
|
|
#endif
|
2024-11-06 14:25:25 +01:00
|
|
|
for ( int i = 0; i < nCells; i++ )
|
|
|
|
|
{
|
|
|
|
|
std::vector<double> samples( numSamples, 0.0 );
|
|
|
|
|
for ( size_t s = 0; s < numSamples; s++ )
|
2025-01-14 21:52:54 +01:00
|
|
|
{
|
|
|
|
|
samples[s] = res[s][i];
|
|
|
|
|
}
|
2024-11-06 14:25:25 +01:00
|
|
|
|
2024-11-13 14:06:23 +01:00
|
|
|
double p10 = std::numeric_limits<double>::infinity();
|
|
|
|
|
double p50 = std::numeric_limits<double>::infinity();
|
|
|
|
|
double p90 = std::numeric_limits<double>::infinity();
|
|
|
|
|
double mean = std::numeric_limits<double>::infinity();
|
2024-11-06 14:25:25 +01:00
|
|
|
|
|
|
|
|
RigStatisticsMath::calculateStatisticsCurves( samples, &p10, &p50, &p90, &mean, RigStatisticsMath::PercentileStyle::SWITCHED );
|
|
|
|
|
|
2024-11-13 14:06:23 +01:00
|
|
|
if ( RiaStatisticsTools::isValidNumber( p10 ) ) p10Results[i] = p10;
|
|
|
|
|
if ( RiaStatisticsTools::isValidNumber( p50 ) ) p50Results[i] = p50;
|
|
|
|
|
if ( RiaStatisticsTools::isValidNumber( p90 ) ) p90Results[i] = p90;
|
|
|
|
|
if ( RiaStatisticsTools::isValidNumber( mean ) ) meanResults[i] = mean;
|
2024-11-06 14:25:25 +01:00
|
|
|
|
2024-11-13 14:06:23 +01:00
|
|
|
double minValue = RiaStatisticsTools::minimumValue( samples );
|
|
|
|
|
if ( RiaStatisticsTools::isValidNumber( minValue ) && minValue < std::numeric_limits<double>::max() ) minResults[i] = minValue;
|
|
|
|
|
|
|
|
|
|
double maxValue = RiaStatisticsTools::maximumValue( samples );
|
|
|
|
|
if ( RiaStatisticsTools::isValidNumber( maxValue ) && maxValue > -std::numeric_limits<double>::max() ) maxResults[i] = maxValue;
|
2024-11-06 14:25:25 +01:00
|
|
|
}
|
2024-11-13 14:06:23 +01:00
|
|
|
|
2025-01-14 21:52:54 +01:00
|
|
|
m_timeResults[timeStep][StatisticsType::P10] = p10Results;
|
|
|
|
|
m_timeResults[timeStep][StatisticsType::P50] = p50Results;
|
|
|
|
|
m_timeResults[timeStep][StatisticsType::P90] = p90Results;
|
|
|
|
|
m_timeResults[timeStep][StatisticsType::MEAN] = meanResults;
|
|
|
|
|
m_timeResults[timeStep][StatisticsType::MIN] = minResults;
|
|
|
|
|
m_timeResults[timeStep][StatisticsType::MAX] = maxResults;
|
2024-11-06 14:25:25 +01:00
|
|
|
}
|
2024-10-23 15:10:03 +02:00
|
|
|
}
|
2024-11-13 14:06:23 +01:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2025-01-14 21:52:54 +01:00
|
|
|
void RimStatisticsContourMap::computeStatistics()
|
2024-11-13 14:06:23 +01:00
|
|
|
{
|
2025-01-14 21:52:54 +01:00
|
|
|
RiaLogging::info( "Computing statistics" );
|
2024-11-13 14:06:23 +01:00
|
|
|
auto ensemble = firstAncestorOrThisOfType<RimEclipseCaseEnsemble>();
|
2025-01-14 21:52:54 +01:00
|
|
|
if ( !ensemble ) return;
|
|
|
|
|
|
|
|
|
|
if ( ensemble->cases().empty() ) return;
|
|
|
|
|
if ( eclipseCase() == nullptr ) return;
|
|
|
|
|
|
|
|
|
|
RigContourMapCalculator::ResultAggregationType resultAggregation = m_resultAggregation();
|
|
|
|
|
|
|
|
|
|
cvf::BoundingBox gridBoundingBox = eclipseCase()->activeCellsBoundingBox();
|
|
|
|
|
gridBoundingBox.expandPercent( m_boundingBoxExpPercent() );
|
|
|
|
|
|
|
|
|
|
double sampleSpacing = 1.0;
|
|
|
|
|
if ( auto mainGrid = eclipseCase()->mainGrid() )
|
|
|
|
|
{
|
2025-01-15 20:44:20 +01:00
|
|
|
sampleSpacing = sampleSpacingFactor() * mainGrid->characteristicIJCellSize();
|
2025-01-14 21:52:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto contourMapGrid = std::make_unique<RigContourMapGrid>( gridBoundingBox, sampleSpacing );
|
2024-11-13 14:06:23 +01:00
|
|
|
|
2025-01-14 21:52:54 +01:00
|
|
|
auto firstEclipseCaseData = eclipseCase()->eclipseCaseData();
|
|
|
|
|
auto firstResultData = firstEclipseCaseData->results( RiaDefines::PorosityModelType::MATRIX_MODEL );
|
|
|
|
|
|
|
|
|
|
RigEclipseContourMapProjection contourMapProjection( *contourMapGrid, *firstEclipseCaseData, *firstResultData );
|
|
|
|
|
m_gridMapping = contourMapProjection.generateGridMapping( resultAggregation, {} );
|
|
|
|
|
|
|
|
|
|
const size_t nCases = ensemble->cases().size();
|
|
|
|
|
|
|
|
|
|
std::map<size_t, std::vector<std::vector<double>>> timestep_results;
|
|
|
|
|
|
|
|
|
|
caf::ProgressInfo progInfo( nCases, QString( "Reading Eclipse Ensemble" ) );
|
|
|
|
|
|
|
|
|
|
auto readerSettings = RiaPreferencesGrid::current()->gridOnlyReaderSettings();
|
|
|
|
|
auto casesInViews = ensemble->casesInViews();
|
|
|
|
|
|
|
|
|
|
int i = 1;
|
|
|
|
|
for ( RimEclipseCase* eCase : ensemble->cases() )
|
|
|
|
|
{
|
|
|
|
|
auto task = progInfo.task( QString( "Processing Case %1 of %2" ).arg( i++ ).arg( nCases ) );
|
|
|
|
|
|
|
|
|
|
RifReaderSettings oldSettings = eCase->readerSettings();
|
|
|
|
|
eCase->setReaderSettings( readerSettings );
|
|
|
|
|
|
|
|
|
|
if ( eCase->ensureReservoirCaseIsOpen() )
|
|
|
|
|
{
|
|
|
|
|
RiaLogging::info( QString( "Grid: %1" ).arg( eCase->caseUserDescription() ) );
|
|
|
|
|
|
|
|
|
|
auto eclipseCaseData = eCase->eclipseCaseData();
|
|
|
|
|
auto resultData = eclipseCaseData->results( RiaDefines::PorosityModelType::MATRIX_MODEL );
|
|
|
|
|
|
|
|
|
|
RigEclipseContourMapProjection contourMapProjection( *contourMapGrid, *eclipseCaseData, *resultData );
|
|
|
|
|
contourMapProjection.generateGridMapping( resultAggregation, {} );
|
|
|
|
|
|
|
|
|
|
if ( m_resultDefinition()->hasDynamicResult() )
|
|
|
|
|
{
|
|
|
|
|
for ( auto ts : selectedTimeSteps() )
|
|
|
|
|
{
|
|
|
|
|
std::vector<double> result =
|
|
|
|
|
contourMapProjection.generateResults( m_resultDefinition()->eclipseResultAddress(), resultAggregation, ts );
|
|
|
|
|
timestep_results[ts].push_back( result );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::vector<double> result =
|
|
|
|
|
contourMapProjection.generateResults( m_resultDefinition()->eclipseResultAddress(), resultAggregation, 0 );
|
|
|
|
|
timestep_results[0].push_back( result );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
eCase->setReaderSettings( oldSettings );
|
|
|
|
|
|
|
|
|
|
if ( eCase->views().empty() && eCase != eclipseCase() && !casesInViews.contains( eCase ) )
|
|
|
|
|
{
|
|
|
|
|
eCase->closeReservoirCase();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_contourMapGrid = std::move( contourMapGrid );
|
|
|
|
|
|
|
|
|
|
doStatisticsCalculation( timestep_results );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimEclipseCase* RimStatisticsContourMap::eclipseCase() const
|
|
|
|
|
{
|
|
|
|
|
if ( !m_resultDefinition() ) return nullptr;
|
|
|
|
|
|
|
|
|
|
return m_resultDefinition->eclipseCase();
|
2024-11-13 14:06:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimStatisticsContourMap::appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const
|
|
|
|
|
{
|
|
|
|
|
menuBuilder << "RicNewStatisticsContourMapViewFeature";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RigContourMapGrid* RimStatisticsContourMap::contourMapGrid() const
|
|
|
|
|
{
|
|
|
|
|
return m_contourMapGrid.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2025-01-14 21:52:54 +01:00
|
|
|
std::vector<double> RimStatisticsContourMap::result( size_t timeStep, StatisticsType statisticsType ) const
|
|
|
|
|
{
|
|
|
|
|
auto realTimeSteps = selectedTimeSteps();
|
|
|
|
|
if ( timeStep >= realTimeSteps.size() ) return {};
|
|
|
|
|
|
|
|
|
|
timeStep = (size_t)realTimeSteps[timeStep];
|
|
|
|
|
|
|
|
|
|
if ( !m_timeResults.contains( timeStep ) ) return {};
|
|
|
|
|
|
|
|
|
|
if ( !m_timeResults.at( timeStep ).contains( statisticsType ) ) return {};
|
|
|
|
|
|
|
|
|
|
return m_timeResults.at( timeStep ).at( statisticsType );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::vector<int> RimStatisticsContourMap::selectedTimeSteps() const
|
|
|
|
|
{
|
|
|
|
|
auto steps = m_selectedTimeSteps();
|
|
|
|
|
if ( m_selectedTimeSteps().empty() )
|
|
|
|
|
{
|
|
|
|
|
if ( eclipseCase() )
|
|
|
|
|
{
|
|
|
|
|
for ( int i = 0; i < (int)eclipseCase()->timeStepStrings().size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
steps.push_back( i );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::sort( steps.begin(), steps.end() );
|
|
|
|
|
}
|
|
|
|
|
return steps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
QString RimStatisticsContourMap::timeStepName( int timeStep ) const
|
2024-11-13 14:06:23 +01:00
|
|
|
{
|
2025-01-14 21:52:54 +01:00
|
|
|
if ( eclipseCase() == nullptr ) return "";
|
|
|
|
|
|
|
|
|
|
if ( ( timeStep < 0 ) || ( timeStep >= eclipseCase()->timeStepStrings().size() ) ) return "";
|
|
|
|
|
|
|
|
|
|
return eclipseCase()->timeStepName( timeStep );
|
2024-11-13 14:06:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimStatisticsContourMap::ensureResultsComputed()
|
|
|
|
|
{
|
|
|
|
|
if ( !m_contourMapGrid ) computeStatistics();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
QString RimStatisticsContourMap::resultAggregationText() const
|
|
|
|
|
{
|
|
|
|
|
return m_resultAggregation().uiText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
QString RimStatisticsContourMap::resultVariable() const
|
|
|
|
|
{
|
2025-01-14 21:52:54 +01:00
|
|
|
if ( m_resultDefinition().isNull() ) return "";
|
2024-11-13 14:06:23 +01:00
|
|
|
return m_resultDefinition()->resultVariable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
bool RimStatisticsContourMap::isColumnResult() const
|
|
|
|
|
{
|
|
|
|
|
return RigContourMapCalculator::isColumnResult( m_resultAggregation() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
double RimStatisticsContourMap::sampleSpacingFactor() const
|
|
|
|
|
{
|
2025-01-15 20:44:20 +01:00
|
|
|
return RimContourMapResolutionTools::resolutionFromEnumValue( m_resolution() );
|
2024-11-13 14:06:23 +01:00
|
|
|
}
|
2025-01-14 21:52:54 +01:00
|
|
|
|
2025-01-16 16:53:05 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::vector<RimStatisticsContourMapView*> RimStatisticsContourMap::views() const
|
|
|
|
|
{
|
|
|
|
|
return m_views.childrenByType();
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 21:52:54 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RimStatisticsContourMap::addView( RimStatisticsContourMapView* view )
|
|
|
|
|
{
|
|
|
|
|
// make sure to update the other views as the calculated data might have changed
|
|
|
|
|
for ( auto view : m_views )
|
|
|
|
|
{
|
|
|
|
|
view->scheduleCreateDisplayModelAndRedraw();
|
|
|
|
|
}
|
|
|
|
|
m_views.push_back( view );
|
|
|
|
|
}
|