OGS
NumLib::MatrixTranslatorGeneral< ODESystemTag::FirstOrderImplicitQuasilinear > Class Reference

Detailed Description

General matrix translator for first order implicit quasi-linear ODEs, used with time discretization schemes that have no special needs.

See also
ODESystemTag::FirstOrderImplicitQuasilinear
Remarks
You might also want read the remarks on time discretization.

Definition at line 90 of file MatrixTranslator.h.

#include <MatrixTranslator.h>

Inheritance diagram for NumLib::MatrixTranslatorGeneral< ODESystemTag::FirstOrderImplicitQuasilinear >:
[legend]
Collaboration diagram for NumLib::MatrixTranslatorGeneral< ODESystemTag::FirstOrderImplicitQuasilinear >:
[legend]

Public Member Functions

 MatrixTranslatorGeneral (TimeDiscretization const &timeDisc)
 
void computeA (GlobalMatrix const &M, GlobalMatrix const &K, GlobalMatrix &A) const override
 Computes \( A = M \cdot \alpha + K \).
 
void computeRhs (const GlobalMatrix &M, const GlobalMatrix &, const GlobalVector &b, const GlobalVector &x_prev, GlobalVector &rhs) const override
 Computes \( \mathtt{rhs} = M \cdot x_O + b \).
 
void normalizeAandRhs (GlobalMatrix &A, GlobalVector &b) const override
 
void computeResidual (GlobalMatrix const &M, GlobalMatrix const &K, GlobalVector const &b, double dt, GlobalVector const &x_curr, GlobalVector const &x_prev, GlobalVector &res) const override
 Computes \( r = M \cdot \hat x + K \cdot x_C - b \).
 
void computeJacobian (GlobalMatrix const &Jac_in, GlobalMatrix &Jac_out) const override
 
- Public Member Functions inherited from NumLib::MatrixTranslator< ODESystemTag::FirstOrderImplicitQuasilinear >
virtual ~MatrixTranslator ()=default
 

Private Attributes

TimeDiscretization const & _time_disc
 the time discretization used.
 
std::size_t _tmp_id = 0u
 ID of the vector storing intermediate computations.
 

Constructor & Destructor Documentation

◆ MatrixTranslatorGeneral()

NumLib::MatrixTranslatorGeneral< ODESystemTag::FirstOrderImplicitQuasilinear >::MatrixTranslatorGeneral ( TimeDiscretization const & timeDisc)
inlineexplicit

Constructs a new instance.

Parameters
timeDiscthe time discretization scheme to be used.

Definition at line 98 of file MatrixTranslator.h.

99 : _time_disc(timeDisc)
100 {
101 }
TimeDiscretization const & _time_disc
the time discretization used.

Member Function Documentation

◆ computeA()

void NumLib::MatrixTranslatorGeneral< ODESystemTag::FirstOrderImplicitQuasilinear >::computeA ( GlobalMatrix const & M,
GlobalMatrix const & K,
GlobalMatrix & A ) const
overridevirtual

Computes \( A = M \cdot \alpha + K \).

Implements NumLib::MatrixTranslator< ODESystemTag::FirstOrderImplicitQuasilinear >.

Definition at line 17 of file MatrixTranslator.cpp.

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}
virtual double getCurrentTimeIncrement() const =0
void copy(PETScVector const &x, PETScVector &y)
Definition LinAlg.cpp:37
void axpy(PETScVector &y, PetscScalar const a, PETScVector const &x)
Definition LinAlg.cpp:57

References MathLib::LinAlg::axpy(), and MathLib::LinAlg::copy().

◆ computeJacobian()

void NumLib::MatrixTranslatorGeneral< ODESystemTag::FirstOrderImplicitQuasilinear >::computeJacobian ( GlobalMatrix const & Jac_in,
GlobalMatrix & Jac_out ) const
overridevirtual

Writes Jac_in to Jac_out.

Todo
Do not copy.

Implements NumLib::MatrixTranslator< ODESystemTag::FirstOrderImplicitQuasilinear >.

Definition at line 83 of file MatrixTranslator.cpp.

85{
86 namespace LinAlg = MathLib::LinAlg;
87
88 LinAlg::copy(Jac_in, Jac_out);
89}

References MathLib::LinAlg::copy().

◆ computeResidual()

void NumLib::MatrixTranslatorGeneral< ODESystemTag::FirstOrderImplicitQuasilinear >::computeResidual ( GlobalMatrix const & M,
GlobalMatrix const & K,
GlobalVector const & b,
double dt,
GlobalVector const & x_curr,
GlobalVector const & x_prev,
GlobalVector & res ) const
overridevirtual

Computes \( r = M \cdot \hat x + K \cdot x_C - b \).

Implements NumLib::MatrixTranslator< ODESystemTag::FirstOrderImplicitQuasilinear >.

Definition at line 65 of file MatrixTranslator.cpp.

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}
Global vector based on Eigen vector.
Definition EigenVector.h:25
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

References MathLib::LinAlg::axpy(), MathLib::LinAlg::copy(), MathLib::LinAlg::matMult(), MathLib::LinAlg::matMultAdd(), and MathLib::LinAlg::scale().

◆ computeRhs()

void NumLib::MatrixTranslatorGeneral< ODESystemTag::FirstOrderImplicitQuasilinear >::computeRhs ( const GlobalMatrix & M,
const GlobalMatrix & ,
const GlobalVector & b,
const GlobalVector & x_prev,
GlobalVector & rhs ) const
overridevirtual

Computes \( \mathtt{rhs} = M \cdot x_O + b \).

Implements NumLib::MatrixTranslator< ODESystemTag::FirstOrderImplicitQuasilinear >.

Definition at line 30 of file MatrixTranslator.cpp.

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}
std::size_t _tmp_id
ID of the vector storing intermediate computations.
virtual void getWeightedOldX(GlobalVector &y, GlobalVector const &x_old) const =0
Returns .
virtual GlobalVector & getVector(std::size_t &id)=0
Get an uninitialized vector with the given id.
virtual void releaseVector(GlobalVector const &x)=0
static NUMLIB_EXPORT VectorProvider & provider

References NumLib::VectorProvider::getVector(), MathLib::LinAlg::matMultAdd(), NumLib::GlobalVectorProvider::provider, and NumLib::VectorProvider::releaseVector().

◆ normalizeAandRhs()

void NumLib::MatrixTranslatorGeneral< ODESystemTag::FirstOrderImplicitQuasilinear >::normalizeAandRhs ( GlobalMatrix & A,
GlobalVector & b ) const
overridevirtual

Computes \( A = A^T \cdot A \), and also \( rhs = A^T \cdot rhs \).

Implements NumLib::MatrixTranslator< ODESystemTag::FirstOrderImplicitQuasilinear >.

Definition at line 46 of file MatrixTranslator.cpp.

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}
void linearSysNormalize(PETScMatrix const &, PETScMatrix &, PETScVector const &, PETScVector &)
Definition LinAlg.cpp:170

References MathLib::LinAlg::copy(), and MathLib::LinAlg::linearSysNormalize().

Member Data Documentation

◆ _time_disc

the time discretization used.

Definition at line 128 of file MatrixTranslator.h.

◆ _tmp_id

ID of the vector storing intermediate computations.

Definition at line 131 of file MatrixTranslator.h.


The documentation for this class was generated from the following files: