2020-11-13 08:37:08 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2020- 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 "RimGridStatisticsPlot.h"
|
|
|
|
|
|
|
|
#include "RiaGuiApplication.h"
|
|
|
|
#include "RiaPreferences.h"
|
|
|
|
|
2020-11-25 09:00:46 -06:00
|
|
|
#include "RimCase.h"
|
2020-11-13 08:37:08 -06:00
|
|
|
#include "RimEclipseCase.h"
|
|
|
|
#include "RimEclipseCaseCollection.h"
|
2021-06-23 08:17:56 -05:00
|
|
|
#include "RimEclipseCellColors.h"
|
2020-11-13 08:37:08 -06:00
|
|
|
#include "RimEclipseResultCase.h"
|
2020-11-25 09:00:46 -06:00
|
|
|
#include "RimEclipseResultDefinition.h"
|
|
|
|
#include "RimEclipseView.h"
|
|
|
|
#include "RimGridView.h"
|
|
|
|
#include "RimHistogramCalculator.h"
|
2020-11-13 08:37:08 -06:00
|
|
|
#include "RimPlot.h"
|
|
|
|
#include "RimProject.h"
|
2020-11-25 09:00:46 -06:00
|
|
|
#include "RimTools.h"
|
2020-12-09 02:54:20 -06:00
|
|
|
|
|
|
|
#include "RigHistogramData.h"
|
|
|
|
|
2020-11-13 08:37:08 -06:00
|
|
|
#include "cafPdmFieldScriptingCapability.h"
|
|
|
|
#include "cafPdmObjectScriptingCapability.h"
|
|
|
|
#include "cafPdmUiComboBoxEditor.h"
|
|
|
|
|
2021-04-28 04:39:28 -05:00
|
|
|
#include "cvfAssert.h"
|
2020-11-13 08:37:08 -06:00
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
CAF_PDM_SOURCE_INIT( RimGridStatisticsPlot, "GridStatisticsPlot" );
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimGridStatisticsPlot::RimGridStatisticsPlot()
|
|
|
|
{
|
2021-06-10 02:33:22 -05:00
|
|
|
CAF_PDM_InitObject( "Grid Statistics Plot", ":/statistics.png", "", "A Plot of Grid Statistics" );
|
2020-11-13 08:37:08 -06:00
|
|
|
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_case, "Case", "Case" );
|
2020-11-25 09:00:46 -06:00
|
|
|
m_case.uiCapability()->setUiTreeChildrenHidden( true );
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitField( &m_timeStep, "TimeStep", -1, "Time Step" );
|
2020-11-25 09:00:46 -06:00
|
|
|
m_timeStep.uiCapability()->setUiEditorTypeName( caf::PdmUiComboBoxEditor::uiEditorTypeName() );
|
|
|
|
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_cellFilterView, "VisibleCellView", "Filter by 3d View Visibility" );
|
2020-11-25 09:00:46 -06:00
|
|
|
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_property, "Property", "Property" );
|
2020-11-25 09:00:46 -06:00
|
|
|
m_property = new RimEclipseResultDefinition( caf::PdmUiItemInfo::TOP );
|
|
|
|
m_property.uiCapability()->setUiTreeChildrenHidden( true );
|
|
|
|
m_property->setTernaryEnabled( false );
|
|
|
|
|
2020-11-30 04:21:48 -06:00
|
|
|
m_plotLegendsHorizontal.uiCapability()->setUiHidden( true );
|
|
|
|
|
2020-12-03 07:46:04 -06:00
|
|
|
setDefaults();
|
|
|
|
|
2020-11-30 04:21:48 -06:00
|
|
|
setDeletable( true );
|
2020-11-13 08:37:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimGridStatisticsPlot::~RimGridStatisticsPlot()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-11-25 09:00:46 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimGridStatisticsPlot::setDefaults()
|
|
|
|
{
|
|
|
|
RimProject* project = RimProject::current();
|
|
|
|
if ( project )
|
|
|
|
{
|
|
|
|
if ( !project->eclipseCases().empty() )
|
|
|
|
{
|
|
|
|
RimEclipseCase* eclipseCase = project->eclipseCases().front();
|
|
|
|
m_case = eclipseCase;
|
|
|
|
m_property->setEclipseCase( eclipseCase );
|
|
|
|
|
|
|
|
m_property->setResultType( RiaDefines::ResultCatType::STATIC_NATIVE );
|
|
|
|
m_property->setResultVariable( "PORO" );
|
2023-02-13 02:59:29 -06:00
|
|
|
|
2024-03-15 03:32:45 -05:00
|
|
|
if ( eclipseCase && !eclipseCase->reservoirViews().empty() )
|
2023-02-13 02:59:29 -06:00
|
|
|
{
|
2024-03-15 03:32:45 -05:00
|
|
|
m_cellFilterView.setValue( eclipseCase->reservoirViews().front() );
|
2023-02-13 02:59:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
m_numHistogramBins = 15;
|
|
|
|
m_tickNumberFormat = RiaNumberFormat::NumberFormatType::FIXED;
|
2020-11-25 09:00:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 08:37:08 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-06-23 08:17:56 -05:00
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimGridStatisticsPlot::setPropertiesFromView( RimEclipseView* view )
|
|
|
|
{
|
|
|
|
CAF_ASSERT( view );
|
|
|
|
|
|
|
|
m_case = view->ownerCase();
|
|
|
|
|
|
|
|
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>( m_case.value() );
|
|
|
|
if ( eclipseCase ) m_property->setEclipseCase( eclipseCase );
|
|
|
|
|
|
|
|
const RimEclipseResultDefinition* resDef = dynamic_cast<const RimEclipseResultDefinition*>( view->cellResult() );
|
|
|
|
if ( resDef ) m_property->simpleCopy( resDef );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-11-13 08:37:08 -06:00
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-02-26 03:48:40 -06:00
|
|
|
void RimGridStatisticsPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
|
2020-11-13 08:37:08 -06:00
|
|
|
{
|
2021-05-03 07:56:12 -05:00
|
|
|
RimStatisticsPlot::fieldChangedByUi( changedField, oldValue, newValue );
|
2020-11-25 09:00:46 -06:00
|
|
|
|
|
|
|
if ( changedField == &m_case )
|
|
|
|
{
|
|
|
|
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>( m_case.value() );
|
|
|
|
if ( eclipseCase )
|
|
|
|
{
|
|
|
|
m_property->setEclipseCase( eclipseCase );
|
|
|
|
m_property->updateConnectedEditors();
|
|
|
|
loadDataAndUpdate();
|
|
|
|
}
|
|
|
|
}
|
2020-11-30 04:21:48 -06:00
|
|
|
else
|
|
|
|
{
|
2020-11-25 09:00:46 -06:00
|
|
|
loadDataAndUpdate();
|
|
|
|
}
|
2020-12-03 07:46:04 -06:00
|
|
|
|
2020-11-13 08:37:08 -06:00
|
|
|
updateConnectedEditors();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimGridStatisticsPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
|
|
|
{
|
2020-11-25 09:00:46 -06:00
|
|
|
uiOrdering.add( &m_case );
|
|
|
|
if ( m_case )
|
|
|
|
{
|
|
|
|
uiOrdering.add( &m_timeStep );
|
|
|
|
uiOrdering.add( &m_cellFilterView );
|
|
|
|
caf::PdmUiGroup* propertyGroup = uiOrdering.addNewGroup( "Property" );
|
|
|
|
m_property->uiOrdering( uiConfigName, *propertyGroup );
|
|
|
|
}
|
2020-11-13 08:37:08 -06:00
|
|
|
|
2023-02-13 02:59:29 -06:00
|
|
|
const bool showNumHistogramBins = true;
|
2021-05-12 08:04:57 -05:00
|
|
|
RimStatisticsPlot::uiOrderingForHistogram( uiConfigName, uiOrdering, showNumHistogramBins );
|
2023-02-13 02:59:29 -06:00
|
|
|
RimStatisticsPlot::uiOrderingForLegendsAndFonts( uiConfigName, uiOrdering );
|
2020-11-13 08:37:08 -06:00
|
|
|
|
|
|
|
uiOrdering.skipRemainingFields( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2022-05-29 06:01:27 -05:00
|
|
|
QList<caf::PdmOptionItemInfo> RimGridStatisticsPlot::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions )
|
2020-11-13 08:37:08 -06:00
|
|
|
{
|
2022-05-29 06:01:27 -05:00
|
|
|
QList<caf::PdmOptionItemInfo> options = RimStatisticsPlot::calculateValueOptions( fieldNeedingOptions );
|
2020-11-13 08:37:08 -06:00
|
|
|
|
2020-11-30 04:21:48 -06:00
|
|
|
if ( fieldNeedingOptions == &m_case )
|
2020-11-25 09:00:46 -06:00
|
|
|
{
|
|
|
|
RimTools::eclipseCaseOptionItems( &options );
|
|
|
|
if ( options.empty() )
|
|
|
|
{
|
|
|
|
options.push_front( caf::PdmOptionItemInfo( "None", nullptr ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( fieldNeedingOptions == &m_timeStep )
|
|
|
|
{
|
|
|
|
options.push_back( caf::PdmOptionItemInfo( "All Time Steps", -1 ) );
|
|
|
|
|
|
|
|
RimTools::timeStepsForCase( m_case, &options );
|
|
|
|
}
|
|
|
|
else if ( fieldNeedingOptions == &m_cellFilterView )
|
|
|
|
{
|
|
|
|
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>( m_case() );
|
|
|
|
if ( eclipseCase )
|
|
|
|
{
|
|
|
|
options.push_back( caf::PdmOptionItemInfo( "Disabled", nullptr ) );
|
2024-03-15 03:32:45 -05:00
|
|
|
for ( RimEclipseView* view : eclipseCase->reservoirViews() )
|
2020-11-25 09:00:46 -06:00
|
|
|
{
|
|
|
|
CVF_ASSERT( view && "Really always should have a valid view pointer in ReservoirViews" );
|
|
|
|
options.push_back( caf::PdmOptionItemInfo( view->name(), view, false, view->uiIconProvider() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-13 08:37:08 -06:00
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimGridStatisticsPlot::initAfterRead()
|
|
|
|
{
|
2021-05-03 07:56:12 -05:00
|
|
|
RimStatisticsPlot::initAfterRead();
|
2020-11-25 09:00:46 -06:00
|
|
|
|
|
|
|
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>( m_case() );
|
|
|
|
if ( eclipseCase )
|
|
|
|
{
|
|
|
|
m_property->setEclipseCase( eclipseCase );
|
|
|
|
}
|
2020-11-13 08:37:08 -06:00
|
|
|
}
|
|
|
|
|
2020-12-03 07:46:04 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimGridStatisticsPlot::cellFilterViewUpdated()
|
|
|
|
{
|
|
|
|
loadDataAndUpdate();
|
|
|
|
}
|
|
|
|
|
2020-11-13 08:37:08 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-28 04:39:28 -05:00
|
|
|
bool RimGridStatisticsPlot::hasStatisticsData() const
|
2020-11-13 08:37:08 -06:00
|
|
|
{
|
2021-04-28 04:39:28 -05:00
|
|
|
return ( m_viewer && m_case() && m_property() );
|
2020-11-13 08:37:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-28 04:39:28 -05:00
|
|
|
RigHistogramData RimGridStatisticsPlot::createStatisticsData() const
|
2020-11-13 08:37:08 -06:00
|
|
|
{
|
2021-04-28 04:39:28 -05:00
|
|
|
std::unique_ptr<RimHistogramCalculator> histogramCalculator;
|
|
|
|
histogramCalculator.reset( new RimHistogramCalculator );
|
2023-02-13 02:59:29 -06:00
|
|
|
histogramCalculator->setNumBins( static_cast<size_t>( m_numHistogramBins() ) );
|
2020-12-03 07:46:04 -06:00
|
|
|
|
2021-04-28 04:39:28 -05:00
|
|
|
RigHistogramData histogramData;
|
2020-11-25 09:00:46 -06:00
|
|
|
|
2021-04-28 04:39:28 -05:00
|
|
|
RimHistogramCalculator::StatisticsCellRangeType cellRange = RimHistogramCalculator::StatisticsCellRangeType::ALL_CELLS;
|
2020-11-25 09:00:46 -06:00
|
|
|
|
2023-02-26 03:48:40 -06:00
|
|
|
RimHistogramCalculator::StatisticsTimeRangeType timeRange = RimHistogramCalculator::StatisticsTimeRangeType::ALL_TIMESTEPS;
|
|
|
|
int timeStep = 0;
|
2021-04-28 04:39:28 -05:00
|
|
|
if ( m_timeStep() != -1 && !m_property()->hasStaticResult() )
|
|
|
|
{
|
|
|
|
timeStep = m_timeStep();
|
|
|
|
timeRange = RimHistogramCalculator::StatisticsTimeRangeType::CURRENT_TIMESTEP;
|
|
|
|
}
|
2020-12-03 07:46:04 -06:00
|
|
|
|
2021-04-28 04:39:28 -05:00
|
|
|
if ( m_cellFilterView.value() )
|
|
|
|
{
|
|
|
|
// Filter by visible cells of the view
|
|
|
|
cellRange = RimHistogramCalculator::StatisticsCellRangeType::VISIBLE_CELLS;
|
|
|
|
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>( m_cellFilterView.value() );
|
2023-02-26 03:48:40 -06:00
|
|
|
histogramData = histogramCalculator->histogramData( eclipseView, m_property.value(), cellRange, timeRange, timeStep );
|
2021-04-28 04:39:28 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RimEclipseView* eclipseView = nullptr;
|
2023-02-26 03:48:40 -06:00
|
|
|
histogramData = histogramCalculator->histogramData( eclipseView, m_property.value(), cellRange, timeRange, timeStep );
|
2020-11-25 09:00:46 -06:00
|
|
|
}
|
2020-11-13 08:37:08 -06:00
|
|
|
|
2021-04-28 04:39:28 -05:00
|
|
|
return histogramData;
|
2020-11-13 08:37:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-11-30 04:21:48 -06:00
|
|
|
QString RimGridStatisticsPlot::createAutoName() const
|
2020-11-13 08:37:08 -06:00
|
|
|
{
|
2020-11-30 04:21:48 -06:00
|
|
|
if ( m_case() == nullptr )
|
|
|
|
{
|
|
|
|
return "Undefined";
|
|
|
|
}
|
2020-11-13 08:37:08 -06:00
|
|
|
|
2020-11-30 04:21:48 -06:00
|
|
|
QStringList nameTags;
|
2020-12-03 07:46:04 -06:00
|
|
|
nameTags += m_property()->resultVariable();
|
2020-11-30 04:21:48 -06:00
|
|
|
nameTags += m_case()->caseUserDescription();
|
|
|
|
|
|
|
|
QString timeStepStr = timeStepString();
|
|
|
|
if ( !timeStepStr.isEmpty() )
|
|
|
|
{
|
|
|
|
nameTags += timeStepStr;
|
|
|
|
}
|
|
|
|
|
2020-12-03 07:46:04 -06:00
|
|
|
return nameTags.join( ", " );
|
2020-11-13 08:37:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-11-30 04:21:48 -06:00
|
|
|
QString RimGridStatisticsPlot::timeStepString() const
|
2020-11-13 08:37:08 -06:00
|
|
|
{
|
2020-11-30 04:21:48 -06:00
|
|
|
if ( m_case() && m_property->hasDynamicResult() )
|
|
|
|
{
|
|
|
|
if ( m_timeStep == -1 )
|
|
|
|
{
|
|
|
|
return "All Time Steps";
|
|
|
|
}
|
|
|
|
return m_case->timeStepStrings()[m_timeStep];
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
2020-11-13 08:37:08 -06:00
|
|
|
}
|
2021-06-30 03:46:10 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RimGridStatisticsPlot::createXAxisTitle() const
|
|
|
|
{
|
|
|
|
if ( m_case() == nullptr ) return "";
|
|
|
|
|
|
|
|
QStringList nameTags;
|
|
|
|
nameTags += m_property()->resultVariable();
|
|
|
|
|
|
|
|
QString timeStepStr = timeStepString();
|
|
|
|
if ( !timeStepStr.isEmpty() )
|
|
|
|
{
|
|
|
|
nameTags += timeStepStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nameTags.join( ", " );
|
|
|
|
}
|