OGS 6.3.0-179-g962fdcd4e.dirty.20200403132553
MathLib::LinAlg Namespace Reference

## Detailed Description

Some general linear algebra functionality.

By using the provided functions linear algebra capabilities can be used for different matrix and vector types in a way that is agnostic towards the specific type used.

For documentation, refer to that of the templated method. All specializations or overload must behave in the same way.

## Functions

template<typename MatrixOrVector >
void copy (MatrixOrVector const &x, MatrixOrVector &y)
Copies x to y. More...

template<typename MatrixOrVector >
void scale (MatrixOrVector &x, double const a)
Scales x by a. More...

template<typename MatrixOrVector >
void aypx (MatrixOrVector &y, double const a, MatrixOrVector const &x)
Computes $$y = a \cdot y + x$$. More...

template<typename MatrixOrVector >
void axpy (MatrixOrVector &y, double const a, MatrixOrVector const &x)
Computes $$y = a \cdot x + y$$. More...

template<typename MatrixOrVector >
void axpby (MatrixOrVector &y, double const a, double const b, MatrixOrVector const &x)
Computes $$y = a \cdot x + b \cdot y$$. More...

template<typename MatrixOrVector >
void componentwiseDivide (MatrixOrVector &w, MatrixOrVector const &x, MatrixOrVector const &y)
Computes $$w = x/y$$ componentwise. More...

template<typename MatrixOrVector >
double norm1 (MatrixOrVector const &x)
Computes the Manhattan norm of x. More...

template<typename MatrixOrVector >
double norm2 (MatrixOrVector const &x)
Computes the Euclidean norm of x. More...

template<typename MatrixOrVector >
double normMax (MatrixOrVector const &x)
Computes the maximum norm of x. More...

template<typename MatrixOrVector >
double norm (MatrixOrVector const &x, MathLib::VecNormType type)

template<typename Matrix >
void finalizeAssembly (Matrix &)

template<typename Matrix , typename Vector >
void matMult (Matrix const &A, Vector const &x, Vector &y)

template<typename Matrix , typename Vector >
void matMultAdd (Matrix const &A, Vector const &v1, Vector const &v2, Vector &v3)

## ◆ axpby()

template<typename MatrixOrVector >
 void MathLib::LinAlg::axpby ( MatrixOrVector & y, double const a, double const b, MatrixOrVector const & x )

Computes $$y = a \cdot x + b \cdot y$$.

Definition at line 65 of file LinAlg.h.

References componentwiseDivide(), norm1(), norm2(), and normMax().

66 {
67  y = a*x + b*y;
68 }

## ◆ axpy()

template<typename MatrixOrVector >
 void MathLib::LinAlg::axpy ( MatrixOrVector & y, double const a, MatrixOrVector const & x )

## ◆ aypx()

template<typename MatrixOrVector >
 void MathLib::LinAlg::aypx ( MatrixOrVector & y, double const a, MatrixOrVector const & x )

Computes $$y = a \cdot y + x$$.

Definition at line 51 of file LinAlg.h.

52 {
53  y = a*y + x;
54 }

## ◆ componentwiseDivide()

template<typename MatrixOrVector >
 void MathLib::LinAlg::componentwiseDivide ( MatrixOrVector & w, MatrixOrVector const & x, MatrixOrVector const & y )

Computes $$w = x/y$$ componentwise.

Referenced by axpby(), and NumLib::LocalLinearLeastSquaresExtrapolator::extrapolate().

## ◆ finalizeAssembly()

template<typename Matrix >
 void MathLib::LinAlg::finalizeAssembly ( Matrix & )

## ◆ matMult()

template<typename Matrix , typename Vector >
 void MathLib::LinAlg::matMult ( Matrix const & A, Vector const & x, Vector & y )

Computes $$y = A \cdot x$$.

Note
x must not be the same object as y. This restirction has been chosen in order to fulfill the requirements of the respective PETSc function.

Definition at line 114 of file LinAlg.h.

115 {
116  assert(&x != &y);
117  y = A*x;
118 }

template<typename Matrix , typename Vector >
 void MathLib::LinAlg::matMultAdd ( Matrix const & A, Vector const & v1, Vector const & v2, Vector & v3 )

Computes $$v_3 = A \cdot v_1 + v_2$$.

Note
x must not be the same object as y. This restirction has been chosen in order to fulfill the requirements of the respective PETSc function.

Definition at line 127 of file LinAlg.h.

References axpby(), axpy(), aypx(), copy(), finalizeAssembly(), matMult(), and scale().

128 {
129  assert(&v1 != &v3);
130  v3 = v2 + A*v1;
131 }

## ◆ norm()

template<typename MatrixOrVector >
 double MathLib::LinAlg::norm ( MatrixOrVector const & x, MathLib::VecNormType type )

Definition at line 88 of file LinAlg.h.

89 {
90  switch (type) {
92  return norm1(x);
94  return norm2(x);
96  return normMax(x);
97  default:
98  OGS_FATAL("Invalid norm type given.");
99  }
100 }
double normMax(MatrixOrVector const &x)
Computes the maximum norm of x.
#define OGS_FATAL(fmt,...)
Definition: Error.h:64
double norm2(MatrixOrVector const &x)
Computes the Euclidean norm of x.
double norm1(MatrixOrVector const &x)
Computes the Manhattan norm of x.

## ◆ norm1()

template<typename MatrixOrVector >
 double MathLib::LinAlg::norm1 ( MatrixOrVector const & x )

Computes the Manhattan norm of x.

Referenced by axpby(), and norm().

## ◆ norm2()

template<typename MatrixOrVector >
 double MathLib::LinAlg::norm2 ( MatrixOrVector const & x )

Computes the Euclidean norm of x.

Referenced by axpby(), and norm().

## ◆ normMax()

template<typename MatrixOrVector >
 double MathLib::LinAlg::normMax ( MatrixOrVector const & x )

Computes the maximum norm of x.

Referenced by axpby(), and norm().

## ◆ scale()

template<typename MatrixOrVector >
 void MathLib::LinAlg::scale ( MatrixOrVector & x, double const a )