From f7248f3999180988333ecc34dbd9c808fd5e220c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Mon, 18 Mar 2013 14:34:29 +0100 Subject: [PATCH] Results Storage: A huge refactorisation to make way for storing generated properties to an internal file. This does not yet compile due to a unfortunate mix of perforce, cmake setup and unit_test project shortcomings. Need to move RigStatistics into ProjectDataModel and rename it before this is running again. p4#: 20945 --- .../FileInterface_UnitTests/CMakeLists.txt | 3 + .../FileInterface/RifReaderEclipseOutput.cpp | 8 +- .../FileInterface/RifReaderEclipseOutput.h | 2 +- .../Rim3dOverlayInfoConfig.cpp | 16 +- .../ProjectDataModel/RimCaseCollection.h | 1 - .../RimCellEdgeResultSlot.cpp | 6 +- .../RimCellPropertyFilter.cpp | 4 +- .../ProjectDataModel/RimInputReservoir.cpp | 32 +- .../ProjectDataModel/RimReservoir.cpp | 94 ++-- .../ProjectDataModel/RimReservoir.h | 61 +-- .../RimReservoirCellResultsCacher.cpp | 440 +++++++++++++++++- .../RimReservoirCellResultsCacher.h | 38 +- .../ProjectDataModel/RimReservoirView.cpp | 19 +- .../ProjectDataModel/RimReservoirView.h | 2 +- .../ProjectDataModel/RimResultDefinition.cpp | 16 +- .../ProjectDataModel/RimResultReservoir.cpp | 25 +- .../RimStatisticalCalculation.cpp | 22 +- .../RimStatisticalCalculation.h | 2 +- .../CMakeLists.txt | 3 + .../ReservoirDataModel/RigEclipseCase.cpp | 3 +- .../ReservoirDataModel/RigEclipseCase.h | 2 +- .../RigReservoirCellResults.cpp | 374 +-------------- .../RigReservoirCellResults.h | 68 ++- .../ReservoirDataModel/RigStatistics.cpp | 45 +- .../ReservoirDataModel/RigStatistics.h | 11 +- .../SocketInterface/RiaSocketServer.cpp | 8 +- .../UserInterface/RIMainWindow.cpp | 2 +- 27 files changed, 705 insertions(+), 602 deletions(-) diff --git a/ApplicationCode/FileInterface/FileInterface_UnitTests/CMakeLists.txt b/ApplicationCode/FileInterface/FileInterface_UnitTests/CMakeLists.txt index 33a34260a3..e66fbc896c 100644 --- a/ApplicationCode/FileInterface/FileInterface_UnitTests/CMakeLists.txt +++ b/ApplicationCode/FileInterface/FileInterface_UnitTests/CMakeLists.txt @@ -18,6 +18,9 @@ include_directories( ${ResInsight_SOURCE_DIR}/cafProjectDataModel ${ResInsight_SOURCE_DIR}/CommonCode + + #Remove when RigStatistics is out + ${ResInsight_SOURCE_DIR}/ApplicationCode/ModelVisualization ) diff --git a/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp index e85260a844..584f731876 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp +++ b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp @@ -377,9 +377,6 @@ bool RifReaderEclipseOutput::open(const QString& fileName, RigEclipseCase* eclip m_eclipseCase = eclipseCase; - eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(this); - eclipseCase->results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(this); - // Build results meta data if (!buildMetaData()) return false; progInfo.incrementProgress(); @@ -397,7 +394,7 @@ bool RifReaderEclipseOutput::open(const QString& fileName, RigEclipseCase* eclip //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RifReaderEclipseOutput::openAndReadActiveCellData(const QString& fileName, RigEclipseCase* mainEclipseCase, RigEclipseCase* eclipseCase) +bool RifReaderEclipseOutput::openAndReadActiveCellData(const QString& fileName, const std::vector& mainCaseTimeSteps, RigEclipseCase* eclipseCase) { CVF_ASSERT(eclipseCase); @@ -417,8 +414,6 @@ bool RifReaderEclipseOutput::openAndReadActiveCellData(const QString& fileName, m_fileSet = fileSet; m_eclipseCase = eclipseCase; - eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(this); - eclipseCase->results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(this); if (!readActiveCellInfo()) { @@ -432,7 +427,6 @@ bool RifReaderEclipseOutput::openAndReadActiveCellData(const QString& fileName, m_dynamicResultsAccess = createDynamicResultsAccess(m_fileSet); - std::vector mainCaseTimeSteps = mainEclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->readerInterface()->timeSteps(); m_dynamicResultsAccess->setTimeSteps(mainCaseTimeSteps); return true; diff --git a/ApplicationCode/FileInterface/RifReaderEclipseOutput.h b/ApplicationCode/FileInterface/RifReaderEclipseOutput.h index bdbec6f0ad..d902795935 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseOutput.h +++ b/ApplicationCode/FileInterface/RifReaderEclipseOutput.h @@ -44,7 +44,7 @@ public: virtual ~RifReaderEclipseOutput(); bool open(const QString& fileName, RigEclipseCase* eclipseCase); - virtual bool openAndReadActiveCellData(const QString& fileName, RigEclipseCase* mainEclipseCase, RigEclipseCase* eclipseCase); + virtual bool openAndReadActiveCellData(const QString& fileName, const std::vector& mainCaseTimeSteps, RigEclipseCase* eclipseCase); void close(); bool staticResult(const QString& result, PorosityModelResultType matrixOrFracture, std::vector* values); diff --git a/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp b/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp index d35b7d9cb7..1e00f95e13 100644 --- a/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp +++ b/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp @@ -117,9 +117,9 @@ void Rim3dOverlayInfoConfig::update3DInfo() double p10, p90; double mean; size_t scalarIndex = m_reservoirView->cellResult()->gridScalarIndex(); - m_reservoirView->currentGridCellResults()->minMaxCellScalarValues(scalarIndex, min, max); - m_reservoirView->currentGridCellResults()->p10p90CellScalarValues(scalarIndex, p10, p90); - m_reservoirView->currentGridCellResults()->meanCellScalarValues(scalarIndex, mean); + m_reservoirView->currentGridCellResults()->cellResults()->minMaxCellScalarValues(scalarIndex, min, max); + m_reservoirView->currentGridCellResults()->cellResults()->p10p90CellScalarValues(scalarIndex, p10, p90); + m_reservoirView->currentGridCellResults()->cellResults()->meanCellScalarValues(scalarIndex, mean); //infoText += QString("
Min: %1 P10: %2 Mean: %3 P90: %4 Max: %5
").arg(min).arg(p10).arg(mean).arg(p90).arg(max); //infoText += QString("
Min: %1   P10: %2   Mean: %3 \n  P90: %4   Max: %5 
").arg(min).arg(p10).arg(mean).arg(p90).arg(max); @@ -141,7 +141,7 @@ void Rim3dOverlayInfoConfig::update3DInfo() || m_reservoirView->wellCollection()->hasVisibleWellPipes()) { int currentTimeStep = m_reservoirView->currentTimeStep(); - QDateTime date = m_reservoirView->currentGridCellResults()->timeStepDate(0, currentTimeStep); + QDateTime date = m_reservoirView->currentGridCellResults()->cellResults()->timeStepDate(0, currentTimeStep); infoText += QString("Time Step: %1 Time: %2").arg(currentTimeStep).arg(date.toString("dd.MMM yyyy")); } @@ -157,12 +157,12 @@ void Rim3dOverlayInfoConfig::update3DInfo() double mean; size_t scalarIndex = m_reservoirView->cellResult()->gridScalarIndex(); - m_reservoirView->currentGridCellResults()->minMaxCellScalarValues(scalarIndex, min, max); - m_reservoirView->currentGridCellResults()->p10p90CellScalarValues(scalarIndex, p10, p90); - m_reservoirView->currentGridCellResults()->meanCellScalarValues(scalarIndex, mean); + m_reservoirView->currentGridCellResults()->cellResults()->minMaxCellScalarValues(scalarIndex, min, max); + m_reservoirView->currentGridCellResults()->cellResults()->p10p90CellScalarValues(scalarIndex, p10, p90); + m_reservoirView->currentGridCellResults()->cellResults()->meanCellScalarValues(scalarIndex, mean); m_reservoirView->viewer()->showHistogram(true); - m_reservoirView->viewer()->setHistogram(min, max, m_reservoirView->currentGridCellResults()->cellScalarValuesHistogram(scalarIndex)); + m_reservoirView->viewer()->setHistogram(min, max, m_reservoirView->currentGridCellResults()->cellResults()->cellScalarValuesHistogram(scalarIndex)); m_reservoirView->viewer()->setHistogramPercentiles(p10, p90, mean); } } diff --git a/ApplicationCode/ProjectDataModel/RimCaseCollection.h b/ApplicationCode/ProjectDataModel/RimCaseCollection.h index 137435fc32..49989fc9b3 100644 --- a/ApplicationCode/ProjectDataModel/RimCaseCollection.h +++ b/ApplicationCode/ProjectDataModel/RimCaseCollection.h @@ -26,7 +26,6 @@ #include "RimStatisticalCalculation.h" - //================================================================================================== // // diff --git a/ApplicationCode/ProjectDataModel/RimCellEdgeResultSlot.cpp b/ApplicationCode/ProjectDataModel/RimCellEdgeResultSlot.cpp index 26721a0bf9..c2558cc09c 100644 --- a/ApplicationCode/ProjectDataModel/RimCellEdgeResultSlot.cpp +++ b/ApplicationCode/ProjectDataModel/RimCellEdgeResultSlot.cpp @@ -133,7 +133,7 @@ QList RimCellEdgeResultSlot::calculateValueOptions(const if (m_reservoirView && m_reservoirView->currentGridCellResults()) { QStringList varList; - varList = m_reservoirView->currentGridCellResults()->resultNames(RimDefines::STATIC_NATIVE); + varList = m_reservoirView->currentGridCellResults()->cellResults()->resultNames(RimDefines::STATIC_NATIVE); //TODO: Must also handle input properties //varList += m_reservoirView->gridCellResults()->resultNames(RimDefines::INPUT_PROPERTY); @@ -208,7 +208,7 @@ QStringList RimCellEdgeResultSlot::findResultVariableNames() if (m_reservoirView && m_reservoirView->currentGridCellResults() && !resultVariable().isEmpty()) { QStringList varList; - varList = m_reservoirView->currentGridCellResults()->resultNames(RimDefines::STATIC_NATIVE); + varList = m_reservoirView->currentGridCellResults()->cellResults()->resultNames(RimDefines::STATIC_NATIVE); //TODO: Must handle Input properties int i; @@ -313,7 +313,7 @@ void RimCellEdgeResultSlot::minMaxCellEdgeValues(double& min, double& max) { double cMin, cMax; - m_reservoirView->currentGridCellResults()->minMaxCellScalarValues(resultIndices[idx], cMin, cMax); + m_reservoirView->currentGridCellResults()->cellResults()->minMaxCellScalarValues(resultIndices[idx], cMin, cMax); globalMin = CVF_MIN(globalMin, cMin); globalMax = CVF_MAX(globalMax, cMax); diff --git a/ApplicationCode/ProjectDataModel/RimCellPropertyFilter.cpp b/ApplicationCode/ProjectDataModel/RimCellPropertyFilter.cpp index 542d6c23f9..ad47fc70c6 100644 --- a/ApplicationCode/ProjectDataModel/RimCellPropertyFilter.cpp +++ b/ApplicationCode/ProjectDataModel/RimCellPropertyFilter.cpp @@ -143,10 +143,10 @@ void RimCellPropertyFilter::setDefaultValues() size_t scalarIndex = resultDefinition->gridScalarIndex(); if (scalarIndex != cvf::UNDEFINED_SIZE_T) { - RigReservoirCellResults* results = m_parentContainer->reservoirView()->currentGridCellResults(); + RimReservoirCellResultsCacher* results = m_parentContainer->reservoirView()->currentGridCellResults(); if (results) { - results->minMaxCellScalarValues(scalarIndex, min, max); + results->cellResults()->minMaxCellScalarValues(scalarIndex, min, max); } } diff --git a/ApplicationCode/ProjectDataModel/RimInputReservoir.cpp b/ApplicationCode/ProjectDataModel/RimInputReservoir.cpp index a86b85f396..c221244c7b 100644 --- a/ApplicationCode/ProjectDataModel/RimInputReservoir.cpp +++ b/ApplicationCode/ProjectDataModel/RimInputReservoir.cpp @@ -72,18 +72,18 @@ void RimInputReservoir::openDataFileSet(const QStringList& filenames) if (caseName().contains("Input Mock Debug Model")) { cvf::ref readerInterface = this->createMockModel(this->caseName()); - m_rigEclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(readerInterface.p()); - m_rigEclipseCase->results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(readerInterface.p()); + results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(readerInterface.p()); + results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(readerInterface.p()); - m_rigEclipseCase->activeCellInfo(RifReaderInterface::MATRIX_RESULTS)->computeDerivedData(); - m_rigEclipseCase->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS)->computeDerivedData(); + reservoirData()->activeCellInfo(RifReaderInterface::MATRIX_RESULTS)->computeDerivedData(); + reservoirData()->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS)->computeDerivedData(); return; } - if (m_rigEclipseCase.isNull()) + if (this->reservoirData() == NULL) { - m_rigEclipseCase = new RigEclipseCase; + this->setReservoirData(new RigEclipseCase); } // First find and read the grid data @@ -157,7 +157,7 @@ void RimInputReservoir::openDataFileSet(const QStringList& filenames) bool RimInputReservoir::openEclipseGridFile() { // Early exit if reservoir data is created - if (m_rigEclipseCase.isNull()) + if (this->reservoirData() == NULL) { cvf::ref readerInterface; @@ -174,14 +174,14 @@ bool RimInputReservoir::openEclipseGridFile() return false; } - m_rigEclipseCase = eclipseCase; + this->setReservoirData( eclipseCase.p() ); } - CVF_ASSERT(m_rigEclipseCase.notNull()); + CVF_ASSERT(this->reservoirData()); CVF_ASSERT(readerInterface.notNull()); - m_rigEclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(readerInterface.p()); - m_rigEclipseCase->results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(readerInterface.p()); + results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(readerInterface.p()); + results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(readerInterface.p()); computeCachedData(); loadAndSyncronizeInputProperties(); @@ -191,8 +191,8 @@ bool RimInputReservoir::openEclipseGridFile() RIApplication* app = RIApplication::instance(); if (app->preferences()->autocomputeDepthRelatedProperties) { - RigReservoirCellResults* matrixResults = m_rigEclipseCase->results(RifReaderInterface::MATRIX_RESULTS); - RigReservoirCellResults* fractureResults = m_rigEclipseCase->results(RifReaderInterface::FRACTURE_RESULTS); + RimReservoirCellResultsCacher* matrixResults = results(RifReaderInterface::MATRIX_RESULTS); + RimReservoirCellResultsCacher* fractureResults = results(RifReaderInterface::FRACTURE_RESULTS); matrixResults->computeDepthRelatedResults(); fractureResults->computeDepthRelatedResults(); @@ -210,7 +210,7 @@ void RimInputReservoir::loadAndSyncronizeInputProperties() { // Make sure we actually have reservoir data - CVF_ASSERT(m_rigEclipseCase.notNull()); + CVF_ASSERT(this->reservoirData()); CVF_ASSERT(this->reservoirData()->mainGrid()->gridPointDimensions() != cvf::Vec3st(0,0,0)); // Then read the properties from all the files referenced by the InputReservoir @@ -359,7 +359,7 @@ void RimInputReservoir::removeProperty(RimInputProperty* inputProperty) } // Remove the results pointed to by this input property - RigReservoirCellResults* results = m_rigEclipseCase->results(RifReaderInterface::MATRIX_RESULTS); + RigReservoirCellResults* results = reservoirData()->results(RifReaderInterface::MATRIX_RESULTS); results->removeResult(inputProperty->resultName); this->removeResult(inputProperty->resultName); @@ -404,7 +404,7 @@ cvf::ref RimInputReservoir::createMockModel(QString modelNam m_inputPropertyCollection->inputProperties.push_back(inputProperty); } - m_rigEclipseCase = reservoir; + this->setReservoirData( reservoir.p() ); return mockFileInterface.p(); } diff --git a/ApplicationCode/ProjectDataModel/RimReservoir.cpp b/ApplicationCode/ProjectDataModel/RimReservoir.cpp index 5da41eae67..4078d2eeb1 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoir.cpp +++ b/ApplicationCode/ProjectDataModel/RimReservoir.cpp @@ -34,6 +34,7 @@ #include #include "RimProject.h" +#include "RimReservoirCellResultsCacher.h" CAF_PDM_SOURCE_INIT(RimReservoir, "RimReservoir"); @@ -42,15 +43,33 @@ CAF_PDM_SOURCE_INIT(RimReservoir, "RimReservoir"); //-------------------------------------------------------------------------------------------------- RimReservoir::RimReservoir() { - m_rigEclipseCase = NULL; - CAF_PDM_InitField(&caseName, "CaseName", QString(), "Case name", "", "" ,""); -// CAF_PDM_InitField(&releaseResultMemory, "ReleaseResultMemory", true, "Release result memory", "", "" ,""); -// releaseResultMemory.setIOReadable(false); -// releaseResultMemory.setIOWritable(false); -// releaseResultMemory.setUiEditorTypeName(caf::PdmUiPushButtonEditor::uiEditorTypeName()); - CAF_PDM_InitFieldNoDefault(&reservoirViews, "ReservoirViews", "", "", "", ""); + + CAF_PDM_InitFieldNoDefault(&m_matrixModelResults, "MatrixModelResults", "", "", "", ""); + CAF_PDM_InitFieldNoDefault(&m_fractureModelResults, "FractureModelResults", "", "", "", ""); + + m_matrixModelResults = new RimReservoirCellResultsCacher; + m_fractureModelResults = new RimReservoirCellResultsCacher; + + this->setReservoirData( NULL ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimReservoir::~RimReservoir() +{ + reservoirViews.deleteAllChildObjects(); + + delete m_matrixModelResults(); + delete m_fractureModelResults(); + + if (this->reservoirData()) + { + // At this point, we assume that memory should be released + CVF_ASSERT(this->reservoirData()->refCount() == 1); + } } //-------------------------------------------------------------------------------------------------- @@ -84,20 +103,6 @@ void RimReservoir::initAfterRead() } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RimReservoir::~RimReservoir() -{ - reservoirViews.deleteAllChildObjects(); - - if (m_rigEclipseCase.notNull()) - { - // At this point, we assume that memory should be released - CVF_ASSERT(m_rigEclipseCase->refCount() == 1); - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -106,12 +111,12 @@ RimReservoirView* RimReservoir::createAndAddReservoirView() // If parent is collection, and number of views is zero, make sure rig is set to NULL to initiate normal case loading if (parentCaseCollection() != NULL && reservoirViews().size() == 0) { - if (m_rigEclipseCase.notNull()) + if (this->reservoirData()) { - CVF_ASSERT(m_rigEclipseCase->refCount() == 1); + CVF_ASSERT(this->reservoirData()->refCount() == 1); } - m_rigEclipseCase = NULL; + this->setReservoirData( NULL ); } RimReservoirView* riv = new RimReservoirView(); @@ -207,7 +212,7 @@ void RimReservoir::fieldChangedByUi(const caf::PdmFieldHandle* changedField, con { if (changedField == &releaseResultMemory) { - if (m_rigEclipseCase.notNull()) + if (this->reservoirData()) { for (size_t i = 0; i < reservoirViews().size(); i++) { @@ -229,13 +234,13 @@ void RimReservoir::fieldChangedByUi(const caf::PdmFieldHandle* changedField, con reservoirView->createDisplayModelAndRedraw(); } - RigReservoirCellResults* matrixModelResults = m_rigEclipseCase->results(RifReaderInterface::MATRIX_RESULTS); + RigReservoirCellResults* matrixModelResults = reservoirData()->results(RifReaderInterface::MATRIX_RESULTS); if (matrixModelResults) { matrixModelResults->clearAllResults(); } - RigReservoirCellResults* fractureModelResults = m_rigEclipseCase->results(RifReaderInterface::FRACTURE_RESULTS); + RigReservoirCellResults* fractureModelResults = reservoirData()->results(RifReaderInterface::FRACTURE_RESULTS); if (fractureModelResults) { fractureModelResults->clearAllResults(); @@ -286,3 +291,38 @@ RimCaseCollection* RimReservoir::parentCaseCollection() return NULL; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimReservoir::setReservoirData(RigEclipseCase* eclipseCase) +{ + m_rigEclipseCase = eclipseCase; + if (this->reservoirData()) + { + m_fractureModelResults()->setCellResults(reservoirData()->results(RifReaderInterface::FRACTURE_RESULTS)); + m_matrixModelResults()->setCellResults(reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)); + m_fractureModelResults()->setMainGrid(this->reservoirData()->mainGrid()); + m_matrixModelResults()->setMainGrid(this->reservoirData()->mainGrid()); + } + else + { + m_fractureModelResults()->setCellResults(NULL); + m_matrixModelResults()->setCellResults(NULL); + m_fractureModelResults()->setMainGrid(NULL); + m_matrixModelResults()->setMainGrid(NULL); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimReservoirCellResultsCacher* RimReservoir::results(RifReaderInterface::PorosityModelResultType porosityModel) +{ + if (porosityModel == RifReaderInterface::MATRIX_RESULTS) + { + return m_matrixModelResults(); + } + + return m_fractureModelResults(); +} + diff --git a/ApplicationCode/ProjectDataModel/RimReservoir.h b/ApplicationCode/ProjectDataModel/RimReservoir.h index 0b3c384eda..05b634e706 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoir.h +++ b/ApplicationCode/ProjectDataModel/RimReservoir.h @@ -22,7 +22,8 @@ #include "cvfObject.h" #include "cafPdmField.h" #include "cafPdmObject.h" - +#include "RimReservoirCellResultsCacher.h" +#include "RifReaderInterface.h" class QString; @@ -30,12 +31,11 @@ class RigEclipseCase; class RigGridBase; class RimReservoirView; class RimCaseCollection; +//class RimReservoirCellResultsCacher; //================================================================================================== // // Interface for reservoirs. -// As this is a pure virtual class, the factory macros are not relevant (nor possible) to use -// CAF_PDM_HEADER_INIT and CAF_PDM_SOURCE_INIT // //================================================================================================== class RimReservoir : public caf::PdmObject @@ -45,38 +45,45 @@ public: RimReservoir(); virtual ~RimReservoir(); - virtual bool openEclipseGridFile() { return false;}; // Should be pure virtual but PDM does not allow that. - - RigEclipseCase* reservoirData(); - const RigEclipseCase* reservoirData() const; - - RimReservoirView* createAndAddReservoirView(); - void removeReservoirView(RimReservoirView* reservoirView); + // Fields: + caf::PdmField caseName; + caf::PdmField releaseResultMemory; + caf::PdmPointersField reservoirViews; - void removeResult(const QString& resultName); - - // Fields: - caf::PdmField caseName; - caf::PdmField releaseResultMemory; + virtual bool openEclipseGridFile() { return false;}; // Should be pure virtual but PDM does not allow that. + + RigEclipseCase* reservoirData(); + const RigEclipseCase* reservoirData() const; - caf::PdmPointersField reservoirViews; + RimReservoirCellResultsCacher* results(RifReaderInterface::PorosityModelResultType porosityModel); + + RimReservoirView* createAndAddReservoirView(); + void removeReservoirView(RimReservoirView* reservoirView); - virtual caf::PdmFieldHandle* userDescriptionField() { return &caseName; } - - virtual QString locationOnDisc() const { return QString(); } + void removeResult(const QString& resultName); + virtual QString locationOnDisc() const { return QString(); } + + // Overridden methods from PdmObject +public: + virtual caf::PdmFieldHandle* userDescriptionField() { return &caseName; } protected: - // Overridden methods - virtual void initAfterRead(); + virtual void initAfterRead(); + virtual void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ); - virtual void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ); - - void computeCachedData(); + // Internal methods +protected: + void computeCachedData(); + void setReservoirData(RigEclipseCase* eclipseCase); private: - RimCaseCollection* parentCaseCollection(); + RimCaseCollection* parentCaseCollection(); -protected: - cvf::ref m_rigEclipseCase; +private: + cvf::ref m_rigEclipseCase; + +private: + caf::PdmField m_matrixModelResults; + caf::PdmField m_fractureModelResults; }; diff --git a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsCacher.cpp b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsCacher.cpp index 3e6878cb57..8213c8e107 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsCacher.cpp +++ b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsCacher.cpp @@ -20,6 +20,8 @@ #include "RimReservoirCellResultsCacher.h" #include "RigReservoirCellResults.h" #include "RIApplication.h" +#include "RigMainGrid.h" +#include "RigCell.h" CAF_PDM_SOURCE_INIT(RimReservoirCellResultsCacher, "ReservoirCellResultCacher"); @@ -27,7 +29,8 @@ CAF_PDM_SOURCE_INIT(RimReservoirCellResultsCacher, "ReservoirCellResultCacher"); /// //-------------------------------------------------------------------------------------------------- RimReservoirCellResultsCacher::RimReservoirCellResultsCacher() - : m_cellResults(NULL) + : m_cellResults(NULL), + m_ownerMainGrid(NULL) { CAF_PDM_InitObject("Cacher", "", "", ""); @@ -72,30 +75,39 @@ void RimReservoirCellResultsCacher::setupBeforeSave() for (int rIdx = 0; rIdx < resInfo.size(); ++rIdx) { - RimReservoirCellResultsCacheEntryInfo* cacheEntry = new RimReservoirCellResultsCacheEntryInfo; - m_resultCacheMetaData.push_back(cacheEntry); - - cacheEntry->m_resultType = resInfo[rIdx].m_resultType; - cacheEntry->m_resultName = resInfo[rIdx].m_resultName; - cacheEntry->m_timeStepDates = resInfo[rIdx].m_timeStepDates; - - cacheEntry->m_filePosition = cacheFile.pos(); - - for (int tsIdx = 0; tsIdx < resInfo[rIdx].m_timeStepDates.size() ; ++tsIdx) + size_t timestepCount = m_cellResults->cellScalarResults(resInfo[rIdx].m_gridScalarResultIndex).size(); + if (timestepCount) { - std::vector& data = m_cellResults->cellScalarResults(resInfo[rIdx].m_gridScalarResultIndex, tsIdx); - if (data.size()) - { - cacheEntry->m_timeStepHasData.v().push_back(1); + RimReservoirCellResultsCacheEntryInfo* cacheEntry = new RimReservoirCellResultsCacheEntryInfo; + m_resultCacheMetaData.push_back(cacheEntry); - for (size_t cIdx = 0; cIdx < data.size(); ++cIdx) - { - stream << data[cIdx]; - } - } - else + cacheEntry->m_resultType = resInfo[rIdx].m_resultType; + cacheEntry->m_resultName = resInfo[rIdx].m_resultName; + cacheEntry->m_timeStepDates = resInfo[rIdx].m_timeStepDates; + + cacheEntry->m_filePosition = cacheFile.pos(); + + for (int tsIdx = 0; tsIdx < resInfo[rIdx].m_timeStepDates.size() ; ++tsIdx) { - cacheEntry->m_timeStepHasData.v().push_back(0); + const std::vector* data = NULL; + if (tsIdx < timestepCount) + { + data = &(m_cellResults->cellScalarResults(resInfo[rIdx].m_gridScalarResultIndex, tsIdx)); + } + + if (data && data->size()) + { + cacheEntry->m_timeStepHasData.v().push_back(1); + + for (size_t cIdx = 0; cIdx < data->size(); ++cIdx) + { + stream << (*data)[cIdx]; + } + } + else + { + cacheEntry->m_timeStepHasData.v().push_back(0); + } } } } @@ -138,6 +150,390 @@ QString RimReservoirCellResultsCacher::getCacheDirectoryPath() return cacheDirPath; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimReservoirCellResultsCacher::setReaderInterface(RifReaderInterface* readerInterface) +{ + m_readerInterface = readerInterface; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RifReaderInterface* RimReservoirCellResultsCacher::readerInterface() +{ + return m_readerInterface.p(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RimReservoirCellResultsCacher::findOrLoadScalarResultForTimeStep(RimDefines::ResultCatType type, const QString& resultName, size_t timeStepIndex) +{ + // Special handling for SOIL + if (type == RimDefines::DYNAMIC_NATIVE && resultName.toUpper() == "SOIL") + { + loadOrComputeSOILForTimeStep(timeStepIndex); + } + + size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T; + + scalarResultIndex = m_cellResults->findScalarResultIndex(type, resultName); + + if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) return cvf::UNDEFINED_SIZE_T; + + if (type == RimDefines::GENERATED) + { + return cvf::UNDEFINED_SIZE_T; + } + + if (m_readerInterface.notNull()) + { + size_t timeStepCount = m_cellResults->infoForEachResultIndex()[scalarResultIndex].m_timeStepDates.size(); + + bool resultLoadingSucess = true; + + if (type == RimDefines::DYNAMIC_NATIVE && timeStepCount > 0) + { + m_cellResults->cellScalarResults(scalarResultIndex).resize(timeStepCount); + + std::vector& values = m_cellResults->cellScalarResults(scalarResultIndex)[timeStepIndex]; + if (values.size() == 0) + { + if (!m_readerInterface->dynamicResult(resultName, RifReaderInterface::MATRIX_RESULTS, timeStepIndex, &values)) + { + resultLoadingSucess = false; + } + } + } + else if (type == RimDefines::STATIC_NATIVE) + { + m_cellResults->cellScalarResults(scalarResultIndex).resize(1); + + std::vector& values = m_cellResults->cellScalarResults(scalarResultIndex)[0]; + if (!m_readerInterface->staticResult(resultName, RifReaderInterface::MATRIX_RESULTS, &values)) + { + resultLoadingSucess = false; + } + } + + if (!resultLoadingSucess) + { + // Error logging + CVF_ASSERT(false); + } + } + + return scalarResultIndex; + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RimReservoirCellResultsCacher::findOrLoadScalarResult(RimDefines::ResultCatType type, const QString& resultName) +{ + size_t resultGridIndex = cvf::UNDEFINED_SIZE_T; + + resultGridIndex = m_cellResults->findScalarResultIndex(type, resultName); + + if (resultGridIndex == cvf::UNDEFINED_SIZE_T) return cvf::UNDEFINED_SIZE_T; + + if (m_cellResults->cellScalarResults(resultGridIndex).size()) return resultGridIndex; + + if (type == RimDefines::GENERATED) + { + return cvf::UNDEFINED_SIZE_T; + } + + if (m_readerInterface.notNull()) + { + // Add one more result to result container + size_t timeStepCount = m_cellResults->infoForEachResultIndex()[resultGridIndex].m_timeStepDates.size(); + + bool resultLoadingSucess = true; + + if (type == RimDefines::DYNAMIC_NATIVE && timeStepCount > 0) + { + m_cellResults->cellScalarResults(resultGridIndex).resize(timeStepCount); + + size_t i; + for (i = 0; i < timeStepCount; i++) + { + std::vector& values = m_cellResults->cellScalarResults(resultGridIndex)[i]; + if (!m_readerInterface->dynamicResult(resultName, RifReaderInterface::MATRIX_RESULTS, i, &values)) + { + resultLoadingSucess = false; + } + } + } + else if (type == RimDefines::STATIC_NATIVE) + { + m_cellResults->cellScalarResults(resultGridIndex).resize(1); + + std::vector& values = m_cellResults->cellScalarResults(resultGridIndex)[0]; + if (!m_readerInterface->staticResult(resultName, RifReaderInterface::MATRIX_RESULTS, &values)) + { + resultLoadingSucess = false; + } + } + + if (!resultLoadingSucess) + { + // Remove last scalar result because loading of result failed + m_cellResults->cellScalarResults(resultGridIndex).clear(); + } + } + + return resultGridIndex; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimReservoirCellResultsCacher::loadOrComputeSOIL() +{ + for (size_t timeStepIdx = 0; timeStepIdx < m_cellResults->maxTimeStepCount(); timeStepIdx++) + { + loadOrComputeSOILForTimeStep(timeStepIdx); + } +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimReservoirCellResultsCacher::loadOrComputeSOILForTimeStep(size_t timeStepIndex) +{ + size_t scalarIndexSWAT = findOrLoadScalarResultForTimeStep(RimDefines::DYNAMIC_NATIVE, "SWAT", timeStepIndex); + size_t scalarIndexSGAS = findOrLoadScalarResultForTimeStep(RimDefines::DYNAMIC_NATIVE, "SGAS", timeStepIndex); + + // Early exit if none of SWAT or SGAS is present + if (scalarIndexSWAT == cvf::UNDEFINED_SIZE_T && scalarIndexSGAS == cvf::UNDEFINED_SIZE_T) + { + return; + } + + size_t soilResultValueCount = 0; + size_t soilTimeStepCount = 0; + + std::vector* swatForTimeStep = NULL; + std::vector* sgasForTimeStep = NULL; + if (scalarIndexSWAT != cvf::UNDEFINED_SIZE_T) + { + swatForTimeStep = &(m_cellResults->cellScalarResults(scalarIndexSWAT, timeStepIndex)); + if (swatForTimeStep->size() == 0) + { + swatForTimeStep = NULL; + } + else + { + soilResultValueCount = swatForTimeStep->size(); + soilTimeStepCount = m_cellResults->infoForEachResultIndex()[scalarIndexSWAT].m_timeStepDates.size(); + } + } + + if (scalarIndexSGAS != cvf::UNDEFINED_SIZE_T) + { + sgasForTimeStep = &(m_cellResults->cellScalarResults(scalarIndexSGAS, timeStepIndex)); + if (sgasForTimeStep->size() == 0) + { + sgasForTimeStep = NULL; + } + else + { + soilResultValueCount = qMax(soilResultValueCount, sgasForTimeStep->size()); + + size_t sgasTimeStepCount = m_cellResults->infoForEachResultIndex()[scalarIndexSGAS].m_timeStepDates.size(); + soilTimeStepCount = qMax(soilTimeStepCount, sgasTimeStepCount); + } + } + + size_t soilResultGridIndex = findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL"); + if (soilResultGridIndex == cvf::UNDEFINED_SIZE_T) + { + soilResultGridIndex = m_cellResults->addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL"); + CVF_ASSERT(soilResultGridIndex != cvf::UNDEFINED_SIZE_T); + + m_cellResults->cellScalarResults(soilResultGridIndex).resize(soilTimeStepCount); + + for (size_t timeStepIdx = 0; timeStepIdx < soilTimeStepCount; timeStepIdx++) + { + m_cellResults->cellScalarResults(soilResultGridIndex, timeStepIdx).resize(soilResultValueCount); + } + } + + std::vector& soilForTimeStep = m_cellResults->cellScalarResults(soilResultGridIndex, timeStepIndex); + +#pragma omp parallel for + for (int idx = 0; idx < static_cast(soilResultValueCount); idx++) + { + double soilValue = 1.0; + if (sgasForTimeStep) + { + soilValue -= sgasForTimeStep->at(idx); + } + + if (swatForTimeStep) + { + soilValue -= swatForTimeStep->at(idx); + } + + soilForTimeStep[idx] = soilValue; + } +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimReservoirCellResultsCacher::computeDepthRelatedResults() +{ + size_t depthResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "DEPTH"); + size_t dxResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "DX"); + size_t dyResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "DY"); + size_t dzResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "DZ"); + size_t topsResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "TOPS"); + size_t bottomResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "BOTTOM"); + + bool computeDepth = false; + bool computeDx = false; + bool computeDy = false; + bool computeDz = false; + bool computeTops = false; + bool computeBottom = false; + + size_t resultValueCount = m_ownerMainGrid->cells().size(); + + if (depthResultGridIndex == cvf::UNDEFINED_SIZE_T) + { + depthResultGridIndex = m_cellResults->addStaticScalarResult(RimDefines::STATIC_NATIVE, "DEPTH", resultValueCount); + computeDepth = true; + } + + if (dxResultGridIndex == cvf::UNDEFINED_SIZE_T) + { + dxResultGridIndex = m_cellResults->addStaticScalarResult(RimDefines::STATIC_NATIVE, "DX", resultValueCount); + computeDx = true; + } + + if (dyResultGridIndex == cvf::UNDEFINED_SIZE_T) + { + dyResultGridIndex = m_cellResults->addStaticScalarResult(RimDefines::STATIC_NATIVE, "DY", resultValueCount); + computeDy = true; + } + + if (dzResultGridIndex == cvf::UNDEFINED_SIZE_T) + { + dzResultGridIndex = m_cellResults->addStaticScalarResult(RimDefines::STATIC_NATIVE, "DZ", resultValueCount); + computeDz = true; + } + + if (topsResultGridIndex == cvf::UNDEFINED_SIZE_T) + { + topsResultGridIndex = m_cellResults->addStaticScalarResult(RimDefines::STATIC_NATIVE, "TOPS", resultValueCount); + computeTops = true; + } + + if (bottomResultGridIndex == cvf::UNDEFINED_SIZE_T) + { + bottomResultGridIndex = m_cellResults->addStaticScalarResult(RimDefines::STATIC_NATIVE, "BOTTOM", resultValueCount); + computeBottom = true; + } + + std::vector< std::vector >& depth = m_cellResults->cellScalarResults(depthResultGridIndex); + std::vector< std::vector >& dx = m_cellResults->cellScalarResults(dxResultGridIndex); + std::vector< std::vector >& dy = m_cellResults->cellScalarResults(dyResultGridIndex); + std::vector< std::vector >& dz = m_cellResults->cellScalarResults(dzResultGridIndex); + std::vector< std::vector >& tops = m_cellResults->cellScalarResults(topsResultGridIndex); + std::vector< std::vector >& bottom = m_cellResults->cellScalarResults(bottomResultGridIndex); + + size_t cellIdx = 0; + for (cellIdx = 0; cellIdx < m_ownerMainGrid->cells().size(); cellIdx++) + { + const RigCell& cell = m_ownerMainGrid->cells()[cellIdx]; + + if (computeDepth) + { + depth[0][cellIdx] = cvf::Math::abs(cell.center().z()); + } + + if (computeDx) + { + cvf::Vec3d cellWidth = cell.faceCenter(cvf::StructGridInterface::NEG_I) - cell.faceCenter(cvf::StructGridInterface::POS_I); + dx[0][cellIdx] = cvf::Math::abs(cellWidth.x()); + } + + if (computeDy) + { + cvf::Vec3d cellWidth = cell.faceCenter(cvf::StructGridInterface::NEG_J) - cell.faceCenter(cvf::StructGridInterface::POS_J); + dy[0][cellIdx] = cvf::Math::abs(cellWidth.y()); + } + + if (computeDz) + { + cvf::Vec3d cellWidth = cell.faceCenter(cvf::StructGridInterface::NEG_K) - cell.faceCenter(cvf::StructGridInterface::POS_K); + dz[0][cellIdx] = cvf::Math::abs(cellWidth.z()); + } + + if (computeTops) + { + tops[0][cellIdx] = cvf::Math::abs(cell.faceCenter(cvf::StructGridInterface::NEG_K).z()); + } + + if (computeBottom) + { + bottom[0][cellIdx] = cvf::Math::abs(cell.faceCenter(cvf::StructGridInterface::POS_K).z()); + } + } +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RimReservoirCellResultsCacher::findOrLoadScalarResult(const QString& resultName) +{ + size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T; + + scalarResultIndex = this->findOrLoadScalarResult(RimDefines::STATIC_NATIVE, resultName); + + if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) + { + scalarResultIndex = this->findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, resultName); + } + + if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) + { + scalarResultIndex = m_cellResults->findScalarResultIndex(RimDefines::GENERATED, resultName); + } + + if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) + { + scalarResultIndex = m_cellResults->findScalarResultIndex(RimDefines::INPUT_PROPERTY, resultName); + } + + return scalarResultIndex; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimReservoirCellResultsCacher::setCellResults(RigReservoirCellResults* cellResults) +{ + m_cellResults = cellResults; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimReservoirCellResultsCacher::setMainGrid(RigMainGrid* mainGrid) +{ + m_ownerMainGrid = mainGrid; +} + CAF_PDM_SOURCE_INIT(RimReservoirCellResultsCacheEntryInfo, "ResultCacheEntryInfo"); diff --git a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsCacher.h b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsCacher.h index a07a3bf7e2..fcf703e02d 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsCacher.h +++ b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsCacher.h @@ -26,6 +26,8 @@ class RimReservoirCellResultsCacheEntryInfo; class RigReservoirCellResults; +class RifReaderInterface; +class RigMainGrid; class RimReservoirCellResultsCacher : public caf::PdmObject { @@ -34,23 +36,37 @@ public: RimReservoirCellResultsCacher(); virtual ~RimReservoirCellResultsCacher(); - //RigReservoirCellResults* cellResults() const { return m_cellResults; } - void setCellResults(RigReservoirCellResults* cellResults) { m_cellResults = cellResults; } + // Fields + caf::PdmField m_resultCacheFileName; + caf::PdmPointersField + m_resultCacheMetaData; + RigReservoirCellResults* cellResults() { return m_cellResults; } + const RigReservoirCellResults* cellResults() const { return m_cellResults; } - virtual void setupBeforeSave(); + void setCellResults(RigReservoirCellResults* cellResults); + void setMainGrid(RigMainGrid* mainGrid); - caf::PdmField m_resultCacheFileName; - caf::PdmPointersField m_resultCacheMetaData; + void setReaderInterface(RifReaderInterface* readerInterface); + RifReaderInterface* readerInterface(); - + void loadOrComputeSOIL(); + void loadOrComputeSOILForTimeStep(size_t timeStepIndex); + void computeDepthRelatedResults(); + + size_t findOrLoadScalarResultForTimeStep(RimDefines::ResultCatType type, const QString& resultName, size_t timeStepIndex); + size_t findOrLoadScalarResult(RimDefines::ResultCatType type, const QString& resultName); + size_t findOrLoadScalarResult(const QString& resultName); ///< Simplified search. Assumes unique names across types. + + // Overridden methods from PdmObject + virtual void setupBeforeSave(); private: - QString getValidCacheFileName(); - QString getCacheDirectoryPath(); - - RigReservoirCellResults* m_cellResults; - + QString getValidCacheFileName(); + QString getCacheDirectoryPath(); + cvf::ref m_readerInterface; + RigReservoirCellResults* m_cellResults; + RigMainGrid* m_ownerMainGrid; }; class RimReservoirCellResultsCacheEntryInfo : public caf::PdmObject diff --git a/ApplicationCode/ProjectDataModel/RimReservoirView.cpp b/ApplicationCode/ProjectDataModel/RimReservoirView.cpp index be44b948a3..353698c7bd 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirView.cpp +++ b/ApplicationCode/ProjectDataModel/RimReservoirView.cpp @@ -272,11 +272,11 @@ void RimReservoirView::updateViewerWidgetWindowTitle() void RimReservoirView::clampCurrentTimestep() { // Clamp the current timestep to actual possibilities - if (this->currentGridCellResults()) + if (this->currentGridCellResults()->cellResults()) { - if (m_currentTimeStep() >= static_cast(this->currentGridCellResults()->maxTimeStepCount())) + if (m_currentTimeStep() >= static_cast(this->currentGridCellResults()->cellResults()->maxTimeStepCount())) { - m_currentTimeStep = static_cast(this->currentGridCellResults()->maxTimeStepCount()) -1; + m_currentTimeStep = static_cast(this->currentGridCellResults()->cellResults()->maxTimeStepCount()) -1; } } @@ -463,7 +463,7 @@ void RimReservoirView::createDisplayModel() CVF_ASSERT(currentGridCellResults()); size_t i; - for (i = 0; i < currentGridCellResults()->maxTimeStepCount(); i++) + for (i = 0; i < currentGridCellResults()->cellResults()->maxTimeStepCount(); i++) { timeStepIndices.push_back(i); } @@ -711,7 +711,7 @@ void RimReservoirView::loadDataAndUpdate() RIApplication* app = RIApplication::instance(); if (app->preferences()->autocomputeSOIL) { - RigReservoirCellResults* results = currentGridCellResults(); + RimReservoirCellResultsCacher* results = currentGridCellResults(); CVF_ASSERT(results); results->loadOrComputeSOIL(); } @@ -970,16 +970,13 @@ void RimReservoirView::setupBeforeSave() //-------------------------------------------------------------------------------------------------- /// Convenience for quick access to results //-------------------------------------------------------------------------------------------------- -RigReservoirCellResults* RimReservoirView::currentGridCellResults() +RimReservoirCellResultsCacher* RimReservoirView::currentGridCellResults() { - if (m_reservoir && - m_reservoir->reservoirData() && - m_reservoir->reservoirData()->mainGrid() - ) + if (m_reservoir) { RifReaderInterface::PorosityModelResultType porosityModel = RigReservoirCellResults::convertFromProjectModelPorosityModel(cellResult->porosityModel()); - return m_reservoir->reservoirData()->results(porosityModel); + return m_reservoir->results(porosityModel); } return NULL; diff --git a/ApplicationCode/ProjectDataModel/RimReservoirView.h b/ApplicationCode/ProjectDataModel/RimReservoirView.h index af46ea2515..a0cb0126e4 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirView.h +++ b/ApplicationCode/ProjectDataModel/RimReservoirView.h @@ -118,7 +118,7 @@ public: caf::PdmField animationMode; // Access internal objects - RigReservoirCellResults* currentGridCellResults(); + RimReservoirCellResultsCacher* currentGridCellResults(); RigActiveCellInfo* currentActiveCellInfo(); void setEclipseCase(RimReservoir* reservoir); diff --git a/ApplicationCode/ProjectDataModel/RimResultDefinition.cpp b/ApplicationCode/ProjectDataModel/RimResultDefinition.cpp index a255d57408..c3fbd388eb 100644 --- a/ApplicationCode/ProjectDataModel/RimResultDefinition.cpp +++ b/ApplicationCode/ProjectDataModel/RimResultDefinition.cpp @@ -94,7 +94,7 @@ QList RimResultDefinition::calculateValueOptions(const c { if (m_reservoirView && m_reservoirView->currentGridCellResults()) { - QStringList varList = m_reservoirView->currentGridCellResults()->resultNames(resultType()); + QStringList varList = m_reservoirView->currentGridCellResults()->cellResults()->resultNames(resultType()); QList optionList; int i; for (i = 0; i < varList.size(); ++i) @@ -119,8 +119,8 @@ size_t RimResultDefinition::gridScalarIndex() const { if (m_gridScalarResultIndex == cvf::UNDEFINED_SIZE_T) { - const RigReservoirCellResults* gridCellResults = m_reservoirView->currentGridCellResults(); - if (gridCellResults) m_gridScalarResultIndex = gridCellResults->findScalarResultIndex(resultType(), resultVariable()); + const RimReservoirCellResultsCacher* gridCellResults = m_reservoirView->currentGridCellResults(); + if (gridCellResults) m_gridScalarResultIndex = gridCellResults->cellResults()->findScalarResultIndex(resultType(), resultVariable()); } return m_gridScalarResultIndex; } @@ -130,7 +130,7 @@ size_t RimResultDefinition::gridScalarIndex() const //-------------------------------------------------------------------------------------------------- void RimResultDefinition::loadResult() { - RigReservoirCellResults* gridCellResults = m_reservoirView->currentGridCellResults(); + RimReservoirCellResultsCacher* gridCellResults = m_reservoirView->currentGridCellResults(); if (gridCellResults) { m_gridScalarResultIndex = gridCellResults->findOrLoadScalarResult(resultType(), resultVariable); @@ -148,8 +148,8 @@ void RimResultDefinition::loadResult() //-------------------------------------------------------------------------------------------------- bool RimResultDefinition::hasStaticResult() const { - const RigReservoirCellResults* gridCellResults = m_reservoirView->currentGridCellResults(); - if (hasResult() && gridCellResults->timeStepCount(m_gridScalarResultIndex) == 1 ) + const RimReservoirCellResultsCacher* gridCellResults = m_reservoirView->currentGridCellResults(); + if (hasResult() && gridCellResults->cellResults()->timeStepCount(m_gridScalarResultIndex) == 1 ) { return true; } @@ -166,7 +166,7 @@ bool RimResultDefinition::hasResult() const { if (m_gridScalarResultIndex != cvf::UNDEFINED_SIZE_T) return true; - const RigReservoirCellResults* gridCellResults = m_reservoirView->currentGridCellResults(); + const RigReservoirCellResults* gridCellResults = m_reservoirView->currentGridCellResults()->cellResults(); if (gridCellResults) { m_gridScalarResultIndex = gridCellResults->findScalarResultIndex(resultType(), resultVariable()); @@ -182,7 +182,7 @@ bool RimResultDefinition::hasResult() const //-------------------------------------------------------------------------------------------------- bool RimResultDefinition::hasDynamicResult() const { - const RigReservoirCellResults* gridCellResults = m_reservoirView->currentGridCellResults(); + const RigReservoirCellResults* gridCellResults = m_reservoirView->currentGridCellResults()->cellResults(); if (hasResult() && gridCellResults->timeStepCount(m_gridScalarResultIndex) > 1 ) return true; else diff --git a/ApplicationCode/ProjectDataModel/RimResultReservoir.cpp b/ApplicationCode/ProjectDataModel/RimResultReservoir.cpp index 0305842bac..655a175c0c 100644 --- a/ApplicationCode/ProjectDataModel/RimResultReservoir.cpp +++ b/ApplicationCode/ProjectDataModel/RimResultReservoir.cpp @@ -52,7 +52,7 @@ bool RimResultReservoir::openEclipseGridFile() progInfo.setProgressDescription("Open Grid File"); progInfo.setNextProgressIncrement(48); // Early exit if reservoir data is created - if (m_rigEclipseCase.notNull()) return true; + if (this->reservoirData()) return true; cvf::ref readerInterface; @@ -60,8 +60,6 @@ bool RimResultReservoir::openEclipseGridFile() { readerInterface = this->createMockModel(this->caseName()); - m_rigEclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(readerInterface.p()); - m_rigEclipseCase->results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(readerInterface.p()); } else { @@ -78,12 +76,15 @@ bool RimResultReservoir::openEclipseGridFile() return false; } - m_rigEclipseCase = eclipseCase; + this->setReservoirData( eclipseCase.p() ); } + results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(readerInterface.p()); + results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(readerInterface.p()); + progInfo.incrementProgress(); - CVF_ASSERT(m_rigEclipseCase.notNull()); + CVF_ASSERT(this->reservoirData()); CVF_ASSERT(readerInterface.notNull()); progInfo.setProgressDescription("Computing Case Cache"); @@ -102,9 +103,6 @@ bool RimResultReservoir::openAndReadActiveCellData(RigEclipseCase* mainEclipseCa if (caseName().contains("Result Mock Debug Model")) { readerInterface = this->createMockModel(this->caseName()); - - m_rigEclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(readerInterface.p()); - m_rigEclipseCase->results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(readerInterface.p()); } else { @@ -127,13 +125,16 @@ bool RimResultReservoir::openAndReadActiveCellData(RigEclipseCase* mainEclipseCa readerInterface->close(); - m_rigEclipseCase = eclipseCase; + this->setReservoirData( eclipseCase.p() ); } - CVF_ASSERT(m_rigEclipseCase.notNull()); + results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(readerInterface.p()); + results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(readerInterface.p()); + + CVF_ASSERT(this->reservoirData()); CVF_ASSERT(readerInterface.notNull()); - m_rigEclipseCase->computeCachedData(); + reservoirData()->computeCachedData(); return true; } @@ -212,7 +213,7 @@ cvf::ref RimResultReservoir::createMockModel(QString modelNa } - m_rigEclipseCase = reservoir; + this->setReservoirData( reservoir.p() ); return mockFileInterface.p(); } diff --git a/ApplicationCode/ProjectDataModel/RimStatisticalCalculation.cpp b/ApplicationCode/ProjectDataModel/RimStatisticalCalculation.cpp index 45639a773c..98a9381a3d 100644 --- a/ApplicationCode/ProjectDataModel/RimStatisticalCalculation.cpp +++ b/ApplicationCode/ProjectDataModel/RimStatisticalCalculation.cpp @@ -60,9 +60,9 @@ RimStatisticalCalculation::~RimStatisticalCalculation() void RimStatisticalCalculation::setMainGrid(RigMainGrid* mainGrid) { CVF_ASSERT(mainGrid); - CVF_ASSERT(m_rigEclipseCase.notNull()); + CVF_ASSERT(this->reservoirData()); - m_rigEclipseCase->setMainGrid(mainGrid); + reservoirData()->setMainGrid(mainGrid); } //-------------------------------------------------------------------------------------------------- @@ -70,7 +70,7 @@ void RimStatisticalCalculation::setMainGrid(RigMainGrid* mainGrid) //-------------------------------------------------------------------------------------------------- bool RimStatisticalCalculation::openEclipseGridFile() { - if (m_rigEclipseCase.notNull()) return true; + if (this->reservoirData()) return true; cvf::ref eclipseCase = new RigEclipseCase; @@ -79,10 +79,10 @@ bool RimStatisticalCalculation::openEclipseGridFile() return false; } - m_rigEclipseCase = eclipseCase; + this->setReservoirData( eclipseCase.p() ); - m_rigEclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(m_readerInterface.p()); - m_rigEclipseCase->results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(m_readerInterface.p()); + results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(m_readerInterface.p()); + results(RifReaderInterface::FRACTURE_RESULTS)->setReaderInterface(m_readerInterface.p()); return true; } @@ -116,12 +116,12 @@ RimStatisticalCollection* RimStatisticalCalculation::parentStatisticalCollection //-------------------------------------------------------------------------------------------------- void RimStatisticalCalculation::computeStatistics() { - if (m_rigEclipseCase.isNull()) + if (this->reservoirData() == NULL) { openEclipseGridFile(); } - cvf::Collection sourceCases; + std::vector sourceCases; getSourceCases(sourceCases); @@ -132,7 +132,7 @@ void RimStatisticalCalculation::computeStatistics() // The first source has been read completely from disk, and contains grid and meta data // Use this information for all cases in the case group - size_t timeStepCount = sourceCases.at(0)->results(RifReaderInterface::MATRIX_RESULTS)->maxTimeStepCount(); + size_t timeStepCount = sourceCases.at(0)->results(RifReaderInterface::MATRIX_RESULTS)->cellResults()->maxTimeStepCount(); RigStatisticsConfig statisticsConfig; @@ -183,7 +183,7 @@ void RimStatisticalCalculation::computeStatistics() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimStatisticalCalculation::getSourceCases(cvf::Collection& sourceCases) +void RimStatisticalCalculation::getSourceCases(std::vector& sourceCases) { RimIdenticalGridCaseGroup* gridCaseGroup = caseGroup(); if (gridCaseGroup) @@ -195,7 +195,7 @@ void RimStatisticalCalculation::getSourceCases(cvf::Collection& CVF_ASSERT(gridCaseGroup->caseCollection->reservoirs[i]); CVF_ASSERT(gridCaseGroup->caseCollection->reservoirs[i]->reservoirData()); - RigEclipseCase* sourceCase = gridCaseGroup->caseCollection->reservoirs[i]->reservoirData(); + RimReservoir* sourceCase = gridCaseGroup->caseCollection->reservoirs[i]; sourceCases.push_back(sourceCase); } } diff --git a/ApplicationCode/ProjectDataModel/RimStatisticalCalculation.h b/ApplicationCode/ProjectDataModel/RimStatisticalCalculation.h index 9fb8b706c3..d7b67ce785 100644 --- a/ApplicationCode/ProjectDataModel/RimStatisticalCalculation.h +++ b/ApplicationCode/ProjectDataModel/RimStatisticalCalculation.h @@ -59,7 +59,7 @@ public: private: RimIdenticalGridCaseGroup* caseGroup(); - void getSourceCases(cvf::Collection& sourceCases); + void getSourceCases(std::vector& sourceCases); private: cvf::ref m_readerInterface; diff --git a/ApplicationCode/ReservoirDataModel/ReservoirDataModel_UnitTests/CMakeLists.txt b/ApplicationCode/ReservoirDataModel/ReservoirDataModel_UnitTests/CMakeLists.txt index d21c6599a9..9f20f90ac9 100644 --- a/ApplicationCode/ReservoirDataModel/ReservoirDataModel_UnitTests/CMakeLists.txt +++ b/ApplicationCode/ReservoirDataModel/ReservoirDataModel_UnitTests/CMakeLists.txt @@ -22,6 +22,9 @@ include_directories( ${ResInsight_SOURCE_DIR}/cafProjectDataModel ${ResInsight_SOURCE_DIR}/CommonCode + + #Remove when RigStatistics is out + ${ResInsight_SOURCE_DIR}/ApplicationCode/ModelVisualization ) # Populate the filenames into variable lists diff --git a/ApplicationCode/ReservoirDataModel/RigEclipseCase.cpp b/ApplicationCode/ReservoirDataModel/RigEclipseCase.cpp index d557e6845b..8724e9ff4c 100644 --- a/ApplicationCode/ReservoirDataModel/RigEclipseCase.cpp +++ b/ApplicationCode/ReservoirDataModel/RigEclipseCase.cpp @@ -425,7 +425,7 @@ cvf::ref RigEclipseCase::dataAccessObject(const return NULL; } - +/* //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -438,3 +438,4 @@ void RigEclipseCase::closeReaderInterface() readerInterface->close(); } } +*/ \ No newline at end of file diff --git a/ApplicationCode/ReservoirDataModel/RigEclipseCase.h b/ApplicationCode/ReservoirDataModel/RigEclipseCase.h index f16ba77562..9deeedf3f0 100644 --- a/ApplicationCode/ReservoirDataModel/RigEclipseCase.h +++ b/ApplicationCode/ReservoirDataModel/RigEclipseCase.h @@ -68,7 +68,7 @@ public: bool findSharedSourceFace(cvf::StructGridInterface::FaceType& sharedSourceFace, const RigWellResultCell& sourceWellCellResult, const RigWellResultCell& otherWellCellResult) const; void computeCachedData(); - void closeReaderInterface(); + //void closeReaderInterface(); private: void computeActiveCellData(); diff --git a/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.cpp b/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.cpp index 35f4829d2c..6bb393d684 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.cpp +++ b/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.cpp @@ -280,146 +280,6 @@ double RigReservoirCellResults::cellScalarResult( size_t scalarResultIndex, size } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -size_t RigReservoirCellResults::findOrLoadScalarResultForTimeStep(RimDefines::ResultCatType type, const QString& resultName, size_t timeStepIndex) -{ - // Special handling for SOIL - if (type == RimDefines::DYNAMIC_NATIVE && resultName.toUpper() == "SOIL") - { - loadOrComputeSOILForTimeStep(timeStepIndex); - } - - size_t resultGridIndex = cvf::UNDEFINED_SIZE_T; - - resultGridIndex = findScalarResultIndex(type, resultName); - - if (resultGridIndex == cvf::UNDEFINED_SIZE_T) return cvf::UNDEFINED_SIZE_T; - - if (type == RimDefines::GENERATED) - { - return cvf::UNDEFINED_SIZE_T; - } - - if (m_readerInterface.notNull()) - { - size_t timeStepCount = m_resultInfos[resultGridIndex].m_timeStepDates.size(); - - bool resultLoadingSucess = true; - - if (type == RimDefines::DYNAMIC_NATIVE && timeStepCount > 0) - { - m_cellScalarResults[resultGridIndex].resize(timeStepCount); - - std::vector& values = m_cellScalarResults[resultGridIndex][timeStepIndex]; - if (values.size() == 0) - { - if (!m_readerInterface->dynamicResult(resultName, RifReaderInterface::MATRIX_RESULTS, timeStepIndex, &values)) - { - resultLoadingSucess = false; - } - } - } - else if (type == RimDefines::STATIC_NATIVE) - { - m_cellScalarResults[resultGridIndex].resize(1); - - std::vector& values = m_cellScalarResults[resultGridIndex][0]; - if (!m_readerInterface->staticResult(resultName, RifReaderInterface::MATRIX_RESULTS, &values)) - { - resultLoadingSucess = false; - } - } - - if (!resultLoadingSucess) - { - // Error logging - CVF_ASSERT(false); - } - } - - return resultGridIndex; - -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -size_t RigReservoirCellResults::findOrLoadScalarResult(RimDefines::ResultCatType type, const QString& resultName) -{ - size_t resultGridIndex = cvf::UNDEFINED_SIZE_T; - - resultGridIndex = findScalarResultIndex(type, resultName); - - if (resultGridIndex == cvf::UNDEFINED_SIZE_T) return cvf::UNDEFINED_SIZE_T; - - if (cellScalarResults(resultGridIndex).size()) return resultGridIndex; - - if (type == RimDefines::GENERATED) - { - return cvf::UNDEFINED_SIZE_T; - } - - if (m_readerInterface.notNull()) - { - // Add one more result to result container - size_t timeStepCount = m_resultInfos[resultGridIndex].m_timeStepDates.size(); - - bool resultLoadingSucess = true; - - if (type == RimDefines::DYNAMIC_NATIVE && timeStepCount > 0) - { - m_cellScalarResults[resultGridIndex].resize(timeStepCount); - - size_t i; - for (i = 0; i < timeStepCount; i++) - { - std::vector& values = m_cellScalarResults[resultGridIndex][i]; - if (!m_readerInterface->dynamicResult(resultName, RifReaderInterface::MATRIX_RESULTS, i, &values)) - { - resultLoadingSucess = false; - } - } - } - else if (type == RimDefines::STATIC_NATIVE) - { - m_cellScalarResults[resultGridIndex].resize(1); - - std::vector& values = m_cellScalarResults[resultGridIndex][0]; - if (!m_readerInterface->staticResult(resultName, RifReaderInterface::MATRIX_RESULTS, &values)) - { - resultLoadingSucess = false; - } - } - - if (!resultLoadingSucess) - { - // Remove last scalar result because loading of result failed - m_cellScalarResults[resultGridIndex].clear(); - } - } - - return resultGridIndex; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigReservoirCellResults::setReaderInterface(RifReaderInterface* readerInterface) -{ - m_readerInterface = readerInterface; -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RifReaderInterface* RigReservoirCellResults::readerInterface() -{ - return m_readerInterface.p(); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -464,234 +324,6 @@ size_t RigReservoirCellResults::findScalarResultIndex(const QString& resultName) return scalarResultIndex; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigReservoirCellResults::loadOrComputeSOIL() -{ - for (size_t timeStepIdx = 0; timeStepIdx < maxTimeStepCount(); timeStepIdx++) - { - loadOrComputeSOILForTimeStep(timeStepIdx); - } -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigReservoirCellResults::loadOrComputeSOILForTimeStep(size_t timeStepIndex) -{ - size_t scalarIndexSWAT = findOrLoadScalarResultForTimeStep(RimDefines::DYNAMIC_NATIVE, "SWAT", timeStepIndex); - size_t scalarIndexSGAS = findOrLoadScalarResultForTimeStep(RimDefines::DYNAMIC_NATIVE, "SGAS", timeStepIndex); - - // Early exit if none of SWAT or SGAS is present - if (scalarIndexSWAT == cvf::UNDEFINED_SIZE_T && scalarIndexSGAS == cvf::UNDEFINED_SIZE_T) - { - return; - } - - size_t soilResultValueCount = 0; - size_t soilTimeStepCount = 0; - - std::vector* swatForTimeStep = NULL; - std::vector* sgasForTimeStep = NULL; - if (scalarIndexSWAT != cvf::UNDEFINED_SIZE_T) - { - swatForTimeStep = &(cellScalarResults(scalarIndexSWAT, timeStepIndex)); - if (swatForTimeStep->size() == 0) - { - swatForTimeStep = NULL; - } - else - { - soilResultValueCount = swatForTimeStep->size(); - soilTimeStepCount = m_resultInfos[scalarIndexSWAT].m_timeStepDates.size(); - } - } - - if (scalarIndexSGAS != cvf::UNDEFINED_SIZE_T) - { - sgasForTimeStep = &(cellScalarResults(scalarIndexSGAS, timeStepIndex)); - if (sgasForTimeStep->size() == 0) - { - sgasForTimeStep = NULL; - } - else - { - soilResultValueCount = qMax(soilResultValueCount, sgasForTimeStep->size()); - - size_t sgasTimeStepCount = m_resultInfos[scalarIndexSGAS].m_timeStepDates.size(); - soilTimeStepCount = qMax(soilTimeStepCount, sgasTimeStepCount); - } - } - - size_t soilResultGridIndex = findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL"); - if (soilResultGridIndex == cvf::UNDEFINED_SIZE_T) - { - soilResultGridIndex = addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL"); - CVF_ASSERT(soilResultGridIndex != cvf::UNDEFINED_SIZE_T); - - m_cellScalarResults[soilResultGridIndex].resize(soilTimeStepCount); - - for (size_t timeStepIdx = 0; timeStepIdx < soilTimeStepCount; timeStepIdx++) - { - m_cellScalarResults[soilResultGridIndex][timeStepIdx].resize(soilResultValueCount); - } - } - - std::vector& soilForTimeStep = cellScalarResults(soilResultGridIndex, timeStepIndex); - -#pragma omp parallel for - for (int idx = 0; idx < static_cast(soilResultValueCount); idx++) - { - double soilValue = 1.0; - if (sgasForTimeStep) - { - soilValue -= sgasForTimeStep->at(idx); - } - - if (swatForTimeStep) - { - soilValue -= swatForTimeStep->at(idx); - } - - soilForTimeStep[idx] = soilValue; - } -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigReservoirCellResults::computeDepthRelatedResults() -{ - size_t depthResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "DEPTH"); - size_t dxResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "DX"); - size_t dyResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "DY"); - size_t dzResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "DZ"); - size_t topsResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "TOPS"); - size_t bottomResultGridIndex = findOrLoadScalarResult(RimDefines::STATIC_NATIVE, "BOTTOM"); - - bool computeDepth = false; - bool computeDx = false; - bool computeDy = false; - bool computeDz = false; - bool computeTops = false; - bool computeBottom = false; - - size_t resultValueCount = m_ownerMainGrid->cells().size(); - - if (depthResultGridIndex == cvf::UNDEFINED_SIZE_T) - { - depthResultGridIndex = addStaticScalarResult(RimDefines::STATIC_NATIVE, "DEPTH", resultValueCount); - computeDepth = true; - } - - if (dxResultGridIndex == cvf::UNDEFINED_SIZE_T) - { - dxResultGridIndex = addStaticScalarResult(RimDefines::STATIC_NATIVE, "DX", resultValueCount); - computeDx = true; - } - - if (dyResultGridIndex == cvf::UNDEFINED_SIZE_T) - { - dyResultGridIndex = addStaticScalarResult(RimDefines::STATIC_NATIVE, "DY", resultValueCount); - computeDy = true; - } - - if (dzResultGridIndex == cvf::UNDEFINED_SIZE_T) - { - dzResultGridIndex = addStaticScalarResult(RimDefines::STATIC_NATIVE, "DZ", resultValueCount); - computeDz = true; - } - - if (topsResultGridIndex == cvf::UNDEFINED_SIZE_T) - { - topsResultGridIndex = addStaticScalarResult(RimDefines::STATIC_NATIVE, "TOPS", resultValueCount); - computeTops = true; - } - - if (bottomResultGridIndex == cvf::UNDEFINED_SIZE_T) - { - bottomResultGridIndex = addStaticScalarResult(RimDefines::STATIC_NATIVE, "BOTTOM", resultValueCount); - computeBottom = true; - } - - std::vector< std::vector >& depth = cellScalarResults(depthResultGridIndex); - std::vector< std::vector >& dx = cellScalarResults(dxResultGridIndex); - std::vector< std::vector >& dy = cellScalarResults(dyResultGridIndex); - std::vector< std::vector >& dz = cellScalarResults(dzResultGridIndex); - std::vector< std::vector >& tops = cellScalarResults(topsResultGridIndex); - std::vector< std::vector >& bottom = cellScalarResults(bottomResultGridIndex); - - size_t cellIdx = 0; - for (cellIdx = 0; cellIdx < m_ownerMainGrid->cells().size(); cellIdx++) - { - const RigCell& cell = m_ownerMainGrid->cells()[cellIdx]; - - if (computeDepth) - { - depth[0][cellIdx] = cvf::Math::abs(cell.center().z()); - } - - if (computeDx) - { - cvf::Vec3d cellWidth = cell.faceCenter(cvf::StructGridInterface::NEG_I) - cell.faceCenter(cvf::StructGridInterface::POS_I); - dx[0][cellIdx] = cvf::Math::abs(cellWidth.x()); - } - - if (computeDy) - { - cvf::Vec3d cellWidth = cell.faceCenter(cvf::StructGridInterface::NEG_J) - cell.faceCenter(cvf::StructGridInterface::POS_J); - dy[0][cellIdx] = cvf::Math::abs(cellWidth.y()); - } - - if (computeDz) - { - cvf::Vec3d cellWidth = cell.faceCenter(cvf::StructGridInterface::NEG_K) - cell.faceCenter(cvf::StructGridInterface::POS_K); - dz[0][cellIdx] = cvf::Math::abs(cellWidth.z()); - } - - if (computeTops) - { - tops[0][cellIdx] = cvf::Math::abs(cell.faceCenter(cvf::StructGridInterface::NEG_K).z()); - } - - if (computeBottom) - { - bottom[0][cellIdx] = cvf::Math::abs(cell.faceCenter(cvf::StructGridInterface::POS_K).z()); - } - } -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -size_t RigReservoirCellResults::findOrLoadScalarResult(const QString& resultName) -{ - size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T; - - scalarResultIndex = this->findOrLoadScalarResult(RimDefines::STATIC_NATIVE, resultName); - - if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) - { - scalarResultIndex = this->findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, resultName); - } - - if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) - { - scalarResultIndex = this->findScalarResultIndex(RimDefines::GENERATED, resultName); - } - - if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) - { - scalarResultIndex = this->findScalarResultIndex(RimDefines::INPUT_PROPERTY, resultName); - } - - return scalarResultIndex; -} - //-------------------------------------------------------------------------------------------------- /// Adds an empty scalar set, and returns the scalarResultIndex to it. /// if resultName already exists, it returns the scalarResultIndex to the existing result. @@ -793,6 +425,10 @@ void RigReservoirCellResults::setTimeStepDates(size_t scalarResultIndex, const s CVF_ASSERT(scalarResultIndex < m_resultInfos.size() ); m_resultInfos[scalarResultIndex].m_timeStepDates = dates; + + // We need this. But not yet ... + //std::vector< std::vector >& dataValues = this->cellScalarResults(scalarResultIndex); + //dataValues.resize(dates.size()); } //-------------------------------------------------------------------------------------------------- @@ -800,7 +436,7 @@ void RigReservoirCellResults::setTimeStepDates(size_t scalarResultIndex, const s //-------------------------------------------------------------------------------------------------- size_t RigReservoirCellResults::maxTimeStepCount() const { - int maxTsCount = 0; + size_t maxTsCount = 0; std::vector::const_iterator it; for (it = m_resultInfos.begin(); it != m_resultInfos.end(); it++) diff --git a/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.h b/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.h index b37c94d2d5..421e9d323f 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.h +++ b/ApplicationCode/ReservoirDataModel/RigReservoirCellResults.h @@ -35,49 +35,45 @@ class RigReservoirCellResults : public cvf::Object public: RigReservoirCellResults(RigMainGrid* ownerGrid); - void setReaderInterface(RifReaderInterface* readerInterface); - RifReaderInterface* readerInterface(); + //void setReaderInterface(RifReaderInterface* readerInterface); + //RifReaderInterface* readerInterface(); // Max and min values of the results - void recalculateMinMax(size_t scalarResultIndex); - void minMaxCellScalarValues(size_t scalarResultIndex, double& min, double& max); - void minMaxCellScalarValues(size_t scalarResultIndex, size_t timeStepIndex, double& min, double& max); - const std::vector& cellScalarValuesHistogram(size_t scalarResultIndex); - void p10p90CellScalarValues(size_t scalarResultIndex, double& p10, double& p90); - void meanCellScalarValues(size_t scalarResultIndex, double& meanValue); + void recalculateMinMax(size_t scalarResultIndex); + void minMaxCellScalarValues(size_t scalarResultIndex, double& min, double& max); + void minMaxCellScalarValues(size_t scalarResultIndex, size_t timeStepIndex, double& min, double& max); + const std::vector& cellScalarValuesHistogram(size_t scalarResultIndex); + void p10p90CellScalarValues(size_t scalarResultIndex, double& p10, double& p90); + void meanCellScalarValues(size_t scalarResultIndex, double& meanValue); // Access meta-information about the results - size_t resultCount() const; - size_t timeStepCount(size_t scalarResultIndex) const; - size_t maxTimeStepCount() const; - QStringList resultNames(RimDefines::ResultCatType type) const; - bool isUsingGlobalActiveIndex(size_t scalarResultIndex) const; + size_t resultCount() const; + size_t timeStepCount(size_t scalarResultIndex) const; + size_t maxTimeStepCount() const; + QStringList resultNames(RimDefines::ResultCatType type) const; + bool isUsingGlobalActiveIndex(size_t scalarResultIndex) const; - QDateTime timeStepDate(size_t scalarResultIndex, size_t timeStepIndex) const; - std::vector timeStepDates(size_t scalarResultIndex) const; - void setTimeStepDates(size_t scalarResultIndex, const std::vector& dates); + QDateTime timeStepDate(size_t scalarResultIndex, size_t timeStepIndex) const; + std::vector timeStepDates(size_t scalarResultIndex) const; + void setTimeStepDates(size_t scalarResultIndex, const std::vector& dates); // Find or create a slot for the results - size_t findOrLoadScalarResultForTimeStep(RimDefines::ResultCatType type, const QString& resultName, size_t timeStepIndex); - size_t findOrLoadScalarResult(RimDefines::ResultCatType type, const QString& resultName); - size_t findOrLoadScalarResult(const QString& resultName); ///< Simplified search. Assumes unique names across types. - size_t findScalarResultIndex(RimDefines::ResultCatType type, const QString& resultName) const; - size_t findScalarResultIndex(const QString& resultName) const; - size_t addEmptyScalarResult(RimDefines::ResultCatType type, const QString& resultName); - QString makeResultNameUnique(const QString& resultNameProposal) const; - void removeResult(const QString& resultName); - void clearAllResults(); + size_t findScalarResultIndex(RimDefines::ResultCatType type, const QString& resultName) const; + size_t findScalarResultIndex(const QString& resultName) const; + + size_t addEmptyScalarResult(RimDefines::ResultCatType type, const QString& resultName); + QString makeResultNameUnique(const QString& resultNameProposal) const; + + void removeResult(const QString& resultName); + void clearAllResults(); - void loadOrComputeSOIL(); - void loadOrComputeSOILForTimeStep(size_t timeStepIndex); - void computeDepthRelatedResults(); // Access the results data - const std::vector< std::vector > & cellScalarResults(size_t scalarResultIndex) const; - std::vector< std::vector > & cellScalarResults(size_t scalarResultIndex); - std::vector& cellScalarResults(size_t scalarResultIndex, size_t timeStepIndex); - double cellScalarResult(size_t scalarResultIndex, size_t timeStepIndex, size_t resultValueIndex); + const std::vector< std::vector > & cellScalarResults(size_t scalarResultIndex) const; + std::vector< std::vector > & cellScalarResults(size_t scalarResultIndex); + std::vector& cellScalarResults(size_t scalarResultIndex, size_t timeStepIndex); + double cellScalarResult(size_t scalarResultIndex, size_t timeStepIndex, size_t resultValueIndex); static RifReaderInterface::PorosityModelResultType convertFromProjectModelPorosityModel(RimDefines::PorosityModelType porosityModel); @@ -97,8 +93,10 @@ public: const std::vector& infoForEachResultIndex() { return m_resultInfos;} -private: - size_t addStaticScalarResult(RimDefines::ResultCatType type, const QString& resultName, size_t resultValueCount); +public: + size_t addStaticScalarResult(RimDefines::ResultCatType type, + const QString& resultName, + size_t resultValueCount); private: std::vector< std::vector< std::vector > > m_cellScalarResults; ///< Scalar results on the complete reservoir for each Result index (ResultVariable) and timestep @@ -113,7 +111,7 @@ private: private: std::vector m_resultInfos; - cvf::ref m_readerInterface; + RigMainGrid* m_ownerMainGrid; }; diff --git a/ApplicationCode/ReservoirDataModel/RigStatistics.cpp b/ApplicationCode/ReservoirDataModel/RigStatistics.cpp index d9ec30b045..cb593a8050 100644 --- a/ApplicationCode/ReservoirDataModel/RigStatistics.cpp +++ b/ApplicationCode/ReservoirDataModel/RigStatistics.cpp @@ -18,7 +18,11 @@ #include "RigStatistics.h" #include "RigReservoirCellResults.h" +#include "RimReservoirView.h" +#include "RimReservoir.h" +#include "RigEclipseCase.h" +//#include "RigEclipseCase.h" #include #include "cafProgressInfo.h" @@ -30,7 +34,8 @@ void RigStatistics::addNamedResult(RigReservoirCellResults* destinationCellResul // Use time step dates from first result in first source case CVF_ASSERT(m_sourceCases.size() > 0); - std::vector sourceTimeStepDates = m_sourceCases[0]->results(RifReaderInterface::MATRIX_RESULTS)->timeStepDates(0); + std::vector sourceTimeStepDates = m_sourceCases[0]->results(RifReaderInterface::MATRIX_RESULTS)->cellResults()->timeStepDates(0); + size_t destinationScalarResultIndex = destinationCellResults->addEmptyScalarResult(resultType, resultName); CVF_ASSERT(destinationScalarResultIndex != cvf::UNDEFINED_SIZE_T); @@ -38,6 +43,7 @@ void RigStatistics::addNamedResult(RigReservoirCellResults* destinationCellResul std::vector< std::vector >& dataValues = destinationCellResults->cellScalarResults(destinationScalarResultIndex); dataValues.resize(sourceTimeStepDates.size()); + // Initializes the size of the destination dataset to active union cell count for (int i = 0; i < sourceTimeStepDates.size(); i++) { @@ -58,7 +64,7 @@ void RigStatistics::computeActiveCellUnion() CVF_ASSERT(m_destinationCase); - RigMainGrid* mainGrid = m_sourceCases[0]->mainGrid(); + RigMainGrid* mainGrid = m_sourceCases[0]->reservoirData()->mainGrid(); CVF_ASSERT(mainGrid); m_destinationCase->activeCellInfo(RifReaderInterface::MATRIX_RESULTS)->setGlobalCellCount(mainGrid->cells().size()); @@ -84,7 +90,7 @@ void RigStatistics::computeActiveCellUnion() if (activeM[localGridCellIdx] == 0) { - if (m_sourceCases[caseIdx]->activeCellInfo(RifReaderInterface::MATRIX_RESULTS)->isActiveInMatrixModel(globalCellIdx)) + if (m_sourceCases[caseIdx]->reservoirData()->activeCellInfo(RifReaderInterface::MATRIX_RESULTS)->isActiveInMatrixModel(globalCellIdx)) { activeM[localGridCellIdx] = 1; } @@ -92,7 +98,7 @@ void RigStatistics::computeActiveCellUnion() if (activeF[localGridCellIdx] == 0) { - if (m_sourceCases[caseIdx]->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS)->isActiveInMatrixModel(globalCellIdx)) + if (m_sourceCases[caseIdx]->reservoirData()->activeCellInfo(RifReaderInterface::FRACTURE_RESULTS)->isActiveInMatrixModel(globalCellIdx)) { activeF[localGridCellIdx] = 1; } @@ -143,20 +149,20 @@ void RigStatistics::buildSourceMetaData(RimDefines::ResultCatType resultType, co { if (m_sourceCases.size() == 0) return; - std::vector timeStepDates = m_sourceCases[0]->results(RifReaderInterface::MATRIX_RESULTS)->timeStepDates(0); + std::vector timeStepDates = m_sourceCases[0]->results(RifReaderInterface::MATRIX_RESULTS)->cellResults()->timeStepDates(0); for (size_t caseIdx = 1; caseIdx < m_sourceCases.size(); caseIdx++) { - RigEclipseCase* eclipseCase = m_sourceCases.at(caseIdx); + RigEclipseCase* eclipseCase = m_sourceCases.at(caseIdx)->reservoirData(); - RigReservoirCellResults* matrixResults = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS); + RimReservoirCellResultsCacher* matrixResults = m_sourceCases[caseIdx]->results(RifReaderInterface::MATRIX_RESULTS); size_t scalarResultIndex = matrixResults->findOrLoadScalarResult(resultType, resultName); if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) { - size_t scalarResultIndex = matrixResults->addEmptyScalarResult(resultType, resultName); - matrixResults->setTimeStepDates(scalarResultIndex, timeStepDates); + size_t scalarResultIndex = matrixResults->cellResults()->addEmptyScalarResult(resultType, resultName); + matrixResults->cellResults()->setTimeStepDates(scalarResultIndex, timeStepDates); - std::vector< std::vector >& dataValues = matrixResults->cellScalarResults(scalarResultIndex); + std::vector< std::vector >& dataValues = matrixResults->cellResults()->cellScalarResults(scalarResultIndex); dataValues.resize(timeStepDates.size()); } } @@ -183,13 +189,13 @@ void RigStatistics::evaluateStatistics(const QListresults(RifReaderInterface::MATRIX_RESULTS)->findScalarResultIndex(resultType, "SWAT"); + size_t swatIndex = m_sourceCases.at(0)->results(RifReaderInterface::MATRIX_RESULTS)->cellResults()->findScalarResultIndex(resultType, "SWAT"); if (swatIndex != cvf::UNDEFINED_SIZE_T) { buildSourceMetaData(resultType, "SWAT"); } - size_t sgasIndex = m_sourceCases.at(0)->results(RifReaderInterface::MATRIX_RESULTS)->findScalarResultIndex(resultType, "SGAS"); + size_t sgasIndex = m_sourceCases.at(0)->results(RifReaderInterface::MATRIX_RESULTS)->cellResults()->findScalarResultIndex(resultType, "SGAS"); if (sgasIndex != cvf::UNDEFINED_SIZE_T) { buildSourceMetaData(resultType, "SGAS"); @@ -248,11 +254,11 @@ void RigStatistics::evaluateStatistics(const QList dataAccesObjectList; for (size_t caseIdx = 0; caseIdx < m_sourceCases.size(); caseIdx++) { - RigEclipseCase* eclipseCase = m_sourceCases.at(caseIdx); + RimReservoir* eclipseCase = m_sourceCases.at(caseIdx); size_t scalarResultIndex = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->findOrLoadScalarResultForTimeStep(resultType, resultName, dataAccessTimeStepIndex); - cvf::ref dataAccessObject = eclipseCase->dataAccessObject(grid, RifReaderInterface::MATRIX_RESULTS, dataAccessTimeStepIndex, scalarResultIndex); + cvf::ref dataAccessObject = eclipseCase->reservoirData()->dataAccessObject(grid, RifReaderInterface::MATRIX_RESULTS, dataAccessTimeStepIndex, scalarResultIndex); if (dataAccessObject.notNull()) { dataAccesObjectList.push_back(dataAccessObject.p()); @@ -355,13 +361,13 @@ void RigStatistics::evaluateStatistics(const QListcloseReaderInterface(); + eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->readerInterface()->close(); } info.setProgress(timeIndicesIdx); @@ -378,7 +384,7 @@ void RigStatistics::debugOutput(RimDefines::ResultCatType resultType, const QStr qDebug() << resultName << "timeIdx : " << timeStepIdx; - size_t scalarResultIndex = m_destinationCase->results(RifReaderInterface::MATRIX_RESULTS)->findOrLoadScalarResult(resultType, resultName); + size_t scalarResultIndex = m_destinationCase->results(RifReaderInterface::MATRIX_RESULTS)->findScalarResultIndex(resultType, resultName); cvf::ref dataAccessObject = m_destinationCase->dataAccessObject(m_destinationCase->mainGrid(), RifReaderInterface::MATRIX_RESULTS, timeStepIdx, scalarResultIndex); if (dataAccessObject.isNull()) return; @@ -392,7 +398,8 @@ void RigStatistics::debugOutput(RimDefines::ResultCatType resultType, const QStr //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RigStatistics::RigStatistics(cvf::Collection& sourceCases, const std::vector& timeStepIndices, const RigStatisticsConfig& statisticsConfig, RigEclipseCase* destinationCase) : m_sourceCases(sourceCases), +RigStatistics::RigStatistics(const std::vector& sourceCases, const std::vector& timeStepIndices, const RigStatisticsConfig& statisticsConfig, RigEclipseCase* destinationCase) + : m_sourceCases(sourceCases), m_statisticsConfig(statisticsConfig), m_destinationCase(destinationCase), m_globalCellCount(0), @@ -400,7 +407,7 @@ RigStatistics::RigStatistics(cvf::Collection& sourceCases, const { if (sourceCases.size() > 0) { - m_globalCellCount = sourceCases[0]->mainGrid()->cells().size(); + m_globalCellCount = sourceCases[0]->reservoirData()->mainGrid()->cells().size(); } CVF_ASSERT(m_destinationCase); diff --git a/ApplicationCode/ReservoirDataModel/RigStatistics.h b/ApplicationCode/ReservoirDataModel/RigStatistics.h index f0792129f8..5f0e42eb99 100644 --- a/ApplicationCode/ReservoirDataModel/RigStatistics.h +++ b/ApplicationCode/ReservoirDataModel/RigStatistics.h @@ -22,12 +22,17 @@ #include "cvfObject.h" #include "cvfCollection.h" -#include "RigEclipseCase.h" + #include #include #include +#include "RimDefines.h" + +class RimReservoir; +class RigEclipseCase; +class RigReservoirCellResults; class RigStatisticsEvaluator { @@ -124,7 +129,7 @@ public: class RigStatistics { public: - RigStatistics(cvf::Collection& sourceCases, + RigStatistics(const std::vector& sourceCases, const std::vector& timeStepIndices, const RigStatisticsConfig& statisticsConfig, RigEclipseCase* destinationCase); @@ -140,7 +145,7 @@ private: void buildSourceMetaData(RimDefines::ResultCatType resultType, const QString& resultName); private: - cvf::Collection m_sourceCases; + std::vector m_sourceCases; std::vector m_timeStepIndices; size_t m_globalCellCount; diff --git a/ApplicationCode/SocketInterface/RiaSocketServer.cpp b/ApplicationCode/SocketInterface/RiaSocketServer.cpp index 8afa8aece5..04c123c1e1 100644 --- a/ApplicationCode/SocketInterface/RiaSocketServer.cpp +++ b/ApplicationCode/SocketInterface/RiaSocketServer.cpp @@ -280,18 +280,18 @@ void RiaSocketServer::readCommandFromOctave() size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T; std::vector< std::vector >* scalarResultFrames = NULL; - if (reservoir && reservoir->reservoirData() && reservoir->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)) + if (reservoir && reservoir->results(RifReaderInterface::MATRIX_RESULTS)) { - scalarResultIndex = reservoir->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->findOrLoadScalarResult(propertyName); + scalarResultIndex = reservoir->results(RifReaderInterface::MATRIX_RESULTS)->findOrLoadScalarResult(propertyName); if (scalarResultIndex == cvf::UNDEFINED_SIZE_T && isSetProperty) { - scalarResultIndex = reservoir->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->addEmptyScalarResult(RimDefines::GENERATED, propertyName); + scalarResultIndex = reservoir->results(RifReaderInterface::MATRIX_RESULTS)->cellResults()->addEmptyScalarResult(RimDefines::GENERATED, propertyName); } if (scalarResultIndex != cvf::UNDEFINED_SIZE_T) { - scalarResultFrames = &(reservoir->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->cellScalarResults(scalarResultIndex)); + scalarResultFrames = &(reservoir->results(RifReaderInterface::MATRIX_RESULTS)->cellResults()->cellScalarResults(scalarResultIndex)); m_currentScalarIndex = scalarResultIndex; m_currentPropertyName = propertyName; } diff --git a/ApplicationCode/UserInterface/RIMainWindow.cpp b/ApplicationCode/UserInterface/RIMainWindow.cpp index 24e12b144d..cf3860f9e7 100644 --- a/ApplicationCode/UserInterface/RIMainWindow.cpp +++ b/ApplicationCode/UserInterface/RIMainWindow.cpp @@ -546,7 +546,7 @@ void RIMainWindow::refreshAnimationActions() || app->activeReservoirView()->propertyFilterCollection()->hasActiveDynamicFilters() || app->activeReservoirView()->wellCollection()->hasVisibleWellPipes()) { - std::vector timeStepDates = app->activeReservoirView()->currentGridCellResults()->timeStepDates(0); + std::vector timeStepDates = app->activeReservoirView()->currentGridCellResults()->cellResults()->timeStepDates(0); bool showHoursAndMinutes = false; for (int i = 0; i < timeStepDates.size(); i++) {