From 8ef54b7c6436882971561bb587ab3ff8a5a29c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Wed, 26 Feb 2014 14:47:24 +0100 Subject: [PATCH] Made phase mixing functors a class hierarchy. In summary: - added RsFunction (base class), - made NoMixing, RsVD, RsSatAtContact inherit RsFunction, - RS and RV are no longer template arguments for EquilReg class, - EquilReg constructor now takes two shared_ptr, - use of constructor updated, mostly using make_shared. --- opm/core/simulator/EquilibrationHelpers.hpp | 84 +++++++++++---------- opm/core/simulator/initStateEquil.hpp | 6 +- tests/test_equil.cpp | 36 ++++----- 3 files changed, 65 insertions(+), 61 deletions(-) diff --git a/opm/core/simulator/EquilibrationHelpers.hpp b/opm/core/simulator/EquilibrationHelpers.hpp index 316b435b..0588f346 100644 --- a/opm/core/simulator/EquilibrationHelpers.hpp +++ b/opm/core/simulator/EquilibrationHelpers.hpp @@ -26,6 +26,8 @@ #include #include +#include + /* ---- synopsis of EquilibrationHelpers.hpp ---- @@ -41,6 +43,7 @@ namespace Opm class DensityCalculator< BlackoilPropertiesInterface >; namespace Miscibility { + class RsFunction; class NoMixing; class RsVD; class RsSatAtContact; @@ -48,9 +51,7 @@ namespace Opm struct EquilRecord; - template + template class EquilReg; @@ -148,15 +149,40 @@ namespace Opm const std::vector c_; }; + /** * Types and routines relating to phase mixing in * equilibration calculations. */ namespace Miscibility { + + /** + * Base class for phase mixing functions. + */ + class RsFunction + { + public: + /** + * Function call operator. + * + * \param[in] depth Depth at which to calculate RS + * value. + * + * \param[in] press Pressure at which to calculate RS + * value. + * + * \return Dissolved gas-oil ratio (RS) at depth @c + * depth and pressure @c press. + */ + virtual double operator()(const double depth, + const double press) const = 0; + }; + + /** * Type that implements "no phase mixing" policy. */ - class NoMixing { + class NoMixing : public RsFunction { public: /** * Function call. @@ -179,12 +205,13 @@ namespace Opm } }; + /** * Type that implements "dissolved gas-oil ratio" * tabulated as a function of depth policy. Data * typically taken from keyword 'RSVD'. */ - class RsVD { + class RsVD : public RsFunction { public: /** * Constructor. @@ -238,7 +265,7 @@ namespace Opm * This should yield Rs-values that are constant below the * contact, and decreasing above the contact. */ - class RsSatAtContact { + class RsSatAtContact : public RsFunction { public: /** * Constructor. @@ -295,6 +322,7 @@ namespace Opm return A_[np*opos + gpos] / A_[np*opos + opos]; } }; + } // namespace Miscibility @@ -347,34 +375,8 @@ namespace Opm * * that calculates the phase densities of all phases in @c * svol at fluid pressure @c press. - * - * \tparam RS Type that provides access to a calculator for - * (initial) dissolved gas-oil ratios as a function of depth - * and (oil) pressure. Must implement an operator() declared - * as - * - * double - * operator()(const double depth, - * const double press) - * - * that calculates the dissolved gas-oil ratio at depth @c - * depth and (oil) pressure @c press. - * - * \tparam RV Type that provides access to a calculator for - * (initial) vapourised oil-gas ratios as a function of depth - * and (gas) pressure. Must implement an operator() declared - * as - * - * double - * operator()(const double depth, - * const double press) - * - * that calculates the vapourised oil-gas ratio at depth @c - * depth and (gas) pressure @c press. */ - template + template class EquilReg { public: /** @@ -388,8 +390,8 @@ namespace Opm */ EquilReg(const EquilRecord& rec, const DensCalc& density, - const RS& rs, - const RV& rv, + std::shared_ptr rs, + std::shared_ptr rv, const PhaseUsage& pu) : rec_ (rec) , density_(density) @@ -407,12 +409,12 @@ namespace Opm /** * Type of dissolved gas-oil ratio calculator. */ - typedef RS CalcDissolution; + typedef Miscibility::RsFunction CalcDissolution; /** * Type of vapourised oil-gas ratio calculator. */ - typedef RV CalcEvaporation; + typedef Miscibility::RsFunction CalcEvaporation; /** * Datum depth in current region @@ -459,14 +461,14 @@ namespace Opm * region. */ const CalcDissolution& - dissolutionCalculator() const { return this->rs_; } + dissolutionCalculator() const { return *this->rs_; } /** * Retrieve vapourised oil-gas ratio calculator of current * region. */ const CalcEvaporation& - evaporationCalculator() const { return this->rv_; } + evaporationCalculator() const { return *this->rv_; } /** * Retrieve active fluid phase summary. @@ -477,8 +479,8 @@ namespace Opm private: EquilRecord rec_; /**< Equilibration data */ DensCalc density_; /**< Density calculator */ - RS rs_; /**< RS calculator */ - RV rv_; /**< RV calculator */ + std::shared_ptr rs_; /**< RS calculator */ + std::shared_ptr rv_; /**< RV calculator */ PhaseUsage pu_; /**< Active phase summary */ }; diff --git a/opm/core/simulator/initStateEquil.hpp b/opm/core/simulator/initStateEquil.hpp index 9be77685..aa9f7862 100644 --- a/opm/core/simulator/initStateEquil.hpp +++ b/opm/core/simulator/initStateEquil.hpp @@ -296,7 +296,8 @@ namespace Opm const int repcell = *cells.begin(); const RhoCalc calc(props, repcell); - const EqReg eqreg(rec[r], calc, NoMix(), NoMix(), + const EqReg eqreg(rec[r], calc, + std::make_shared(), std::make_shared(), props.phaseUsage()); const PPress& res = phasePressures(G, eqreg, cells, grav); @@ -334,7 +335,8 @@ namespace Opm const int repcell = *cells.begin(); const RhoCalc calc(props, repcell); - const EqReg eqreg(rec[r], calc, NoMix(), NoMix(), + const EqReg eqreg(rec[r], calc, + std::make_shared(), std::make_shared(), props.phaseUsage()); const PPress press = phasePressures(G, eqreg, cells, grav); diff --git a/tests/test_equil.cpp b/tests/test_equil.cpp index 88bec072..5a5e9019 100644 --- a/tests/test_equil.cpp +++ b/tests/test_equil.cpp @@ -76,8 +76,8 @@ BOOST_AUTO_TEST_CASE (PhasePressure) Opm::Equil::EquilReg region(record, calc, - Opm::Equil::Miscibility::NoMixing(), - Opm::Equil::Miscibility::NoMixing(), + std::make_shared(), + std::make_shared(), props.phaseUsage()); std::vector cells(G->number_of_cells); @@ -139,23 +139,23 @@ BOOST_AUTO_TEST_CASE (CellSubset) Opm::Equil::EquilReg region[] = { Opm::Equil::EquilReg(record[0], calc, - Opm::Equil::Miscibility::NoMixing(), - Opm::Equil::Miscibility::NoMixing(), + std::make_shared(), + std::make_shared(), props.phaseUsage()) , Opm::Equil::EquilReg(record[0], calc, - Opm::Equil::Miscibility::NoMixing(), - Opm::Equil::Miscibility::NoMixing(), + std::make_shared(), + std::make_shared(), props.phaseUsage()) , Opm::Equil::EquilReg(record[1], calc, - Opm::Equil::Miscibility::NoMixing(), - Opm::Equil::Miscibility::NoMixing(), + std::make_shared(), + std::make_shared(), props.phaseUsage()) , Opm::Equil::EquilReg(record[1], calc, - Opm::Equil::Miscibility::NoMixing(), - Opm::Equil::Miscibility::NoMixing(), + std::make_shared(), + std::make_shared(), props.phaseUsage()) }; @@ -254,23 +254,23 @@ BOOST_AUTO_TEST_CASE (RegMapping) Opm::Equil::EquilReg region[] = { Opm::Equil::EquilReg(record[0], calc, - Opm::Equil::Miscibility::NoMixing(), - Opm::Equil::Miscibility::NoMixing(), + std::make_shared(), + std::make_shared(), props.phaseUsage()) , Opm::Equil::EquilReg(record[0], calc, - Opm::Equil::Miscibility::NoMixing(), - Opm::Equil::Miscibility::NoMixing(), + std::make_shared(), + std::make_shared(), props.phaseUsage()) , Opm::Equil::EquilReg(record[1], calc, - Opm::Equil::Miscibility::NoMixing(), - Opm::Equil::Miscibility::NoMixing(), + std::make_shared(), + std::make_shared(), props.phaseUsage()) , Opm::Equil::EquilReg(record[1], calc, - Opm::Equil::Miscibility::NoMixing(), - Opm::Equil::Miscibility::NoMixing(), + std::make_shared(), + std::make_shared(), props.phaseUsage()) };