Performance : Simplify use of update schedulers

Extract code to RiaScheduler
Add PlotCollectionScheduler
This commit is contained in:
Magne Sjaastad 2022-05-05 11:29:07 +02:00
parent 8daf25ffb3
commit cc397efe3e
12 changed files with 330 additions and 120 deletions

View File

@ -27,6 +27,8 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaNumberFormat.h ${CMAKE_CURRENT_LIST_DIR}/RiaNumberFormat.h
${CMAKE_CURRENT_LIST_DIR}/RiaRftDefines.h ${CMAKE_CURRENT_LIST_DIR}/RiaRftDefines.h
${CMAKE_CURRENT_LIST_DIR}/RiaDateTimeDefines.h ${CMAKE_CURRENT_LIST_DIR}/RiaDateTimeDefines.h
${CMAKE_CURRENT_LIST_DIR}/RiaPlotCollectionScheduler.h
${CMAKE_CURRENT_LIST_DIR}/RiaScheduler.h
) )
set(SOURCE_GROUP_SOURCE_FILES set(SOURCE_GROUP_SOURCE_FILES
@ -58,6 +60,8 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaNumberFormat.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaNumberFormat.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaRftDefines.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaRftDefines.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaDateTimeDefines.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaDateTimeDefines.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaPlotCollectionScheduler.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaScheduler.cpp
) )
list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
@ -71,6 +75,7 @@ set(QT_MOC_HEADERS
${CMAKE_CURRENT_LIST_DIR}/RiaCompletionTypeCalculationScheduler.h ${CMAKE_CURRENT_LIST_DIR}/RiaCompletionTypeCalculationScheduler.h
${CMAKE_CURRENT_LIST_DIR}/RiaViewRedrawScheduler.h ${CMAKE_CURRENT_LIST_DIR}/RiaViewRedrawScheduler.h
${CMAKE_CURRENT_LIST_DIR}/RiaPlotWindowRedrawScheduler.h ${CMAKE_CURRENT_LIST_DIR}/RiaPlotWindowRedrawScheduler.h
${CMAKE_CURRENT_LIST_DIR}/RiaScheduler.h
) )
source_group( source_group(

View File

@ -78,38 +78,50 @@ void RiaCompletionTypeCalculationScheduler::scheduleRecalculateCompletionTypeAnd
void RiaCompletionTypeCalculationScheduler::scheduleRecalculateCompletionTypeAndRedrawAllViews( void RiaCompletionTypeCalculationScheduler::scheduleRecalculateCompletionTypeAndRedrawAllViews(
const std::vector<RimEclipseCase*>& eclipseCases ) const std::vector<RimEclipseCase*>& eclipseCases )
{ {
clearCompletionTypeResults( eclipseCases );
for ( RimEclipseCase* eclipseCase : eclipseCases ) for ( RimEclipseCase* eclipseCase : eclipseCases )
{ {
CVF_ASSERT( eclipseCase ); if ( eclipseCase ) m_eclipseCasesToRecalculate.emplace_back( eclipseCase );
if ( eclipseCase->eclipseCaseData() )
{
eclipseCase->eclipseCaseData()
->results( RiaDefines::PorosityModelType::MATRIX_MODEL )
->clearScalarResult( RiaDefines::ResultCatType::DYNAMIC_NATIVE,
RiaResultNames::completionTypeResultName() );
// Delete virtual perforation transmissibilities, as these are the basis for the computation of completion type
eclipseCase->eclipseCaseData()->setVirtualPerforationTransmissibilities( nullptr );
}
m_eclipseCasesToRecalculate.push_back( eclipseCase );
} }
startTimer(); startTimer( 0 );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiaCompletionTypeCalculationScheduler::slotRecalculateCompletionType() void RiaCompletionTypeCalculationScheduler::clearCompletionTypeResultsInAllCases()
{ {
if ( caf::ProgressState::isActive() ) std::vector<RimEclipseCase*> eclipseCases =
{ RimProject::current()->activeOilField()->analysisModels->cases().childObjects();
startTimer();
return;
}
clearCompletionTypeResults( eclipseCases );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaCompletionTypeCalculationScheduler::clearCompletionTypeResults( const std::vector<RimEclipseCase*>& eclipseCases )
{
for ( RimEclipseCase* eclipseCase : eclipseCases )
{
if ( !eclipseCase || !eclipseCase->eclipseCaseData() ) continue;
eclipseCase->eclipseCaseData()
->results( RiaDefines::PorosityModelType::MATRIX_MODEL )
->clearScalarResult( RiaDefines::ResultCatType::DYNAMIC_NATIVE, RiaResultNames::completionTypeResultName() );
// Delete virtual perforation transmissibilities, as these are the basis for the computation of completion type
eclipseCase->eclipseCaseData()->setVirtualPerforationTransmissibilities( nullptr );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaCompletionTypeCalculationScheduler::performScheduledUpdates()
{
std::set<RimEclipseCase*> uniqueCases( m_eclipseCasesToRecalculate.begin(), m_eclipseCasesToRecalculate.end() ); std::set<RimEclipseCase*> uniqueCases( m_eclipseCasesToRecalculate.begin(), m_eclipseCasesToRecalculate.end() );
Rim3dView* activeView = RiaApplication::instance()->activeReservoirView(); Rim3dView* activeView = RiaApplication::instance()->activeReservoirView();
@ -149,28 +161,11 @@ void RiaCompletionTypeCalculationScheduler::slotRecalculateCompletionType()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RiaCompletionTypeCalculationScheduler::~RiaCompletionTypeCalculationScheduler() RiaCompletionTypeCalculationScheduler::~RiaCompletionTypeCalculationScheduler()
{ {
delete m_recalculateCompletionTypeTimer;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RiaCompletionTypeCalculationScheduler::RiaCompletionTypeCalculationScheduler() RiaCompletionTypeCalculationScheduler::RiaCompletionTypeCalculationScheduler()
: m_recalculateCompletionTypeTimer( nullptr )
{ {
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaCompletionTypeCalculationScheduler::startTimer()
{
if ( !m_recalculateCompletionTypeTimer )
{
m_recalculateCompletionTypeTimer = new QTimer( this );
m_recalculateCompletionTypeTimer->setSingleShot( true );
connect( m_recalculateCompletionTypeTimer, SIGNAL( timeout() ), this, SLOT( slotRecalculateCompletionType() ) );
}
m_recalculateCompletionTypeTimer->start( 1500 );
}

View File

@ -18,29 +18,30 @@
#pragma once #pragma once
#include "cafPdmPointer.h" #include "RiaScheduler.h"
#include <QObject> #include "cafPdmPointer.h"
#include <vector> #include <vector>
class QTimer;
class RimEclipseCase; class RimEclipseCase;
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
class RiaCompletionTypeCalculationScheduler : public QObject class RiaCompletionTypeCalculationScheduler : public RiaScheduler
{ {
Q_OBJECT; Q_OBJECT;
public: public:
static RiaCompletionTypeCalculationScheduler* instance(); static RiaCompletionTypeCalculationScheduler* instance();
void scheduleRecalculateCompletionTypeAndRedrawAllViews(); void scheduleRecalculateCompletionTypeAndRedrawAllViews();
void scheduleRecalculateCompletionTypeAndRedrawAllViews( RimEclipseCase* eclipseCase ); void clearCompletionTypeResultsInAllCases();
private slots: void scheduleRecalculateCompletionTypeAndRedrawAllViews( RimEclipseCase* eclipseCase );
void slotRecalculateCompletionType(); void clearCompletionTypeResults( const std::vector<RimEclipseCase*>& eclipseCases );
void performScheduledUpdates() override;
private: private:
RiaCompletionTypeCalculationScheduler(); RiaCompletionTypeCalculationScheduler();
@ -51,9 +52,6 @@ private:
void scheduleRecalculateCompletionTypeAndRedrawAllViews( const std::vector<RimEclipseCase*>& eclipseCases ); void scheduleRecalculateCompletionTypeAndRedrawAllViews( const std::vector<RimEclipseCase*>& eclipseCases );
void startTimer();
private: private:
std::vector<caf::PdmPointer<RimEclipseCase>> m_eclipseCasesToRecalculate; std::vector<caf::PdmPointer<RimEclipseCase>> m_eclipseCasesToRecalculate;
QTimer* m_recalculateCompletionTypeTimer;
}; };

View File

@ -0,0 +1,73 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RiaPlotCollectionScheduler.h"
#include "RimAbstractPlotCollection.h"
#include "RimViewWindow.h"
#include "cafProgressState.h"
#include <QTimer>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaPlotCollectionScheduler::RiaPlotCollectionScheduler()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaPlotCollectionScheduler::~RiaPlotCollectionScheduler()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaPlotCollectionScheduler* RiaPlotCollectionScheduler::instance()
{
static RiaPlotCollectionScheduler theInstance;
return &theInstance;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaPlotCollectionScheduler::schedulePlotCollectionUpdate( const std::vector<RimPlotCollection*> plotCollections )
{
m_plotCollectionsToUpdate.insert( m_plotCollectionsToUpdate.end(), plotCollections.begin(), plotCollections.end() );
startTimer( 0 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaPlotCollectionScheduler::performScheduledUpdates()
{
for ( auto p : m_plotCollectionsToUpdate )
{
if ( p == nullptr ) continue;
p->loadDataAndUpdateAllPlots();
}
}

View File

@ -0,0 +1,42 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RiaScheduler.h"
class RimPlotCollection;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RiaPlotCollectionScheduler : public RiaScheduler
{
public:
RiaPlotCollectionScheduler();
~RiaPlotCollectionScheduler() override;
static RiaPlotCollectionScheduler* instance();
void schedulePlotCollectionUpdate( const std::vector<RimPlotCollection*> plotCollections );
void performScheduledUpdates() override;
private:
std::vector<RimPlotCollection*> m_plotCollectionsToUpdate;
};

View File

@ -0,0 +1,83 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RiaScheduler.h"
#include "cafProgressState.h"
#include <QCoreApplication>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaScheduler::RiaScheduler()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaScheduler::~RiaScheduler()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaScheduler::slotUpdateScheduledItemsWhenReady()
{
if ( caf::ProgressState::isActive() )
{
startTimer( 100 );
return;
}
performScheduledUpdates();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaScheduler::startTimer( int msecs )
{
if ( !m_updateTimer )
{
m_updateTimer.reset( new QTimer( this ) );
connect( m_updateTimer.data(), SIGNAL( timeout() ), this, SLOT( slotUpdateScheduledItemsWhenReady() ) );
}
if ( !m_updateTimer->isActive() )
{
m_updateTimer->setSingleShot( true );
m_updateTimer->start( msecs );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaScheduler::waitUntilWorkIsDone()
{
if ( m_updateTimer )
{
while ( m_updateTimer->isActive() )
{
QCoreApplication::processEvents();
}
}
}

View File

@ -0,0 +1,47 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <QObject>
#include <QScopedPointer>
#include <QTimer>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RiaScheduler : public QObject
{
Q_OBJECT
public:
RiaScheduler();
virtual ~RiaScheduler();
virtual void performScheduledUpdates() = 0;
protected:
void startTimer( int msecs );
void waitUntilWorkIsDone();
private slots:
void slotUpdateScheduledItemsWhenReady();
private:
QScopedPointer<QTimer> m_updateTimer;
};

View File

@ -17,14 +17,25 @@
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
#include "RiaViewRedrawScheduler.h" #include "RiaViewRedrawScheduler.h"
#include "Rim3dView.h" #include "Rim3dView.h"
#include <QCoreApplication>
#include <QTimer>
#include "cafProgressState.h"
#include <set> #include <set>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaViewRedrawScheduler::RiaViewRedrawScheduler()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaViewRedrawScheduler::~RiaViewRedrawScheduler()
{
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -51,13 +62,8 @@ void RiaViewRedrawScheduler::scheduleDisplayModelUpdateAndRedraw( Rim3dView* res
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiaViewRedrawScheduler::clearViewsScheduledForUpdate() void RiaViewRedrawScheduler::clearViewsScheduledForUpdate()
{ {
if ( m_resViewUpdateTimer ) waitUntilWorkIsDone();
{
while ( m_resViewUpdateTimer->isActive() )
{
QCoreApplication::processEvents();
}
}
m_resViewsToUpdate.clear(); m_resViewsToUpdate.clear();
} }
@ -105,39 +111,7 @@ void RiaViewRedrawScheduler::updateAndRedrawScheduledViews()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiaViewRedrawScheduler::slotUpdateAndRedrawScheduledViewsWhenReady() void RiaViewRedrawScheduler::performScheduledUpdates()
{ {
if ( caf::ProgressState::isActive() )
{
startTimer( 100 );
return;
}
updateAndRedrawScheduledViews(); updateAndRedrawScheduledViews();
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaViewRedrawScheduler::startTimer( int msecs )
{
if ( !m_resViewUpdateTimer )
{
m_resViewUpdateTimer = new QTimer( this );
connect( m_resViewUpdateTimer, SIGNAL( timeout() ), this, SLOT( slotUpdateAndRedrawScheduledViewsWhenReady() ) );
}
if ( !m_resViewUpdateTimer->isActive() )
{
m_resViewUpdateTimer->setSingleShot( true );
m_resViewUpdateTimer->start( msecs );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaViewRedrawScheduler::~RiaViewRedrawScheduler()
{
delete m_resViewUpdateTimer;
}

View File

@ -18,38 +18,28 @@
#pragma once #pragma once
#include "RiaScheduler.h"
#include "cafPdmPointer.h" #include "cafPdmPointer.h"
#include <QObject>
#include <vector> #include <vector>
class QTimer;
class Rim3dView; class Rim3dView;
class RiaViewRedrawScheduler : public QObject class RiaViewRedrawScheduler : public RiaScheduler
{ {
Q_OBJECT;
public: public:
static RiaViewRedrawScheduler* instance(); RiaViewRedrawScheduler();
void scheduleDisplayModelUpdateAndRedraw( Rim3dView* resViewToUpdate );
void clearViewsScheduledForUpdate();
void updateAndRedrawScheduledViews();
private slots:
void slotUpdateAndRedrawScheduledViewsWhenReady();
private:
void startTimer( int msecs );
RiaViewRedrawScheduler()
: m_resViewUpdateTimer( nullptr )
{
}
~RiaViewRedrawScheduler() override; ~RiaViewRedrawScheduler() override;
RiaViewRedrawScheduler( const RiaViewRedrawScheduler& o ) = delete; static RiaViewRedrawScheduler* instance();
void operator=( const RiaViewRedrawScheduler& o ) = delete;
void scheduleDisplayModelUpdateAndRedraw( Rim3dView* resViewToUpdate );
void clearViewsScheduledForUpdate();
void updateAndRedrawScheduledViews();
void performScheduledUpdates() override;
private:
std::vector<caf::PdmPointer<Rim3dView>> m_resViewsToUpdate; std::vector<caf::PdmPointer<Rim3dView>> m_resViewsToUpdate;
QTimer* m_resViewUpdateTimer;
}; };

View File

@ -19,6 +19,8 @@
#include "RimMainPlotCollection.h" #include "RimMainPlotCollection.h"
#include "RiaPlotCollectionScheduler.h"
#include "PlotBuilderCommands/RicSummaryPlotBuilder.h" #include "PlotBuilderCommands/RicSummaryPlotBuilder.h"
#include "RimAbstractPlotCollection.h" #include "RimAbstractPlotCollection.h"
@ -340,10 +342,11 @@ void RimMainPlotCollection::updatePlotsWithFormations()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimMainPlotCollection::updatePlotsWithCompletions() void RimMainPlotCollection::scheduleUpdatePlotsWithCompletions()
{ {
std::vector<RimPlotCollection*> plotCollections = plotCollectionsWithCompletions(); std::vector<RimPlotCollection*> plotCollections = plotCollectionsWithCompletions();
loadDataAndUpdatePlotCollections( plotCollections );
RiaPlotCollectionScheduler::instance()->schedulePlotCollectionUpdate( plotCollections );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -84,7 +84,7 @@ public:
void deleteAllContainedObjects(); void deleteAllContainedObjects();
void updateCurrentTimeStepInPlots(); void updateCurrentTimeStepInPlots();
void updatePlotsWithFormations(); void updatePlotsWithFormations();
void updatePlotsWithCompletions(); void scheduleUpdatePlotsWithCompletions();
void deleteAllCachedData(); void deleteAllCachedData();
void ensureDefaultFlowPlotsAreCreated(); void ensureDefaultFlowPlotsAreCreated();
void ensureCalculationIdsAreAssigned(); void ensureCalculationIdsAreAssigned();

View File

@ -999,10 +999,10 @@ void RimProject::setSubWindowsTiledInPlotWindow( bool tiled )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimProject::reloadCompletionTypeResultsInAllViews() void RimProject::reloadCompletionTypeResultsInAllViews()
{ {
RiaCompletionTypeCalculationScheduler::instance()->clearCompletionTypeResultsInAllCases();
scheduleCreateDisplayModelAndRedrawAllViews(); scheduleCreateDisplayModelAndRedrawAllViews();
RiaCompletionTypeCalculationScheduler::instance()->scheduleRecalculateCompletionTypeAndRedrawAllViews();
this->mainPlotCollection()->updatePlotsWithCompletions(); mainPlotCollection()->scheduleUpdatePlotsWithCompletions();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------