From 31133af803847b7dfae9556791350f7c4b2dd0a1 Mon Sep 17 00:00:00 2001 From: Tor Harald Sandve Date: Thu, 12 May 2016 10:32:39 +0200 Subject: [PATCH 1/3] Add member hydroCarbonState to the BlackoilState The hydroCarbonState is used to store the hydroCarbonState State 1: Gas only State 2: Gas and Oil State 3: Oil only An empty vector is return at initialization as no default values are provided by the blackoilstate. --- opm/core/simulator/BlackoilState.cpp | 2 ++ opm/core/simulator/BlackoilState.hpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/opm/core/simulator/BlackoilState.cpp b/opm/core/simulator/BlackoilState.cpp index 1f51dabb..c274136a 100644 --- a/opm/core/simulator/BlackoilState.cpp +++ b/opm/core/simulator/BlackoilState.cpp @@ -24,12 +24,14 @@ BlackoilState::BlackoilState( const BlackoilState& other ) : SimulationDataContainer(other) { setBlackoilStateReferencePointers(); + hydrocarbonstate_ = other.hydroCarbonState(); } BlackoilState& BlackoilState::operator=( const BlackoilState& other ) { SimulationDataContainer::operator=(other); setBlackoilStateReferencePointers(); + hydrocarbonstate_ = other.hydroCarbonState(); return *this; } diff --git a/opm/core/simulator/BlackoilState.hpp b/opm/core/simulator/BlackoilState.hpp index 7f45e029..51c6c21c 100644 --- a/opm/core/simulator/BlackoilState.hpp +++ b/opm/core/simulator/BlackoilState.hpp @@ -62,10 +62,12 @@ namespace Opm std::vector& surfacevol () { return *surfacevol_ref_; } std::vector& gasoilratio () { return *gasoilratio_ref_; } std::vector& rv () { return *rv_ref_; } + 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_; } private: void setBlackoilStateReferencePointers(); @@ -73,6 +75,9 @@ namespace Opm std::vector* gasoilratio_ref_; std::vector* rv_ref_; + // A vector storing the hydro carbon state. + std::vector hydrocarbonstate_; + }; } // namespace Opm From cb4b698b515f64e2e588883153e5825e4eb5f66c Mon Sep 17 00:00:00 2001 From: Tor Harald Sandve Date: Fri, 13 May 2016 09:10:13 +0200 Subject: [PATCH 2/3] Add method for calculating the initial hydroCarbonState The following hydroCarbonState are used enum HydroCarbonState { GasOnly = 0, GasAndOil = 1, OilOnly = 2 }; Cells almost filled with water are treated as a GasAndOil state --- CMakeLists_files.cmake | 1 + opm/core/simulator/BlackoilState.hpp | 6 ++++ opm/core/utility/initHydroCarbonState.hpp | 42 +++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 opm/core/utility/initHydroCarbonState.hpp diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index a5ee0621..d36438cb 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -377,6 +377,7 @@ list (APPEND PUBLIC_HEADER_FILES opm/core/utility/Event.hpp opm/core/utility/Event_impl.hpp opm/core/utility/Factory.hpp + opm/core/utility/initHydroCarbonState.hpp opm/core/utility/MonotCubicInterpolator.hpp opm/core/utility/NonuniformTableLinear.hpp opm/core/utility/NullStream.hpp diff --git a/opm/core/simulator/BlackoilState.hpp b/opm/core/simulator/BlackoilState.hpp index 51c6c21c..905b0943 100644 --- a/opm/core/simulator/BlackoilState.hpp +++ b/opm/core/simulator/BlackoilState.hpp @@ -30,6 +30,12 @@ namespace Opm { +enum HydroCarbonState { + GasOnly = 0, + GasAndOil = 1, + OilOnly = 2 +}; + /// Simulator state for a blackoil simulator. class BlackoilState : public SimulationDataContainer { diff --git a/opm/core/utility/initHydroCarbonState.hpp b/opm/core/utility/initHydroCarbonState.hpp new file mode 100644 index 00000000..c0be0f68 --- /dev/null +++ b/opm/core/utility/initHydroCarbonState.hpp @@ -0,0 +1,42 @@ +#ifndef INITHYDROCARBONSTATE_HPP +#define INITHYDROCARBONSTATE_HPP + +#include "opm/core/simulator/BlackoilState.hpp" + +namespace Opm +{ + +void initHydroCarbonState(BlackoilState& state, const PhaseUsage& pu, const int num_cells) { + 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; + hydroCarbonState.resize(num_cells); + std::fill(hydroCarbonState.begin(), hydroCarbonState.end(), HydroCarbonState::GasAndOil); + + // set hydrocarbon state + const double epsilon = std::sqrt(std::numeric_limits::epsilon()); + const std::vector& saturation = state.saturation(); + for (int c = 0; c < num_cells; ++c) { + if (pu.phase_used[Water]) { + if ( saturation[c*np + pu.phase_pos[ Water ]] > (1.0 - epsilon)) { + continue; // cases (almost) filled with water is treated as GasAndOil case; + } + } + if ( saturation[c*np + pu.phase_pos[ Gas ]] == 0.0) { + hydroCarbonState[c] = HydroCarbonState::OilOnly; + continue; + } + if ( saturation[c*np + pu.phase_pos[ Oil ]] == 0.0) { + hydroCarbonState[c] = HydroCarbonState::GasOnly; + } + } +} + + +} // namespace Opm +#endif // INITHYDROCARBONSTATE_HPP From 79f04b6c9e0d3cc16c8279a034d5d1f4d6171f1b Mon Sep 17 00:00:00 2001 From: Tor Harald Sandve Date: Fri, 13 May 2016 12:35:08 +0200 Subject: [PATCH 3/3] 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 c274136a..66d83938 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 905b0943..fe6c0dbc 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 c0be0f68..611b0639 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