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{
49 namespace LinAlg = MathLib::LinAlg;
50
51 // check whether A is square?
52
53 GlobalMatrix new_A(A);
54 GlobalVector new_b(b);
55 LinAlg::copy(A, new_A);
56 LinAlg::copy(b, new_b);
57 // rhs = A^T * rhs
58 // A = A^T * A
59 LinAlg::linearSysNormalize(A, new_A, b, new_b);
60
61 LinAlg::copy(new_A, A);
62 LinAlg::copy(new_b, b);
63}
64
67 GlobalVector const& b, double const dt,
68 GlobalVector const& x_curr, GlobalVector const& x_prev,
69 GlobalVector& res) const
70{
71 namespace LinAlg = MathLib::LinAlg;
72
73 // res = M * x_dot + K * x_curr - b
74 GlobalVector x_dot;
75 LinAlg::copy(x_curr, x_dot); // x_dot = x
76 LinAlg::axpy(x_dot, -1., x_prev); // x_dot = x - x_prev
77 LinAlg::scale(x_dot, 1. / dt); // x_dot = (x - x_prev)/dt
78 LinAlg::matMult(M, x_dot, res); // res = M*x_dot
79 LinAlg::matMultAdd(K, x_curr, res, res); // res = M*x_dot + K*x
80 LinAlg::axpy(res, -1., b); // res = M*x_dot + X*x - b
81}
82
90
91} // 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 linearSysNormalize(PETScMatrix const &, PETScMatrix &, PETScVector const &, PETScVector &)
Definition LinAlg.cpp:170
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