diff --git a/opm/core/simulator/BlackoilState.cpp b/opm/core/simulator/BlackoilState.cpp index 1bd5341a..1f51dabb 100644 --- a/opm/core/simulator/BlackoilState.cpp +++ b/opm/core/simulator/BlackoilState.cpp @@ -17,4 +17,27 @@ BlackoilState::BlackoilState( size_t num_cells , size_t num_faces , size_t num_p registerCellData( GASOILRATIO , 1 ); registerCellData( RV, 1 ); registerCellData( SURFACEVOL, num_phases ); + setBlackoilStateReferencePointers(); +} + +BlackoilState::BlackoilState( const BlackoilState& other ) + : SimulationDataContainer(other) +{ + setBlackoilStateReferencePointers(); +} + +BlackoilState& BlackoilState::operator=( const BlackoilState& other ) +{ + SimulationDataContainer::operator=(other); + setBlackoilStateReferencePointers(); + return *this; +} + +void BlackoilState::setBlackoilStateReferencePointers() +{ + // This sets the reference pointers for the fast + // accessors, the fields must have been created first. + gasoilratio_ref_ = &getCellData(GASOILRATIO); + rv_ref_ = &getCellData(RV); + surfacevol_ref_ = &getCellData(SURFACEVOL); } diff --git a/opm/core/simulator/BlackoilState.hpp b/opm/core/simulator/BlackoilState.hpp index ad2ba3d5..7f45e029 100644 --- a/opm/core/simulator/BlackoilState.hpp +++ b/opm/core/simulator/BlackoilState.hpp @@ -38,16 +38,41 @@ namespace Opm static const std::string RV; static const std::string SURFACEVOL; - BlackoilState(size_t num_cells , size_t num_faces, size_t num_phases); + /// Main constructor setting the sizes for the contained data + /// types. + /// \param num_cells number of elements in cell data vectors + /// \param num_faces number of elements in face data vectors + /// \param num_phases number of phases, the number of components + /// in any data vector must equal 1 or this + /// number (this behaviour and argument is deprecated). + BlackoilState(size_t num_cells, size_t num_faces, size_t num_phases); + /// Copy constructor. + /// Must be defined explicitly because class contains non-value objects + /// (the reference pointers rv_ref_ etc.) that should not simply + /// be copied. + BlackoilState(const BlackoilState& other); - std::vector& surfacevol () { return getCellData("SURFACEVOL"); } - std::vector& gasoilratio () { return getCellData(GASOILRATIO); } - std::vector& rv () { return getCellData(RV); } + /// Copy assignment operator. + /// Must be defined explicitly because class contains non-value objects + /// (the reference pointers rv_ref_ etc.) that should not simply + /// be copied. + BlackoilState& operator=(const BlackoilState& other); + + std::vector& surfacevol () { return *surfacevol_ref_; } + std::vector& gasoilratio () { return *gasoilratio_ref_; } + std::vector& rv () { return *rv_ref_; } + + const std::vector& surfacevol () const { return *surfacevol_ref_; } + const std::vector& gasoilratio () const { return *gasoilratio_ref_; } + const std::vector& rv () const { return *rv_ref_; } + + private: + void setBlackoilStateReferencePointers(); + std::vector* surfacevol_ref_; + std::vector* gasoilratio_ref_; + std::vector* rv_ref_; - const std::vector& surfacevol () const { return getCellData("SURFACEVOL"); } - const std::vector& gasoilratio () const { return getCellData("GASOILRATIO"); } - const std::vector& rv () const { return getCellData(RV); } }; } // namespace Opm