From 79fd23700e17382ba35e8acfdc83596681ce6650 Mon Sep 17 00:00:00 2001 From: Tor Harald Sandve Date: Fri, 13 May 2016 12:35:08 +0200 Subject: [PATCH] Fixing PR comments - Use std::vector instead of std::vector - Use the initializer list to initialize members in constructors - Fix indent - Return OilOnly for cases without gas to avoid potential trouble further down the line --- opm/core/simulator/BlackoilState.cpp | 5 +++-- opm/core/simulator/BlackoilState.hpp | 16 ++++++++-------- opm/core/utility/initHydroCarbonState.hpp | 12 +++++++----- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/opm/core/simulator/BlackoilState.cpp b/opm/core/simulator/BlackoilState.cpp index c274136a9..66d83938e 100644 --- a/opm/core/simulator/BlackoilState.cpp +++ b/opm/core/simulator/BlackoilState.cpp @@ -21,10 +21,11 @@ BlackoilState::BlackoilState( size_t num_cells , size_t num_faces , size_t num_p } BlackoilState::BlackoilState( const BlackoilState& other ) - : SimulationDataContainer(other) + : SimulationDataContainer(other), + hydrocarbonstate_(other.hydroCarbonState()) { setBlackoilStateReferencePointers(); - hydrocarbonstate_ = other.hydroCarbonState(); + } BlackoilState& BlackoilState::operator=( const BlackoilState& other ) diff --git a/opm/core/simulator/BlackoilState.hpp b/opm/core/simulator/BlackoilState.hpp index 905b09434..fe6c0dbc5 100644 --- a/opm/core/simulator/BlackoilState.hpp +++ b/opm/core/simulator/BlackoilState.hpp @@ -30,11 +30,11 @@ namespace Opm { -enum HydroCarbonState { - GasOnly = 0, - GasAndOil = 1, - OilOnly = 2 -}; + enum HydroCarbonState { + GasOnly = 0, + GasAndOil = 1, + OilOnly = 2 + }; /// Simulator state for a blackoil simulator. class BlackoilState : public SimulationDataContainer @@ -68,12 +68,12 @@ enum HydroCarbonState { std::vector& surfacevol () { return *surfacevol_ref_; } std::vector& gasoilratio () { return *gasoilratio_ref_; } std::vector& rv () { return *rv_ref_; } - std::vector& hydroCarbonState() { return hydrocarbonstate_; } + std::vector& hydroCarbonState() { return hydrocarbonstate_; } const std::vector& surfacevol () const { return *surfacevol_ref_; } const std::vector& gasoilratio () const { return *gasoilratio_ref_; } const std::vector& rv () const { return *rv_ref_; } - const std::vector& hydroCarbonState() const { return hydrocarbonstate_; } + const std::vector& hydroCarbonState() const { return hydrocarbonstate_; } private: void setBlackoilStateReferencePointers(); @@ -82,7 +82,7 @@ enum HydroCarbonState { std::vector* rv_ref_; // A vector storing the hydro carbon state. - std::vector hydrocarbonstate_; + std::vector hydrocarbonstate_; }; diff --git a/opm/core/utility/initHydroCarbonState.hpp b/opm/core/utility/initHydroCarbonState.hpp index c0be0f685..611b0639e 100644 --- a/opm/core/utility/initHydroCarbonState.hpp +++ b/opm/core/utility/initHydroCarbonState.hpp @@ -10,12 +10,14 @@ void initHydroCarbonState(BlackoilState& state, const PhaseUsage& pu, const int enum { Oil = BlackoilPhases::Liquid, Gas = BlackoilPhases::Vapour, Water = BlackoilPhases::Aqua }; // hydrocarbonstate is only used when gas and oil is present assert(pu.phase_used[Oil]); - if (!pu.phase_used[Gas]) { - return; // do nothing - } - std::vector& hydroCarbonState = state.hydroCarbonState(); - const int np = pu.num_phases; + std::vector& hydroCarbonState = state.hydroCarbonState(); hydroCarbonState.resize(num_cells); + if (!pu.phase_used[Gas]) { + // hydroCarbonState should only be used when oil and gas is present. Return OilOnly to avoid potential trouble. + std::fill(hydroCarbonState.begin(), hydroCarbonState.end(), HydroCarbonState::OilOnly); + return; + } + const int np = pu.num_phases; std::fill(hydroCarbonState.begin(), hydroCarbonState.end(), HydroCarbonState::GasAndOil); // set hydrocarbon state