OGS
MatrixTranslator.cpp
Go to the documentation of this file.
1
11#include "MatrixTranslator.h"
12
14
15namespace NumLib
16{
18 computeA(GlobalMatrix const& M, GlobalMatrix const& K,
19 GlobalMatrix& A) const
20{
21 namespace LinAlg = MathLib::LinAlg;
22
23 double const dt = _time_disc.getCurrentTimeIncrement();
24
25 // A = M * 1/dt + K
26 LinAlg::copy(K, A);
27 LinAlg::axpy(A, 1. / dt, M);
28}
29
31 computeRhs(const GlobalMatrix& M, const GlobalMatrix& /*K*/,
32 const GlobalVector& b, const GlobalVector& x_prev,
33 GlobalVector& rhs) const
34{
35 namespace LinAlg = MathLib::LinAlg;
36
38 _time_disc.getWeightedOldX(tmp, x_prev);
39
40 // rhs = M * weighted_old_x + b
41 LinAlg::matMultAdd(M, tmp, b, rhs);
42
44}
45
48 GlobalVector const& b, double const dt,
49 GlobalVector const& x_curr, GlobalVector const& x_prev,
50 GlobalVector& res) const
51{
52 namespace LinAlg = MathLib::LinAlg;
53
54 // res = M * x_dot + K * x_curr - b
55 GlobalVector x_dot;
56 LinAlg::copy(x_curr, x_dot); // x_dot = x
57 LinAlg::axpy(x_dot, -1., x_prev); // x_dot = x - x_prev
58 LinAlg::scale(x_dot, 1. / dt); // x_dot = (x - x_prev)/dt
59 LinAlg::matMult(M, x_dot, res); // res = M*x_dot
60 LinAlg::matMultAdd(K, x_curr, res, res); // res = M*x_dot + K*x
61 LinAlg::axpy(res, -1., b); // res = M*x_dot + X*x - b
62}
63
71
72} // namespace NumLib
Global vector based on Eigen vector.
Definition EigenVector.h:25
virtual GlobalVector & getVector(std::size_t &id)=0
Get an uninitialized vector with the given id.
virtual void releaseVector(GlobalVector const &x)=0
void copy(PETScVector const &x, PETScVector &y)
Definition LinAlg.cpp:37
void matMult(PETScMatrix const &A, PETScVector const &x, PETScVector &y)
Definition LinAlg.cpp:149
void matMultAdd(PETScMatrix const &A, PETScVector const &v1, PETScVector const &v2, PETScVector &v3)
Definition LinAlg.cpp:159
void scale(PETScVector &x, PetscScalar const a)
Definition LinAlg.cpp:44
void axpy(PETScVector &y, PetscScalar const a, PETScVector const &x)
Definition LinAlg.cpp:57
static NUMLIB_EXPORT VectorProvider & provider