Merged upstream/master

This commit is contained in:
Joakim Hove 2014-01-29 15:25:21 +01:00
commit 0138fc43ef
12 changed files with 1242 additions and 152 deletions

View File

@ -35,6 +35,7 @@ list (APPEND MAIN_SOURCE_FILES
opm/autodiff/SimulatorIncompTwophaseAd.cpp
opm/autodiff/TransportSolverTwophaseAd.cpp
opm/autodiff/BlackoilPropsAdFromDeck.cpp
opm/autodiff/WellDensitySegmented.cpp
)
# originally generated with the command:
@ -45,6 +46,7 @@ list (APPEND TEST_SOURCE_FILES
tests/test_span.cpp
tests/test_syntax.cpp
tests/test_scalar_mult.cpp
tests/test_welldensitysegmented.cpp
)
if (INCLUDE_NON_PUBLIC_TESTS)
@ -103,4 +105,5 @@ list (APPEND PUBLIC_HEADER_FILES
opm/autodiff/SimulatorFullyImplicitBlackoil.hpp
opm/autodiff/SimulatorIncompTwophaseAd.hpp
opm/autodiff/TransportSolverTwophaseAd.hpp
opm/autodiff/WellDensitySegmented.hpp
)

View File

@ -19,5 +19,5 @@ set (opm-autodiff_DEPS
dune-istl REQUIRED;
opm-core REQUIRED"
# Eigen
"Eigen3 3.1 REQUIRED"
"Eigen3 3.1.2 REQUIRED"
)

View File

@ -166,6 +166,35 @@ namespace Opm
return mu.col(pu_.phase_pos[Gas]);
}
/// Gas viscosity.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
V BlackoilPropsAd::muGas(const V& pg,
const V& rv,
const std::vector<PhasePresence>& /*cond*/,
const Cells& cells) const
{
if (!pu_.phase_used[Gas]) {
OPM_THROW(std::runtime_error, "Cannot call muGas(): gas phase not present.");
}
const int n = cells.size();
assert(pg.size() == n);
const int np = props_.numPhases();
Block z = Block::Zero(n, np);
if (pu_.phase_used[Oil]) {
// Faking a z with the right ratio:
// rv = zo/zg
z.col(pu_.phase_pos[Oil]) = rv;
z.col(pu_.phase_pos[Gas]) = V::Ones(n, 1);
}
Block mu(n, np);
props_.viscosity(n, pg.data(), z.data(), cells.data(), mu.data(), 0);
return mu.col(pu_.phase_pos[Gas]);
}
/// Water viscosity.
/// \param[in] pw Array of n water pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
@ -268,6 +297,45 @@ namespace Opm
return ADB::function(mu.col(pu_.phase_pos[Gas]), jacs);
#endif
}
/// Gas viscosity.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n viscosity values.
ADB BlackoilPropsAd::muGas(const ADB& pg,
const ADB& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const
{
#if 1
return ADB::constant(muGas(pg.value(), rv.value(),cond,cells), pg.blockPattern());
#else
if (!pu_.phase_used[Gas]) {
OPM_THROW(std::runtime_error, "Cannot call muGas(): gas phase not present.");
}
const int n = cells.size();
assert(pg.value().size() == n);
const int np = props_.numPhases();
Block z = Block::Zero(n, np);
if (pu_.phase_used[Oil]) {
// Faking a z with the right ratio:
// rv = zo/zg
z.col(pu_.phase_pos[Oil]) = rv;
z.col(pu_.phase_pos[Gas]) = V::Ones(n, 1);
}
Block mu(n, np);
Block dmu(n, np);
props_.viscosity(n, pg.value().data(), z.data(), cells.data(), mu.data(), dmu.data());
ADB::M dmu_diag = spdiag(dmu.col(pu_.phase_pos[Gas]));
const int num_blocks = pg.numBlocks();
std::vector<ADB::M> jacs(num_blocks);
for (int block = 0; block < num_blocks; ++block) {
jacs[block] = dmu_diag * pg.derivative()[block];
}
return ADB::function(mu.col(pu_.phase_pos[Gas]), jacs);
#endif
}
// ------ Formation volume factor (b) ------
@ -357,6 +425,36 @@ namespace Opm
return matrix.col(gi*np + gi);
}
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
V BlackoilPropsAd::bGas(const V& pg,
const V& rv,
const std::vector<PhasePresence>& /*cond*/,
const Cells& cells) const
{
if (!pu_.phase_used[Gas]) {
OPM_THROW(std::runtime_error, "Cannot call bGas(): gas phase not present.");
}
const int n = cells.size();
assert(pg.size() == n);
const int np = props_.numPhases();
Block z = Block::Zero(n, np);
if (pu_.phase_used[Oil]) {
// Faking a z with the right ratio:
// rv = zo/zg
z.col(pu_.phase_pos[Oil]) = rv;
z.col(pu_.phase_pos[Gas]) = V::Ones(n, 1);
}
Block matrix(n, np*np);
props_.matrix(n, pg.data(), z.data(), cells.data(), matrix.data(), 0);
const int gi = pu_.phase_pos[Gas];
return matrix.col(gi*np + gi);
}
/// Water formation volume factor.
/// \param[in] pw Array of n water pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
@ -454,6 +552,44 @@ namespace Opm
return ADB::function(matrix.col(column), jacs);
}
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
ADB BlackoilPropsAd::bGas(const ADB& pg,
const ADB& rv,
const std::vector<PhasePresence>& /*cond*/,
const Cells& cells) const
{
if (!pu_.phase_used[Gas]) {
OPM_THROW(std::runtime_error, "Cannot call muGas(): gas phase not present.");
}
const int n = cells.size();
assert(pg.value().size() == n);
const int np = props_.numPhases();
Block z = Block::Zero(n, np);
if (pu_.phase_used[Oil]) {
// Faking a z with the right ratio:
// rv = zo/zg
z.col(pu_.phase_pos[Oil]) = rv.value();
z.col(pu_.phase_pos[Gas]) = V::Ones(n, 1);
}
Block matrix(n, np*np);
Block dmatrix(n, np*np);
props_.matrix(n, pg.value().data(), z.data(), cells.data(), matrix.data(), dmatrix.data());
const int phase_ind = pu_.phase_pos[Gas];
const int column = phase_ind*np + phase_ind; // Index of our sought diagonal column.
ADB::M db_diag = spdiag(dmatrix.col(column));
const int num_blocks = pg.numBlocks();
std::vector<ADB::M> jacs(num_blocks);
for (int block = 0; block < num_blocks; ++block) {
jacs[block] = db_diag * pg.derivative()[block];
}
return ADB::function(matrix.col(column), jacs);
}
// ------ Rs bubble point curve ------
@ -461,7 +597,7 @@ namespace Opm
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
V BlackoilPropsAd::rsMax(const V& po,
V BlackoilPropsAd::rsSat(const V& po,
const Cells& cells) const
{
// Suppress warning about "unused parameters".
@ -475,7 +611,37 @@ namespace Opm
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
ADB BlackoilPropsAd::rsMax(const ADB& po,
ADB BlackoilPropsAd::rsSat(const ADB& po,
const Cells& cells) const
{
// Suppress warning about "unused parameters".
static_cast<void>(po);
static_cast<void>(cells);
OPM_THROW(std::runtime_error, "Method rsMax() not implemented.");
}
// ------ Rs bubble point curve ------
/// Bubble point curve for Rs as function of oil pressure.
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
V BlackoilPropsAd::rvSat(const V& po,
const Cells& cells) const
{
// Suppress warning about "unused parameters".
static_cast<void>(po);
static_cast<void>(cells);
OPM_THROW(std::runtime_error, "Method rsMax() not implemented.");
}
/// Bubble point curve for Rs as function of oil pressure.
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
ADB BlackoilPropsAd::rvSat(const ADB& po,
const Cells& cells) const
{
// Suppress warning about "unused parameters".

View File

@ -124,6 +124,17 @@ namespace Opm
V muGas(const V& pg,
const Cells& cells) const;
/// Gas viscosity.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] rv Array of n gas solution factor values.
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n viscosity values.
V muGas(const V& pg,
const V& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const;
/// Water viscosity.
/// \param[in] pw Array of n water pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
@ -149,6 +160,16 @@ namespace Opm
ADB muGas(const ADB& pg,
const Cells& cells) const;
/// Gas viscosity.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] rv Array of n gas solution factor values.
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n viscosity values.
ADB muGas(const ADB& pg,
const ADB& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const;
// ------ Formation volume factor (b) ------
@ -177,6 +198,17 @@ namespace Opm
V bGas(const V& pg,
const Cells& cells) const;
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
V bGas(const V& pg,
const V& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const;
/// Water formation volume factor.
/// \param[in] pw Array of n water pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
@ -203,22 +235,47 @@ namespace Opm
const Cells& cells) const;
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
ADB bGas(const ADB& pg,
const ADB& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const;
// ------ Rs bubble point curve ------
/// Bubble point curve for Rs as function of oil pressure.
/// Solution gas/oil ratio and its derivatives at saturated condition as a function of p.
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
V rsMax(const V& po,
V rsSat(const V& po,
const Cells& cells) const;
/// Bubble point curve for Rs as function of oil pressure.
/// Solution gas/oil ratio and its derivatives at saturated condition as a function of p.
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
ADB rsMax(const ADB& po,
ADB rsSat(const ADB& po,
const Cells& cells) const;
// ------ Rv condensation curve ------
/// Vapor oil/gas ratio and its derivatives at saturated conditions as a function of p.
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
V rvSat(const V& po,
const Cells& cells) const;
/// Vapor oil/gas ratio and its derivatives at saturated conditions as a function of p.
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
ADB rvSat(const ADB& po,
const Cells& cells) const;
// ------ Relative permeability ------

View File

@ -28,6 +28,7 @@
#include <opm/core/props/pvt/SinglePvtDead.hpp>
#include <opm/core/props/pvt/SinglePvtDeadSpline.hpp>
#include <opm/core/props/pvt/SinglePvtLiveOil.hpp>
#include <opm/core/props/pvt/SinglePvtLiveGas.hpp>
#include <opm/core/utility/ErrorMacros.hpp>
#include <opm/core/utility/Units.hpp>
@ -108,8 +109,8 @@ namespace Opm
} else {
props_[phase_usage_.phase_pos[Vapour]].reset(new SinglePvtDead(deck.getPVDG().pvdg_));
}
// } else if (deck.hasField("PVTG")) {
// props_[phase_usage_.phase_pos[Vapour]].reset(new SinglePvtLiveGas(deck.getPVTG().pvtg_));
} else if (deck.hasField("PVTG")) {
props_[phase_usage_.phase_pos[Vapour]].reset(new SinglePvtLiveGas(deck.getPVTG().pvtg_));
} else {
OPM_THROW(std::runtime_error, "Input is missing PVDG or PVTG\n");
}
@ -256,6 +257,29 @@ namespace Opm
return mu;
}
/// Gas viscosity.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n viscosity values.
V BlackoilPropsAdFromDeck::muGas(const V& pg,
const V& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const
{
if (!phase_usage_.phase_used[Gas]) {
OPM_THROW(std::runtime_error, "Cannot call muGas(): gas phase not present.");
}
const int n = cells.size();
assert(pg.size() == n);
V mu(n);
V dmudp(n);
V dmudr(n);
props_[phase_usage_.phase_pos[Gas]]->mu(n, pg.data(), rv.data(),&cond[0],
mu.data(), dmudp.data(), dmudr.data());
return mu;
}
/// Water viscosity.
/// \param[in] pw Array of n water pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
@ -332,9 +356,9 @@ namespace Opm
V mu(n);
V dmudp(n);
V dmudr(n);
const double* rs = 0;
const double* rv = 0;
props_[phase_usage_.phase_pos[Gas]]->mu(n, pg.value().data(), rs,
props_[phase_usage_.phase_pos[Gas]]->mu(n, pg.value().data(), rv,
mu.data(), dmudp.data(), dmudr.data());
ADB::M dmudp_diag = spdiag(dmudp);
@ -346,6 +370,39 @@ namespace Opm
return ADB::function(mu, jacs);
}
/// Gas viscosity.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n taxonomies classifying fluid condition.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n viscosity values.
ADB BlackoilPropsAdFromDeck::muGas(const ADB& pg,
const ADB& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const
{
if (!phase_usage_.phase_used[Gas]) {
OPM_THROW(std::runtime_error, "Cannot call muGas(): gas phase not present.");
}
const int n = cells.size();
assert(pg.value().size() == n);
V mu(n);
V dmudp(n);
V dmudr(n);
props_[phase_usage_.phase_pos[Gas]]->mu(n, pg.value().data(), rv.value().data(),&cond[0],
mu.data(), dmudp.data(), dmudr.data());
ADB::M dmudp_diag = spdiag(dmudp);
ADB::M dmudr_diag = spdiag(dmudr);
const int num_blocks = pg.numBlocks();
std::vector<ADB::M> jacs(num_blocks);
for (int block = 0; block < num_blocks; ++block) {
jacs[block] = dmudp_diag * pg.derivative()[block] + dmudr_diag * rv.derivative()[block];
}
return ADB::function(mu, jacs);
}
// ------ Formation volume factor (b) ------
@ -439,6 +496,33 @@ namespace Opm
return b;
}
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
V BlackoilPropsAdFromDeck::bGas(const V& pg,
const V& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const
{
if (!phase_usage_.phase_used[Gas]) {
OPM_THROW(std::runtime_error, "Cannot call muGas(): gas phase not present.");
}
const int n = cells.size();
assert(pg.size() == n);
V b(n);
V dbdp(n);
V dbdr(n);
props_[phase_usage_.phase_pos[Gas]]->b(n, pg.data(), rv.data(), &cond[0],
b.data(), dbdp.data(), dbdr.data());
return b;
}
/// Water formation volume factor.
/// \param[in] pw Array of n water pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
@ -519,9 +603,9 @@ namespace Opm
V b(n);
V dbdp(n);
V dbdr(n);
const double* rs = 0;
const double* rv = 0;
props_[phase_usage_.phase_pos[Gas]]->b(n, pg.value().data(), rs,
props_[phase_usage_.phase_pos[Gas]]->b(n, pg.value().data(), rv,
b.data(), dbdp.data(), dbdr.data());
ADB::M dbdp_diag = spdiag(dbdp);
@ -533,6 +617,40 @@ namespace Opm
return ADB::function(b, jacs);
}
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
ADB BlackoilPropsAdFromDeck::bGas(const ADB& pg,
const ADB& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const
{
if (!phase_usage_.phase_used[Gas]) {
OPM_THROW(std::runtime_error, "Cannot call muGas(): gas phase not present.");
}
const int n = cells.size();
assert(pg.size() == n);
V b(n);
V dbdp(n);
V dbdr(n);
props_[phase_usage_.phase_pos[Gas]]->b(n, pg.value().data(), rv.value().data(), &cond[0],
b.data(), dbdp.data(), dbdr.data());
ADB::M dbdp_diag = spdiag(dbdp);
ADB::M dmudr_diag = spdiag(dbdr);
const int num_blocks = pg.numBlocks();
std::vector<ADB::M> jacs(num_blocks);
for (int block = 0; block < num_blocks; ++block) {
jacs[block] = dbdp_diag * pg.derivative()[block] + dmudr_diag * rv.derivative()[block];;
}
return ADB::function(b, jacs);
}
// ------ Rs bubble point curve ------
@ -541,7 +659,7 @@ namespace Opm
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
V BlackoilPropsAdFromDeck::rsMax(const V& po,
V BlackoilPropsAdFromDeck::rsSat(const V& po,
const Cells& cells) const
{
if (!phase_usage_.phase_used[Oil]) {
@ -551,7 +669,7 @@ namespace Opm
assert(po.size() == n);
V rbub(n);
V drbubdp(n);
props_[Oil]->rbub(n, po.data(), rbub.data(), drbubdp.data());
props_[Oil]->rsSat(n, po.data(), rbub.data(), drbubdp.data());
return rbub;
}
@ -559,7 +677,7 @@ namespace Opm
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
ADB BlackoilPropsAdFromDeck::rsMax(const ADB& po,
ADB BlackoilPropsAdFromDeck::rsSat(const ADB& po,
const Cells& cells) const
{
if (!phase_usage_.phase_used[Oil]) {
@ -569,7 +687,7 @@ namespace Opm
assert(po.size() == n);
V rbub(n);
V drbubdp(n);
props_[Oil]->rbub(n, po.value().data(), rbub.data(), drbubdp.data());
props_[Oil]->rsSat(n, po.value().data(), rbub.data(), drbubdp.data());
ADB::M drbubdp_diag = spdiag(drbubdp);
const int num_blocks = po.numBlocks();
std::vector<ADB::M> jacs(num_blocks);
@ -579,6 +697,50 @@ namespace Opm
return ADB::function(rbub, jacs);
}
// ------ Condensation curve ------
/// Condensation curve for Rv as function of oil pressure.
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
V BlackoilPropsAdFromDeck::rvSat(const V& po,
const Cells& cells) const
{
if (!phase_usage_.phase_used[Gas]) {
OPM_THROW(std::runtime_error, "Cannot call rvMax(): gas phase not present.");
}
const int n = cells.size();
assert(po.size() == n);
V rv(n);
V drvdp(n);
props_[Gas]->rvSat(n, po.data(), rv.data(), drvdp.data());
return rv;
}
/// Condensation curve for Rv as function of oil pressure.
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
ADB BlackoilPropsAdFromDeck::rvSat(const ADB& po,
const Cells& cells) const
{
if (!phase_usage_.phase_used[Gas]) {
OPM_THROW(std::runtime_error, "Cannot call rvMax(): gas phase not present.");
}
const int n = cells.size();
assert(po.size() == n);
V rv(n);
V drvdp(n);
props_[Gas]->rvSat(n, po.value().data(), rv.data(), drvdp.data());
ADB::M drvdp_diag = spdiag(drvdp);
const int num_blocks = po.numBlocks();
std::vector<ADB::M> jacs(num_blocks);
for (int block = 0; block < num_blocks; ++block) {
jacs[block] = drvdp_diag * po.derivative()[block];
}
return ADB::function(rv, jacs);
}
// ------ Relative permeability ------
/// Relative permeabilities for all phases.

View File

@ -125,6 +125,17 @@ namespace Opm
V muGas(const V& pg,
const Cells& cells) const;
/// Oil viscosity.
/// \param[in] po Array of n oil pressure values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n viscosity values.
V muGas(const V& po,
const V& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const;
/// Water viscosity.
/// \param[in] pw Array of n water pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
@ -150,6 +161,14 @@ namespace Opm
ADB muGas(const ADB& pg,
const Cells& cells) const;
/// Gas viscosity.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n viscosity values.
ADB muGas(const ADB& pg,
const ADB& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const;
// ------ Formation volume factor (b) ------
@ -178,6 +197,17 @@ namespace Opm
V bGas(const V& pg,
const Cells& cells) const;
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
V bGas(const V& pg,
const V& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const;
/// Water formation volume factor.
/// \param[in] pw Array of n water pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
@ -203,6 +233,16 @@ namespace Opm
ADB bGas(const ADB& pg,
const Cells& cells) const;
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
ADB bGas(const ADB& pg,
const ADB& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const;
// ------ Rs bubble point curve ------
@ -210,16 +250,31 @@ namespace Opm
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
V rsMax(const V& po,
V rsSat(const V& po,
const Cells& cells) const;
/// Bubble point curve for Rs as function of oil pressure.
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
ADB rsMax(const ADB& po,
ADB rsSat(const ADB& po,
const Cells& cells) const;
// ------ Rv condensation curve ------
/// Condensation curve for Rv as function of oil pressure.
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
V rvSat(const V& po,
const Cells& cells) const;
/// Condensation curve for Rv as function of oil pressure.
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
ADB rvSat(const ADB& po,
const Cells& cells) const;
// ------ Relative permeability ------

View File

@ -145,6 +145,15 @@ namespace Opm
ADB muGas(const ADB& pg,
const Cells& cells) const = 0;
/// Gas viscosity.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n viscosity values.
virtual
ADB muGas(const ADB& pg,
const ADB& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const = 0;
// ------ Formation volume factor (b) ------
@ -176,6 +185,18 @@ namespace Opm
V bGas(const V& pg,
const Cells& cells) const = 0;
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
virtual
V bGas(const V& pg,
const V& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const = 0;
/// Water formation volume factor.
/// \param[in] pw Array of n water pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
@ -204,6 +225,17 @@ namespace Opm
ADB bGas(const ADB& pg,
const Cells& cells) const = 0;
/// Gas formation volume factor.
/// \param[in] pg Array of n gas pressure values.
/// \param[in] rv Array of n vapor oil/gas ratio
/// \param[in] cond Array of n objects, each specifying which phases are present with non-zero saturation in a cell.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n formation volume factor values.
virtual
ADB bGas(const ADB& pg,
const ADB& rv,
const std::vector<PhasePresence>& cond,
const Cells& cells) const = 0;
// ------ Rs bubble point curve ------
@ -212,7 +244,7 @@ namespace Opm
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
virtual
V rsMax(const V& po,
V rsSat(const V& po,
const Cells& cells) const = 0;
/// Bubble point curve for Rs as function of oil pressure.
@ -220,7 +252,25 @@ namespace Opm
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
virtual
ADB rsMax(const ADB& po,
ADB rsSat(const ADB& po,
const Cells& cells) const = 0;
// ------ Rs bubble point curve ------
/// Bubble point curve for Rs as function of oil pressure.
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
virtual
V rvSat(const V& po,
const Cells& cells) const = 0;
/// Bubble point curve for Rs as function of oil pressure.
/// \param[in] po Array of n oil pressure values.
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
/// \return Array of n bubble point values for Rs.
virtual
ADB rvSat(const ADB& po,
const Cells& cells) const = 0;
// ------ Relative permeability ------

View File

@ -37,6 +37,7 @@
#include <cmath>
#include <iostream>
#include <iomanip>
//#include <fstream>
// A debugging utility.
#define DUMP(foo) \
@ -211,6 +212,7 @@ namespace {
ADB::null(),
ADB::null(),
ADB::null() } )
, phaseCondition_(grid.number_of_cells)
{
}
@ -226,6 +228,7 @@ namespace {
{
const V pvdt = geo_.poreVolume() / dt;
classifyCondition(x);
{
const SolutionState state = constantState(x, xw);
computeAccum(state, 0);
@ -286,6 +289,7 @@ namespace {
: pressure ( ADB::null())
, saturation(np, ADB::null())
, rs ( ADB::null())
, rv ( ADB::null())
, qs ( ADB::null())
, bhp ( ADB::null())
{
@ -336,18 +340,16 @@ namespace {
// The block pattern assumes the following primary variables:
// pressure
// water saturation (if water present)
// gas saturation (if gas present)
// gas solution factor (if both gas and oil present)
// gas saturation, Rv (vapor oil/gas ratio) or Rs (solution gas/oil ratio) depending on hydrocarbon state
// Gas only (undersaturated gas): Rv
// Gas and oil: Sg
// Oil only (undersaturated oil): Rs
// well rates per active phase and well
// well bottom-hole pressure
// Note that oil is assumed to always be present, but is never
// a primary variable.
assert(active_[ Oil ]);
std::vector<int> bpat(np, nc);
const bool gasandoil = (active_[ Oil ] && active_[ Gas ]);
if (gasandoil) {
bpat.push_back(nc);
}
bpat.push_back(xw.bhp().size() * np);
bpat.push_back(xw.bhp().size());
@ -384,7 +386,7 @@ namespace {
}
}
// Gas-oil ratio (rs).
// Solution Gas-oil ratio (rs).
if (active_[ Oil ] && active_[ Gas ]) {
const V rs = Eigen::Map<const V>(& x.gasoilratio()[0], x.gasoilratio().size());
state.rs = ADB::constant(rs, bpat);
@ -393,6 +395,15 @@ namespace {
state.rs = ADB::constant(Rs, bpat);
}
// Vapor Oil-gas ratio (rv).
if (active_[ Oil ] && active_[ Gas ]) {
const V rv = Eigen::Map<const V>(& x.rv()[0], x.rv().size());
state.rv = ADB::constant(rv, bpat);
} else {
const V rv = V::Zero(nc, 1);
state.rv = ADB::constant(rv, bpat);
}
// Well rates.
assert (not xw.wellRates().empty());
// Need to reshuffle well rates, from ordered by wells, then phase,
@ -423,8 +434,8 @@ namespace {
const int np = x.numPhases();
std::vector<V> vars0;
vars0.reserve(active_[Oil] && active_[Gas] ? np + 2 : np + 1); // Rs is primary if oil and gas present.
// p, Sw and Rs, Rv or Sg is used as primary depending on solution conditions
vars0.reserve(np + 1);
// Initial pressure.
assert (not x.pressure().empty());
const V p = Eigen::Map<const V>(& x.pressure()[0], nc, 1);
@ -440,16 +451,49 @@ namespace {
const V sw = s.col(pu.phase_pos[ Water ]);
vars0.push_back(sw);
}
if (active_[ Gas ]) {
// store cell status in vectors
V isRs = V::Zero(nc,1);
V isRv = V::Zero(nc,1);
V isSg = V::Zero(nc,1);
bool disgas = false;
bool vapoil = false;
if (active_[ Gas ]){
// this is a temporary hack to find if vapoil or disgas
// is a active component. Should be given directly from
// DISGAS and VAPOIL keywords in the deck.
for (int c = 0; c < nc; c++){
if(x.rv()[c] > 0)
vapoil = true;
if(x.gasoilratio ()[c] > 0)
disgas = true;
}
for (int c = 0; c < nc ; c++ ) {
const PhasePresence cond = phaseCondition()[c];
if ( (!cond.hasFreeGas()) && disgas ) {
isRs[c] = 1;
}
else if ( (!cond.hasFreeOil()) && vapoil ) {
isRv[c] = 1;
}
else {
isSg[c] = 1;
}
}
// define new primary variable xvar depending on solution condition
V xvar(nc);
const V sg = s.col(pu.phase_pos[ Gas ]);
vars0.push_back(sg);
const V rs = Eigen::Map<const V>(& x.gasoilratio()[0], x.gasoilratio().size());
const V rv = Eigen::Map<const V>(& x.rv()[0], x.rv().size());
xvar = isRs*rs + isRv*rv + isSg*sg;
vars0.push_back(xvar);
}
// Initial gas-oil ratio (Rs).
if (active_[ Oil ] && active_[ Gas ]) {
const V rs = Eigen::Map<const V>(& x.gasoilratio()[0], x.gasoilratio().size());
vars0.push_back(rs);
}
// Initial well rates.
assert (not xw.wellRates().empty());
@ -474,36 +518,45 @@ namespace {
int nextvar = 0;
state.pressure = vars[ nextvar++ ];
// Saturation.
// Saturations
const std::vector<int>& bpat = vars[0].blockPattern();
{
ADB so = ADB::constant(V::Ones(nc, 1), bpat);
if (active_[ Water ]) {
ADB& sw = vars[ nextvar++ ];
state.saturation[ pu.phase_pos[ Water ] ] = sw;
state.saturation[pu.phase_pos[ Water ]] = sw;
so = so - sw;
}
if (active_[ Gas ]) {
ADB& sg = vars[ nextvar++ ];
state.saturation[ pu.phase_pos[ Gas ] ] = sg;
// Define Sg Rs and Rv in terms of xvar.
std::vector<int> all_cells = buildAllCells(nc);
ADB rsSat = fluidRsSat(state.pressure,all_cells);
ADB rvSat = fluidRvSat(state.pressure,all_cells);
ADB xvar = vars[ nextvar++ ];
if (active_[ Gas]) {
ADB sg = isSg*xvar + isRv* so;
state.saturation[ pu.phase_pos[ Gas ] ] = sg;
so = so - sg;
if (disgas) {
state.rs = (1-isRs) * rsSat + isRs*xvar;
} else {
state.rs = rsSat;
}
if (vapoil) {
state.rv = (1-isRv) * rvSat + isRv*xvar;
} else {
state.rv = rvSat;
}
}
if (active_[ Oil ]) {
// Note that so is never a primary variable.
state.saturation[ pu.phase_pos[ Oil ] ] = so;
}
}
// Rs.
if (active_[ Oil ] && active_[ Gas ]) {
state.rs = vars[ nextvar++ ];
} else {
state.rs = ADB::constant(V::Zero(nc), bpat);
}
// Qs.
state.qs = vars[ nextvar++ ];
@ -528,9 +581,9 @@ namespace {
const ADB& press = state.pressure;
const std::vector<ADB>& sat = state.saturation;
const ADB& rs = state.rs;
const ADB& rv = state.rv;
std::vector<PhasePresence> cond;
classifyCondition(state, cond);
const std::vector<PhasePresence> cond = phaseCondition();
const ADB pv_mult = poroMult(press);
@ -538,7 +591,7 @@ namespace {
for (int phase = 0; phase < maxnp; ++phase) {
if (active_[ phase ]) {
const int pos = pu.phase_pos[ phase ];
rq_[pos].b = fluidReciprocFVF(phase, press, rs, cond, cells_);
rq_[pos].b = fluidReciprocFVF(phase, press, rs, rv, cond, cells_);
rq_[pos].accum[aix] = pv_mult * rq_[pos].b * sat[pos];
// DUMP(rq_[pos].b);
// DUMP(rq_[pos].accum[aix]);
@ -546,11 +599,12 @@ namespace {
}
if (active_[ Oil ] && active_[ Gas ]) {
// Account for gas dissolved in oil.
// Account for gas dissolved in oil and vaporized oil
const int po = pu.phase_pos[ Oil ];
const int pg = pu.phase_pos[ Gas ];
rq_[pg].accum[aix] += state.rs * rq_[po].accum[aix];
rq_[po].accum[aix] += state.rv * rq_[pg].accum[aix];
//DUMP(rq_[pg].accum[aix]);
}
}
@ -594,32 +648,33 @@ namespace {
pvdt*(rq_[phaseIdx].accum[1] - rq_[phaseIdx].accum[0])
+ ops_.div*rq_[phaseIdx].mflux;
// DUMP(ops_.div*rq_[phase].mflux);
// DUMP(residual_.mass_balance[phase]);
}
// -------- Extra (optional) sg or rs equation, and rs contributions to the mass balance equations --------
// -------- Extra (optional) rs and rv contributions to the mass balance equations --------
// Add the extra (flux) terms to the gas mass balance equations
// from gas dissolved in the oil phase.
// Add the extra (flux) terms to the mass balance equations
// From gas dissolved in the oil phase (rs) and oil vaporized in the gas phase (rv)
// The extra terms in the accumulation part of the equation are already handled.
if (active_[ Oil ] && active_[ Gas ]) {
const int po = fluid_.phaseUsage().phase_pos[ Oil ];
const UpwindSelector<double> upwind(grid_, ops_,
const UpwindSelector<double> upwindOil(grid_, ops_,
rq_[po].head.value());
const ADB rs_face = upwind.select(state.rs);
const ADB rs_face = upwindOil.select(state.rs);
residual_.mass_balance[ Gas ] += ops_.div * (rs_face * rq_[po].mflux);
const int pg = fluid_.phaseUsage().phase_pos[ Gas ];
const UpwindSelector<double> upwindGas(grid_, ops_,
rq_[pg].head.value());
const ADB rv_face = upwindGas.select(state.rv);
residual_.mass_balance[ Oil ] += ops_.div * (rv_face * rq_[pg].mflux);
// DUMP(residual_.mass_balance[ Gas ]);
// Also, we have another equation: sg = 0 or rs = rsMax.
const int pg = fluid_.phaseUsage().phase_pos[ Gas ];
const ADB sg_eq = state.saturation[pg];
const ADB rs_max = fluidRsMax(state.pressure, cells_);
const ADB rs_eq = state.rs - rs_max;
// Consider the fluid to be saturated if sg >= 1e-14 (a small number)
Selector<double> use_sat_eq(sg_eq.value()-1e-14);
residual_.rs_or_sg_eq = use_sat_eq.select(rs_eq, sg_eq);
// DUMP(residual_.rs_or_sg_eq);
}
// -------- Well equation, and well contributions to the mass balance equations --------
@ -655,14 +710,14 @@ namespace {
}
}
std::vector<PhasePresence> cond;
classifyCondition(state, cond);
// make a copy of the phaseConditions
std::vector<PhasePresence> cond = phaseCondition_;
ADB cell_rho_total = ADB::constant(V::Zero(nc), state.pressure.blockPattern());
for (int phase = 0; phase < 3; ++phase) {
if (active_[phase]) {
const int pos = pu.phase_pos[phase];
const ADB cell_rho = fluidDensity(phase, state.pressure, state.rs, cond, cells_);
const ADB cell_rho = fluidDensity(phase, state.pressure, state.rs, state.rv,cond, cells_);
cell_rho_total += state.saturation[pos] * cell_rho;
}
}
@ -672,7 +727,7 @@ namespace {
for (int phase = 0; phase < 3; ++phase) {
if (active_[phase]) {
const int pos = pu.phase_pos[phase];
const ADB cell_rho = fluidDensity(phase, state.pressure, state.rs, cond, cells_);
const ADB cell_rho = fluidDensity(phase, state.pressure, state.rs, state.rv,cond, cells_);
const V fraction = compi.col(pos);
inj_rho_total += (wops_.w2p * fraction.matrix()).array() * subset(cell_rho, well_cells);
}
@ -724,9 +779,12 @@ namespace {
const int oilpos = pu.phase_pos[Oil];
const int gaspos = pu.phase_pos[Gas];
const ADB rs_perf = subset(state.rs, well_cells);
const ADB rv_perf = subset(state.rv, well_cells);
well_rates_all += superset(wops_.p2w * (well_perf_rates[oilpos]*rs_perf), Span(nw, 1, gaspos*nw), nw*np);
well_rates_all += superset(wops_.p2w * (well_perf_rates[gaspos]*rv_perf), Span(nw, 1, oilpos*nw), nw*np);
// DUMP(well_contribs[gaspos] + well_contribs[oilpos]*state.rs);
residual_.mass_balance[gaspos] += well_contribs[oilpos]*state.rs;
residual_.mass_balance[oilpos] += well_contribs[gaspos]*state.rv;
}
// Set the well flux equation
@ -774,9 +832,6 @@ namespace {
for (int phase = 1; phase < np; ++phase) {
mass_res = vertcat(mass_res, residual_.mass_balance[phase]);
}
if (active_[Oil] && active_[Gas]) {
mass_res = vertcat(mass_res, residual_.rs_or_sg_eq);
}
const ADB well_res = vertcat(residual_.well_flux_eq, residual_.well_eq);
const ADB total_residual = collapseJacs(vertcat(mass_res, well_res));
// DUMP(total_residual);
@ -788,6 +843,18 @@ namespace {
= linsolver_.solve(matr.rows(), matr.nonZeros(),
matr.outerIndexPtr(), matr.innerIndexPtr(), matr.valuePtr(),
total_residual.value().data(), dx.data());
/*
std::ofstream filestream("matrix.out");
filestream << matr;
filestream.close();
std::ofstream filestream2("sol.out");
filestream2 << dx;
filestream2.close();
std::ofstream filestream3("r.out");
filestream3 << total_residual.value();
filestream3.close(); */
if (!rep.converged) {
OPM_THROW(std::runtime_error,
"FullyImplicitBlackoilSolver::solveJacobianSystem(): "
@ -812,7 +879,7 @@ namespace {
void FullyImplicitBlackoilSolver::updateState(const V& dx,
BlackoilState& state,
WellState& well_state) const
WellState& well_state)
{
const int np = fluid_.numPhases();
const int nc = grid_.number_of_cells;
@ -822,15 +889,47 @@ namespace {
const V zero = V::Zero(nc);
const V one = V::Constant(nc, 1.0);
// store cell status in vectors
V isRs = V::Zero(nc,1);
V isRv = V::Zero(nc,1);
V isSg = V::Zero(nc,1);
bool disgas = false;
bool vapoil = false;
// this is a temporary hack to find if vapoil or disgas
// is a active component. Should be given directly from
// DISGAS and VAPOIL keywords in the deck.
for (int c = 0; c<nc; c++){
if(state.rv()[c]>0)
vapoil = true;
if(state.gasoilratio()[c]>0)
disgas = true;
}
const std::vector<PhasePresence> conditions = phaseCondition();
for (int c = 0; c < nc; c++ ) {
const PhasePresence cond = conditions[c];
if ( (!cond.hasFreeGas()) && disgas ) {
isRs[c] = 1;
}
else if ( (!cond.hasFreeOil()) && vapoil ) {
isRv[c] = 1;
}
else {
isSg[c] = 1;
}
}
// Extract parts of dx corresponding to each part.
const V dp = subset(dx, Span(nc));
int varstart = nc;
const V dsw = active_[Water] ? subset(dx, Span(nc, 1, varstart)) : null;
varstart += dsw.size();
const V dsg = active_[Gas] ? subset(dx, Span(nc, 1, varstart)) : null;
varstart += dsg.size();
const V drs = (active_[Water] && active_[Gas]) ? subset(dx, Span(nc, 1, varstart)) : null;
varstart += drs.size();
const V dxvar = active_[Gas] ? subset(dx, Span(nc, 1, varstart)): null;
varstart += dxvar.size();
const V dqs = subset(dx, Span(np*nw, 1, varstart));
varstart += dqs.size();
const V dbhp = subset(dx, Span(nw, 1, varstart));
@ -845,81 +944,151 @@ namespace {
const V p = (p_old - dp_limited).max(zero);
std::copy(&p[0], &p[0] + nc, state.pressure().begin());
// Rs update. Moved before the saturation update because it is
// needed there.
if (active_[Oil] && active_[Gas]) {
const double drsmaxrel = 0.8;
const V rs_old = Eigen::Map<const V>(&state.gasoilratio()[0], nc);
const V absdrsmax = drsmaxrel*rs_old.abs();
const V drs_limited = sign(drs) * drs.abs().min(absdrsmax);
const V rs = rs_old - drs_limited;
std::copy(&rs[0], &rs[0] + nc, state.gasoilratio().begin());
}
// Saturation updates.
const double dsmax = 0.3;
const DataBlock s_old = Eigen::Map<const DataBlock>(& state.saturation()[0], nc, np);
V so = one;
const Opm::PhaseUsage& pu = fluid_.phaseUsage();
const DataBlock s_old = Eigen::Map<const DataBlock>(& state.saturation()[0], nc, np);
const double dsmax = 0.3;
V so = one;
V sw;
if (active_[ Water ]) {
const int pos = pu.phase_pos[ Water ];
const V sw_old = s_old.col(pos);
const V dsw_limited = sign(dsw) * dsw.abs().min(dsmax);
const V sw = (sw_old - dsw_limited).unaryExpr(Chop01());
sw = (sw_old - dsw_limited).unaryExpr(Chop01());
so -= sw;
for (int c = 0; c < nc; ++c) {
state.saturation()[c*np + pos] = sw[c];
}
}
if (active_[ Gas ]) {
V sg;
if (active_[Gas]) {
const int pos = pu.phase_pos[ Gas ];
const V sg_old = s_old.col(pos);
const V dsg = isSg * dxvar - isRv * dsw;
const V dsg_limited = sign(dsg) * dsg.abs().min(dsmax);
V sg = sg_old - dsg_limited;
if (active_[ Oil ]) {
// Appleyard chop process.
const double epsilon = std::sqrt(std::numeric_limits<double>::epsilon());
const double above_epsilon = 2.0*epsilon;
const double rs_adjust = 1.0;
auto sat2usat = (sg_old > 0.0) && (sg <= 0.0);
Eigen::Map<V> rs(&state.gasoilratio()[0], nc);
const V rs_sat = fluidRsMax(p, cells_);
auto over_saturated = ((sg > 0) || (rs > rs_sat*rs_adjust)) && (sat2usat == false);
auto usat2sat = (sg_old < epsilon) && over_saturated;
auto zerosg = (sat2usat && sg_old <= above_epsilon);
auto epssg = (sat2usat && sg_old > epsilon);
// With no simple support for Matlab-style statements below,
// we use an explicit for loop.
// sg(zerosg) = 0.0;
// sg(epssg) = epsilon;
// sg(usat2sat) = above_epsilon;
// rs(sg > 0) = rs_sat(sg > 0);
// rs(rs > rs_sat*rs_adjust) = rs_sat(rs > rs_sat*rs_adjust);
for (int c = 0; c < nc; ++c) {
if (zerosg[c]) {
sg[c] = 0.0;
}
if (epssg[c]) {
sg[c] = epsilon;
}
if (usat2sat[c]) {
sg[c] = above_epsilon;
}
if (sg[c] > 0.0) {
rs[c] = rs_sat[c];
}
if (rs[c] > rs_sat[c]*rs_adjust) {
rs[c] = rs_sat[c];
}
}
}
sg.unaryExpr(Chop01());
sg = sg_old - dsg_limited;
so -= sg;
}
const double drsmax = 1e9;
const double drvmax = 1e9;//% same as in Mrst
V rs;
if (disgas) {
const V rs_old = Eigen::Map<const V>(&state.gasoilratio()[0], nc);
const V drs = isRs * dxvar;
const V drs_limited = sign(drs) * drs.abs().min(drsmax);
rs = rs_old - drs_limited;
}
V rv;
if (vapoil) {
const V rv_old = Eigen::Map<const V>(&state.rv()[0], nc);
const V drv = isRv * dxvar;
const V drv_limited = sign(drv) * drv.abs().min(drvmax);
rv = rv_old - drv_limited;
}
// Appleyard chop process.
const double epsilon = std::sqrt(std::numeric_limits<double>::epsilon());
auto watOnly = sw > (1 - epsilon);
// phase translation sg <-> rs
const V rsSat0 = fluidRsSat(p_old, cells_);
const V rsSat = fluidRsSat(p, cells_);
// reset the phase conditions
std::vector<PhasePresence> cond(nc);
if (disgas) {
// The obvioious case
auto ix0 = (sg > 0 && isRs == 0);
// keep oil saturated if previous sg is sufficient large:
const int pos = pu.phase_pos[ Gas ];
auto ix1 = (sg < 0 && s_old.col(pos) > epsilon);
// Set oil saturated if previous rs is sufficiently large
const V rs_old = Eigen::Map<const V>(&state.gasoilratio()[0], nc);
auto ix2 = ( (rs > rsSat * (1+epsilon) && isRs == 1 ) && (rs_old > rsSat0 * (1-epsilon)) );
auto gasPresent = watOnly || ix0 || ix1 || ix2;
for (int c = 0; c < nc; ++c) {
state.saturation()[c*np + pos] = sg[c];
if (gasPresent[c]) {
rs[c] = rsSat[c];
cond[c].setFreeGas();
}
}
}
// phase transitions so <-> rv
const V rvSat0 = fluidRvSat(p_old, cells_);
const V rvSat = fluidRvSat(p, cells_);
if (vapoil) {
// The obvious case
auto ix0 = (so > 0 && isRv == 0);
// keep oil saturated if previous sg is sufficient large:
const int pos = pu.phase_pos[ Oil ];
auto ix1 = (so < 0 && s_old.col(pos) > epsilon );
// Set oil saturated if previous rs is sufficiently large
const V rv_old = Eigen::Map<const V>(&state.rv()[0], nc);
auto ix2 = ( (rv > rvSat * (1+epsilon) && isRv == 1) && (rv_old > rvSat0 * (1-epsilon)) );
auto oilPresent = watOnly || ix0 || ix1 || ix2;
for (int c = 0; c < nc; ++c) {
if (oilPresent[c]) {
rv[c] = rvSat[c];
cond[c].setFreeOil();
}
}
}
std::copy(&cond[0], &cond[0] + nc, phaseCondition_.begin());
auto ixg = sg < 0;
for (int c = 0; c < nc; ++c) {
if (ixg[c]) {
sw[c] = sw[c] / (1-sg[c]);
so[c] = so[c] / (1-sg[c]);
sg[c] = 0;
}
}
auto ixo = so < 0;
for (int c = 0; c < nc; ++c) {
if (ixo[c]) {
sw[c] = sw[c] / (1-so[c]);
sg[c] = sg[c] / (1-so[c]);
so[c] = 0;
}
}
auto ixw = sw < 0;
for (int c = 0; c < nc; ++c) {
if (ixw[c]) {
so[c] = so[c] / (1-sw[c]);
sg[c] = sg[c] / (1-so[c]);
sw[c] = 0;
}
}
// Update saturations
for (int c = 0; c < nc; ++c) {
state.saturation()[c*np + pu.phase_pos[ Water ]] = sw[c];
}
for (int c = 0; c < nc; ++c) {
state.saturation()[c*np + pu.phase_pos[ Gas ]] = sg[c];
}
if (active_[ Oil ]) {
const int pos = pu.phase_pos[ Oil ];
for (int c = 0; c < nc; ++c) {
@ -927,6 +1096,15 @@ namespace {
}
}
// Rs and Rv updates
if (disgas)
std::copy(&rs[0], &rs[0] + nc, state.gasoilratio().begin());
if (vapoil)
std::copy(&rv[0], &rv[0] + nc, state.rv().begin());
// Qs update.
// Since we need to update the wellrates, that are ordered by wells,
// from dqs which are ordered by phase, the simplest is to compute
@ -1054,15 +1232,14 @@ namespace {
{
const int canonicalPhaseIdx = canph_[ actph ];
std::vector<PhasePresence> cond;
classifyCondition(state, cond);
const std::vector<PhasePresence> cond = phaseCondition();
const ADB tr_mult = transMult(state.pressure);
const ADB mu = fluidViscosity(canonicalPhaseIdx, phasePressure, state.rs, cond, cells_);
const ADB mu = fluidViscosity(canonicalPhaseIdx, phasePressure, state.rs, state.rv,cond, cells_);
rq_[ actph ].mob = tr_mult * kr / mu;
const ADB rho = fluidDensity(canonicalPhaseIdx, phasePressure, state.rs, cond, cells_);
const ADB rho = fluidDensity(canonicalPhaseIdx, phasePressure, state.rs, state.rv,cond, cells_);
ADB& head = rq_[ actph ].head;
@ -1115,6 +1292,7 @@ namespace {
FullyImplicitBlackoilSolver::fluidViscosity(const int phase,
const ADB& p ,
const ADB& rs ,
const ADB& rv ,
const std::vector<PhasePresence>& cond,
const std::vector<int>& cells) const
{
@ -1125,7 +1303,7 @@ namespace {
return fluid_.muOil(p, rs, cond, cells);
}
case Gas:
return fluid_.muGas(p, cells);
return fluid_.muGas(p, rv, cond, cells);
default:
OPM_THROW(std::runtime_error, "Unknown phase index " << phase);
}
@ -1139,6 +1317,7 @@ namespace {
FullyImplicitBlackoilSolver::fluidReciprocFVF(const int phase,
const ADB& p ,
const ADB& rs ,
const ADB& rv ,
const std::vector<PhasePresence>& cond,
const std::vector<int>& cells) const
{
@ -1149,7 +1328,7 @@ namespace {
return fluid_.bOil(p, rs, cond, cells);
}
case Gas:
return fluid_.bGas(p, cells);
return fluid_.bGas(p, rv, cond, cells);
default:
OPM_THROW(std::runtime_error, "Unknown phase index " << phase);
}
@ -1163,16 +1342,21 @@ namespace {
FullyImplicitBlackoilSolver::fluidDensity(const int phase,
const ADB& p ,
const ADB& rs ,
const ADB& rv ,
const std::vector<PhasePresence>& cond,
const std::vector<int>& cells) const
{
const double* rhos = fluid_.surfaceDensity();
ADB b = fluidReciprocFVF(phase, p, rs, cond, cells);
ADB b = fluidReciprocFVF(phase, p, rs, rv, cond, cells);
ADB rho = V::Constant(p.size(), 1, rhos[phase]) * b;
if (phase == Oil && active_[Gas]) {
// It is correct to index into rhos with canonical phase indices.
rho += V::Constant(p.size(), 1, rhos[Gas]) * rs * b;
}
if (phase == Gas && active_[Oil]) {
// It is correct to index into rhos with canonical phase indices.
rho += V::Constant(p.size(), 1, rhos[Oil]) * rv * b;
}
return rho;
}
@ -1181,10 +1365,10 @@ namespace {
V
FullyImplicitBlackoilSolver::fluidRsMax(const V& p,
FullyImplicitBlackoilSolver::fluidRsSat(const V& p,
const std::vector<int>& cells) const
{
return fluid_.rsMax(p, cells);
return fluid_.rsSat(p, cells);
}
@ -1192,16 +1376,32 @@ namespace {
ADB
FullyImplicitBlackoilSolver::fluidRsMax(const ADB& p,
FullyImplicitBlackoilSolver::fluidRsSat(const ADB& p,
const std::vector<int>& cells) const
{
return fluid_.rsMax(p, cells);
return fluid_.rsSat(p, cells);
}
V
FullyImplicitBlackoilSolver::fluidRvSat(const V& p,
const std::vector<int>& cells) const
{
return fluid_.rvSat(p, cells);
}
ADB
FullyImplicitBlackoilSolver::fluidRvSat(const ADB& p,
const std::vector<int>& cells) const
{
return fluid_.rvSat(p, cells);
}
ADB
FullyImplicitBlackoilSolver::poroMult(const ADB& p) const
{
@ -1253,6 +1453,7 @@ namespace {
}
/*
void
FullyImplicitBlackoilSolver::
classifyCondition(const SolutionState& state,
@ -1291,7 +1492,43 @@ namespace {
if (so[c] > 0) { cond[c].setFreeOil(); }
}
}
} */
void
FullyImplicitBlackoilSolver::classifyCondition(const BlackoilState& state)
{
const int nc = grid_.number_of_cells;
const int np = state.numPhases();
const PhaseUsage& pu = fluid_.phaseUsage();
const DataBlock s = Eigen::Map<const DataBlock>(& state.saturation()[0], nc, np);
if (active_[ Gas ]) {
// Oil/Gas or Water/Oil/Gas system
const V so = s.col(pu.phase_pos[ Oil ]);
const V sg = s.col(pu.phase_pos[ Gas ]);
for (V::Index c = 0, e = sg.size(); c != e; ++c) {
if (so[c] > 0) { phaseCondition_[c].setFreeOil (); }
if (sg[c] > 0) { phaseCondition_[c].setFreeGas (); }
if (active_[ Water ]) { phaseCondition_[c].setFreeWater(); }
}
}
else {
// Water/Oil system
assert (active_[ Water ]);
const V so = s.col(pu.phase_pos[ Oil ]);
for (V::Index c = 0, e = so.size(); c != e; ++c) {
phaseCondition_[c].setFreeWater();
if (so[c] > 0) { phaseCondition_[c].setFreeOil(); }
}
}
}
} // namespace Opm

View File

@ -102,8 +102,9 @@ namespace Opm {
ADB pressure;
std::vector<ADB> saturation;
ADB rs;
ADB rv;
ADB qs;
ADB bhp;
ADB bhp;
};
struct WellOps {
@ -133,6 +134,7 @@ namespace Opm {
const M grav_;
std::vector<ReservoirResidualQuant> rq_;
std::vector<PhasePresence> phaseCondition_;
// The mass_balance vector has one element for each active phase,
// each of which has size equal to the number of cells.
@ -166,7 +168,7 @@ namespace Opm {
void updateState(const V& dx,
BlackoilState& state,
WellState& well_state) const;
WellState& well_state);
std::vector<ADB>
computePressures(const SolutionState& state) const;
@ -193,6 +195,7 @@ namespace Opm {
fluidViscosity(const int phase,
const ADB& p ,
const ADB& rs ,
const ADB& rv ,
const std::vector<PhasePresence>& cond,
const std::vector<int>& cells) const;
@ -200,6 +203,7 @@ namespace Opm {
fluidReciprocFVF(const int phase,
const ADB& p ,
const ADB& rs ,
const ADB& rv ,
const std::vector<PhasePresence>& cond,
const std::vector<int>& cells) const;
@ -207,15 +211,24 @@ namespace Opm {
fluidDensity(const int phase,
const ADB& p ,
const ADB& rs ,
const ADB& rv ,
const std::vector<PhasePresence>& cond,
const std::vector<int>& cells) const;
V
fluidRsMax(const V& p,
fluidRsSat(const V& p,
const std::vector<int>& cells) const;
ADB
fluidRsMax(const ADB& p,
fluidRsSat(const ADB& p,
const std::vector<int>& cells) const;
V
fluidRvSat(const V& p,
const std::vector<int>& cells) const;
ADB
fluidRvSat(const ADB& p,
const std::vector<int>& cells) const;
ADB
@ -227,6 +240,14 @@ namespace Opm {
void
classifyCondition(const SolutionState& state,
std::vector<PhasePresence>& cond ) const;
const std::vector<PhasePresence>
phaseCondition() const {return phaseCondition_;}
void
classifyCondition(const BlackoilState& state);
};
} // namespace Opm

View File

@ -0,0 +1,172 @@
/*
Copyright 2014 SINTEF ICT, Applied Mathematics.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <opm/autodiff/WellDensitySegmented.hpp>
#include <opm/core/wells.h>
#include <opm/core/simulator/WellState.hpp>
#include <opm/core/utility/ErrorMacros.hpp>
#include <opm/core/props/BlackoilPhases.hpp>
#include <numeric>
#include <cmath>
std::vector<double> Opm::WellDensitySegmented::computeConnectionPressureDelta(const Wells& wells,
const WellState& wstate,
const PhaseUsage& phase_usage,
const std::vector<double>& b_perf,
const std::vector<double>& rsmax_perf,
const std::vector<double>& rvmax_perf,
const std::vector<double>& z_perf,
const std::vector<double>& surf_dens,
const double gravity)
{
// Verify that we have consistent input.
const int np = wells.number_of_phases;
const int nw = wells.number_of_wells;
const int nperf = wells.well_connpos[nw];
if (wells.number_of_phases != phase_usage.num_phases) {
OPM_THROW(std::logic_error, "Inconsistent input: wells vs. phase_usage.");
}
if (surf_dens.size() != size_t(wells.number_of_phases)) {
OPM_THROW(std::logic_error, "Inconsistent input: surf_dens vs. phase_usage.");
}
if (nperf*np != int(wstate.perfRates().size())) {
OPM_THROW(std::logic_error, "Inconsistent input: wells vs. wstate.");
}
if (nperf*np != int(b_perf.size())) {
OPM_THROW(std::logic_error, "Inconsistent input: wells vs. b_perf.");
}
if (nperf != int(z_perf.size())) {
OPM_THROW(std::logic_error, "Inconsistent input: wells vs. z_perf.");
}
if ((!rsmax_perf.empty()) || (!rvmax_perf.empty())) {
// Need both oil and gas phases.
if (!phase_usage.phase_used[BlackoilPhases::Liquid]) {
OPM_THROW(std::logic_error, "Oil phase inactive, but non-empty rsmax_perf or rvmax_perf.");
}
if (!phase_usage.phase_used[BlackoilPhases::Vapour]) {
OPM_THROW(std::logic_error, "Gas phase inactive, but non-empty rsmax_perf or rvmax_perf.");
}
}
// Algorithm:
// We'll assume the perforations are given in order from top to
// bottom for each well. By top and bottom we do not necessarily
// mean in a geometric sense (depth), but in a topological sense:
// the 'top' perforation is nearest to the surface topologically.
// Our goal is to compute a pressure delta for each perforation.
// 1. Compute the flow (in surface volume units for each
// component) exiting up the wellbore from each perforation,
// taking into account flow from lower in the well, and
// in/out-flow at each perforation.
std::vector<double> q_out_perf(nperf*np);
for (int w = 0; w < nw; ++w) {
// Iterate over well perforations from bottom to top.
for (int perf = wells.well_connpos[w+1] - 1; perf >= wells.well_connpos[w]; --perf) {
for (int phase = 0; phase < np; ++phase) {
if (perf == wells.well_connpos[w+1] - 1) {
// This is the bottom perforation. No flow from below.
q_out_perf[perf*np + phase] = 0.0;
} else {
// Set equal to flow from below.
q_out_perf[perf*np + phase] = q_out_perf[(perf+1)*np + phase];
}
// Subtract outflow through perforation.
q_out_perf[perf*np + phase] -= wstate.perfRates()[perf*np + phase];
}
}
}
// 2. Compute the component mix at each perforation as the
// absolute values of the surface rates divided by their sum.
// Then compute volume ratios (formation factors) for each perforation.
// Finally compute densities for the segments associated with each perforation.
const int gaspos = phase_usage.phase_pos[BlackoilPhases::Vapour];
const int oilpos = phase_usage.phase_pos[BlackoilPhases::Liquid];
std::vector<double> mix(np);
std::vector<double> x(np);
std::vector<double> dens(nperf);
for (int w = 0; w < nw; ++w) {
for (int perf = wells.well_connpos[w]; perf < wells.well_connpos[w+1]; ++perf) {
// Find component mix.
const double tot_surf_rate = std::accumulate(q_out_perf.begin() + np*perf,
q_out_perf.begin() + np*(perf+1), 0.0);
if (tot_surf_rate != 0.0) {
for (int phase = 0; phase < np; ++phase) {
mix[phase] = std::fabs(q_out_perf[perf*np + phase]/tot_surf_rate);
}
} else {
// No flow => use well specified fractions for mix.
std::copy(wells.comp_frac + w*np, wells.comp_frac + (w+1)*np, mix.begin());
}
// Compute volume ratio.
x = mix;
double rs = 0.0;
double rv = 0.0;
if (!rsmax_perf.empty() && mix[oilpos] > 0.0) {
rs = std::min(mix[gaspos]/mix[oilpos], rsmax_perf[perf]);
}
if (!rvmax_perf.empty() && mix[gaspos] > 0.0) {
rv = std::min(mix[oilpos]/mix[gaspos], rvmax_perf[perf]);
}
if (rs != 0.0) {
// Subtract gas in oil from gas mixture
x[gaspos] = (mix[gaspos] - mix[oilpos]*rs)/(1.0 - rs*rv);
}
if (rv != 0.0) {
// Subtract oil in gas from oil mixture
x[oilpos] = (mix[oilpos] - mix[gaspos]*rv)/(1.0 - rs*rv);;
}
double volrat = 0.0;
for (int phase = 0; phase < np; ++phase) {
volrat += x[phase] / b_perf[perf*np + phase];
}
// Compute segment density.
dens[perf] = std::inner_product(surf_dens.begin(), surf_dens.end(), mix.begin(), 0.0) / volrat;
}
}
// 3. Compute pressure differences between perforations.
// dp_perf will contain the pressure difference between a
// perforation and the one above it, except for the first
// perforation for each well, for which it will be the
// difference to the reference (bhp) depth.
std::vector<double> dp_perf(nperf);
for (int w = 0; w < nw; ++w) {
for (int perf = wells.well_connpos[w]; perf < wells.well_connpos[w+1]; ++perf) {
const double z_above = perf == wells.well_connpos[w] ? wells.depth_ref[w] : z_perf[perf - 1];
const double dz = z_perf[perf] - z_above;
dp_perf[perf] = dz * dens[perf] * gravity;
}
}
// 4. Compute pressure differences to the reference point (bhp) by
// accumulating the already computed adjacent pressure
// differences, storing the result in dp_perf.
// This accumulation must be done per well.
for (int w = 0; w < nw; ++w) {
const auto beg = dp_perf.begin() + wells.well_connpos[w];
const auto end = dp_perf.begin() + wells.well_connpos[w + 1];
std::partial_sum(beg, end, beg);
}
return dp_perf;
}

View File

@ -0,0 +1,66 @@
/*
Copyright 2014 SINTEF ICT, Applied Mathematics.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_WELLDENSITYSEGMENTED_HEADER_INCLUDED
#define OPM_WELLDENSITYSEGMENTED_HEADER_INCLUDED
#include <vector>
struct Wells;
namespace Opm
{
class WellState;
class PhaseUsage;
/// A class giving a well model, by which we mean a way to compute
/// the pressure deltas of each perforation and the bottom-hole
/// pressure. This class contains an explicit model, that uses a
/// different density for each well segment, that is between each
/// pair of perforations.
class WellDensitySegmented
{
public:
/// Compute pressure deltas.
/// Notation: N = number of perforations, P = number of phases.
/// \param[in] wells struct with static well info
/// \param[in] wstate dynamic well solution information, only perfRates() is used
/// \param[in] phase_usage specifies which phases are active and not
/// \param[in] b_perf inverse ('little b') formation volume factor, size NP, P values per perforation
/// \param[in] rsmax_perf saturation point for rs (gas in oil) at each perforation, size N
/// \param[in] rvmax_perf saturation point for rv (oil in gas) at each perforation, size N
/// \param[in] z_perf depth values for each perforation, size N
/// \param[in] surf_dens surface densities for active components, size P
/// \param[in] gravity gravity acceleration constant
static std::vector<double> computeConnectionPressureDelta(const Wells& wells,
const WellState& wstate,
const PhaseUsage& phase_usage,
const std::vector<double>& b_perf,
const std::vector<double>& rsmax_perf,
const std::vector<double>& rvmax_perf,
const std::vector<double>& z_perf,
const std::vector<double>& surf_dens,
const double gravity);
};
} // namespace Opm
#endif // OPM_WELLDENSITYSEGMENTED_HEADER_INCLUDED

View File

@ -0,0 +1,101 @@
/*
Copyright 2014 SINTEF ICT, Applied Mathematics.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#if HAVE_DYNAMIC_BOOST_TEST
#define BOOST_TEST_DYN_LINK
#endif
#define BOOST_TEST_MODULE WellDensitySegmentedTest
#include <opm/autodiff/WellDensitySegmented.hpp>
#include <opm/core/wells.h>
#include <opm/core/simulator/WellState.hpp>
#include <opm/core/props/BlackoilPhases.hpp>
#include <opm/core/utility/Units.hpp>
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <memory>
using namespace Opm;
BOOST_AUTO_TEST_CASE(TestPressureDeltas)
{
// Simple water injector.
const int np = 3;
const int nperf = 10;
const double ref_depth = 0.0;
const double comp_frac_w[np] = { 1.0, 0.0, 0.0 };
const double comp_frac_o[np] = { 0.0, 1.0, 0.0 };
const int cells[nperf/2] = { 0, 1, 2, 3, 4 };
const double WI[nperf/2] = { 1.0, 1.0, 1.0, 1.0, 1.0 };
std::shared_ptr<Wells> wells(create_wells(np, 2, nperf), destroy_wells);
BOOST_REQUIRE(wells);
int ok = add_well(INJECTOR, ref_depth, nperf/2, comp_frac_w, cells, WI, "INJ", wells.get());
BOOST_REQUIRE(ok);
ok = add_well(PRODUCER, ref_depth, nperf/2, comp_frac_o, cells, WI, "PROD", wells.get());
BOOST_REQUIRE(ok);
std::vector<double> rates = { 1.0, 0.0, 0.0,
1.0, 0.0, 0.0,
1.0, 0.0, 0.0,
1.0, 0.0, 0.0,
1.0, 0.0, 0.0,
1.0, 0.0, 0.0,
1.0, 0.0, 0.0,
1.0, 0.0, 0.0,
1.0, 0.0, 0.0,
1.0, 0.0, 0.0 };
WellState wellstate;
wellstate.perfRates() = rates;
PhaseUsage pu;
pu.num_phases = 3;
pu.phase_used[0] = true;
pu.phase_used[1] = true;
pu.phase_used[2] = true;
pu.phase_pos[0] = 0;
pu.phase_pos[1] = 1;
pu.phase_pos[2] = 2;
const std::vector<double> b_perf = { 2.0, 3.0, 100,
2.1, 3.3, 110,
2.2, 3.6, 120,
2.3, 4.0, 130,
2.4, 4.5, 140,
2.0, 3.0, 100,
2.1, 3.3, 110,
2.2, 3.6, 120,
2.3, 4.0, 130,
2.4, 4.5, 140 };
const std::vector<double> rsmax_perf = { 50, 50, 50, 50, 50, 50, 50, 50, 50, 50 };
const std::vector<double> rvmax_perf = { 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01 };
const std::vector<double> z_perf = { 10, 30, 50, 70, 90, 10, 30, 50, 70, 90 };
const std::vector<double> surf_dens = { 1000.0, 800.0, 10.0 };
const double gravity = Opm::unit::gravity;
const std::vector<double> dp = WellDensitySegmented::computeConnectionPressureDelta(*wells, wellstate, pu, b_perf, rsmax_perf, rvmax_perf, z_perf, surf_dens, gravity);
const std::vector<double> answer = { 20e3*gravity, 62e3*gravity, 106e3*gravity, 152e3*gravity, 200e3*gravity,
20e3*gravity, 62e3*gravity, 106e3*gravity, 152e3*gravity, 200e3*gravity };
BOOST_REQUIRE_EQUAL(dp.size(), answer.size());
// for (auto p : dp) { std::cout << p << std::endl; }
for (size_t i = 0; i < dp.size(); ++i) {
BOOST_CHECK_CLOSE(dp[i], answer[i], 1e-8);
}
}