OGS 6.2.1-499-g3b941532c.dirty.20191012113459
NumLib::MatrixTranslatorForwardEuler< ODESystemTag::FirstOrderImplicitQuasilinear > Class Template Reference

Detailed Description

template<>
class NumLib::MatrixTranslatorForwardEuler< ODESystemTag::FirstOrderImplicitQuasilinear >

GlobalMatrix translator for first order implicit quasi-linear ODEs, used with the ForwardEuler scheme.

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

Definition at line 155 of file MatrixTranslator.h.

#include <MatrixTranslator.h>

Inheritance diagram for NumLib::MatrixTranslatorForwardEuler< ODESystemTag::FirstOrderImplicitQuasilinear >:
Collaboration diagram for NumLib::MatrixTranslatorForwardEuler< ODESystemTag::FirstOrderImplicitQuasilinear >:

Public Member Functions

 MatrixTranslatorForwardEuler (ForwardEuler const &timeDisc)
 
void computeA (GlobalMatrix const &M, GlobalMatrix const &, GlobalMatrix &A) const override
 Computes $ A = M \cdot \alpha $. More...
 
void computeRhs (const GlobalMatrix &M, const GlobalMatrix &K, const GlobalVector &b, GlobalVector &rhs) const override
 Computes $ \mathtt{rhs} = M \cdot x_O - K \cdot x_O + b $. More...
 
void computeResidual (GlobalMatrix const &M, GlobalMatrix const &K, GlobalVector const &b, GlobalVector const &x_new_timestep, GlobalVector const &xdot, GlobalVector &res) const override
 Computes $ r = M \cdot \hat x + K \cdot x_C - b $. More...
 
void computeJacobian (GlobalMatrix const &Jac_in, GlobalMatrix &Jac_out) const override
 
- Public Member Functions inherited from NumLib::MatrixTranslator< ODESystemTag::FirstOrderImplicitQuasilinear >
virtual void pushMatrices (GlobalMatrix const &, GlobalMatrix const &, GlobalVector const &)
 
virtual ~MatrixTranslator ()=default
 

Private Attributes

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

Constructor & Destructor Documentation

◆ MatrixTranslatorForwardEuler()

Constructs a new instance.

Parameters
timeDiscthe time discretization scheme to be used.

Definition at line 163 of file MatrixTranslator.h.

164  : _fwd_euler(timeDisc)
165  {
166  }

Member Function Documentation

◆ computeA()

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

Computes $ A = M \cdot \alpha $.

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

Definition at line 70 of file MatrixTranslator.cpp.

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

72 {
73  namespace LinAlg = MathLib::LinAlg;
74 
75  auto const dxdot_dx = _fwd_euler.getNewXWeight();
76 
77  // A = M * dxdot_dx
78  LinAlg::copy(M, A);
79  LinAlg::scale(A, dxdot_dx);
80 }
double getNewXWeight() const override
Returns .
void copy(MatrixOrVector const &x, MatrixOrVector &y)
Copies x to y.
Definition: LinAlg.h:37
void scale(MatrixOrVector &x, double const a)
Scales x by a.
Definition: LinAlg.h:44

◆ computeJacobian()

void NumLib::MatrixTranslatorForwardEuler< 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 117 of file MatrixTranslator.cpp.

References MathLib::LinAlg::copy(), and NumLib::FirstOrderImplicitQuasilinear.

118 {
119  namespace LinAlg = MathLib::LinAlg;
120 
121  LinAlg::copy(Jac_in, Jac_out);
122 }
void copy(MatrixOrVector const &x, MatrixOrVector &y)
Copies x to y.
Definition: LinAlg.h:37

◆ computeResidual()

void NumLib::MatrixTranslatorForwardEuler< ODESystemTag::FirstOrderImplicitQuasilinear >::computeResidual ( GlobalMatrix const &  M,
GlobalMatrix const &  K,
GlobalVector const &  b,
GlobalVector const &  x_new_timestep,
GlobalVector const &  xdot,
GlobalVector &  res 
) const
overridevirtual

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

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

Definition at line 102 of file MatrixTranslator.cpp.

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

105 {
106  namespace LinAlg = MathLib::LinAlg;
107 
108  auto const& x_curr = _fwd_euler.getCurrentX(x_new_timestep);
109 
110  // res = M * x_dot + K * x_curr - b
111  LinAlg::matMult(M, xdot, res);
112  LinAlg::matMultAdd(K, x_curr, res, res);
113  LinAlg::axpy(res, -1.0, b);
114 }
void matMult(Matrix const &A, Vector const &x, Vector &y)
Definition: LinAlg.h:114
GlobalVector const & getCurrentX(const GlobalVector &) const override
void axpy(MatrixOrVector &y, double const a, MatrixOrVector const &x)
Computes .
Definition: LinAlg.h:58
void matMultAdd(Matrix const &A, Vector const &v1, Vector const &v2, Vector &v3)
Definition: LinAlg.h:127

◆ computeRhs()

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

Computes $ \mathtt{rhs} = M \cdot x_O - K \cdot x_O + b $.

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

Definition at line 83 of file MatrixTranslator.cpp.

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

85 {
86  namespace LinAlg = MathLib::LinAlg;
87 
90 
91  auto const& x_old = _fwd_euler.getXOld();
92 
93  // rhs = b + M * weighted_old_x - K * x_old
94  LinAlg::matMult(K, x_old, rhs); // rhs = K * x_old
95  LinAlg::aypx(rhs, -1.0, b); // rhs = b - K * x_old
96  LinAlg::matMultAdd(M, tmp, rhs, rhs); // rhs += M * weighted_old_x
97 
99 }
void aypx(MatrixOrVector &y, double const a, MatrixOrVector const &x)
Computes .
Definition: LinAlg.h:51
std::size_t _tmp_id
ID of the vector storing intermediate computations.
void matMult(Matrix const &A, Vector const &x, Vector &y)
Definition: LinAlg.h:114
virtual GlobalVector & getVector()=0
Get an uninitialized vector.
static NUMLIB_EXPORT VectorProvider & provider
GlobalVector const & getXOld() const
Returns the solution from the preceding timestep.
virtual void releaseVector(GlobalVector const &x)=0
void getWeightedOldX(GlobalVector &y) const override
Returns .
void matMultAdd(Matrix const &A, Vector const &v1, Vector const &v2, Vector &v3)
Definition: LinAlg.h:127

Member Data Documentation

◆ _fwd_euler

the time discretization used.

Definition at line 189 of file MatrixTranslator.h.

◆ _tmp_id

ID of the vector storing intermediate computations.

Definition at line 192 of file MatrixTranslator.h.


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