Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve summary calculation performance #11225

Merged
merged 8 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ApplicationLibCode/Commands/RicUserDefinedCalculatorUi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ bool RicUserDefinedCalculatorUi::parseExpression() const
{
notifyCalculatedNameChanged( m_currentCalculation()->id(), currentCurveName );
}

m_currentCalculation()->updateDependentObjects();
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion ApplicationLibCode/FileInterface/RifEclEclipseSummary.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class RifEclEclipseSummary : public RifSummaryReaderInterface

private:
int indexFromAddress( const RifEclipseSummaryAddress& resultAddress ) const;
void buildMetaData();
void buildMetaData() override;

private:
ecl_sum_type* m_ecl_sum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void RifMultipleSummaryReaders::addReader( RifSummaryReaderInterface* reader )

m_readers.push_back( reader );

rebuildMetaData();
buildMetaData();
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -45,7 +45,7 @@ void RifMultipleSummaryReaders::addReader( RifSummaryReaderInterface* reader )
void RifMultipleSummaryReaders::removeReader( RifSummaryReaderInterface* reader )
{
m_readers.erase( reader );
rebuildMetaData();
buildMetaData();
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -100,7 +100,7 @@ RiaDefines::EclipseUnitSystem RifMultipleSummaryReaders::unitSystem() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifMultipleSummaryReaders::rebuildMetaData()
void RifMultipleSummaryReaders::buildMetaData()
{
m_allErrorAddresses.clear();
m_allResultAddresses.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RifMultipleSummaryReaders : public RifSummaryReaderInterface
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
RiaDefines::EclipseUnitSystem unitSystem() const override;

void rebuildMetaData();
void buildMetaData() override;

private:
cvf::Collection<RifSummaryReaderInterface> m_readers;
Expand Down
2 changes: 1 addition & 1 deletion ApplicationLibCode/FileInterface/RifOpmCommonSummary.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class RifOpmCommonEclipseSummary : public RifSummaryReaderInterface
RiaDefines::EclipseUnitSystem unitSystem() const override;

private:
void buildMetaData();
void buildMetaData() override;
bool openFileReader( const QString& fileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger );

static void increaseEsmryFileCount();
Expand Down
2 changes: 1 addition & 1 deletion ApplicationLibCode/FileInterface/RifOpmHdf5Summary.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class RifOpmHdf5Summary : public RifSummaryReaderInterface
RiaDefines::EclipseUnitSystem unitSystem() const override;

private:
void buildMetaData();
void buildMetaData() override;
bool openESmryFile( const QString& headerFileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger );

private:
Expand Down
3 changes: 1 addition & 2 deletions ApplicationLibCode/FileInterface/RifReaderEclipseSummary.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ class RifReaderEclipseSummary : public RifSummaryReaderInterface
std::pair<bool, std::vector<double>> values( const RifEclipseSummaryAddress& resultAddress ) const override;
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;
RiaDefines::EclipseUnitSystem unitSystem() const override;
void buildMetaData() override;

private:
void buildMetaData();

RifSummaryReaderInterface* currentSummaryReader() const;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ RifEclipseSummaryAddress RifSummaryReaderInterface::errorAddress( const RifEclip
return m_allErrorAddresses.find( errAddr ) != m_allErrorAddresses.end() ? errAddr : RifEclipseSummaryAddress();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifSummaryReaderInterface::buildMetaData()
{
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions ApplicationLibCode/FileInterface/RifSummaryReaderInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class RifSummaryReaderInterface : public cvf::Object
virtual std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const = 0;
virtual RiaDefines::EclipseUnitSystem unitSystem() const = 0;

virtual void buildMetaData();

protected:
std::set<RifEclipseSummaryAddress> m_allResultAddresses; // Result and error addresses
std::set<RifEclipseSummaryAddress> m_allErrorAddresses; // Error addresses
Expand Down
41 changes: 2 additions & 39 deletions ApplicationLibCode/ProjectDataModel/RimSummaryCalculation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,17 @@

#include "RifSummaryReaderInterface.h"
#include "RimDataSourceSteppingTools.h"
#include "RimObservedDataCollection.h"
#include "RimObservedSummaryData.h"
#include "RimProject.h"
#include "RimSummaryAddress.h"
#include "RimSummaryCalculationCollection.h"
#include "RimSummaryCalculationVariable.h"
#include "RimSummaryCase.h"
#include "RimSummaryCaseCollection.h"
#include "RimSummaryCaseMainCollection.h"
#include "RimSummaryCurve.h"
#include "RimSummaryMultiPlot.h"
#include "RimSummaryMultiPlotCollection.h"
#include "RimSummaryPlot.h"

#include "RiuExpressionContextMenuManager.h"

#include "cafPdmUiCheckBoxEditor.h"
#include "cafPdmUiLineEditor.h"
#include "cafPdmUiTableViewEditor.h"
#include "cafPdmUiTextEditor.h"

#include "expressionparser/ExpressionParser.h"

Expand Down Expand Up @@ -402,43 +393,14 @@ std::optional<std::pair<std::vector<double>, std::vector<time_t>>>
//--------------------------------------------------------------------------------------------------
void RimSummaryCalculation::updateDependentObjects()
{
RimSummaryCalculationCollection* calcColl = firstAncestorOrThisOfTypeAsserted<RimSummaryCalculationCollection>();
calcColl->rebuildCaseMetaData();

// Refresh data sources tree.
// TODO: refresh too much: would be enough to only refresh calculated resutls.
RimSummaryCaseMainCollection* summaryCaseCollection = RiaSummaryTools::summaryCaseMainCollection();
auto summaryCases = summaryCaseCollection->allSummaryCases();
for ( RimSummaryCase* summaryCase : summaryCases )
{
summaryCase->createSummaryReaderInterface();
summaryCase->createRftReaderInterface();
summaryCase->refreshMetaData();
}

RimObservedDataCollection* observedDataCollection = RiaSummaryTools::observedDataCollection();
auto observedData = observedDataCollection->allObservedSummaryData();
for ( auto obs : observedData )
{
obs->createSummaryReaderInterface();
obs->createRftReaderInterface();
obs->refreshMetaData();
}

auto summaryCaseCollections = summaryCaseCollection->summaryCaseCollections();
for ( RimSummaryCaseCollection* summaryCaseCollection : summaryCaseCollections )
{
summaryCaseCollection->refreshMetaData();
}

RimSummaryMultiPlotCollection* summaryPlotCollection = RiaSummaryTools::summaryMultiPlotCollection();
for ( auto multiPlot : summaryPlotCollection->multiPlots() )
{
for ( RimSummaryPlot* sumPlot : multiPlot->summaryPlots() )
{
bool plotContainsCalculatedCurves = false;

for ( RimSummaryCurve* sumCurve : sumPlot->summaryCurves() )
for ( RimSummaryCurve* sumCurve : sumPlot->summaryAndEnsembleCurves() )
{
if ( sumCurve->summaryAddressY().isCalculated() )
{
Expand All @@ -461,6 +423,7 @@ void RimSummaryCalculation::updateDependentObjects()
//--------------------------------------------------------------------------------------------------
void RimSummaryCalculation::removeDependentObjects()
{
updateDependentObjects();
}

//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@

#include "RimSummaryCalculationCollection.h"

#include "RiaSummaryTools.h"

#include "RifSummaryReaderInterface.h"

#include "RimObservedSummaryData.h"
#include "RimSummaryCalculation.h"
#include "RimSummaryCase.h"
#include "RimSummaryCaseCollection.h"
#include "RimSummaryCaseMainCollection.h"

CAF_PDM_SOURCE_INIT( RimSummaryCalculationCollection, "RimSummaryCalculationCollection" );
//--------------------------------------------------------------------------------------------------
Expand All @@ -37,12 +45,53 @@ RimSummaryCalculation* RimSummaryCalculationCollection::createCalculation() cons
return new RimSummaryCalculation;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryCalculationCollection::updateDataDependingOnCalculations()
{
// Refresh data sources tree
// Refresh meta data for all summary cases and rebuild AddressNodes in the summary tree
RimSummaryCaseMainCollection* summaryCaseCollection = RiaSummaryTools::summaryCaseMainCollection();
auto summaryCases = summaryCaseCollection->allSummaryCases();
for ( RimSummaryCase* summaryCase : summaryCases )
{
if ( !summaryCase ) continue;

if ( auto reader = summaryCase->summaryReader() )
{
reader->buildMetaData();
summaryCase->onCalculationUpdated();
}
}

RimObservedDataCollection* observedDataCollection = RiaSummaryTools::observedDataCollection();
auto observedData = observedDataCollection->allObservedSummaryData();
for ( auto obs : observedData )
{
if ( !obs ) continue;

if ( auto reader = obs->summaryReader() )
{
reader->buildMetaData();
obs->onCalculationUpdated();
}
}

auto summaryCaseCollections = summaryCaseCollection->summaryCaseCollections();
for ( RimSummaryCaseCollection* summaryCaseCollection : summaryCaseCollections )
{
summaryCaseCollection->onCalculationUpdated();
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryCalculationCollection::rebuildCaseMetaData()
{
ensureValidCalculationIds();
updateDataDependingOnCalculations();
}

//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ class RimSummaryCalculationCollection : public RimUserDefinedCalculationCollecti
RimSummaryCalculation* createCalculation() const override;

private:
void updateDataDependingOnCalculations();
void initAfterRead() override;
};
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ RimUserDefinedCalculation* RimUserDefinedCalculationCollection::addCalculationCo
//--------------------------------------------------------------------------------------------------
void RimUserDefinedCalculationCollection::deleteCalculation( RimUserDefinedCalculation* calculation )
{
calculation->removeDependentObjects();
m_calculations.removeChild( calculation );

// Call this function after the object is removed from the collection
calculation->removeDependentObjects();

rebuildCaseMetaData();

delete calculation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ void RifCalculatedSummaryCurveReader::buildMetaData()

for ( RimUserDefinedCalculation* calc : m_calculationCollection->calculations() )
{
RimSummaryCalculation* sumCalc = dynamic_cast<RimSummaryCalculation*>( calc );
auto* sumCalc = dynamic_cast<RimSummaryCalculation*>( calc );
CAF_ASSERT( sumCalc );

const auto& allAddresses = sumCalc->allAddressesForSummaryCase( m_summaryCase );
for ( auto calculationAddress : allAddresses )
for ( const auto& calculationAddress : allAddresses )
{
if ( calculationAddress.address().isValid() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class RifCalculatedSummaryCurveReader : public RifSummaryReaderInterface
std::pair<bool, std::vector<double>> values( const RifEclipseSummaryAddress& resultAddress ) const override;
std::string unitName( const RifEclipseSummaryAddress& resultAddress ) const override;

void buildMetaData();
void buildMetaData() override;

RiaDefines::EclipseUnitSystem unitSystem() const override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ RimSummaryAddressCollection::~RimSummaryAddressCollection()
//--------------------------------------------------------------------------------------------------
bool RimSummaryAddressCollection::hasDataVector( const QString quantityName ) const
{
for ( auto& address : m_adresses )
for ( const auto& address : m_adresses )
{
if ( address->quantityName() == quantityName ) return true;
}
Expand Down Expand Up @@ -346,6 +346,32 @@ void RimSummaryAddressCollection::deleteChildren()
m_subfolders.deleteChildren();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryAddressCollection::deleteCalculatedObjects()
{
std::vector<RimSummaryAddress*> toDelete;
for ( const auto& a : m_adresses )
{
if ( a->address().isCalculated() )
{
toDelete.push_back( a );
}
}

for ( auto a : toDelete )
{
m_adresses.removeChild( a );
delete a;
}

for ( auto& folder : m_subfolders )
{
folder->deleteCalculatedObjects();
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class RimSummaryAddressCollection : public RimNamedObject
void updateFolderStructure( const std::set<RifEclipseSummaryAddress>& addresses, int caseId, int ensembleId = -1 );

void deleteChildren();
void deleteCalculatedObjects();

bool isEmpty() const;
bool isEnsemble() const;
Expand Down
17 changes: 17 additions & 0 deletions ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,20 @@ void RimSummaryCase::refreshMetaData()
buildChildNodes();
updateConnectedEditors();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryCase::onCalculationUpdated()
{
// Delete all calculated address objects
m_dataVectorFolders->deleteCalculatedObjects();

if ( auto reader = summaryReader() )
{
auto addresses = reader->allResultAddresses();
m_dataVectorFolders->updateFolderStructure( addresses, m_caseId );
}

updateConnectedEditors();
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class RimSummaryCase : public caf::PdmObject
int caseId() const;

void refreshMetaData();
void onCalculationUpdated();

virtual void createSummaryReaderInterface() = 0;
virtual void createRftReaderInterface() {}
Expand Down
Loading
Loading