2013-05-07 12:58:10 -05:00
|
|
|
/*
|
|
|
|
Copyright 2013 SINTEF ICT, Applied Mathematics.
|
|
|
|
Copyright 2013 Statoil ASA.
|
|
|
|
|
|
|
|
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_IMPESTPFAAD_HEADER_INCLUDED
|
|
|
|
#define OPM_IMPESTPFAAD_HEADER_INCLUDED
|
|
|
|
|
|
|
|
#include "AutoDiffBlock.hpp"
|
|
|
|
|
|
|
|
#include <opm/core/simulator/BlackoilState.hpp>
|
|
|
|
#include <opm/core/simulator/WellState.hpp>
|
|
|
|
|
|
|
|
#include <algorithm>
|
2013-05-07 17:11:21 -05:00
|
|
|
#include <cassert>
|
2013-05-07 12:58:10 -05:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
|
|
|
struct UnstructuredGrid;
|
|
|
|
|
2013-05-07 14:40:17 -05:00
|
|
|
namespace {
|
2013-05-07 12:58:10 -05:00
|
|
|
std::vector<int>
|
|
|
|
buildAllCells(const int nc)
|
|
|
|
{
|
|
|
|
std::vector<int> all_cells(nc);
|
|
|
|
|
|
|
|
for (int c = 0; c < nc; ++c) { all_cells[c] = c; }
|
|
|
|
|
|
|
|
return all_cells;
|
|
|
|
}
|
2013-05-07 14:40:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace Opm {
|
|
|
|
class LinearSolverInterface;
|
2013-05-07 12:58:10 -05:00
|
|
|
|
2013-05-08 02:39:48 -05:00
|
|
|
template <typename Scalar, class BOFluid>
|
2013-05-07 12:58:10 -05:00
|
|
|
class PressureDependentFluidData {
|
|
|
|
public:
|
|
|
|
typedef AutoDiff::ForwardBlock<Scalar> ADB;
|
|
|
|
|
|
|
|
PressureDependentFluidData(const int nc,
|
2013-05-08 02:39:48 -05:00
|
|
|
const BOFluid& fluid)
|
2013-05-07 12:58:10 -05:00
|
|
|
: nc_ (nc)
|
2013-05-08 02:39:48 -05:00
|
|
|
, np_ (fluid.numPhases())
|
2013-05-07 12:58:10 -05:00
|
|
|
, cells_(buildAllCells(nc))
|
2013-05-08 02:39:48 -05:00
|
|
|
, fluid_(fluid)
|
2013-05-07 12:58:10 -05:00
|
|
|
, A_ (nc_, np_ * np_)
|
|
|
|
, dA_ (nc_, np_ * np_)
|
|
|
|
, mu_ (nc_, np_ )
|
|
|
|
, dmu_ (nc_, np_ )
|
|
|
|
, kr_ (nc_, np_ )
|
|
|
|
, zero_ (ADB::V::Zero(nc, 1))
|
|
|
|
, one_ (ADB::V::Ones(nc, 1))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
computeSatQuant(const BlackoilState& state)
|
|
|
|
{
|
|
|
|
const std::vector<double>& s = state.saturation();
|
|
|
|
|
2013-05-08 06:02:51 -05:00
|
|
|
assert (s.size() == std::vector<double>::size_type(nc_ * np_));
|
|
|
|
|
2013-05-07 12:58:10 -05:00
|
|
|
double* dkrds = 0; // Ignore rel-perm derivatives
|
2013-05-08 02:39:48 -05:00
|
|
|
fluid_.relperm(nc_, & s[0], & cells_[0],
|
2013-05-07 12:58:10 -05:00
|
|
|
kr_.data(), dkrds);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
computePressQuant(const BlackoilState& state)
|
|
|
|
{
|
|
|
|
const std::vector<double>& p = state.pressure();
|
|
|
|
const std::vector<double>& z = state.surfacevol();
|
|
|
|
|
2013-05-08 06:02:51 -05:00
|
|
|
assert (p.size() == std::vector<double>::size_type(nc_ * 1 ));
|
|
|
|
assert (z.size() == std::vector<double>::size_type(nc_ * np_));
|
|
|
|
|
2013-05-08 02:39:48 -05:00
|
|
|
fluid_.matrix (nc_, & p[0], & z[0], & cells_[0],
|
2013-05-07 12:58:10 -05:00
|
|
|
A_ .data(), dA_ .data());
|
|
|
|
|
2013-05-08 02:39:48 -05:00
|
|
|
fluid_.viscosity(nc_, & p[0], & z[0], & cells_[0],
|
2013-05-07 12:58:10 -05:00
|
|
|
mu_.data(), dmu_.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
ADB
|
|
|
|
fvf(const int p) const
|
|
|
|
{
|
|
|
|
assert (0 <= p );
|
|
|
|
assert (p < np_);
|
|
|
|
|
|
|
|
typename ADB::V A = A_ .block(0, p * (np_ + 1), nc_, 1);
|
|
|
|
typename ADB::V dA = dA_.block(0, p * (np_ + 1), nc_, 1);
|
|
|
|
typename ADB::M jac = dA.matrix().asDiagonal();
|
|
|
|
|
|
|
|
return one_ / ADB::function(A, jac);
|
|
|
|
}
|
|
|
|
|
|
|
|
typename ADB::V
|
|
|
|
phaseRelPerm(const int p) const
|
|
|
|
{
|
|
|
|
typename ADB::V kr = kr_.block(0, p, nc_, 1);
|
|
|
|
|
|
|
|
return kr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ADB
|
|
|
|
phaseViscosity(const int p) const
|
|
|
|
{
|
|
|
|
assert (0 <= p );
|
|
|
|
assert (p < np_);
|
|
|
|
|
|
|
|
typename ADB::V mu = mu_ .block(0, p, nc_, 1);
|
|
|
|
typename ADB::V dmu = dmu_.block(0, p, nc_, 1);
|
|
|
|
typename ADB::M jac = dmu.matrix().asDiagonal();
|
|
|
|
|
|
|
|
return ADB::function(mu, jac);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const int nc_;
|
|
|
|
const int np_;
|
|
|
|
|
|
|
|
const std::vector<int> cells_;
|
2013-05-08 02:39:48 -05:00
|
|
|
const BOFluid& fluid_;
|
2013-05-07 12:58:10 -05:00
|
|
|
|
|
|
|
typedef Eigen::Array<Scalar,
|
|
|
|
Eigen::Dynamic,
|
|
|
|
Eigen::Dynamic,
|
|
|
|
Eigen::RowMajor> DerivedQuant;
|
|
|
|
|
|
|
|
// Pressure dependent quantities (essentially B and \mu)
|
|
|
|
DerivedQuant A_ ;
|
|
|
|
DerivedQuant dA_ ;
|
|
|
|
DerivedQuant mu_ ;
|
|
|
|
DerivedQuant dmu_;
|
|
|
|
|
|
|
|
// Saturation dependent quantities (rel-perm only)
|
|
|
|
DerivedQuant kr_;
|
|
|
|
|
|
|
|
const typename ADB::V zero_;
|
|
|
|
const typename ADB::V one_ ;
|
|
|
|
};
|
|
|
|
|
2013-05-08 02:39:48 -05:00
|
|
|
template <class BOFluid, class GeoProps>
|
2013-05-07 12:58:10 -05:00
|
|
|
class ImpesTPFAAD {
|
|
|
|
public:
|
|
|
|
ImpesTPFAAD(const UnstructuredGrid& grid ,
|
2013-05-08 02:39:48 -05:00
|
|
|
const BOFluid& fluid,
|
|
|
|
const GeoProps& geo )
|
2013-05-07 12:58:10 -05:00
|
|
|
: grid_ (grid)
|
2013-05-08 02:39:48 -05:00
|
|
|
, geo_ (geo)
|
|
|
|
, pdepfdata_(grid.number_of_cells, fluid)
|
2013-05-07 12:58:10 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Disallow copying and assignment
|
|
|
|
ImpesTPFAAD(const ImpesTPFAAD& rhs);
|
|
|
|
ImpesTPFAAD& operator=(const ImpesTPFAAD& rhs);
|
|
|
|
|
2013-05-08 02:39:48 -05:00
|
|
|
typedef PressureDependentFluidData<double, BOFluid> PDepFData;
|
|
|
|
typedef typename PDepFData::ADB ADB;
|
2013-05-07 12:58:10 -05:00
|
|
|
|
|
|
|
const UnstructuredGrid& grid_;
|
2013-05-08 02:39:48 -05:00
|
|
|
const GeoProps& geo_ ;
|
2013-05-07 12:58:10 -05:00
|
|
|
PDepFData pdepfdata_;
|
|
|
|
};
|
|
|
|
} // namespace Opm
|
|
|
|
|
|
|
|
#endif /* OPM_IMPESTPFAAD_HEADER_INCLUDED */
|