36#ifndef OPENRS_MIMETICIPEVALUATOR_HEADER
37#define OPENRS_MIMETICIPEVALUATOR_HEADER
44#include <opm/common/ErrorMacros.hpp>
45#include <opm/grid/utility/SparseTable.hpp>
83 template <
class Gr
idInterface,
class RockInterface>
89 enum {
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;
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());
201 const RockInterface& r,
205 typedef typename CellIter::FaceIterator FI;
209 const int ci = c->index();
211 static_assert (FV::dimension == int(
dim),
"");
212 assert (
int(t1_.size()) >= nf *
dim);
213 assert (
int(t2_.size()) >= nf *
dim);
214 assert (
int(fa_.size()) >= nf * nf);
224 typename RockInterface::PermTensor K = r.permeability(ci);
225 const CV Kg =
prod(K, grav);
229 const CV cc = c->centroid();
231 for (FI f = c->facebegin(); f != c->faceend(); ++f, ++i) {
235 FV fc = f->centroid(); fc -= cc; fc *= fa(i,i);
236 FV fn = f->normal (); fn *= fa(i,i);
238 gflux_[ci][i] = fn * Kg;
240 for (
int j = 0;
j <
dim; ++
j) {
268 t / c->volume(), Binv );
295 template<
class Flu
idInterface,
class Sat>
297 const FluidInterface& fl,
298 const std::vector<Sat>& s)
300 const int ci = c->index();
302 std::array<Scalar, FluidInterface::NumberOfPhases> mob ;
303 std::array<Scalar, FluidInterface::NumberOfPhases>
rho ;
304 fl.phaseMobilities(ci, s[ci], mob);
305 fl.phaseDensities (ci,
rho);
307 totmob_ = std::accumulate (mob.begin(), mob.end(),
Scalar(0.0));
308 mob_dens_ = std::inner_product(
rho.begin(),
rho.end(), mob.begin(),
334 template<
template<
typename>
class SP>
336 FullMatrix<Scalar,SP,FortranOrdering>& Binv)
const
341 template<
template<
typename>
class SP>
344 FullMatrix<Scalar,SP,FortranOrdering>& Binv)
const
346 const int ci = c->index();
347 std::transform(Binv_[ci].begin(), Binv_[ci].end(), Binv.data(),
348 [totmob](
const Scalar& input) { return input*totmob; });
382 template<
class PermTensor,
template<
typename>
class SP>
385 FullMatrix<Scalar,SP,FortranOrdering>& Binv)
387 typedef typename CellIter::FaceIterator FI;
391 const int nf = Binv.numRows();
393 static_assert(FV::dimension == int(
dim),
"");
394 assert(Binv.numRows() <= max_nf_);
395 assert(Binv.numRows() == Binv.numCols());
396 assert(
int(t1_.size()) >= nf *
dim);
397 assert(
int(t2_.size()) >= nf *
dim);
398 assert(
int(fa_.size()) >= nf * nf);
408 const CV cc = c->centroid();
410 for (FI f = c->facebegin(); f != c->faceend(); ++f, ++i) {
414 FV fc = f->centroid(); fc -= cc; fc *= fa(i,i);
415 FV fn = f->normal (); fn *= fa(i,i);
417 for (
int j = 0;
j <
dim; ++
j) {
445 t / c->volume(), Binv );
475 template<
class Vector>
481 typedef typename CellIter::FaceIterator FI;
484 assert (gterm.size() <= max_nf_);
486 const Point cc = c->centroid();
488 for (FI f = c->facebegin(); f != c->faceend(); ++f, ++i) {
489 Point fc = f->centroid();
491 gterm[i] = omega * (fc * grav);
495 template<
class Vector>
503 template<
class Flu
idInterface,
class Sat,
class Vector>
505 const FluidInterface& fl,
506 const std::vector<Sat>& s,
510 const int ci = c->index();
512 std::array<Scalar, FluidInterface::NumberOfPhases> mob;
513 std::array<Scalar, FluidInterface::NumberOfPhases>
rho;
514 fl.phaseMobilities(ci, s[ci], mob);
515 fl.phaseDensities (ci,
rho);
517 Scalar totmob = std::accumulate (mob.begin(), mob.end(),
Scalar(0.0));
518 Scalar omega = std::inner_product(
rho.begin(),
rho.end(), mob.begin(),
538 template<
class Vector>
542 Scalar mob_dens = mob_dens_;
543 std::transform(gflux_[c->index()].begin(), gflux_[c->index()].end(),
545 [mob_dens](
const Scalar& input) { return input*mob_dens; });
552 std::vector<Scalar> fa_, t1_, t2_;
553 Opm::SparseTable<Scalar> Binv_ ;
554 Opm::SparseTable<Scalar> gflux_ ;
Definition: MimeticIPEvaluator.hpp:85
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:476
void gravityTerm(const CellIter &c, const FluidInterface &fl, const std::vector< Sat > &s, const typename CellIter::Vector &grav, Vector >erm) const
Definition: MimeticIPEvaluator.hpp:504
void evaluate(const CellIter &c, const PermTensor &K, FullMatrix< Scalar, SP, FortranOrdering > &Binv)
Main evaluation routine. Computes the inverse of the matrix representation of the mimetic inner produ...
Definition: MimeticIPEvaluator.hpp:383
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:296
void gravityTerm(const CellIter &c, const typename CellIter::Vector &grav, Vector >erm) const
Definition: MimeticIPEvaluator.hpp:496
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. Computes the inverse of the matrix representation of the mimetic inner produ...
Definition: MimeticIPEvaluator.hpp:200
@ dim
Definition: MimeticIPEvaluator.hpp:89
CellIter::Scalar Scalar
The element type of the matrix representation of the mimetic inner product. Assumed to be a floating ...
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:539
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:335
void getInverseMatrix(const CellIter &c, const Scalar totmob, FullMatrix< Scalar, SP, FortranOrdering > &Binv) const
Definition: MimeticIPEvaluator.hpp:342
int j
Definition: elasticity_upscale_impl.hpp:658
Dune::BlockVector< Dune::FieldVector< double, 1 > > Vector
A vector holding our RHS.
Definition: matrixops.hpp:33
std::vector< double > rho
Definition: elasticity_upscale_impl.hpp:581
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. Specificlly, .
Definition: Matrix.hpp:1136
int orthogonalizeColumns(FullMatrix< T, StoragePolicy, FortranOrdering > &A)
Construct orthonormal basis for matrix range (i.e., column space). Based on a QR factorization of the...
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. Specifically, .
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. Specificlly, .
Definition: Matrix.hpp:1194
void zero(Matrix &A)
Zero-fill a.
Definition: Matrix.hpp:602
FullMatrix< double, SharedData, FortranOrdering > SharedFortranMatrix
Definition: Matrix.hpp:589
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