///////////////////////////////////////////////////////////////////////////////// // // 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 // for more details. // ///////////////////////////////////////////////////////////////////////////////// #pragma once #include "RimNamedObject.h" #include "ContourMap/RimContourMapResolutionTools.h" #include "RimContourMapProjection.h" #include "cafPdmChildArrayField.h" #include "cafPdmField.h" #include "cafPdmPtrArrayField.h" #include "cafPdmPtrField.h" #include "cvfVector3.h" #include #include #include #include class RigContourMapGrid; class RimCellFilter; class RimEclipseCase; class RimEclipseResultDefinition; class RimEclipseCaseEnsemble; class RimReservoirGridEnsemble; class RimEclipseContourMapView; class RimStatisticsContourMapView; class RimPolygon; class RigPolyLinesData; //================================================================================================== // //================================================================================================== class RimStatisticsContourMap : public RimNamedObject { CAF_PDM_HEADER_INIT; public: enum class StatisticsType { P10, P50, P90, MEAN, MIN, MAX }; enum class GridImportMode { SHARED_GRID, INDIVIDUAL_GRIDS }; RimStatisticsContourMap(); void setEclipseCase( RimEclipseCase* eclipseCase ); RimEclipseCase* eclipseCase() const; RimCellFilter* dataFilter() const; void setGridImportMode( GridImportMode mode ); QString ensembleName() const; RigContourMapGrid* contourMapGrid() const; std::vector result( size_t timeStep, StatisticsType statisticsType ) const; void addView( RimStatisticsContourMapView* view ); std::vector views() const; void ensureResultsComputed(); static void computeStatisticsForMaps( const std::vector& maps ); QString resultAggregationText() const; QString resultVariable() const; double sampleSpacingFactor() const; bool isColumnResult() const; std::vector selectedTimeSteps() const; std::vector selectedTimeStepDates() const; QString timeStepName( int timeStep ) const; std::vector> selectedPolygons() const; void switchToSelectedSourceCase(); protected: void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override; void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; void initAfterRead() override; void setupBeforeSave() override; void appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const override; QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override; void onChildDeleted( caf::PdmChildArrayFieldHandle* childArray, std::vector& referringObjects ) override; private: using TimestepResultsMap = std::map>>; void computeStatistics(); void onComputeStatisticsClicked(); void doStatisticsCalculation( TimestepResultsMap& timestep_results ); // Project-adjacent statistics cache, keyed by a hash of all settings affecting the results. // The results are stored as one GRI surface file per statistics type per time step, so that // the cached maps can also be imported as regular surfaces. QString computeCacheValidityKey() const; bool loadCachedResults(); bool writeCachedResults( const QString& baseName ) const; QString cacheFileName( const QString& baseName, StatisticsType statisticsType, size_t timeStep ) const; QString getValidCacheFileBaseName() const; void deleteCacheFiles() const; void clearCacheFields(); static QString getCacheDirectoryPath(); std::vector ensembleCases() const; std::set ensembleCasesInViews() const; std::vector> mapLocalToGlobalTimeSteps( std::vector localDates ) const; private: caf::PdmField m_boundingBoxExpPercent; caf::PdmField m_resultAggregation; caf::PdmField> m_selectedTimeSteps; caf::PdmChildField m_resultDefinition; caf::PdmPtrField m_primaryCase; caf::PdmPtrArrayField m_selectedPolygons; caf::PdmPtrField m_dataFilter; caf::PdmField> m_gridImportMode; caf::PdmField> m_resolution; caf::PdmField> m_oilFloodingType; caf::PdmField> m_gasFloodingType; caf::PdmField m_userDefinedFloodingGas; caf::PdmField m_userDefinedFloodingOil; // Base file name of the cache files within the project cache directory. Stored as a plain file // name to stay relocatable with the project and out of reach of the global path list macros. // The contour map grid definition is stored in fields, since the GRI files only hold the 2D // sample grid and values. caf::PdmField m_cacheFileBaseName; caf::PdmField m_cacheValidityKey; caf::PdmField> m_cacheTimeSteps; caf::PdmField m_cacheSampleSpacing; caf::PdmField> m_cacheOriginalBoundingBox; caf::PdmField> m_cacheExpandedBoundingBox; caf::PdmField> m_cacheMapSize; std::unique_ptr m_contourMapGrid; std::map>> m_timeResults; caf::PdmChildArrayField m_views; RimEclipseCase* m_openEclipseCase; // Obsolete formation filter, replaced by ensemble data filters (#14710). Kept for the warning in initAfterRead(). caf::PdmField m_enableFormationFilter_OBSOLETE; caf::PdmField> m_selectedFormations_OBSOLETE; // Validity key captured when the results were computed or loaded from cache, so that results // from outdated settings are never written to the cache QString m_computedValidityKey; };