2013-05-27 07:55:32 -05:00
|
|
|
/*
|
|
|
|
Copyright 2013 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>
|
|
|
|
|
|
|
|
#include <opm/autodiff/BlackoilPropsAdFromDeck.hpp>
|
|
|
|
#include <opm/autodiff/AutoDiffHelpers.hpp>
|
|
|
|
#include <opm/core/props/BlackoilPropertiesInterface.hpp>
|
|
|
|
#include <opm/core/props/BlackoilPhases.hpp>
|
2013-05-27 15:01:20 -05:00
|
|
|
#include <opm/core/props/pvt/SinglePvtInterface.hpp>
|
|
|
|
#include <opm/core/props/pvt/SinglePvtConstCompr.hpp>
|
|
|
|
#include <opm/core/props/pvt/SinglePvtDead.hpp>
|
|
|
|
#include <opm/core/props/pvt/SinglePvtDeadSpline.hpp>
|
|
|
|
#include <opm/core/props/pvt/SinglePvtLiveOil.hpp>
|
2014-01-10 07:19:37 -06:00
|
|
|
#include <opm/core/props/pvt/SinglePvtLiveGas.hpp>
|
2013-05-27 07:55:32 -05:00
|
|
|
#include <opm/core/utility/ErrorMacros.hpp>
|
2013-05-27 15:01:20 -05:00
|
|
|
#include <opm/core/utility/Units.hpp>
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-12-12 09:23:56 -06:00
|
|
|
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
2014-04-11 04:54:16 -05:00
|
|
|
#include <opm/parser/eclipse/Utility/PvtoTable.hpp>
|
2014-01-16 09:45:46 -06:00
|
|
|
#include <opm/parser/eclipse/Utility/PvtgTable.hpp>
|
2014-04-11 04:54:16 -05:00
|
|
|
#include <opm/parser/eclipse/Utility/PvtwTable.hpp>
|
|
|
|
#include <opm/parser/eclipse/Utility/PvdoTable.hpp>
|
2014-04-11 04:54:56 -05:00
|
|
|
#include <opm/parser/eclipse/Utility/PvcdoTable.hpp>
|
2013-12-12 09:23:56 -06:00
|
|
|
|
2013-05-27 07:55:32 -05:00
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
// Making these typedef to make the code more readable.
|
|
|
|
typedef BlackoilPropsAdFromDeck::ADB ADB;
|
|
|
|
typedef BlackoilPropsAdFromDeck::V V;
|
|
|
|
typedef Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> Block;
|
2013-05-27 15:01:20 -05:00
|
|
|
enum { Aqua = BlackoilPhases::Aqua,
|
|
|
|
Liquid = BlackoilPhases::Liquid,
|
|
|
|
Vapour = BlackoilPhases::Vapour };
|
2013-05-27 07:55:32 -05:00
|
|
|
|
|
|
|
/// Constructor wrapping an opm-core black oil interface.
|
2014-04-11 04:54:16 -05:00
|
|
|
BlackoilPropsAdFromDeck::BlackoilPropsAdFromDeck(Opm::DeckConstPtr deck,
|
2013-05-27 15:01:20 -05:00
|
|
|
const UnstructuredGrid& grid,
|
|
|
|
const bool init_rock)
|
2014-02-20 06:15:02 -06:00
|
|
|
{
|
|
|
|
init(deck, grid.number_of_cells, grid.global_cell, grid.cartdims,
|
|
|
|
grid.cell_centroids, grid.dimensions, init_rock);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_DUNE_CORNERPOINT
|
|
|
|
/// Constructor wrapping an opm-core black oil interface.
|
2014-04-11 04:54:16 -05:00
|
|
|
BlackoilPropsAdFromDeck::BlackoilPropsAdFromDeck(Opm::DeckConstPtr deck,
|
2014-02-20 06:15:02 -06:00
|
|
|
const Dune::CpGrid& grid,
|
|
|
|
const bool init_rock )
|
|
|
|
{
|
|
|
|
init(deck, grid.numCells(), static_cast<const int*>(&grid.globalCell()[0]),
|
|
|
|
static_cast<const int*>(&grid.logicalCartesianSize()[0]),
|
|
|
|
grid.beginCellCentroids(), Dune::CpGrid::dimension, init_rock);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-04-11 04:54:16 -05:00
|
|
|
/// Initializes the properties.
|
|
|
|
template <class CentroidIterator>
|
|
|
|
void BlackoilPropsAdFromDeck::init(Opm::DeckConstPtr deck,
|
2014-02-20 06:15:02 -06:00
|
|
|
int number_of_cells,
|
|
|
|
const int* global_cell,
|
|
|
|
const int* cart_dims,
|
2014-04-11 04:54:16 -05:00
|
|
|
const CentroidIterator& begin_cell_centroids,
|
|
|
|
int dimension,
|
2014-02-20 06:15:02 -06:00
|
|
|
const bool init_rock)
|
2013-05-27 15:01:20 -05:00
|
|
|
{
|
|
|
|
if (init_rock){
|
2014-02-20 06:15:02 -06:00
|
|
|
rock_.init(deck, number_of_cells, global_cell, cart_dims);
|
2013-05-27 15:01:20 -05:00
|
|
|
}
|
2013-12-21 12:17:03 -06:00
|
|
|
|
2014-03-03 03:31:21 -06:00
|
|
|
const int samples = 0;
|
2013-12-19 11:22:20 -06:00
|
|
|
const int region_number = 0;
|
|
|
|
|
2014-04-11 04:54:16 -05:00
|
|
|
phase_usage_ = phaseUsageFromDeck(deck);
|
2013-12-19 11:22:20 -06:00
|
|
|
|
|
|
|
// Surface densities. Accounting for different orders in eclipse and our code.
|
2014-04-11 04:54:16 -05:00
|
|
|
if (deck->hasKeyword("DENSITY")) {
|
|
|
|
const auto keyword = deck->getKeyword("DENSITY");
|
2013-12-19 11:22:20 -06:00
|
|
|
const auto record = keyword->getRecord(region_number);
|
|
|
|
enum { ECL_oil = 0, ECL_water = 1, ECL_gas = 2 };
|
|
|
|
if (phase_usage_.phase_used[Aqua]) {
|
|
|
|
densities_[phase_usage_.phase_pos[Aqua]] = record->getItem("WATER")->getSIDouble(0);
|
|
|
|
}
|
|
|
|
if (phase_usage_.phase_used[Vapour]) {
|
|
|
|
densities_[phase_usage_.phase_pos[Vapour]] = record->getItem("GAS")->getSIDouble(0);
|
|
|
|
}
|
|
|
|
if (phase_usage_.phase_used[Liquid]) {
|
|
|
|
densities_[phase_usage_.phase_pos[Liquid]] = record->getItem("OIL")->getSIDouble(0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
OPM_THROW(std::runtime_error, "Input is missing DENSITY\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the properties.
|
|
|
|
props_.resize(phase_usage_.num_phases);
|
|
|
|
// Water PVT
|
|
|
|
if (phase_usage_.phase_used[Aqua]) {
|
2014-04-11 04:54:16 -05:00
|
|
|
if (deck->hasKeyword("PVTW")) {
|
|
|
|
Opm::PvtwTable pvtwTable(deck->getKeyword("PVTW"), region_number);
|
2013-12-19 11:22:20 -06:00
|
|
|
props_[phase_usage_.phase_pos[Aqua]].reset(new SinglePvtConstCompr(pvtwTable));
|
|
|
|
} else {
|
|
|
|
// Eclipse 100 default.
|
|
|
|
props_[phase_usage_.phase_pos[Aqua]].reset(new SinglePvtConstCompr(0.5*Opm::prefix::centi*Opm::unit::Poise));
|
|
|
|
}
|
|
|
|
}
|
2013-12-21 12:17:03 -06:00
|
|
|
|
2013-12-19 11:22:20 -06:00
|
|
|
// Oil PVT
|
|
|
|
if (phase_usage_.phase_used[Liquid]) {
|
2014-04-11 04:54:16 -05:00
|
|
|
if (deck->hasKeyword("PVDO")) {
|
|
|
|
Opm::PvdoTable pvdoTable(deck->getKeyword("PVDO"), region_number);
|
2014-03-03 03:31:21 -06:00
|
|
|
if (samples > 0) {
|
|
|
|
props_[phase_usage_.phase_pos[Liquid]].reset(new SinglePvtDeadSpline(pvdoTable, samples));
|
|
|
|
} else {
|
|
|
|
props_[phase_usage_.phase_pos[Liquid]].reset(new SinglePvtDead(pvdoTable));
|
|
|
|
}
|
2013-12-19 11:22:20 -06:00
|
|
|
}
|
2014-04-11 04:54:16 -05:00
|
|
|
else if (deck->hasKeyword("PVTO")) {
|
|
|
|
Opm::PvtoTable pvtoTable(deck->getKeyword("PVTO"), /*tableIdx=*/0);
|
2013-12-19 11:22:20 -06:00
|
|
|
props_[phase_usage_.phase_pos[Liquid]].reset(new SinglePvtLiveOil(pvtoTable));
|
2014-04-11 04:54:16 -05:00
|
|
|
} else if (deck->hasKeyword("PVCDO")) {
|
|
|
|
Opm::PvcdoTable pvdcoTable(deck->getKeyword("PVCDO"), region_number);
|
2014-01-09 10:33:47 -06:00
|
|
|
props_[phase_usage_.phase_pos[Liquid]].reset(new SinglePvtConstCompr(pvdcoTable));
|
2013-12-19 11:22:20 -06:00
|
|
|
} else {
|
2014-03-03 03:29:13 -06:00
|
|
|
OPM_THROW(std::runtime_error, "Input is missing PVDO, PVTO or PVCDO\n");
|
2013-12-19 11:22:20 -06:00
|
|
|
}
|
|
|
|
}
|
2013-12-21 12:17:03 -06:00
|
|
|
|
2013-12-19 11:22:20 -06:00
|
|
|
// Gas PVT
|
|
|
|
if (phase_usage_.phase_used[Vapour]) {
|
2014-04-11 04:54:16 -05:00
|
|
|
if (deck->hasKeyword("PVDG")) {
|
|
|
|
Opm::PvdoTable pvdgTable(deck->getKeyword("PVDG"), region_number);
|
2014-03-03 03:31:21 -06:00
|
|
|
if (samples > 0) {
|
|
|
|
props_[phase_usage_.phase_pos[Vapour]].reset(new SinglePvtDeadSpline(pvdgTable, samples));
|
|
|
|
} else {
|
|
|
|
props_[phase_usage_.phase_pos[Vapour]].reset(new SinglePvtDead(pvdgTable));
|
|
|
|
}
|
2014-04-11 04:54:16 -05:00
|
|
|
} else if (deck->hasKeyword("PVTG")) {
|
|
|
|
Opm::PvtgTable pvtgTable(deck->getKeyword("PVTG"), /*tableIdx=*/0);
|
2014-01-16 09:45:46 -06:00
|
|
|
props_[phase_usage_.phase_pos[Vapour]].reset(new SinglePvtLiveGas(pvtgTable));
|
2013-12-19 11:22:20 -06:00
|
|
|
} else {
|
2014-01-16 09:45:46 -06:00
|
|
|
OPM_THROW(std::runtime_error, "Input is missing PVDG or PVTG\n");
|
2013-12-19 11:22:20 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SaturationPropsFromDeck<SatFuncGwsegNonuniform>* ptr
|
|
|
|
= new SaturationPropsFromDeck<SatFuncGwsegNonuniform>();
|
|
|
|
satprops_.reset(ptr);
|
2014-04-11 04:54:16 -05:00
|
|
|
ptr->init(deck, number_of_cells, global_cell, begin_cell_centroids, dimension, -1);
|
2013-12-19 11:22:20 -06:00
|
|
|
|
|
|
|
if (phase_usage_.num_phases != satprops_->numPhases()) {
|
|
|
|
OPM_THROW(std::runtime_error, "BlackoilPropsAdFromDeck::BlackoilPropsAdFromDeck() - "
|
2014-04-11 04:54:16 -05:00
|
|
|
"Inconsistent number of phases in pvt data (" << phase_usage_.num_phases
|
|
|
|
<< ") and saturation-dependent function data (" << satprops_->numPhases() << ").");
|
2013-12-19 11:22:20 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-27 07:55:32 -05:00
|
|
|
////////////////////////////
|
|
|
|
// Rock interface //
|
|
|
|
////////////////////////////
|
|
|
|
|
|
|
|
/// \return D, the number of spatial dimensions.
|
|
|
|
int BlackoilPropsAdFromDeck::numDimensions() const
|
|
|
|
{
|
|
|
|
return rock_.numDimensions();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \return N, the number of cells.
|
|
|
|
int BlackoilPropsAdFromDeck::numCells() const
|
|
|
|
{
|
|
|
|
return rock_.numCells();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \return Array of N porosity values.
|
|
|
|
const double* BlackoilPropsAdFromDeck::porosity() const
|
|
|
|
{
|
|
|
|
return rock_.porosity();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \return Array of ND^2 permeability values.
|
|
|
|
/// The D^2 permeability values for a cell are organized as a matrix,
|
|
|
|
/// which is symmetric (so ordering does not matter).
|
|
|
|
const double* BlackoilPropsAdFromDeck::permeability() const
|
|
|
|
{
|
|
|
|
return rock_.permeability();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////
|
|
|
|
// Fluid interface //
|
|
|
|
////////////////////////////
|
|
|
|
|
2013-05-27 15:01:20 -05:00
|
|
|
/// \return Number of active phases (also the number of components).
|
|
|
|
int BlackoilPropsAdFromDeck::numPhases() const
|
|
|
|
{
|
|
|
|
return phase_usage_.num_phases;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \return Object describing the active phases.
|
|
|
|
PhaseUsage BlackoilPropsAdFromDeck::phaseUsage() const
|
|
|
|
{
|
|
|
|
return phase_usage_;
|
|
|
|
}
|
2013-05-27 07:55:32 -05:00
|
|
|
|
|
|
|
// ------ Density ------
|
|
|
|
|
|
|
|
/// Densities of stock components at surface conditions.
|
|
|
|
/// \return Array of 3 density values.
|
|
|
|
const double* BlackoilPropsAdFromDeck::surfaceDensity() const
|
|
|
|
{
|
|
|
|
return densities_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------ Viscosity ------
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
/// \return Array of n viscosity values.
|
|
|
|
V BlackoilPropsAdFromDeck::muWat(const V& pw,
|
2013-05-27 15:01:20 -05:00
|
|
|
const Cells& cells) const
|
2013-05-27 07:55:32 -05:00
|
|
|
{
|
|
|
|
if (!phase_usage_.phase_used[Water]) {
|
2013-09-03 08:00:29 -05:00
|
|
|
OPM_THROW(std::runtime_error, "Cannot call muWat(): water phase not present.");
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
const int n = cells.size();
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(pw.size() == n);
|
2013-05-27 15:01:20 -05:00
|
|
|
V mu(n);
|
|
|
|
V dmudp(n);
|
|
|
|
V dmudr(n);
|
|
|
|
const double* rs = 0;
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-05-27 15:01:20 -05:00
|
|
|
props_[phase_usage_.phase_pos[Water]]->mu(n, pw.data(), rs,
|
|
|
|
mu.data(), dmudp.data(), dmudr.data());
|
2013-05-27 07:55:32 -05:00
|
|
|
return mu;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Oil viscosity.
|
|
|
|
/// \param[in] po Array of n oil pressure values.
|
|
|
|
/// \param[in] rs Array of n gas solution factor values.
|
2013-12-03 11:12:54 -06:00
|
|
|
/// \param[in] cond Array of n taxonomies classifying fluid condition.
|
2013-05-27 07:55:32 -05:00
|
|
|
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
|
|
|
|
/// \return Array of n viscosity values.
|
|
|
|
V BlackoilPropsAdFromDeck::muOil(const V& po,
|
2013-05-27 15:01:20 -05:00
|
|
|
const V& rs,
|
2013-12-03 11:12:54 -06:00
|
|
|
const std::vector<PhasePresence>& cond,
|
2013-05-27 15:01:20 -05:00
|
|
|
const Cells& cells) const
|
2013-05-27 07:55:32 -05:00
|
|
|
{
|
|
|
|
if (!phase_usage_.phase_used[Oil]) {
|
2013-09-03 08:00:29 -05:00
|
|
|
OPM_THROW(std::runtime_error, "Cannot call muOil(): oil phase not present.");
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
const int n = cells.size();
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(po.size() == n);
|
2013-05-27 15:01:20 -05:00
|
|
|
V mu(n);
|
|
|
|
V dmudp(n);
|
|
|
|
V dmudr(n);
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-12-03 11:12:54 -06:00
|
|
|
props_[phase_usage_.phase_pos[Oil]]->mu(n, po.data(), rs.data(), &cond[0],
|
2013-05-27 15:01:20 -05:00
|
|
|
mu.data(), dmudp.data(), dmudr.data());
|
2013-05-27 07:55:32 -05:00
|
|
|
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,
|
2013-05-27 15:01:20 -05:00
|
|
|
const Cells& cells) const
|
2013-05-27 07:55:32 -05:00
|
|
|
{
|
|
|
|
if (!phase_usage_.phase_used[Gas]) {
|
2013-09-03 08:00:29 -05:00
|
|
|
OPM_THROW(std::runtime_error, "Cannot call muGas(): gas phase not present.");
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
const int n = cells.size();
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(pg.size() == n);
|
2013-05-27 15:01:20 -05:00
|
|
|
V mu(n);
|
|
|
|
V dmudp(n);
|
|
|
|
V dmudr(n);
|
|
|
|
const double* rs = 0;
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-05-27 15:01:20 -05:00
|
|
|
props_[phase_usage_.phase_pos[Gas]]->mu(n, pg.data(), rs,
|
|
|
|
mu.data(), dmudp.data(), dmudr.data());
|
2013-05-27 07:55:32 -05:00
|
|
|
return mu;
|
|
|
|
}
|
|
|
|
|
2014-01-10 07:19:37 -06:00
|
|
|
/// 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;
|
|
|
|
}
|
|
|
|
|
2013-05-27 07:55:32 -05:00
|
|
|
/// 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.
|
|
|
|
/// \return Array of n viscosity values.
|
|
|
|
ADB BlackoilPropsAdFromDeck::muWat(const ADB& pw,
|
2013-05-27 15:01:20 -05:00
|
|
|
const Cells& cells) const
|
2013-05-27 07:55:32 -05:00
|
|
|
{
|
|
|
|
if (!phase_usage_.phase_used[Water]) {
|
2013-09-03 08:00:29 -05:00
|
|
|
OPM_THROW(std::runtime_error, "Cannot call muWat(): water phase not present.");
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
const int n = cells.size();
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(pw.size() == n);
|
2013-05-27 15:01:20 -05:00
|
|
|
V mu(n);
|
|
|
|
V dmudp(n);
|
|
|
|
V dmudr(n);
|
|
|
|
const double* rs = 0;
|
|
|
|
|
|
|
|
props_[phase_usage_.phase_pos[Water]]->mu(n, pw.value().data(), rs,
|
|
|
|
mu.data(), dmudp.data(), dmudr.data());
|
|
|
|
ADB::M dmudp_diag = spdiag(dmudp);
|
2013-05-27 07:55:32 -05:00
|
|
|
const int num_blocks = pw.numBlocks();
|
|
|
|
std::vector<ADB::M> jacs(num_blocks);
|
|
|
|
for (int block = 0; block < num_blocks; ++block) {
|
2013-05-27 15:01:20 -05:00
|
|
|
jacs[block] = dmudp_diag * pw.derivative()[block];
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
return ADB::function(mu, jacs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Oil viscosity.
|
|
|
|
/// \param[in] po Array of n oil pressure values.
|
|
|
|
/// \param[in] rs Array of n gas solution factor values.
|
2013-12-03 11:12:54 -06:00
|
|
|
/// \param[in] cond Array of n taxonomies classifying fluid condition.
|
2013-05-27 07:55:32 -05:00
|
|
|
/// \param[in] cells Array of n cell indices to be associated with the pressure values.
|
|
|
|
/// \return Array of n viscosity values.
|
|
|
|
ADB BlackoilPropsAdFromDeck::muOil(const ADB& po,
|
2013-05-27 15:01:20 -05:00
|
|
|
const ADB& rs,
|
2013-12-03 11:12:54 -06:00
|
|
|
const std::vector<PhasePresence>& cond,
|
2013-05-27 15:01:20 -05:00
|
|
|
const Cells& cells) const
|
2013-05-27 07:55:32 -05:00
|
|
|
{
|
|
|
|
if (!phase_usage_.phase_used[Oil]) {
|
2013-09-03 08:00:29 -05:00
|
|
|
OPM_THROW(std::runtime_error, "Cannot call muOil(): oil phase not present.");
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
const int n = cells.size();
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(po.size() == n);
|
2013-05-27 15:01:20 -05:00
|
|
|
V mu(n);
|
|
|
|
V dmudp(n);
|
|
|
|
V dmudr(n);
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-12-03 11:12:54 -06:00
|
|
|
props_[phase_usage_.phase_pos[Oil]]->mu(n, po.value().data(), rs.value().data(),
|
|
|
|
&cond[0], mu.data(), dmudp.data(), dmudr.data());
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-05-27 15:01:20 -05:00
|
|
|
ADB::M dmudp_diag = spdiag(dmudp);
|
|
|
|
ADB::M dmudr_diag = spdiag(dmudr);
|
2013-05-27 07:55:32 -05:00
|
|
|
const int num_blocks = po.numBlocks();
|
|
|
|
std::vector<ADB::M> jacs(num_blocks);
|
|
|
|
for (int block = 0; block < num_blocks; ++block) {
|
2013-05-27 15:01:20 -05:00
|
|
|
jacs[block] = dmudp_diag * po.derivative()[block] + dmudr_diag * rs.derivative()[block];
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
return ADB::function(mu, jacs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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 BlackoilPropsAdFromDeck::muGas(const ADB& pg,
|
2013-05-27 15:01:20 -05:00
|
|
|
const Cells& cells) const
|
2013-05-27 07:55:32 -05:00
|
|
|
{
|
|
|
|
if (!phase_usage_.phase_used[Gas]) {
|
2013-09-03 08:00:29 -05:00
|
|
|
OPM_THROW(std::runtime_error, "Cannot call muGas(): gas phase not present.");
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
const int n = cells.size();
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(pg.value().size() == n);
|
2013-05-27 15:01:20 -05:00
|
|
|
V mu(n);
|
|
|
|
V dmudp(n);
|
|
|
|
V dmudr(n);
|
2014-01-10 07:19:37 -06:00
|
|
|
const double* rv = 0;
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2014-01-10 07:19:37 -06:00
|
|
|
props_[phase_usage_.phase_pos[Gas]]->mu(n, pg.value().data(), rv,
|
2013-05-27 15:01:20 -05:00
|
|
|
mu.data(), dmudp.data(), dmudr.data());
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-05-27 15:01:20 -05:00
|
|
|
ADB::M dmudp_diag = spdiag(dmudp);
|
2013-05-27 07:55:32 -05:00
|
|
|
const int num_blocks = pg.numBlocks();
|
|
|
|
std::vector<ADB::M> jacs(num_blocks);
|
|
|
|
for (int block = 0; block < num_blocks; ++block) {
|
2013-05-27 15:01:20 -05:00
|
|
|
jacs[block] = dmudp_diag * pg.derivative()[block];
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
return ADB::function(mu, jacs);
|
|
|
|
}
|
|
|
|
|
2014-01-10 07:19:37 -06:00
|
|
|
/// Gas viscosity.
|
|
|
|
/// \param[in] pg Array of n gas pressure values.
|
2014-01-24 06:15:29 -06:00
|
|
|
/// \param[in] rv Array of n vapor oil/gas ratio
|
|
|
|
/// \param[in] cond Array of n taxonomies classifying fluid condition.
|
2014-01-10 07:19:37 -06:00
|
|
|
/// \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);
|
|
|
|
}
|
|
|
|
|
2013-05-27 07:55:32 -05:00
|
|
|
|
|
|
|
// ------ Formation volume factor (b) ------
|
|
|
|
|
|
|
|
// These methods all call the matrix() method, after which the variable
|
|
|
|
// (also) called 'matrix' contains, in each row, the A = RB^{-1} matrix for
|
|
|
|
// a cell. For three-phase black oil:
|
|
|
|
// A = [ bw 0 0
|
|
|
|
// 0 bo 0
|
|
|
|
// 0 b0*rs bw ]
|
|
|
|
// Where b = B^{-1}.
|
|
|
|
// Therefore, we extract the correct diagonal element, and are done.
|
|
|
|
// When we need the derivatives (w.r.t. p, since we don't do w.r.t. rs),
|
|
|
|
// we also get the following derivative matrix:
|
|
|
|
// A = [ dbw 0 0
|
|
|
|
// 0 dbo 0
|
|
|
|
// 0 db0*rs dbw ]
|
|
|
|
// Again, we just extract a diagonal element.
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
/// \return Array of n formation volume factor values.
|
|
|
|
V BlackoilPropsAdFromDeck::bWat(const V& pw,
|
2013-05-27 15:01:20 -05:00
|
|
|
const Cells& cells) const
|
2013-05-27 07:55:32 -05:00
|
|
|
{
|
|
|
|
if (!phase_usage_.phase_used[Water]) {
|
2013-09-03 08:00:29 -05:00
|
|
|
OPM_THROW(std::runtime_error, "Cannot call bWat(): water phase not present.");
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
const int n = cells.size();
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(pw.size() == n);
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-05-27 15:01:20 -05:00
|
|
|
V b(n);
|
|
|
|
V dbdp(n);
|
|
|
|
V dbdr(n);
|
|
|
|
const double* rs = 0;
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-05-27 15:01:20 -05:00
|
|
|
props_[phase_usage_.phase_pos[Water]]->b(n, pw.data(), rs,
|
|
|
|
b.data(), dbdp.data(), dbdr.data());
|
2013-05-27 07:55:32 -05:00
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Oil formation volume factor.
|
|
|
|
/// \param[in] po Array of n oil pressure values.
|
|
|
|
/// \param[in] rs Array of n gas solution factor values.
|
2013-12-03 11:12:54 -06:00
|
|
|
/// \param[in] cond Array of n taxonomies classifying fluid condition.
|
2013-05-27 07:55:32 -05:00
|
|
|
/// \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::bOil(const V& po,
|
2013-05-27 15:01:20 -05:00
|
|
|
const V& rs,
|
2013-12-03 11:12:54 -06:00
|
|
|
const std::vector<PhasePresence>& cond,
|
2013-05-27 15:01:20 -05:00
|
|
|
const Cells& cells) const
|
2013-05-27 07:55:32 -05:00
|
|
|
{
|
|
|
|
if (!phase_usage_.phase_used[Oil]) {
|
2013-09-03 08:00:29 -05:00
|
|
|
OPM_THROW(std::runtime_error, "Cannot call bOil(): oil phase not present.");
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
const int n = cells.size();
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(po.size() == n);
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-05-27 15:01:20 -05:00
|
|
|
V b(n);
|
|
|
|
V dbdp(n);
|
|
|
|
V dbdr(n);
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-12-03 11:12:54 -06:00
|
|
|
props_[phase_usage_.phase_pos[Oil]]->b(n, po.data(), rs.data(), &cond[0],
|
2013-05-27 15:01:20 -05:00
|
|
|
b.data(), dbdp.data(), dbdr.data());
|
2013-05-27 07:55:32 -05:00
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Gas formation volume factor.
|
|
|
|
/// \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 formation volume factor values.
|
|
|
|
V BlackoilPropsAdFromDeck::bGas(const V& pg,
|
2013-05-27 15:01:20 -05:00
|
|
|
const Cells& cells) const
|
2013-05-27 07:55:32 -05:00
|
|
|
{
|
|
|
|
if (!phase_usage_.phase_used[Gas]) {
|
2013-09-03 08:00:29 -05:00
|
|
|
OPM_THROW(std::runtime_error, "Cannot call bGas(): gas phase not present.");
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
const int n = cells.size();
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(pg.size() == n);
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-05-27 15:01:20 -05:00
|
|
|
V b(n);
|
|
|
|
V dbdp(n);
|
|
|
|
V dbdr(n);
|
|
|
|
const double* rs = 0;
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-05-27 15:01:20 -05:00
|
|
|
props_[phase_usage_.phase_pos[Gas]]->b(n, pg.data(), rs,
|
|
|
|
b.data(), dbdp.data(), dbdr.data());
|
2013-05-27 07:55:32 -05:00
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2013-12-13 10:01:43 -06:00
|
|
|
/// 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;
|
|
|
|
}
|
|
|
|
|
2013-05-27 07:55:32 -05:00
|
|
|
/// 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.
|
|
|
|
/// \return Array of n formation volume factor values.
|
|
|
|
ADB BlackoilPropsAdFromDeck::bWat(const ADB& pw,
|
2013-05-27 15:01:20 -05:00
|
|
|
const Cells& cells) const
|
2013-05-27 07:55:32 -05:00
|
|
|
{
|
|
|
|
if (!phase_usage_.phase_used[Water]) {
|
2013-09-03 08:00:29 -05:00
|
|
|
OPM_THROW(std::runtime_error, "Cannot call muWat(): water phase not present.");
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
const int n = cells.size();
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(pw.size() == n);
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-05-27 15:01:20 -05:00
|
|
|
V b(n);
|
|
|
|
V dbdp(n);
|
|
|
|
V dbdr(n);
|
|
|
|
const double* rs = 0;
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-05-27 15:01:20 -05:00
|
|
|
props_[phase_usage_.phase_pos[Water]]->b(n, pw.value().data(), rs,
|
|
|
|
b.data(), dbdp.data(), dbdr.data());
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-05-27 15:01:20 -05:00
|
|
|
ADB::M dbdp_diag = spdiag(dbdp);
|
2013-05-27 07:55:32 -05:00
|
|
|
const int num_blocks = pw.numBlocks();
|
|
|
|
std::vector<ADB::M> jacs(num_blocks);
|
|
|
|
for (int block = 0; block < num_blocks; ++block) {
|
2013-05-27 15:01:20 -05:00
|
|
|
jacs[block] = dbdp_diag * pw.derivative()[block];
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
return ADB::function(b, jacs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Oil formation volume factor.
|
|
|
|
/// \param[in] po Array of n oil pressure values.
|
|
|
|
/// \param[in] rs Array of n gas solution factor values.
|
2013-12-03 11:12:54 -06:00
|
|
|
/// \param[in] cond Array of n taxonomies classifying fluid condition.
|
2013-05-27 07:55:32 -05:00
|
|
|
/// \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::bOil(const ADB& po,
|
2013-05-27 15:01:20 -05:00
|
|
|
const ADB& rs,
|
2013-12-03 11:12:54 -06:00
|
|
|
const std::vector<PhasePresence>& cond,
|
2013-05-27 15:01:20 -05:00
|
|
|
const Cells& cells) const
|
2013-05-27 07:55:32 -05:00
|
|
|
{
|
|
|
|
if (!phase_usage_.phase_used[Oil]) {
|
2013-09-03 08:00:29 -05:00
|
|
|
OPM_THROW(std::runtime_error, "Cannot call muOil(): oil phase not present.");
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
const int n = cells.size();
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(po.size() == n);
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-05-27 15:01:20 -05:00
|
|
|
V b(n);
|
|
|
|
V dbdp(n);
|
|
|
|
V dbdr(n);
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-12-03 11:12:54 -06:00
|
|
|
props_[phase_usage_.phase_pos[Oil]]->b(n, po.value().data(), rs.value().data(),
|
|
|
|
&cond[0], b.data(), dbdp.data(), dbdr.data());
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-05-27 15:01:20 -05:00
|
|
|
ADB::M dbdp_diag = spdiag(dbdp);
|
|
|
|
ADB::M dbdr_diag = spdiag(dbdr);
|
2013-05-27 07:55:32 -05:00
|
|
|
const int num_blocks = po.numBlocks();
|
|
|
|
std::vector<ADB::M> jacs(num_blocks);
|
|
|
|
for (int block = 0; block < num_blocks; ++block) {
|
2013-05-27 15:01:20 -05:00
|
|
|
jacs[block] = dbdp_diag * po.derivative()[block] + dbdr_diag * rs.derivative()[block];
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
return ADB::function(b, jacs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Gas formation volume factor.
|
|
|
|
/// \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 formation volume factor values.
|
|
|
|
ADB BlackoilPropsAdFromDeck::bGas(const ADB& pg,
|
2013-05-27 15:01:20 -05:00
|
|
|
const Cells& cells) const
|
2013-05-27 07:55:32 -05:00
|
|
|
{
|
|
|
|
if (!phase_usage_.phase_used[Gas]) {
|
2013-09-03 08:00:29 -05:00
|
|
|
OPM_THROW(std::runtime_error, "Cannot call muGas(): gas phase not present.");
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
const int n = cells.size();
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(pg.size() == n);
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-05-27 15:01:20 -05:00
|
|
|
V b(n);
|
|
|
|
V dbdp(n);
|
|
|
|
V dbdr(n);
|
2013-12-13 10:01:43 -06:00
|
|
|
const double* rv = 0;
|
|
|
|
|
|
|
|
props_[phase_usage_.phase_pos[Gas]]->b(n, pg.value().data(), rv,
|
|
|
|
b.data(), dbdp.data(), dbdr.data());
|
|
|
|
|
|
|
|
ADB::M dbdp_diag = spdiag(dbdp);
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
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);
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-12-13 10:01:43 -06:00
|
|
|
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],
|
2013-05-27 15:01:20 -05:00
|
|
|
b.data(), dbdp.data(), dbdr.data());
|
2013-05-27 07:55:32 -05:00
|
|
|
|
2013-05-27 15:01:20 -05:00
|
|
|
ADB::M dbdp_diag = spdiag(dbdp);
|
2014-01-10 07:19:37 -06:00
|
|
|
ADB::M dmudr_diag = spdiag(dbdr);
|
2013-05-27 07:55:32 -05:00
|
|
|
const int num_blocks = pg.numBlocks();
|
|
|
|
std::vector<ADB::M> jacs(num_blocks);
|
|
|
|
for (int block = 0; block < num_blocks; ++block) {
|
2014-01-10 07:19:37 -06:00
|
|
|
jacs[block] = dbdp_diag * pg.derivative()[block] + dmudr_diag * rv.derivative()[block];;
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
return ADB::function(b, jacs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ------ 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.
|
2013-12-13 10:01:43 -06:00
|
|
|
V BlackoilPropsAdFromDeck::rsSat(const V& po,
|
2013-05-27 15:01:20 -05:00
|
|
|
const Cells& cells) const
|
2013-05-27 07:55:32 -05:00
|
|
|
{
|
|
|
|
if (!phase_usage_.phase_used[Oil]) {
|
2013-09-03 08:00:29 -05:00
|
|
|
OPM_THROW(std::runtime_error, "Cannot call rsMax(): oil phase not present.");
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
const int n = cells.size();
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(po.size() == n);
|
2013-05-27 15:01:20 -05:00
|
|
|
V rbub(n);
|
|
|
|
V drbubdp(n);
|
2013-12-13 10:01:43 -06:00
|
|
|
props_[Oil]->rsSat(n, po.data(), rbub.data(), drbubdp.data());
|
2013-05-27 07:55:32 -05:00
|
|
|
return rbub;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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.
|
2013-12-13 10:01:43 -06:00
|
|
|
ADB BlackoilPropsAdFromDeck::rsSat(const ADB& po,
|
2013-05-27 15:01:20 -05:00
|
|
|
const Cells& cells) const
|
2013-05-27 07:55:32 -05:00
|
|
|
{
|
|
|
|
if (!phase_usage_.phase_used[Oil]) {
|
2013-09-03 08:00:29 -05:00
|
|
|
OPM_THROW(std::runtime_error, "Cannot call rsMax(): oil phase not present.");
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
const int n = cells.size();
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(po.size() == n);
|
2013-05-27 15:01:20 -05:00
|
|
|
V rbub(n);
|
|
|
|
V drbubdp(n);
|
2013-12-13 10:01:43 -06:00
|
|
|
props_[Oil]->rsSat(n, po.value().data(), rbub.data(), drbubdp.data());
|
2013-05-27 15:01:20 -05:00
|
|
|
ADB::M drbubdp_diag = spdiag(drbubdp);
|
2013-05-27 07:55:32 -05:00
|
|
|
const int num_blocks = po.numBlocks();
|
|
|
|
std::vector<ADB::M> jacs(num_blocks);
|
|
|
|
for (int block = 0; block < num_blocks; ++block) {
|
2013-05-27 15:01:20 -05:00
|
|
|
jacs[block] = drbubdp_diag * po.derivative()[block];
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
return ADB::function(rbub, jacs);
|
|
|
|
}
|
|
|
|
|
2013-12-13 10:01:43 -06:00
|
|
|
// ------ 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);
|
2014-01-10 07:19:37 -06:00
|
|
|
props_[Gas]->rvSat(n, po.data(), rv.data(), drvdp.data());
|
2013-12-13 10:01:43 -06:00
|
|
|
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);
|
2014-01-10 07:19:37 -06:00
|
|
|
props_[Gas]->rvSat(n, po.value().data(), rv.data(), drvdp.data());
|
2013-12-13 10:01:43 -06:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-05-27 07:55:32 -05:00
|
|
|
// ------ Relative permeability ------
|
|
|
|
|
|
|
|
/// Relative permeabilities for all phases.
|
|
|
|
/// \param[in] sw Array of n water saturation values.
|
|
|
|
/// \param[in] so Array of n oil saturation values.
|
|
|
|
/// \param[in] sg Array of n gas saturation values.
|
|
|
|
/// \param[in] cells Array of n cell indices to be associated with the saturation values.
|
|
|
|
/// \return An std::vector with 3 elements, each an array of n relperm values,
|
|
|
|
/// containing krw, kro, krg. Use PhaseIndex for indexing into the result.
|
|
|
|
std::vector<V> BlackoilPropsAdFromDeck::relperm(const V& sw,
|
2013-05-27 15:01:20 -05:00
|
|
|
const V& so,
|
|
|
|
const V& sg,
|
|
|
|
const Cells& cells) const
|
2013-05-27 07:55:32 -05:00
|
|
|
{
|
|
|
|
const int n = cells.size();
|
2013-05-27 15:01:20 -05:00
|
|
|
const int np = numPhases();
|
2013-05-27 07:55:32 -05:00
|
|
|
Block s_all(n, np);
|
|
|
|
if (phase_usage_.phase_used[Water]) {
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(sw.size() == n);
|
2013-05-27 07:55:32 -05:00
|
|
|
s_all.col(phase_usage_.phase_pos[Water]) = sw;
|
|
|
|
}
|
|
|
|
if (phase_usage_.phase_used[Oil]) {
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(so.size() == n);
|
2013-05-27 07:55:32 -05:00
|
|
|
s_all.col(phase_usage_.phase_pos[Oil]) = so;
|
|
|
|
}
|
|
|
|
if (phase_usage_.phase_used[Gas]) {
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(sg.size() == n);
|
2013-05-27 07:55:32 -05:00
|
|
|
s_all.col(phase_usage_.phase_pos[Gas]) = sg;
|
|
|
|
}
|
|
|
|
Block kr(n, np);
|
2013-05-27 15:01:20 -05:00
|
|
|
satprops_->relperm(n, s_all.data(), cells.data(), kr.data(), 0);
|
2013-05-27 07:55:32 -05:00
|
|
|
std::vector<V> relperms;
|
|
|
|
relperms.reserve(3);
|
|
|
|
for (int phase = 0; phase < 3; ++phase) {
|
|
|
|
if (phase_usage_.phase_used[phase]) {
|
|
|
|
relperms.emplace_back(kr.col(phase_usage_.phase_pos[phase]));
|
|
|
|
} else {
|
|
|
|
relperms.emplace_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return relperms;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Relative permeabilities for all phases.
|
|
|
|
/// \param[in] sw Array of n water saturation values.
|
|
|
|
/// \param[in] so Array of n oil saturation values.
|
|
|
|
/// \param[in] sg Array of n gas saturation values.
|
|
|
|
/// \param[in] cells Array of n cell indices to be associated with the saturation values.
|
|
|
|
/// \return An std::vector with 3 elements, each an array of n relperm values,
|
|
|
|
/// containing krw, kro, krg. Use PhaseIndex for indexing into the result.
|
|
|
|
std::vector<ADB> BlackoilPropsAdFromDeck::relperm(const ADB& sw,
|
2013-05-27 15:01:20 -05:00
|
|
|
const ADB& so,
|
|
|
|
const ADB& sg,
|
|
|
|
const Cells& cells) const
|
2013-05-27 07:55:32 -05:00
|
|
|
{
|
|
|
|
const int n = cells.size();
|
2013-05-27 15:01:20 -05:00
|
|
|
const int np = numPhases();
|
2013-05-27 07:55:32 -05:00
|
|
|
Block s_all(n, np);
|
|
|
|
if (phase_usage_.phase_used[Water]) {
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(sw.value().size() == n);
|
2013-05-27 07:55:32 -05:00
|
|
|
s_all.col(phase_usage_.phase_pos[Water]) = sw.value();
|
|
|
|
}
|
|
|
|
if (phase_usage_.phase_used[Oil]) {
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(so.value().size() == n);
|
2013-05-27 07:55:32 -05:00
|
|
|
s_all.col(phase_usage_.phase_pos[Oil]) = so.value();
|
|
|
|
} else {
|
2013-09-03 08:00:29 -05:00
|
|
|
OPM_THROW(std::runtime_error, "BlackoilPropsAdFromDeck::relperm() assumes oil phase is active.");
|
2013-05-27 07:55:32 -05:00
|
|
|
}
|
|
|
|
if (phase_usage_.phase_used[Gas]) {
|
2013-09-03 06:55:36 -05:00
|
|
|
assert(sg.value().size() == n);
|
2013-05-27 07:55:32 -05:00
|
|
|
s_all.col(phase_usage_.phase_pos[Gas]) = sg.value();
|
|
|
|
}
|
|
|
|
Block kr(n, np);
|
|
|
|
Block dkr(n, np*np);
|
2013-05-27 15:01:20 -05:00
|
|
|
satprops_->relperm(n, s_all.data(), cells.data(), kr.data(), dkr.data());
|
2013-05-27 07:55:32 -05:00
|
|
|
const int num_blocks = so.numBlocks();
|
|
|
|
std::vector<ADB> relperms;
|
|
|
|
relperms.reserve(3);
|
|
|
|
typedef const ADB* ADBPtr;
|
|
|
|
ADBPtr s[3] = { &sw, &so, &sg };
|
|
|
|
for (int phase1 = 0; phase1 < 3; ++phase1) {
|
|
|
|
if (phase_usage_.phase_used[phase1]) {
|
|
|
|
const int phase1_pos = phase_usage_.phase_pos[phase1];
|
|
|
|
std::vector<ADB::M> jacs(num_blocks);
|
|
|
|
for (int block = 0; block < num_blocks; ++block) {
|
|
|
|
jacs[block] = ADB::M(n, s[phase1]->derivative()[block].cols());
|
|
|
|
}
|
|
|
|
for (int phase2 = 0; phase2 < 3; ++phase2) {
|
|
|
|
if (!phase_usage_.phase_used[phase2]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const int phase2_pos = phase_usage_.phase_pos[phase2];
|
|
|
|
// Assemble dkr1/ds2.
|
|
|
|
const int column = phase1_pos + np*phase2_pos; // Recall: Fortran ordering from props_.relperm()
|
|
|
|
ADB::M dkr1_ds2_diag = spdiag(dkr.col(column));
|
|
|
|
for (int block = 0; block < num_blocks; ++block) {
|
|
|
|
jacs[block] += dkr1_ds2_diag * s[phase2]->derivative()[block];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
relperms.emplace_back(ADB::function(kr.col(phase1_pos), jacs));
|
|
|
|
} else {
|
|
|
|
relperms.emplace_back(ADB::null());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return relperms;
|
|
|
|
}
|
|
|
|
|
2013-11-26 06:51:10 -06:00
|
|
|
std::vector<ADB> BlackoilPropsAdFromDeck::capPress(const ADB& sw,
|
|
|
|
const ADB& so,
|
|
|
|
const ADB& sg,
|
|
|
|
const Cells& cells) const
|
|
|
|
{
|
|
|
|
const int numCells = cells.size();
|
|
|
|
const int numActivePhases = numPhases();
|
|
|
|
const int numBlocks = so.numBlocks();
|
|
|
|
|
|
|
|
Block activeSat(numCells, numActivePhases);
|
|
|
|
if (phase_usage_.phase_used[Water]) {
|
|
|
|
assert(sw.value().size() == numCells);
|
|
|
|
activeSat.col(phase_usage_.phase_pos[Water]) = sw.value();
|
|
|
|
}
|
|
|
|
if (phase_usage_.phase_used[Oil]) {
|
|
|
|
assert(so.value().size() == numCells);
|
|
|
|
activeSat.col(phase_usage_.phase_pos[Oil]) = so.value();
|
|
|
|
} else {
|
|
|
|
OPM_THROW(std::runtime_error, "BlackoilPropsAdFromDeck::relperm() assumes oil phase is active.");
|
|
|
|
}
|
|
|
|
if (phase_usage_.phase_used[Gas]) {
|
|
|
|
assert(sg.value().size() == numCells);
|
|
|
|
activeSat.col(phase_usage_.phase_pos[Gas]) = sg.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
Block pc(numCells, numActivePhases);
|
|
|
|
Block dpc(numCells, numActivePhases*numActivePhases);
|
|
|
|
satprops_->capPress(numCells, activeSat.data(), cells.data(), pc.data(), dpc.data());
|
|
|
|
|
|
|
|
std::vector<ADB> adbCapPressures;
|
|
|
|
adbCapPressures.reserve(3);
|
|
|
|
const ADB* s[3] = { &sw, &so, &sg };
|
|
|
|
for (int phase1 = 0; phase1 < 3; ++phase1) {
|
|
|
|
if (phase_usage_.phase_used[phase1]) {
|
|
|
|
const int phase1_pos = phase_usage_.phase_pos[phase1];
|
|
|
|
std::vector<ADB::M> jacs(numBlocks);
|
|
|
|
for (int block = 0; block < numBlocks; ++block) {
|
|
|
|
jacs[block] = ADB::M(numCells, s[phase1]->derivative()[block].cols());
|
|
|
|
}
|
|
|
|
for (int phase2 = 0; phase2 < 3; ++phase2) {
|
|
|
|
if (!phase_usage_.phase_used[phase2])
|
|
|
|
continue;
|
|
|
|
const int phase2_pos = phase_usage_.phase_pos[phase2];
|
|
|
|
// Assemble dpc1/ds2.
|
|
|
|
const int column = phase1_pos + numActivePhases*phase2_pos; // Recall: Fortran ordering from props_.relperm()
|
|
|
|
ADB::M dpc1_ds2_diag = spdiag(dpc.col(column));
|
|
|
|
for (int block = 0; block < numBlocks; ++block) {
|
|
|
|
jacs[block] += dpc1_ds2_diag * s[phase2]->derivative()[block];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
adbCapPressures.emplace_back(ADB::function(pc.col(phase1_pos), jacs));
|
|
|
|
} else {
|
|
|
|
adbCapPressures.emplace_back(ADB::null());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return adbCapPressures;
|
|
|
|
}
|
2014-02-18 07:50:29 -06:00
|
|
|
|
|
|
|
/// Saturation update for hysteresis behavior.
|
|
|
|
/// \param[in] cells Array of n cell indices to be associated with the saturation values.
|
|
|
|
void BlackoilPropsAdFromDeck::updateSatHyst(const std::vector<double>& saturation,
|
|
|
|
const std::vector<int>& cells)
|
|
|
|
{
|
|
|
|
const int n = cells.size();
|
|
|
|
satprops_->updateSatHyst(n, cells.data(), saturation.data());
|
|
|
|
}
|
2013-11-26 06:51:10 -06:00
|
|
|
|
2013-05-27 07:55:32 -05:00
|
|
|
} // namespace Opm
|
|
|
|
|