HyperHDG
Classes | Functions
SparseLA Namespace Reference

A namespace containing different functions that implement basic linear algebra operations using large vectors. More...

Classes

struct  SolveException
 Exception to be thrown if conjugate gradient fails. More...
 

Functions

template<typename vectorT >
vectorT::value_type inner_product (const vectorT &left, const vectorT &right)
 Evaluate the inner product of two vectors. More...
 
template<typename vectorT >
vectorT::value_type norm_2 (const vectorT &vec)
 Evaluate 2 norm of a vector. More...
 
template<typename vectorT >
vectorT linear_combination (const typename vectorT::value_type leftFac, const vectorT &leftVec, const typename vectorT::value_type rightFac, const vectorT &rightVec)
 Evaluate linear combination of vectors and return the result. More...
 
template<typename vectorT >
void linear_combination (const typename vectorT::value_type leftFac, const vectorT &leftV, const typename vectorT::value_type rightFac, const vectorT &rightV, vectorT &result)
 Evaluate linear combination of vectors and return reference to result. More...
 
template<class ProblemT , typename vectorT >
vectorT conjugate_gradient (const vectorT &b, ProblemT &problem, unsigned int n_iterations=0, const typename vectorT::value_type tolerance=1e-9)
 Execute conjugate gradient algorithm to find solution to system of equations. More...
 

Detailed Description

A namespace containing different functions that implement basic linear algebra operations using large vectors.


This namespace provides several functions to implement basic linear algebra operations of (long) vector type in combination with a class providing a function matrix_vector_multiply. This is mainly used for C++ examples and test cases that do not use the Python interface and its version of an CG method, for example.

Authors
Guido Kanschat, Heidelberg University, 2020.
Andreas Rupp, Heidelberg University, 2020.

Function Documentation

◆ conjugate_gradient()

template<class ProblemT , typename vectorT >
vectorT SparseLA::conjugate_gradient ( const vectorT &  b,
ProblemT &  problem,
unsigned int  n_iterations = 0,
const typename vectorT::value_type  tolerance = 1e-9 
)

Execute conjugate gradient algorithm to find solution to system of equations.


Execute conjugate gradient algorithm where the matrix is not explicitly given, but the template class ProblemT is supposed to implement a function matrix_vector_multiply which only takes a large vector and generates the matrix vector product from that. The associated matrix is assumed to be square and symmetric positive definite.

Template Parameters
ProblemTClass to implement matrix vector multiplication.
vectorTThe class name of the large vector.
Parameters
bRight-hand side of linear system of equations.
problemClass instantiation to implement matrix vector multiplication.
n_iterationsMaximum number of iterations. 0 is default and the size of b.
toleranceAbsolute tolerance value in 2 norm. Default is 1e-9.
Return values
solutionVector sufficing Ax = b up to given tolerance if converged.
n_iterationsNumber of needed iterations. -1 indicates no convergence.
Authors
Guido Kanschat, Heidelberg University, 2020.
Andreas Rupp, Heidelberg University, 2020.
Here is the call graph for this function:

◆ inner_product()

template<typename vectorT >
vectorT::value_type SparseLA::inner_product ( const vectorT &  left,
const vectorT &  right 
)

Evaluate the inner product of two vectors.


Naive implementation of an Euclidean inner product of two large vectors which are supposed to be of the same size. This function is needed to calculate a vector's 2 norm or to implement a CG scheme.

Template Parameters
vectorTThe class name of the large vector.
Parameters
leftLeft argument of the inner product.
rightRight argument of the inner product.
Return values
productInner product of the two arguments.
Authors
Guido Kanschat, Heidelberg University, 2020.
Andreas Rupp, Heidelberg University, 2020.

◆ linear_combination() [1/2]

template<typename vectorT >
void SparseLA::linear_combination ( const typename vectorT::value_type  leftFac,
const vectorT &  leftV,
const typename vectorT::value_type  rightFac,
const vectorT &  rightV,
vectorT &  result 
)

Evaluate linear combination of vectors and return reference to result.


This functions takes two large vectors and two floating points, and returns their linear combination "leftFac * leftVec + rightFac * rightVec" as a reference to a vector. This vector needs to be passed to the function

Template Parameters
vectorTThe class name of the large vector.
Parameters
leftFacScaling factor of left vector.
leftVLeft vector in linear combination.
rightFacScaling factor of right vector.
rightVRight vector in linear combination.
resultReference to vector whicb is supposed to contain the result.
Return values
resultLinear combination of vectors with respective coefficients.
Authors
Guido Kanschat, Heidelberg University, 2020.
Andreas Rupp, Heidelberg University, 2020.

◆ linear_combination() [2/2]

template<typename vectorT >
vectorT SparseLA::linear_combination ( const typename vectorT::value_type  leftFac,
const vectorT &  leftVec,
const typename vectorT::value_type  rightFac,
const vectorT &  rightVec 
)

Evaluate linear combination of vectors and return the result.


This functions takes two large vectors and two floating points, and returns their linear combination "leftFac * leftVec + rightFac * rightVec" as a new vector (in contrast to just a reference to a vector).

Template Parameters
vectorTThe class name of the large vector.
Parameters
leftFacScaling factor of left vector.
leftVecLeft vector in linear combination.
rightFacScaling factor of right vector.
rightVecRight vector in linear combination.
Return values
lin_combLinear combination of vectors with respective coefficients.
Authors
Guido Kanschat, Heidelberg University, 2020.
Andreas Rupp, Heidelberg University, 2020.

◆ norm_2()

template<typename vectorT >
vectorT::value_type SparseLA::norm_2 ( const vectorT &  vec)

Evaluate 2 norm of a vector.


Naive implementation of an 2 norm of a vector. This is the square root of the inner_product of a vector paired with itself.

Template Parameters
vectorTThe class name of the large vector.
Parameters
vecVector whose 2 norm is to be calculates.
Return values
norm2 norm of given vector.
Authors
Guido Kanschat, Heidelberg University, 2020.
Andreas Rupp, Heidelberg University, 2020.
Here is the call graph for this function: