Discontinuous Galerkin Library
#include "dg/algorithm.h"
dg::Operator< T > Class Template Reference

A square nxn matrix. More...

Public Types

typedef T value_type
 typically double or float More...
 

Public Member Functions

 Operator ()=default
 Construct empty Operator. More...
 
 Operator (const unsigned n)
 allocate storage for nxn matrix More...
 
 Operator (const unsigned n, const T &value)
 Initialize elements. More...
 
template<class InputIterator >
 Operator (InputIterator first, InputIterator last, std::enable_if_t<!std::is_integral< InputIterator >::value > *=0)
 Construct from iterators. More...
 
 Operator (const std::vector< T > &src)
 Copy from existing data. More...
 
void zero ()
 Assign zero to all elements. More...
 
T & operator() (const size_t i, const size_t j)
 access operator More...
 
const T & operator() (const size_t i, const size_t j) const
 const access operator More...
 
unsigned size () const
 Size n of the Operator. More...
 
void resize (unsigned m, T val=T())
 Resize. More...
 
const std::vector< value_type > & data () const
 access underlying data More...
 
void swap_lines (const size_t i, const size_t k)
 Swap two lines in the square matrix. More...
 
Operator transpose () const
 Transposition. More...
 
bool operator!= (const Operator &rhs) const
 two Matrices are considered equal if elements are equal More...
 
bool operator== (const Operator &rhs) const
 two Matrices are considered equal if elements are equal More...
 
Operator operator- () const
 subtract More...
 
Operatoroperator+= (const Operator &op)
 add More...
 
Operatoroperator-= (const Operator &op)
 subtract More...
 
Operatoroperator*= (const T &value)
 scalar multiply More...
 

Friends

Operator operator+ (const Operator &lhs, const Operator &rhs)
 add More...
 
Operator operator- (const Operator &lhs, const Operator &rhs)
 subtract More...
 
Operator operator* (const T &value, const Operator &rhs)
 scalar multiplication More...
 
Operator operator* (const Operator &lhs, const T &value)
 scalar multiplication More...
 
Operator operator* (const Operator &lhs, const Operator &rhs)
 matrix multiplication More...
 
template<class Ostream >
Ostream & operator<< (Ostream &os, const Operator &mat)
 puts a matrix linewise in output stream More...
 
template<class Istream >
Istream & operator>> (Istream &is, Operator< T > &mat)
 Read values into a Matrix from given istream. More...
 

Detailed Description

template<class T>
class dg::Operator< T >

A square nxn matrix.

An enhanced square dynamic matrix for which arithmetic operators are overloaded. It is not meant for performance critical code but is very convenient for example for the assembly of matrices.

See also
dg::create::inverse, dg::create::lu_pivot, dg::create::lu_solve
Template Parameters
Tvalue type

Member Typedef Documentation

◆ value_type

template<class T >
typedef T dg::Operator< T >::value_type

typically double or float

Constructor & Destructor Documentation

◆ Operator() [1/5]

template<class T >
dg::Operator< T >::Operator ( )
default

Construct empty Operator.

◆ Operator() [2/5]

template<class T >
dg::Operator< T >::Operator ( const unsigned  n)
inlineexplicit

allocate storage for nxn matrix

Parameters
nsize

◆ Operator() [3/5]

template<class T >
dg::Operator< T >::Operator ( const unsigned  n,
const T &  value 
)
inline

Initialize elements.

Parameters
nmatrix is of size n x n
valueEvery element is initialized to.

◆ Operator() [4/5]

template<class T >
template<class InputIterator >
dg::Operator< T >::Operator ( InputIterator  first,
InputIterator  last,
std::enable_if_t<!std::is_integral< InputIterator >::value > *  = 0 
)
inline

Construct from iterators.

Template Parameters
InputIterator
Parameters
first
last

◆ Operator() [5/5]

template<class T >
dg::Operator< T >::Operator ( const std::vector< T > &  src)
inline

Copy from existing data.

Parameters
srcsize must be a square number

Member Function Documentation

◆ data()

template<class T >
const std::vector< value_type > & dg::Operator< T >::data ( ) const
inline

access underlying data

Returns

◆ operator!=()

template<class T >
bool dg::Operator< T >::operator!= ( const Operator< T > &  rhs) const
inline

two Matrices are considered equal if elements are equal

Parameters
rhsMatrix to be compared to this
Returns
true if rhs does not equal this

◆ operator()() [1/2]

template<class T >
T & dg::Operator< T >::operator() ( const size_t  i,
const size_t  j 
)
inline

access operator

A range check is performed if DG_DEBUG is defined

Parameters
irow index
jcolumn index
Returns
reference to value at that location

◆ operator()() [2/2]

template<class T >
const T & dg::Operator< T >::operator() ( const size_t  i,
const size_t  j 
) const
inline

const access operator

Parameters
irow index
jcolumn index
Returns
const value at that location

◆ operator*=()

template<class T >
Operator & dg::Operator< T >::operator*= ( const T &  value)
inline

scalar multiply

Parameters
value
Returns

◆ operator+=()

template<class T >
Operator & dg::Operator< T >::operator+= ( const Operator< T > &  op)
inline

add

Parameters
op
Returns

◆ operator-()

template<class T >
Operator dg::Operator< T >::operator- ( ) const
inline

subtract

Returns

◆ operator-=()

template<class T >
Operator & dg::Operator< T >::operator-= ( const Operator< T > &  op)
inline

subtract

Parameters
op
Returns

◆ operator==()

template<class T >
bool dg::Operator< T >::operator== ( const Operator< T > &  rhs) const
inline

two Matrices are considered equal if elements are equal

Parameters
rhsMatrix to be compared to this
Returns
true if rhs equals this

◆ resize()

template<class T >
void dg::Operator< T >::resize ( unsigned  m,
val = T() 
)
inline

Resize.

Parameters
mnew size
valif m is greater than the current size new elements are initialized with val

◆ size()

template<class T >
unsigned dg::Operator< T >::size ( ) const
inline

Size n of the Operator.

Returns
n

◆ swap_lines()

template<class T >
void dg::Operator< T >::swap_lines ( const size_t  i,
const size_t  k 
)
inline

Swap two lines in the square matrix.

Parameters
ifirst line
ksecond line

◆ transpose()

template<class T >
Operator dg::Operator< T >::transpose ( ) const
inline

Transposition.

Returns
A newly generated Operator containing the transpose.

◆ zero()

template<class T >
void dg::Operator< T >::zero ( )
inline

Assign zero to all elements.

Friends And Related Function Documentation

◆ operator* [1/3]

template<class T >
Operator operator* ( const Operator< T > &  lhs,
const Operator< T > &  rhs 
)
friend

matrix multiplication

Parameters
lhs
rhs
Returns

◆ operator* [2/3]

template<class T >
Operator operator* ( const Operator< T > &  lhs,
const T &  value 
)
friend

scalar multiplication

Parameters
lhs
value
Returns

◆ operator* [3/3]

template<class T >
Operator operator* ( const T &  value,
const Operator< T > &  rhs 
)
friend

scalar multiplication

Parameters
value
rhs
Returns

◆ operator+

template<class T >
Operator operator+ ( const Operator< T > &  lhs,
const Operator< T > &  rhs 
)
friend

add

Parameters
lhs
rhs
Returns

◆ operator-

template<class T >
Operator operator- ( const Operator< T > &  lhs,
const Operator< T > &  rhs 
)
friend

subtract

Parameters
lhs
rhs
Returns

◆ operator<<

template<class T >
template<class Ostream >
Ostream & operator<< ( Ostream &  os,
const Operator< T > &  mat 
)
friend

puts a matrix linewise in output stream

Template Parameters
OstreamThe stream e.g. std::cout
Parameters
osthe outstream
matthe matrix to output
Returns
the outstream

◆ operator>>

template<class T >
template<class Istream >
Istream & operator>> ( Istream &  is,
Operator< T > &  mat 
)
friend

Read values into a Matrix from given istream.

The values are filled linewise into the matrix. Values are seperated by whitespace characters. (i.e. newline, blank, etc)

Template Parameters
IstreamThe stream e.g. std::cin
Parameters
isThe istream
matThe Matrix into which the values are written
Returns
The istream

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