2014-03-14 14:12:26 +08:00
|
|
|
/*
|
|
|
|
|
Copyright 2014 SINTEF ICT, Applied Mathematics.
|
2014-03-17 10:54:29 +08:00
|
|
|
Copyright 2014 STATOIL ASA.
|
2013-12-06 22:13:29 +08:00
|
|
|
|
2014-03-14 14:12:26 +08:00
|
|
|
This file is part of the Open Porous Media project (OPM).
|
2013-12-06 22:13:29 +08:00
|
|
|
|
2014-03-14 14:12:26 +08:00
|
|
|
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.
|
2013-12-06 22:13:29 +08:00
|
|
|
|
2014-03-14 14:12:26 +08:00
|
|
|
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.
|
2013-12-06 22:13:29 +08:00
|
|
|
|
2014-03-14 14:12:26 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2013-12-06 22:13:29 +08:00
|
|
|
|
2014-03-14 14:12:26 +08:00
|
|
|
#include <cmath>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <opm/autodiff/AutoDiffBlock.hpp>
|
|
|
|
|
#include <opm/autodiff/AutoDiffHelpers.hpp>
|
|
|
|
|
#include <opm/polymer/fullyimplicit/PolymerPropsAd.hpp>
|
|
|
|
|
|
|
|
|
|
namespace Opm {
|
2013-12-06 22:13:29 +08:00
|
|
|
|
2014-02-25 09:52:10 +08:00
|
|
|
typedef PolymerPropsAd::ADB ADB;
|
|
|
|
|
typedef PolymerPropsAd::V V;
|
2013-12-06 22:13:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-12 20:29:40 +08:00
|
|
|
double
|
|
|
|
|
PolymerPropsAd::rockDensity() const
|
|
|
|
|
{
|
|
|
|
|
return polymer_props_.rockDensity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-01-10 14:15:24 +08:00
|
|
|
|
|
|
|
|
|
2014-02-25 09:52:10 +08:00
|
|
|
|
2013-12-12 22:46:29 +08:00
|
|
|
double
|
|
|
|
|
PolymerPropsAd::deadPoreVol() const
|
|
|
|
|
{
|
|
|
|
|
return polymer_props_.deadPoreVol();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-25 09:52:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-14 12:59:45 +08:00
|
|
|
double
|
|
|
|
|
PolymerPropsAd::cMax() const
|
|
|
|
|
{
|
|
|
|
|
return polymer_props_.cMax();
|
|
|
|
|
}
|
2014-02-25 09:52:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-14 12:59:45 +08:00
|
|
|
|
2013-12-12 20:29:40 +08:00
|
|
|
|
2013-12-06 23:35:13 +08:00
|
|
|
PolymerPropsAd::PolymerPropsAd(const PolymerProperties& polymer_props)
|
|
|
|
|
: polymer_props_ (polymer_props)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-25 09:52:10 +08:00
|
|
|
|
2013-12-06 23:35:13 +08:00
|
|
|
PolymerPropsAd::~PolymerPropsAd()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-25 09:52:10 +08:00
|
|
|
|
2013-12-06 22:13:29 +08:00
|
|
|
V PolymerPropsAd::effectiveInvWaterVisc(const V& c,
|
|
|
|
|
const double* visc) const
|
|
|
|
|
{
|
|
|
|
|
const int nc = c.size();
|
2013-12-09 20:33:05 +08:00
|
|
|
V inv_mu_w_eff(nc);
|
2013-12-06 22:13:29 +08:00
|
|
|
for (int i = 0; i < nc; ++i) {
|
2013-12-06 23:35:13 +08:00
|
|
|
double im = 0;
|
2013-12-06 22:13:29 +08:00
|
|
|
polymer_props_.effectiveInvVisc(c(i), visc, im);
|
|
|
|
|
inv_mu_w_eff(i) = im;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return inv_mu_w_eff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ADB PolymerPropsAd::effectiveInvWaterVisc(const ADB& c,
|
2013-12-09 20:33:05 +08:00
|
|
|
const double* visc) const
|
2013-12-06 22:13:29 +08:00
|
|
|
{
|
2013-12-06 23:35:13 +08:00
|
|
|
const int nc = c.size();
|
2013-12-09 20:33:05 +08:00
|
|
|
V inv_mu_w_eff(nc);
|
|
|
|
|
V dinv_mu_w_eff(nc);
|
2013-12-06 23:35:13 +08:00
|
|
|
for (int i = 0; i < nc; ++i) {
|
|
|
|
|
double im = 0, dim = 0;
|
2013-12-06 22:13:29 +08:00
|
|
|
polymer_props_.effectiveInvViscWithDer(c.value()(i), visc, im, dim);
|
|
|
|
|
inv_mu_w_eff(i) = im;
|
|
|
|
|
dinv_mu_w_eff(i) = dim;
|
|
|
|
|
}
|
2013-12-06 23:35:13 +08:00
|
|
|
ADB::M dim_diag = spdiag(dinv_mu_w_eff);
|
|
|
|
|
const int num_blocks = c.numBlocks();
|
|
|
|
|
std::vector<ADB::M> jacs(num_blocks);
|
|
|
|
|
for (int block = 0; block < num_blocks; ++block) {
|
|
|
|
|
jacs[block] = dim_diag * c.derivative()[block];
|
|
|
|
|
}
|
2013-12-06 22:13:29 +08:00
|
|
|
return ADB::function(inv_mu_w_eff, jacs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-25 09:52:10 +08:00
|
|
|
|
2013-12-06 22:13:29 +08:00
|
|
|
V PolymerPropsAd::polymerWaterVelocityRatio(const V& c) const
|
|
|
|
|
{
|
2013-12-06 23:35:13 +08:00
|
|
|
const int nc = c.size();
|
2013-12-09 20:33:05 +08:00
|
|
|
V mc(nc);
|
2013-12-06 23:35:13 +08:00
|
|
|
|
|
|
|
|
for (int i = 0; i < nc; ++i) {
|
|
|
|
|
double m = 0;
|
|
|
|
|
polymer_props_.computeMc(c(i), m);
|
|
|
|
|
mc(i) = m;
|
|
|
|
|
}
|
2013-12-06 22:13:29 +08:00
|
|
|
|
2013-12-06 23:35:13 +08:00
|
|
|
return mc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ADB PolymerPropsAd::polymerWaterVelocityRatio(const ADB& c) const
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
const int nc = c.size();
|
2013-12-09 20:33:05 +08:00
|
|
|
V mc(nc);
|
|
|
|
|
V dmc(nc);
|
2013-12-06 23:35:13 +08:00
|
|
|
|
|
|
|
|
for (int i = 0; i < nc; ++i) {
|
|
|
|
|
double m = 0;
|
|
|
|
|
double dm = 0;
|
2013-12-09 20:33:05 +08:00
|
|
|
polymer_props_.computeMcWithDer(c.value()(i), m, dm);
|
2013-12-06 23:35:13 +08:00
|
|
|
|
|
|
|
|
mc(i) = m;
|
|
|
|
|
dmc(i) = dm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ADB::M dmc_diag = spdiag(dmc);
|
|
|
|
|
const int num_blocks = c.numBlocks();
|
|
|
|
|
std::vector<ADB::M> jacs(num_blocks);
|
|
|
|
|
for (int block = 0; block < num_blocks; ++block) {
|
|
|
|
|
jacs[block] = dmc_diag * c.derivative()[block];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ADB::function(mc, jacs);
|
2013-12-06 22:13:29 +08:00
|
|
|
}
|
|
|
|
|
|
2013-12-11 22:52:11 +08:00
|
|
|
|
|
|
|
|
|
2014-02-25 09:52:10 +08:00
|
|
|
|
|
|
|
|
|
2013-12-11 22:52:11 +08:00
|
|
|
V PolymerPropsAd::adsorption(const V& c, const V& cmax_cells) const
|
|
|
|
|
{
|
|
|
|
|
const int nc = c.size();
|
|
|
|
|
V ads(nc);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < nc; ++i) {
|
|
|
|
|
double c_ads = 0;
|
|
|
|
|
polymer_props_.adsorption(c(i), cmax_cells(i), c_ads);
|
|
|
|
|
|
|
|
|
|
ads(i) = c_ads;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ads;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-25 09:52:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-11 22:52:11 +08:00
|
|
|
ADB PolymerPropsAd::adsorption(const ADB& c, const ADB& cmax_cells) const
|
|
|
|
|
{
|
|
|
|
|
const int nc = c.value().size();
|
|
|
|
|
|
|
|
|
|
V ads(nc);
|
|
|
|
|
V dads(nc);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < nc; ++i) {
|
|
|
|
|
double c_ads = 0;
|
|
|
|
|
double dc_ads = 0;
|
|
|
|
|
polymer_props_.adsorptionWithDer(c.value()(i), cmax_cells.value()(i), c_ads, dc_ads);
|
|
|
|
|
ads(i) = c_ads;
|
|
|
|
|
dads(i) = dc_ads;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ADB::M dads_diag = spdiag(dads);
|
|
|
|
|
int num_blocks = c.numBlocks();
|
|
|
|
|
std::vector<ADB::M> jacs(num_blocks);
|
|
|
|
|
for (int block = 0; block < num_blocks; ++block) {
|
|
|
|
|
jacs[block] = dads_diag * c.derivative()[block];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ADB::function(ads, jacs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-02-25 09:52:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-11 22:52:11 +08:00
|
|
|
V
|
|
|
|
|
PolymerPropsAd::effectiveRelPerm(const V& c,
|
|
|
|
|
const V& cmax_cells,
|
|
|
|
|
const V& krw) const
|
|
|
|
|
{
|
|
|
|
|
const int nc = c.size();
|
|
|
|
|
|
|
|
|
|
V one = V::Ones(nc);
|
2013-12-12 21:58:25 +08:00
|
|
|
V ads = adsorption(c, cmax_cells);
|
2013-12-11 22:52:11 +08:00
|
|
|
double max_ads = polymer_props_.cMaxAds();
|
|
|
|
|
double res_factor = polymer_props_.resFactor();
|
|
|
|
|
double factor = (res_factor -1.) / max_ads;
|
|
|
|
|
V rk = one + factor * ads;
|
|
|
|
|
V krw_eff = krw / rk;
|
|
|
|
|
|
2013-12-12 21:58:25 +08:00
|
|
|
return krw_eff;
|
2013-12-11 22:52:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-02-25 09:52:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-11 22:52:11 +08:00
|
|
|
ADB
|
|
|
|
|
PolymerPropsAd::effectiveRelPerm(const ADB& c,
|
|
|
|
|
const ADB& cmax_cells,
|
|
|
|
|
const ADB& krw,
|
|
|
|
|
const ADB& sw) const
|
|
|
|
|
{
|
|
|
|
|
const int nc = c.value().size();
|
|
|
|
|
V one = V::Ones(nc);
|
2013-12-12 21:58:25 +08:00
|
|
|
ADB ads = adsorption(c, cmax_cells);
|
2013-12-11 22:52:11 +08:00
|
|
|
V krw_eff = effectiveRelPerm(c.value(), cmax_cells.value(), krw.value());
|
|
|
|
|
|
|
|
|
|
double max_ads = polymer_props_.cMaxAds();
|
|
|
|
|
double res_factor = polymer_props_.resFactor();
|
|
|
|
|
double factor = (res_factor - 1.) / max_ads;
|
|
|
|
|
ADB rk = one + ads * factor;
|
2014-01-10 14:15:24 +08:00
|
|
|
ADB dkrw_ds = krw / rk;
|
|
|
|
|
ADB dkrw_dc = -factor * krw / (rk * rk) * ads ;
|
2013-12-11 22:52:11 +08:00
|
|
|
|
|
|
|
|
const int num_blocks = c.numBlocks();
|
|
|
|
|
std::vector<ADB::M> jacs(num_blocks);
|
|
|
|
|
for (int block = 0; block < num_blocks; ++block) {
|
2014-02-25 09:52:10 +08:00
|
|
|
jacs[block] = dkrw_ds.derivative()[block] * sw.derivative()[block]
|
|
|
|
|
+ dkrw_dc.derivative()[block] * c.derivative()[block];
|
2013-12-11 22:52:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ADB::function(krw_eff, jacs);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-06 23:35:13 +08:00
|
|
|
}// namespace Opm
|