OGS
MatrixTranslator.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "MatrixTranslator.h"
5
7
8namespace NumLib
9{
11 computeA(GlobalMatrix const& M, GlobalMatrix const& K,
12 GlobalMatrix& A) const
13{
14 namespace LinAlg = MathLib::LinAlg;
15
16 double const dt = _time_disc.getCurrentTimeIncrement();
17
18 // A = M * 1/dt + K
19 LinAlg::copy(K, A);
20 LinAlg::axpy(A, 1. / dt, M);
21}
22
24 computeRhs(const GlobalMatrix& M, const GlobalMatrix& /*K*/,
25 const GlobalVector& b, const GlobalVector& x_prev,
26 GlobalVector& rhs) const
27{
28 namespace LinAlg = MathLib::LinAlg;
29
31 _time_disc.getWeightedOldX(tmp, x_prev);
32
33 // rhs = M * weighted_old_x + b
34 LinAlg::matMultAdd(M, tmp, b, rhs);
35
37}
38
41{
42 namespace LinAlg = MathLib::LinAlg;
43
44 // check whether A is square?
45
46 GlobalMatrix new_A(A);
47 GlobalVector new_b(b);
48 LinAlg::copy(A, new_A);
49 LinAlg::copy(b, new_b);
50 // rhs = A^T * rhs
51 // A = A^T * A
52 LinAlg::linearSysNormalize(A, new_A, b, new_b);
53
54 LinAlg::copy(new_A, A);
55 LinAlg::copy(new_b, b);
56}
57
60 GlobalVector const& b, double const dt,
61 GlobalVector const& x_curr, GlobalVector const& x_prev,
62 GlobalVector& res) const
63{
64 namespace LinAlg = MathLib::LinAlg;
65
66 // res = M * x_dot + K * x_curr - b
67 GlobalVector x_dot;
68 LinAlg::copy(x_curr, x_dot); // x_dot = x
69 LinAlg::axpy(x_dot, -1., x_prev); // x_dot = x - x_prev
70 LinAlg::scale(x_dot, 1. / dt); // x_dot = (x - x_prev)/dt
71 LinAlg::matMult(M, x_dot, res); // res = M*x_dot
72 LinAlg::matMultAdd(K, x_curr, res, res); // res = M*x_dot + K*x
73 LinAlg::axpy(res, -1., b); // res = M*x_dot + X*x - b
74}
75
83
84} // namespace NumLib
MathLib::EigenMatrix GlobalMatrix
MathLib::EigenVector GlobalVector
std::size_t _tmp_id
ID of the vector storing intermediate computations.
TimeDiscretization const & _time_disc
the time discretization used.
void linearSysNormalize(PETScMatrix const &, PETScMatrix &, PETScVector const &, PETScVector &)
Definition LinAlg.cpp:163
void copy(PETScVector const &x, PETScVector &y)
Definition LinAlg.cpp:30
void matMult(PETScMatrix const &A, PETScVector const &x, PETScVector &y)
Definition LinAlg.cpp:142
void matMultAdd(PETScMatrix const &A, PETScVector const &v1, PETScVector const &v2, PETScVector &v3)
Definition LinAlg.cpp:152
void scale(PETScVector &x, PetscScalar const a)
Definition LinAlg.cpp:37
void axpy(PETScVector &y, PetscScalar const a, PETScVector const &x)
Definition LinAlg.cpp:50
static NUMLIB_EXPORT VectorProvider & provider