diff --git a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp index aa5670c95..b230288fe 100644 --- a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.cpp @@ -679,26 +679,27 @@ namespace Opm { } const std::vector& EclipseGrid::getActiveMap() const { - if (!activeMap) { - std::vector * data_ptr = new std::vector( getNumActive() ); - std::vector& data = *data_ptr; - activeMap.reset( data_ptr ); + if( !this->activeMap.empty() ) return this->activeMap; - for (int global_index = 0; global_index < static_cast(getCartesianSize()); global_index++) { - // Using the low level C function to get the active index, because the C++ - // version will throw for inactive cells. - int active_index = ecl_grid_get_active_index1( m_grid.get() , global_index ); - if (active_index >= 0) - data[active_index] = global_index; - } + this->activeMap.resize( this->getNumActive() ); + const auto size = int(this->getCartesianSize()); + + for( int global_index = 0; global_index < size; global_index++) { + // Using the low level C function to get the active index, because the C++ + // version will throw for inactive cells. + int active_index = ecl_grid_get_active_index1( m_grid.get() , global_index ); + if (active_index >= 0) + this->activeMap[ active_index ] = global_index; } - return *activeMap; + return this->activeMap; } void EclipseGrid::resetACTNUM( const int * actnum) { - activeMap.reset( 0 ); ecl_grid_reset_actnum( m_grid.get() , actnum ); + /* re-build the active map cache */ + this->activeMap.clear(); + this->getActiveMap(); } diff --git a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp index 371da4c51..9369073f5 100644 --- a/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp @@ -87,9 +87,7 @@ namespace Opm { double getMinpvValue( ) const; /// Will return a vector a length num_active; where the value - /// of each element is the corresponding global index. Observe - /// that this reference is *invalidated* if there is a call to - /// resetACTNUM(). + /// of each element is the corresponding global index. const std::vector& getActiveMap() const; std::array getCellCenter(size_t i,size_t j, size_t k) const; std::array getCellCenter(size_t globalIndex) const; @@ -123,7 +121,7 @@ namespace Opm { Value m_pinch; PinchMode::ModeEnum m_pinchoutMode; PinchMode::ModeEnum m_multzMode; - mutable std::unique_ptr< std::vector > activeMap; + mutable std::vector< int > activeMap; void initCornerPointGrid(const std::array& dims , const std::vector& coord ,