From 1a17875dc1b292151eb1a296cbdddd2a261b6135 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 12 Feb 2013 14:46:45 +0100 Subject: [PATCH] Restructured data access objects, added factory method p4#: 20471 --- .../RifEclipseInputFileTools.cpp | 3 +- .../FileInterface/RifReaderEclipseOutput.cpp | 4 +- .../ModelVisualization/RivGridPartMgr.cpp | 6 +- .../RivReservoirViewPartMgr.cpp | 19 +- .../RivReservoirViewPartMgr.h | 3 +- .../ProjectDataModel/RimReservoirView.cpp | 6 +- .../ReservoirDataModel/RigGridBase.cpp | 4 +- .../ReservoirDataModel/RigGridBase.h | 3 +- .../RigGridScalarDataAccess.cpp | 208 ++++++++++++++---- .../RigGridScalarDataAccess.h | 31 +-- .../ReservoirDataModel/RigReservoir.cpp | 8 + .../ReservoirDataModel/RigReservoir.h | 3 +- 12 files changed, 214 insertions(+), 84 deletions(-) diff --git a/ApplicationCode/FileInterface/RifEclipseInputFileTools.cpp b/ApplicationCode/FileInterface/RifEclipseInputFileTools.cpp index 11a7335234..ac83e2e22a 100644 --- a/ApplicationCode/FileInterface/RifEclipseInputFileTools.cpp +++ b/ApplicationCode/FileInterface/RifEclipseInputFileTools.cpp @@ -418,7 +418,8 @@ bool RifEclipseInputFileTools::writeBinaryResultToTextFile(const QString& fileNa return false; } - cvf::ref dataAccessObject = reservoir->mainGrid()->dataAccessObject(porosityModel, timeStep, resultIndex); + RigActiveCellInfo* activeCellInfo = reservoir->activeCellInfo(); + cvf::ref dataAccessObject = reservoir->mainGrid()->dataAccessObject(activeCellInfo, porosityModel, timeStep, resultIndex); if (dataAccessObject.isNull()) { return false; diff --git a/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp index d5121039f4..b73dc55234 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp +++ b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp @@ -119,7 +119,7 @@ bool transferGridCellData(RigMainGrid* mainGrid, RigActiveCellInfo* activeCellIn if (matrixActiveIndex != -1) { cell.setActiveIndexInMatrixModel(matrixActiveStartIndex + matrixActiveIndex); - activeCellInfo->setActiveIndexInMatrixModel(localCellIdx, matrixActiveStartIndex + matrixActiveIndex); + activeCellInfo->setActiveIndexInMatrixModel(cellStartIndex + localCellIdx, matrixActiveStartIndex + matrixActiveIndex); } else { @@ -130,7 +130,7 @@ bool transferGridCellData(RigMainGrid* mainGrid, RigActiveCellInfo* activeCellIn if (fractureActiveIndex != -1) { cell.setActiveIndexInFractureModel(fractureActiveStartIndex + fractureActiveIndex); - activeCellInfo->setActiveIndexInFractureModel(localCellIdx, fractureActiveStartIndex + fractureActiveIndex); + activeCellInfo->setActiveIndexInFractureModel(cellStartIndex + localCellIdx, fractureActiveStartIndex + fractureActiveIndex); } else { diff --git a/ApplicationCode/ModelVisualization/RivGridPartMgr.cpp b/ApplicationCode/ModelVisualization/RivGridPartMgr.cpp index b27f38c339..269b4742b3 100644 --- a/ApplicationCode/ModelVisualization/RivGridPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivGridPartMgr.cpp @@ -29,6 +29,7 @@ #include "RimCellEdgeResultSlot.h" #include "RigGridScalarDataAccess.h" #include "RigReservoirCellResults.h" +#include "RigReservoir.h" //-------------------------------------------------------------------------------------------------- @@ -221,7 +222,10 @@ void RivGridPartMgr::updateCellResultColor(size_t timeStepIndex, RimResultSlot* if (cellResultSlot->hasStaticResult()) resTimeStepIdx = 0; RifReaderInterface::PorosityModelResultType porosityModel = RigReservoirCellResults::convertFromProjectModelPorosityModel(cellResultSlot->porosityModel()); - cvf::ref dataAccessObject = m_grid->dataAccessObject(porosityModel, resTimeStepIdx, scalarSetIndex); + + RigActiveCellInfo* activeCellInfo = cellResultSlot->reservoirView()->eclipseCase()->reservoirData()->activeCellInfo(); + cvf::ref dataAccessObject = m_grid->dataAccessObject(activeCellInfo, porosityModel, resTimeStepIdx, scalarSetIndex); + if (dataAccessObject.isNull()) return; // Outer surface diff --git a/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.cpp b/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.cpp index a9d1817e16..5fe2acbfdf 100644 --- a/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.cpp @@ -246,10 +246,13 @@ void RivReservoirViewPartMgr::createGeometry(ReservoirGeometryCacheType geometry //-------------------------------------------------------------------------------------------------- void RivReservoirViewPartMgr::computeVisibility(cvf::UByteArray* cellVisibility, ReservoirGeometryCacheType geometryType, RigGridBase* grid, size_t gridIdx) { + RigReservoir* reservoir = m_reservoirView->eclipseCase()->reservoirData(); + RigActiveCellInfo* activeCellInfo = reservoir->activeCellInfo(); + switch (geometryType) { case ACTIVE: - computeNativeVisibility(cellVisibility, grid, false, false, true, m_reservoirView->showMainGrid() ); + computeNativeVisibility(cellVisibility, grid, activeCellInfo, false, false, true, m_reservoirView->showMainGrid() ); break; case ALL_WELL_CELLS: computeAllWellCellsVisibility(cellVisibility, grid); @@ -287,7 +290,7 @@ void RivReservoirViewPartMgr::computeVisibility(cvf::UByteArray* cellVisibility, } break; case INACTIVE: - computeNativeVisibility(cellVisibility, grid, m_reservoirView->showInvalidCells(), true, false, m_reservoirView->showMainGrid()); + computeNativeVisibility(cellVisibility, grid, activeCellInfo, m_reservoirView->showInvalidCells(), true, false, m_reservoirView->showMainGrid()); break; case RANGE_FILTERED: { @@ -460,7 +463,7 @@ void RivReservoirViewPartMgr::createPropertyFilteredWellGeometry(size_t frameInd //-------------------------------------------------------------------------------------------------- /// Evaluate visibility based on cell state //-------------------------------------------------------------------------------------------------- -void RivReservoirViewPartMgr::computeNativeVisibility(cvf::UByteArray* cellVisibility, const RigGridBase* grid, +void RivReservoirViewPartMgr::computeNativeVisibility(cvf::UByteArray* cellVisibility, const RigGridBase* grid, const RigActiveCellInfo* activeCellInfo, bool invalidCellsIsVisible, bool inactiveCellsIsVisible, bool activeCellsIsVisible, @@ -468,16 +471,18 @@ void RivReservoirViewPartMgr::computeNativeVisibility(cvf::UByteArray* cellVisib { CVF_ASSERT(cellVisibility != NULL); CVF_ASSERT(grid != NULL); + CVF_ASSERT(activeCellInfo != NULL); cellVisibility->resize(grid->cellCount()); #pragma omp parallel for for (int cellIndex = 0; cellIndex < static_cast(grid->cellCount()); cellIndex++) { const RigCell& cell = grid->cell(cellIndex); + size_t globalCellIndex = cell.mainGridCellIndex(); if ( !invalidCellsIsVisible && cell.isInvalid() - || !inactiveCellsIsVisible && !cell.isActiveInMatrixModel() - || !activeCellsIsVisible && cell.isActiveInMatrixModel() + || !inactiveCellsIsVisible && !activeCellInfo->isActiveInMatrixModel(globalCellIndex) + || !activeCellsIsVisible && activeCellInfo->isActiveInMatrixModel(globalCellIndex) || mainGridIsVisible && (cell.subGrid() != NULL) || cell.isWellCell() ) @@ -600,7 +605,9 @@ void RivReservoirViewPartMgr::computePropertyVisibility(cvf::UByteArray* cellVis const RimCellFilter::FilterModeType filterType = (*pfIt)->filterMode(); RifReaderInterface::PorosityModelResultType porosityModel = RigReservoirCellResults::convertFromProjectModelPorosityModel((*pfIt)->resultDefinition()->porosityModel()); - cvf::ref dataAccessObject = grid->dataAccessObject(porosityModel, timeStepIndex, scalarResultIndex); + RigActiveCellInfo* activeCellInfo = propFilterColl->reservoirView()->eclipseCase()->reservoirData()->activeCellInfo(); + + cvf::ref dataAccessObject = grid->dataAccessObject(activeCellInfo, porosityModel, timeStepIndex, scalarResultIndex); CVF_ASSERT(dataAccessObject.notNull()); #pragma omp parallel for schedule(dynamic) diff --git a/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.h b/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.h index 286e2c4a45..b70bd89051 100644 --- a/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.h +++ b/ApplicationCode/ModelVisualization/RivReservoirViewPartMgr.h @@ -28,6 +28,7 @@ class RimReservoirView; class RigGridBase; class RimCellRangeFilterCollection; class RimCellPropertyFilterCollection; +class RigActiveCellInfo; class RivReservoirViewPartMgr: public cvf::Object { @@ -77,7 +78,7 @@ private: void clearGeometryCache(ReservoirGeometryCacheType geomType); - static void computeNativeVisibility (cvf::UByteArray* cellVisibility, const RigGridBase* grid, bool invalidCellsIsVisible, bool inactiveCellsIsVisible, bool activeCellsIsVisible, bool mainGridIsVisible); + static void computeNativeVisibility (cvf::UByteArray* cellVisibility, const RigGridBase* grid, const RigActiveCellInfo* activeCellInfo, bool invalidCellsIsVisible, bool inactiveCellsIsVisible, bool activeCellsIsVisible, bool mainGridIsVisible); static void computeRangeVisibility (cvf::UByteArray* cellVisibility, const RigGridBase* grid, const cvf::UByteArray* nativeVisibility, const RimCellRangeFilterCollection* rangeFilterColl); static void computePropertyVisibility(cvf::UByteArray* cellVisibility, const RigGridBase* grid, size_t timeStepIndex, const cvf::UByteArray* rangeFilterVisibility, RimCellPropertyFilterCollection* propFilterColl); static void computeAllWellCellsVisibility(cvf::UByteArray* cellVisibility, const RigGridBase* grid ); diff --git a/ApplicationCode/ProjectDataModel/RimReservoirView.cpp b/ApplicationCode/ProjectDataModel/RimReservoirView.cpp index 7097f003a6..7bc85b33d8 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirView.cpp +++ b/ApplicationCode/ProjectDataModel/RimReservoirView.cpp @@ -870,10 +870,12 @@ void RimReservoirView::appendCellResultInfo(size_t gridIndex, size_t cellIndex, { const RigReservoir* reservoir = m_reservoir->reservoirData(); const RigGridBase* grid = reservoir->grid(gridIndex); + const RigActiveCellInfo* activeCellInfo = reservoir->activeCellInfo(); + if (this->cellResult()->hasResult()) { RifReaderInterface::PorosityModelResultType porosityModel = RigReservoirCellResults::convertFromProjectModelPorosityModel(cellResult()->porosityModel()); - cvf::ref dataAccessObject = grid->dataAccessObject(porosityModel, m_currentTimeStep, this->cellResult()->gridScalarIndex()); + cvf::ref dataAccessObject = grid->dataAccessObject(activeCellInfo, porosityModel, m_currentTimeStep, this->cellResult()->gridScalarIndex()); if (dataAccessObject.notNull()) { double scalarValue = dataAccessObject->cellScalar(cellIndex); @@ -894,7 +896,7 @@ void RimReservoirView::appendCellResultInfo(size_t gridIndex, size_t cellIndex, // Cell edge results are static, results are loaded for first time step only RifReaderInterface::PorosityModelResultType porosityModel = RigReservoirCellResults::convertFromProjectModelPorosityModel(cellResult()->porosityModel()); - cvf::ref dataAccessObject = grid->dataAccessObject(porosityModel, 0, resultIndices[idx]); + cvf::ref dataAccessObject = grid->dataAccessObject(activeCellInfo, porosityModel, 0, resultIndices[idx]); if (dataAccessObject.notNull()) { double scalarValue = dataAccessObject->cellScalar(cellIndex); diff --git a/ApplicationCode/ReservoirDataModel/RigGridBase.cpp b/ApplicationCode/ReservoirDataModel/RigGridBase.cpp index dac8ae9c83..1bf2958108 100644 --- a/ApplicationCode/ReservoirDataModel/RigGridBase.cpp +++ b/ApplicationCode/ReservoirDataModel/RigGridBase.cpp @@ -471,12 +471,12 @@ size_t RigGridBase::fractureModelActiveCellCount() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -cvf::ref RigGridBase::dataAccessObject(RifReaderInterface::PorosityModelResultType porosityModel, size_t timeStepIndex, size_t scalarSetIndex) const +cvf::ref RigGridBase::dataAccessObject(const RigActiveCellInfo* activeCellInfo, RifReaderInterface::PorosityModelResultType porosityModel, size_t timeStepIndex, size_t scalarSetIndex) const { if (timeStepIndex != cvf::UNDEFINED_SIZE_T && scalarSetIndex != cvf::UNDEFINED_SIZE_T) { - cvf::ref dataAccess = RigGridScalarDataAccess::createDataAccessObject(this, porosityModel, timeStepIndex, scalarSetIndex); + cvf::ref dataAccess = RigGridScalarDataAccessFactory::createDataAccessObject(this, activeCellInfo, porosityModel, timeStepIndex, scalarSetIndex); return dataAccess; } diff --git a/ApplicationCode/ReservoirDataModel/RigGridBase.h b/ApplicationCode/ReservoirDataModel/RigGridBase.h index 8cdc541f3e..3712e77719 100644 --- a/ApplicationCode/ReservoirDataModel/RigGridBase.h +++ b/ApplicationCode/ReservoirDataModel/RigGridBase.h @@ -34,6 +34,7 @@ class RigMainGrid; class RigCell; class RigGridScalarDataAccess; +class RigActiveCellInfo; class RigGridBase : public cvf::StructGridInterface { @@ -98,7 +99,7 @@ public: virtual bool isCellValid( size_t i, size_t j, size_t k ) const; virtual bool cellIJKNeighbor(size_t i, size_t j, size_t k, FaceType face, size_t* neighborCellIndex ) const; - cvf::ref dataAccessObject(RifReaderInterface::PorosityModelResultType porosityModel, size_t timeStepIndex, size_t scalarSetIndex) const; + cvf::ref dataAccessObject(const RigActiveCellInfo* activeCellInfo, RifReaderInterface::PorosityModelResultType porosityModel, size_t timeStepIndex, size_t scalarSetIndex) const; private: std::string m_gridName; diff --git a/ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.cpp b/ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.cpp index bcdef620c9..4a9fc6e2d7 100644 --- a/ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.cpp +++ b/ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.cpp @@ -21,53 +21,52 @@ #include "cvfLibCore.h" #include "cvfBase.h" +#include "cvfObject.h" #include "cvfAssert.h" #include "RigMainGrid.h" #include "RigReservoirCellResults.h" +#include "RigActiveCellInfo.h" +#include "RigGridBase.h" + + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RigGridScalarDataAccess::RigGridScalarDataAccess(const RigGridBase* grid, bool useGlobalActiveIndex, std::vector* resultValues) : - m_grid(grid), - m_useGlobalActiveIndex(useGlobalActiveIndex), +class RigGridAllCellsScalarDataAccess : public cvf::StructGridScalarDataAccess +{ +public: + RigGridAllCellsScalarDataAccess(const RigGridBase* grid, std::vector* resultValues); + + virtual double cellScalar(size_t i, size_t j, size_t k) const; + virtual double cellScalar(size_t cellIndex) const; + virtual void cellCornerScalars(size_t i, size_t j, size_t k, double scalars[8]) const; + virtual double gridPointScalar(size_t i, size_t j, size_t k) const; + virtual bool pointScalar(const cvf::Vec3d& p, double* scalarValue) const; + + virtual const cvf::Vec3d* cellVector(size_t i, size_t j, size_t k) const; + +protected: + cvf::cref m_grid; + std::vector* m_resultValues; +}; + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RigGridAllCellsScalarDataAccess::RigGridAllCellsScalarDataAccess(const RigGridBase* grid, std::vector* resultValues) : +m_grid(grid), m_resultValues(resultValues) { } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::ref RigGridScalarDataAccess::createDataAccessObject(const RigGridBase* grid, RifReaderInterface::PorosityModelResultType porosityModel, size_t timeStepIndex, size_t scalarSetIndex) -{ - CVF_ASSERT(grid); - CVF_ASSERT(grid->mainGrid()); - CVF_ASSERT(grid->mainGrid()->results(porosityModel)); - - if (!grid || !grid->mainGrid() || !grid->mainGrid()->results(porosityModel)) - { - return NULL; - } - - bool useGlobalActiveIndex = grid->mainGrid()->results(porosityModel)->isUsingGlobalActiveIndex(scalarSetIndex); - - std::vector< std::vector > & scalarSetResults = grid->mainGrid()->results(porosityModel)->cellScalarResults(scalarSetIndex); - if (timeStepIndex >= scalarSetResults.size()) - { - return NULL; - } - - std::vector* resultValues = &(scalarSetResults[timeStepIndex]); - - cvf::ref object = new RigGridScalarDataAccess(grid, useGlobalActiveIndex, resultValues); - return object; -} //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -double RigGridScalarDataAccess::cellScalar(size_t i, size_t j, size_t k) const +double RigGridAllCellsScalarDataAccess::cellScalar(size_t i, size_t j, size_t k) const { size_t cellIndex = m_grid->cellIndexFromIJK(i, j, k); @@ -77,27 +76,19 @@ double RigGridScalarDataAccess::cellScalar(size_t i, size_t j, size_t k) const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -double RigGridScalarDataAccess::cellScalar(size_t cellIndex) const +double RigGridAllCellsScalarDataAccess::cellScalar(size_t cellIndex) const { if (m_resultValues->size() == 0 ) return HUGE_VAL; - size_t resultValueIndex = cellIndex; + if (m_resultValues->size() <= cellIndex) return HUGE_VAL; - if (m_useGlobalActiveIndex) - { - resultValueIndex = m_grid->cell(cellIndex).activeIndexInMatrixModel(); - if (resultValueIndex == cvf::UNDEFINED_SIZE_T) return HUGE_VAL; - } - - if (m_resultValues->size() <= resultValueIndex) return HUGE_VAL; - - return m_resultValues->at(resultValueIndex); + return m_resultValues->at(cellIndex); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -double RigGridScalarDataAccess::gridPointScalar(size_t i, size_t j, size_t k) const +double RigGridAllCellsScalarDataAccess::gridPointScalar(size_t i, size_t j, size_t k) const { CVF_ASSERT(false); return 0.0; @@ -106,7 +97,7 @@ double RigGridScalarDataAccess::gridPointScalar(size_t i, size_t j, size_t k) co //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RigGridScalarDataAccess::cellCornerScalars(size_t i, size_t j, size_t k, double scalars[8]) const +void RigGridAllCellsScalarDataAccess::cellCornerScalars(size_t i, size_t j, size_t k, double scalars[8]) const { CVF_ASSERT(false); } @@ -114,7 +105,7 @@ void RigGridScalarDataAccess::cellCornerScalars(size_t i, size_t j, size_t k, do //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RigGridScalarDataAccess::pointScalar(const cvf::Vec3d& p, double* scalarValue) const +bool RigGridAllCellsScalarDataAccess::pointScalar(const cvf::Vec3d& p, double* scalarValue) const { CVF_ASSERT(false); return false; @@ -123,9 +114,134 @@ bool RigGridScalarDataAccess::pointScalar(const cvf::Vec3d& p, double* scalarVal //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -const cvf::Vec3d* RigGridScalarDataAccess::cellVector(size_t i, size_t j, size_t k) const +const cvf::Vec3d* RigGridAllCellsScalarDataAccess::cellVector(size_t i, size_t j, size_t k) const { CVF_ASSERT(false); return new cvf::Vec3d(); } + + + + + + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +class RigGridMatrixActiveCellsScalarDataAccess : public RigGridAllCellsScalarDataAccess +{ +public: + RigGridMatrixActiveCellsScalarDataAccess(const RigGridBase* grid, std::vector* resultValues, const RigActiveCellInfo* activeCellInfo) : + RigGridAllCellsScalarDataAccess(grid, resultValues), + m_activeCellInfo(activeCellInfo) + { + + } + + virtual double cellScalar(size_t cellIndex) const + { + if (m_resultValues->size() == 0 ) return HUGE_VAL; + + size_t mainGridCellIndex = m_grid->cell(cellIndex).mainGridCellIndex(); + + size_t resultValueIndex = m_activeCellInfo->activeIndexInMatrixModel(mainGridCellIndex); + if (resultValueIndex == cvf::UNDEFINED_SIZE_T) return HUGE_VAL; + + if (m_resultValues->size() <= resultValueIndex) return HUGE_VAL; + + return m_resultValues->at(resultValueIndex); + } + +protected: + const RigActiveCellInfo* m_activeCellInfo; +}; + + + + + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +class RigGridFractureActiveCellsScalarDataAccess : public RigGridAllCellsScalarDataAccess +{ +public: + RigGridFractureActiveCellsScalarDataAccess(const RigGridBase* grid, std::vector* resultValues, const RigActiveCellInfo* activeCellInfo) : + RigGridAllCellsScalarDataAccess(grid, resultValues), + m_activeCellInfo(activeCellInfo) + { + } + + virtual double cellScalar(size_t cellIndex) const + { + if (m_resultValues->size() == 0 ) return HUGE_VAL; + + size_t mainGridCellIndex = m_grid->cell(cellIndex).mainGridCellIndex(); + + size_t resultValueIndex = m_activeCellInfo->activeIndexInFractureModel(mainGridCellIndex); + if (resultValueIndex == cvf::UNDEFINED_SIZE_T) return HUGE_VAL; + + if (m_resultValues->size() <= resultValueIndex) return HUGE_VAL; + + return m_resultValues->at(resultValueIndex); + } + +protected: + const RigActiveCellInfo* m_activeCellInfo; +}; + + + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::ref RigGridScalarDataAccessFactory::createDataAccessObject(const RigGridBase* grid, + const RigActiveCellInfo* activeCellInfo, + RifReaderInterface::PorosityModelResultType porosityModel, + size_t timeStepIndex, + size_t scalarSetIndex) +{ + CVF_ASSERT(grid); + CVF_ASSERT(grid->mainGrid()); + CVF_ASSERT(grid->mainGrid()->results(porosityModel)); + CVF_ASSERT(activeCellInfo); + + if (!grid || !grid->mainGrid() || !grid->mainGrid()->results(porosityModel) || !activeCellInfo) + { + return NULL; + } + + std::vector< std::vector > & scalarSetResults = grid->mainGrid()->results(porosityModel)->cellScalarResults(scalarSetIndex); + if (timeStepIndex >= scalarSetResults.size()) + { + return NULL; + } + + std::vector* resultValues = &(scalarSetResults[timeStepIndex]); + + + bool useGlobalActiveIndex = grid->mainGrid()->results(porosityModel)->isUsingGlobalActiveIndex(scalarSetIndex); + if (useGlobalActiveIndex) + { + if (porosityModel == RifReaderInterface::MATRIX_RESULTS) + { + cvf::ref object = new RigGridMatrixActiveCellsScalarDataAccess(grid, resultValues, activeCellInfo); + return object; + } + else + { + cvf::ref object = new RigGridFractureActiveCellsScalarDataAccess(grid, resultValues, activeCellInfo); + return object; + } + } + else + { + cvf::ref object = new RigGridAllCellsScalarDataAccess(grid, resultValues); + return object; + } +} + diff --git a/ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.h b/ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.h index ad4f1fb46d..871a45a82f 100644 --- a/ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.h +++ b/ApplicationCode/ReservoirDataModel/RigGridScalarDataAccess.h @@ -20,32 +20,21 @@ #pragma once #include "cvfStructGridScalarDataAccess.h" -#include "RigGridBase.h" #include "RifReaderInterface.h" -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -class RigGridScalarDataAccess : public cvf::StructGridScalarDataAccess +class RigActiveCellInfo; +class RigGridBase; + +class RigGridScalarDataAccessFactory { -private: - RigGridScalarDataAccess(const RigGridBase* grid, bool useGlobalActiveIndex, std::vector* resultValues); - public: - static cvf::ref createDataAccessObject(const RigGridBase* grid, RifReaderInterface::PorosityModelResultType porosityModel, size_t timeStepIndex, size_t scalarSetIndex); + static cvf::ref createDataAccessObject(const RigGridBase* grid, + const RigActiveCellInfo* activeCellInfo, + RifReaderInterface::PorosityModelResultType porosityModel, + size_t timeStepIndex, + size_t scalarSetIndex); - virtual double cellScalar(size_t i, size_t j, size_t k) const; - virtual double cellScalar(size_t cellIndex) const; - virtual void cellCornerScalars(size_t i, size_t j, size_t k, double scalars[8]) const; - virtual double gridPointScalar(size_t i, size_t j, size_t k) const; - virtual bool pointScalar(const cvf::Vec3d& p, double* scalarValue) const; - - virtual const cvf::Vec3d* cellVector(size_t i, size_t j, size_t k) const; - -private: - cvf::cref m_grid; - bool m_useGlobalActiveIndex; - std::vector* m_resultValues; }; + diff --git a/ApplicationCode/ReservoirDataModel/RigReservoir.cpp b/ApplicationCode/ReservoirDataModel/RigReservoir.cpp index ac557ca21c..3f510510c8 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoir.cpp +++ b/ApplicationCode/ReservoirDataModel/RigReservoir.cpp @@ -310,3 +310,11 @@ RigActiveCellInfo* RigReservoir::activeCellInfo() { return &m_activeCellInfo; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const RigActiveCellInfo* RigReservoir::activeCellInfo() const +{ + return &m_activeCellInfo; +} diff --git a/ApplicationCode/ReservoirDataModel/RigReservoir.h b/ApplicationCode/ReservoirDataModel/RigReservoir.h index 111146df83..360054d18c 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoir.h +++ b/ApplicationCode/ReservoirDataModel/RigReservoir.h @@ -52,7 +52,8 @@ public: RigCell& cellFromWellResultCell(const RigWellResultCell& wellResultCell); bool findSharedSourceFace(cvf::StructGridInterface::FaceType& sharedSourceFace, const RigWellResultCell& sourceWellCellResult, const RigWellResultCell& otherWellCellResult) const; - RigActiveCellInfo* activeCellInfo(); + RigActiveCellInfo* activeCellInfo(); + const RigActiveCellInfo* activeCellInfo() const; private: