36#ifndef OPENRS_MIMETICIPEVALUATOR_HEADER
37#define OPENRS_MIMETICIPEVALUATOR_HEADER
44#include <opm/common/ErrorMacros.hpp>
45#include <opm/grid/utility/SparseTable.hpp>
47#include <opm/porsol/common/fortran.hpp>
48#include <opm/porsol/common/blas_lapack.hpp>
49#include <opm/porsol/common/Matrix.hpp>
83 template <
class Gr
idInterface,
class RockInterface>
89 static constexpr int dim = GridInterface::Dimension;
92 typedef typename GridInterface::CellIterator
CellIter;
98 typedef typename CellIter::Scalar
Scalar;
120 fa_ (max_nf * max_nf),
138 std::vector<double>(max_nf * max_nf).swap(fa_);
139 std::vector<double>(max_nf *
dim ).swap(t1_);
140 std::vector<double>(max_nf *
dim ).swap(t2_);
157 template<
class Vector>
160 typedef typename Vector::value_type vt;
162 Vector sz2(sz.size());
164 std::transform(sz.begin(), sz.end(), sz2.begin(),
165 [](
const vt& input) { return input*input; });
167 Binv_ .allocate(sz2.begin(), sz2.end());
168 gflux_.allocate(sz .begin(), sz .end());
203 const RockInterface& r,
204 const typename CellIter::Vector& grav,
207 typedef typename CellIter::FaceIterator FI;
208 typedef typename CellIter::Vector CV;
209 typedef typename FI ::Vector FV;
211 const int ci = c->index();
213 static_assert (FV::dimension == int(
dim),
"");
214 assert (
int(t1_.size()) >= nf *
dim);
215 assert (
int(t2_.size()) >= nf *
dim);
216 assert (
int(fa_.size()) >= nf * nf);
218 SharedFortranMatrix T1 (nf,
dim, &t1_ [0]);
219 SharedFortranMatrix T2 (nf,
dim, &t2_ [0]);
220 SharedFortranMatrix fa (nf, nf , &fa_ [0]);
221 SharedFortranMatrix Binv(nf, nf , &Binv_[ci][0]);
226 typename RockInterface::PermTensor K = r.permeability(ci);
227 const CV Kg =
prod(K, grav);
231 const CV cc = c->centroid();
233 for (FI f = c->facebegin(); f != c->faceend(); ++f, ++i) {
237 FV fc = f->centroid(); fc -= cc; fc *= fa(i,i);
238 FV fn = f->normal (); fn *= fa(i,i);
240 gflux_[ci][i] = fn * Kg;
242 for (
int j = 0; j <
dim; ++j) {
270 t / c->volume(), Binv );
297 template<
class Flu
idInterface,
class Sat>
299 const FluidInterface& fl,
300 const std::vector<Sat>& s)
302 const int ci = c->index();
304 std::array<Scalar, FluidInterface::NumberOfPhases> mob ;
305 std::array<Scalar, FluidInterface::NumberOfPhases> rho ;
306 fl.phaseMobilities(ci, s[ci], mob);
307 fl.phaseDensities (ci, rho);
309 totmob_ = std::accumulate (mob.begin(), mob.end(),
Scalar(0.0));
310 mob_dens_ = std::inner_product(rho.begin(), rho.end(), mob.begin(),
336 template<
template<
typename>
class SP>
338 FullMatrix<Scalar,SP,FortranOrdering>& Binv)
const
343 template<
template<
typename>
class SP>
346 FullMatrix<Scalar,SP,FortranOrdering>& Binv)
const
348 const int ci = c->index();
349 std::transform(Binv_[ci].begin(), Binv_[ci].end(), Binv.data(),
350 [totmob](
const Scalar& input) { return input*totmob; });
384 template<
class PermTensor,
template<
typename>
class SP>
387 FullMatrix<Scalar,SP,FortranOrdering>& Binv)
389 typedef typename CellIter::FaceIterator FI;
390 typedef typename CellIter::Vector CV;
391 typedef typename FI ::Vector FV;
393 const int nf = Binv.numRows();
395 static_assert(FV::dimension == int(
dim),
"");
396 assert(Binv.numRows() <= max_nf_);
397 assert(Binv.numRows() == Binv.numCols());
398 assert(
int(t1_.size()) >= nf *
dim);
399 assert(
int(t2_.size()) >= nf *
dim);
400 assert(
int(fa_.size()) >= nf * nf);
402 SharedFortranMatrix T1(nf,
dim, &t1_[0]);
403 SharedFortranMatrix T2(nf,
dim, &t2_[0]);
404 SharedFortranMatrix fa(nf, nf , &fa_[0]);
410 const CV cc = c->centroid();
412 for (FI f = c->facebegin(); f != c->faceend(); ++f, ++i) {
416 FV fc = f->centroid(); fc -= cc; fc *= fa(i,i);
417 FV fn = f->normal (); fn *= fa(i,i);
419 for (
int j = 0; j <
dim; ++j) {
447 t / c->volume(), Binv );
477 template<
class Vector>
479 const typename CellIter::Vector& grav,
483 typedef typename CellIter::FaceIterator FI;
484 typedef typename CellIter::Vector Point;
486 assert (gterm.size() <= max_nf_);
488 const Point cc = c->centroid();
490 for (FI f = c->facebegin(); f != c->faceend(); ++f, ++i) {
491 Point fc = f->centroid();
493 gterm[i] = omega * (fc * grav);
497 template<
class Vector>
499 const typename CellIter::Vector& grav,
505 template<
class Flu
idInterface,
class Sat,
class Vector>
507 const FluidInterface& fl,
508 const std::vector<Sat>& s,
509 const typename CellIter::Vector& grav,
512 const int ci = c->index();
514 std::array<Scalar, FluidInterface::NumberOfPhases> mob;
515 std::array<Scalar, FluidInterface::NumberOfPhases> rho;
516 fl.phaseMobilities(ci, s[ci], mob);
517 fl.phaseDensities (ci, rho);
519 Scalar totmob = std::accumulate (mob.begin(), mob.end(),
Scalar(0.0));
520 Scalar omega = std::inner_product(rho.begin(), rho.end(), mob.begin(),
540 template<
class Vector>
544 Scalar mob_dens = mob_dens_;
545 std::transform(gflux_[c->index()].begin(), gflux_[c->index()].end(),
547 [mob_dens](
const Scalar& input) { return input*mob_dens; });
554 std::vector<Scalar> fa_, t1_, t2_;
555 Opm::SparseTable<Scalar> Binv_ ;
556 Opm::SparseTable<Scalar> gflux_ ;
void init(const int max_nf)
Initialization routine.
Definition MimeticIPEvaluator.hpp:135
MimeticIPEvaluator(const int max_nf)
Constructor.
Definition MimeticIPEvaluator.hpp:118
void gravityTerm(const CellIter &c, const typename CellIter::Vector &grav, const Scalar omega, Vector >erm) const
Computes the mimetic discretization of the gravity term in Darcy's law.
Definition MimeticIPEvaluator.hpp:478
void evaluate(const CellIter &c, const PermTensor &K, FullMatrix< Scalar, SP, FortranOrdering > &Binv)
Main evaluation routine.
Definition MimeticIPEvaluator.hpp:385
MimeticIPEvaluator()
Default constructor.
Definition MimeticIPEvaluator.hpp:102
void computeDynamicParams(const CellIter &c, const FluidInterface &fl, const std::vector< Sat > &s)
Evaluate dynamic (saturation dependent) properties in single cell.
Definition MimeticIPEvaluator.hpp:298
GridInterface::CellIterator CellIter
The iterator type for iterating over grid cells.
Definition MimeticIPEvaluator.hpp:92
void buildStaticContrib(const CellIter &c, const RockInterface &r, const typename CellIter::Vector &grav, const int nf)
Main evaluation routine.
Definition MimeticIPEvaluator.hpp:202
CellIter::Scalar Scalar
The element type of the matrix representation of the mimetic inner product.
Definition MimeticIPEvaluator.hpp:98
void reserveMatrices(const Vector &sz)
Reserve internal space for storing values of (static) IP contributions for given set of cells.
Definition MimeticIPEvaluator.hpp:158
void gravityFlux(const CellIter &c, Vector &gflux) const
Compute gravity flux for all faces of single cell.
Definition MimeticIPEvaluator.hpp:541
static constexpr int dim
The number of space dimensions.
Definition MimeticIPEvaluator.hpp:89
void getInverseMatrix(const CellIter &c, FullMatrix< Scalar, SP, FortranOrdering > &Binv) const
Retrieve the dynamic (mobility updated) inverse mimetic inner product matrix for specific cell.
Definition MimeticIPEvaluator.hpp:337
Inverting small matrices.
Definition ImplicitAssembly.hpp:43
void matMulAdd_NN(const T &a1, const FullMatrix< T, SP1, FortranOrdering > &A, const FullMatrix< T, SP2, FortranOrdering > &B, const T &a2, FullMatrix< T, SP3, FortranOrdering > &C)
GEneral Matrix-Matrix product update of other matrix.
Definition Matrix.hpp:1136
int orthogonalizeColumns(FullMatrix< T, StoragePolicy, FortranOrdering > &A)
Construct orthonormal basis for matrix range (i.e., column space).
Definition Matrix.hpp:729
void symmetricUpdate(const T &a1, const FullMatrix< T, StoragePolicy, FortranOrdering > &A, const T &a2, FullMatrix< T, StoragePolicy, FortranOrdering > &C)
Symmetric, rank update of symmetric matrix.
Definition Matrix.hpp:829
Matrix::value_type trace(const Matrix &A)
Compute matrix trace (i.e., sum(diag(A))).
Definition Matrix.hpp:638
void matMulAdd_NT(const T &a1, const FullMatrix< T, SP1, FortranOrdering > &A, const FullMatrix< T, SP2, FortranOrdering > &B, const T &a2, FullMatrix< T, SP3, FortranOrdering > &C)
GEneral Matrix-Matrix product update of other matrix.
Definition Matrix.hpp:1194
void zero(Matrix &A)
Zero-fill a.
Definition Matrix.hpp:602
Dune::FieldVector< typename Matrix::value_type, rows > prod(const Matrix &A, const Dune::FieldVector< typename Matrix::value_type, rows > &x)
Matrix applied to a vector.
Definition Matrix.hpp:668