Public Member Functions | Private Member Functions | Private Attributes | List of all members
oomph::DenseComplexMatrix Class Reference

Class of matrices containing double complex, and stored as a DenseMatrix<complex<double> >, but with solving functionality inherited from the abstract ComplexMatrix class. More...

#include <complex_matrices.h>

+ Inheritance diagram for oomph::DenseComplexMatrix:

Public Member Functions

 DenseComplexMatrix ()
 Empty constructor, simply assign the lengths N and M to 0. More...
 
 DenseComplexMatrix (const unsigned long &n)
 Constructor to build a square n by n matrix. More...
 
 DenseComplexMatrix (const unsigned long &n, const unsigned long &m)
 Constructor to build a matrix with n rows and m columns. More...
 
 DenseComplexMatrix (const unsigned long &n, const unsigned long &m, const std::complex< double > &initial_val)
 Constructor to build a matrix with n rows and m columns, with initial value initial_val. More...
 
 DenseComplexMatrix (const DenseComplexMatrix &matrix)=delete
 Broken copy constructor. More...
 
void operator= (const DenseComplexMatrix &)=delete
 Broken assignment operator. More...
 
unsigned long nrow () const
 Return the number of rows of the matrix. More...
 
unsigned long ncol () const
 Return the number of columns of the matrix. More...
 
std::complex< double > operator() (const unsigned long &i, const unsigned long &j) const
 Overload the const version of the round-bracket access operator for read-only access. More...
 
std::complex< double > & operator() (const unsigned long &i, const unsigned long &j)
 Overload the non-const version of the round-bracket access operator for read-write access. More...
 
virtual ~DenseComplexMatrix ()
 Destructor, delete the storage for Index vector and LU storage (if any) More...
 
int ludecompose ()
 Overload the LU decomposition. For this storage scheme the matrix storage will be over-writeen by its LU decomposition. More...
 
void lubksub (Vector< std::complex< double >> &rhs)
 Overload the LU back substitution. Note that the rhs will be overwritten with the solution vector. More...
 
void residual (const Vector< std::complex< double >> &x, const Vector< std::complex< double >> &rhs, Vector< std::complex< double >> &residual)
 Find the residual of Ax=b, ie r=b-Ax for the "solution" x. More...
 
void multiply (const Vector< std::complex< double >> &x, Vector< std::complex< double >> &soln)
 Multiply the matrix by the vector x: soln=Ax. More...
 
void multiply_transpose (const Vector< std::complex< double >> &x, Vector< std::complex< double >> &soln)
 Multiply the transposed matrix by the vector x: soln=A^T x. More...
 
- Public Member Functions inherited from oomph::ComplexMatrixBase
 ComplexMatrixBase ()
 (Empty) constructor. More...
 
 ComplexMatrixBase (const ComplexMatrixBase &matrix)=delete
 Broken copy constructor. More...
 
void operator= (const ComplexMatrixBase &)=delete
 Broken assignment operator. More...
 
virtual ~ComplexMatrixBase ()
 virtual (empty) destructor More...
 
virtual void solve (Vector< std::complex< double >> &rhs)
 Complete LU solve (replaces matrix by its LU decomposition and overwrites RHS with solution). The default should not need to be over-written. More...
 
virtual void solve (const Vector< std::complex< double >> &rhs, Vector< std::complex< double >> &soln)
 Complete LU solve (Nothing gets overwritten!). The default should not need to be overwritten. More...
 
virtual double max_residual (const Vector< std::complex< double >> &x, const Vector< std::complex< double >> &rhs)
 Find the maximum residual r=b-Ax – generic version, can be overloaded for specific derived classes where the max. can be determined "on the fly". More...
 
- Public Member Functions inherited from oomph::DenseMatrix< std::complex< double > >
 DenseMatrix ()
 Empty constructor, simply assign the lengths N and M to 0. More...
 
 DenseMatrix (const DenseMatrix &source_matrix)
 Copy constructor: Deep copy! More...
 
 DenseMatrix (const unsigned long &n)
 Constructor to build a square n by n matrix. More...
 
 DenseMatrix (const unsigned long &n, const unsigned long &m)
 Constructor to build a matrix with n rows and m columns. More...
 
 DenseMatrix (const unsigned long &n, const unsigned long &m, const std::complex< double > &initial_val)
 Constructor to build a matrix with n rows and m columns, with initial value initial_val. More...
 
DenseMatrixoperator= (const DenseMatrix &source_matrix)
 Copy assignment. More...
 
std::complex< double > & entry (const unsigned long &i, const unsigned long &j)
 The access function that will be called by the read-write round-bracket operator. More...
 
std::complex< double > get_entry (const unsigned long &i, const unsigned long &j) const
 The access function the will be called by the read-only (const version) round-bracket operator. More...
 
virtual ~DenseMatrix ()
 Destructor, clean up the matrix data. More...
 
unsigned long nrow () const
 Return the number of rows of the matrix. More...
 
unsigned long ncol () const
 Return the number of columns of the matrix. More...
 
void resize (const unsigned long &n)
 Resize to a square nxn matrix; any values already present will be transfered. More...
 
void resize (const unsigned long &n, const unsigned long &m)
 Resize to a non-square n x m matrix; any values already present will be transfered. More...
 
void resize (const unsigned long &n, const unsigned long &m, const std::complex< double > &initial_value)
 Resize to a non-square n x m matrix and initialize the new values to initial_value. More...
 
void initialise (const std::complex< double > &val)
 Initialize all values in the matrix to val. More...
 
void output (std::ostream &outfile) const
 Output function to print a matrix row-by-row to the stream outfile. More...
 
void output (std::string filename) const
 Output function to print a matrix row-by-row to a file. Specify filename. More...
 
void indexed_output (std::ostream &outfile) const
 Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) More...
 
void indexed_output (std::string filename) const
 Indexed output function to print a matrix to a file as i,j,a(i,j). Specify filename. More...
 
void output_bottom_right_zero_helper (std::ostream &outfile) const
 Output the "bottom right" entry regardless of it being zero or not (this allows automatic detection of matrix size in e.g. matlab, python). More...
 
void sparse_indexed_output_helper (std::ostream &outfile) const
 Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,j)!=0 only. More...
 
- Public Member Functions inherited from oomph::Matrix< T, MATRIX_TYPE >
 Matrix ()
 (Empty) constructor More...
 
 Matrix (const Matrix &matrix)=delete
 Broken copy constructor. More...
 
void operator= (const Matrix &)=delete
 Broken assignment operator. More...
 
virtual ~Matrix ()
 Virtual (empty) destructor. More...
 
operator() (const unsigned long &i, const unsigned long &j) const
 Round brackets to give access as a(i,j) for read only (we're not providing a general interface for component-wise write access since not all matrix formats allow efficient direct access!) The function uses the MATRIX_TYPE template parameter to call the get_entry() function which must be defined in all derived classes that are to be fully instantiated. More...
 
T & operator() (const unsigned long &i, const unsigned long &j)
 Round brackets to give access as a(i,j) for read-write access. The function uses the MATRIX_TYPE template parameter to call the entry() function which must be defined in all derived classes that are to be fully instantiated. If the particular Matrix does not allow write access, the function should break with an error message. More...
 
void sparse_indexed_output (std::ostream &outfile, const unsigned &precision=0, const bool &output_bottom_right_zero=false) const
 Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,j)!=0 only with specified precision (if precision=0 then nothing is changed). If optional boolean flag is set to true we also output the "bottom right" entry regardless of it being zero or not (this allows automatic detection of matrix size in e.g. matlab, python). More...
 
void sparse_indexed_output (std::string filename, const unsigned &precision=0, const bool &output_bottom_right_zero=false) const
 Indexed output function to print a matrix to the file named filename as i,j,a(i,j) for a(i,j)!=0 only with specified precision. If optional boolean flag is set to true we also output the "bottom right" entry regardless of it being zero or not (this allows automatic detection of matrix size in e.g. matlab, python). More...
 

Private Member Functions

void delete_lu_factors ()
 Function that deletes the storage for the LU_factors, if it is not the same as the matrix storage. More...
 

Private Attributes

Vector< long > * Index
 Pointer to storage for the index of permutations in the LU solve. More...
 
std::complex< double > * LU_factors
 Pointer to storage for the LU decomposition. More...
 
bool Overwrite_matrix_storage
 Boolean flag used to decided whether the LU decomposition is stored separately, or not. More...
 

Additional Inherited Members

- Protected Member Functions inherited from oomph::Matrix< T, MATRIX_TYPE >
void range_check (const unsigned long &i, const unsigned long &j) const
 Range check to catch when an index is out of bounds, if so, it issues a warning message and dies by throwing an OomphLibError. More...
 
- Protected Attributes inherited from oomph::DenseMatrix< std::complex< double > >
std::complex< double > * Matrixdata
 Internal representation of matrix as a pointer to data. More...
 
unsigned long N
 Number of rows. More...
 
unsigned long M
 Number of columns. More...
 

Detailed Description

Class of matrices containing double complex, and stored as a DenseMatrix<complex<double> >, but with solving functionality inherited from the abstract ComplexMatrix class.

Definition at line 153 of file complex_matrices.h.

Constructor & Destructor Documentation

◆ DenseComplexMatrix() [1/5]

oomph::DenseComplexMatrix::DenseComplexMatrix ( )
inline

Empty constructor, simply assign the lengths N and M to 0.

Definition at line 173 of file complex_matrices.h.

◆ DenseComplexMatrix() [2/5]

oomph::DenseComplexMatrix::DenseComplexMatrix ( const unsigned long &  n)
inline

Constructor to build a square n by n matrix.

Definition at line 182 of file complex_matrices.h.

◆ DenseComplexMatrix() [3/5]

oomph::DenseComplexMatrix::DenseComplexMatrix ( const unsigned long &  n,
const unsigned long &  m 
)
inline

Constructor to build a matrix with n rows and m columns.

Definition at line 191 of file complex_matrices.h.

◆ DenseComplexMatrix() [4/5]

oomph::DenseComplexMatrix::DenseComplexMatrix ( const unsigned long &  n,
const unsigned long &  m,
const std::complex< double > &  initial_val 
)
inline

Constructor to build a matrix with n rows and m columns, with initial value initial_val.

Definition at line 201 of file complex_matrices.h.

◆ DenseComplexMatrix() [5/5]

oomph::DenseComplexMatrix::DenseComplexMatrix ( const DenseComplexMatrix matrix)
delete

Broken copy constructor.

◆ ~DenseComplexMatrix()

oomph::DenseComplexMatrix::~DenseComplexMatrix ( )
virtual

Destructor, delete the storage for Index vector and LU storage (if any)

Destructor clean up the LU factors that have been allocated.

Definition at line 105 of file complex_matrices.cc.

References Index, and LU_factors.

Member Function Documentation

◆ delete_lu_factors()

void oomph::DenseComplexMatrix::delete_lu_factors ( )
private

Function that deletes the storage for the LU_factors, if it is not the same as the matrix storage.

Delete the storage that has been allocated for the LU factors, if the matrix data is not itself being overwritten.

Definition at line 88 of file complex_matrices.cc.

References LU_factors, and Overwrite_matrix_storage.

Referenced by ludecompose().

◆ lubksub()

void oomph::DenseComplexMatrix::lubksub ( Vector< std::complex< double >> &  rhs)
virtual

Overload the LU back substitution. Note that the rhs will be overwritten with the solution vector.

Back substitute an LU decomposed matrix.

Reimplemented from oomph::ComplexMatrixBase.

Definition at line 377 of file complex_matrices.cc.

References i, Index, LU_factors, oomph::DenseMatrix< std::complex< double > >::M, and oomph::DenseMatrix< std::complex< double > >::N.

◆ ludecompose()

int oomph::DenseComplexMatrix::ludecompose ( )
virtual

Overload the LU decomposition. For this storage scheme the matrix storage will be over-writeen by its LU decomposition.

LU decompose a matrix, over-writing it and recording the pivots numbers in the Index vector. Returns the sign of the determinant.

Reimplemented from oomph::ComplexMatrixBase.

Definition at line 122 of file complex_matrices.cc.

References delete_lu_factors(), oomph::DenseMatrix< std::complex< double > >::entry(), i, Index, LU_factors, oomph::DenseMatrix< std::complex< double > >::M, oomph::DenseMatrix< std::complex< double > >::Matrixdata, oomph::DenseMatrix< std::complex< double > >::N, and Overwrite_matrix_storage.

◆ multiply()

void oomph::DenseComplexMatrix::multiply ( const Vector< std::complex< double >> &  x,
Vector< std::complex< double >> &  soln 
)
virtual

◆ multiply_transpose()

void oomph::DenseComplexMatrix::multiply_transpose ( const Vector< std::complex< double >> &  x,
Vector< std::complex< double >> &  soln 
)
virtual

◆ ncol()

unsigned long oomph::DenseComplexMatrix::ncol ( ) const
inlinevirtual

Return the number of columns of the matrix.

Implements oomph::ComplexMatrixBase.

Definition at line 225 of file complex_matrices.h.

◆ nrow()

unsigned long oomph::DenseComplexMatrix::nrow ( ) const
inlinevirtual

Return the number of rows of the matrix.

Implements oomph::ComplexMatrixBase.

Definition at line 219 of file complex_matrices.h.

◆ operator()() [1/2]

std::complex<double>& oomph::DenseComplexMatrix::operator() ( const unsigned long &  i,
const unsigned long &  j 
)
inline

Overload the non-const version of the round-bracket access operator for read-write access.

Definition at line 240 of file complex_matrices.h.

References oomph::DenseMatrix< std::complex< double > >::entry(), and i.

◆ operator()() [2/2]

std::complex<double> oomph::DenseComplexMatrix::operator() ( const unsigned long &  i,
const unsigned long &  j 
) const
inlinevirtual

Overload the const version of the round-bracket access operator for read-only access.

Implements oomph::ComplexMatrixBase.

Definition at line 232 of file complex_matrices.h.

References oomph::DenseMatrix< std::complex< double > >::get_entry(), and i.

◆ operator=()

void oomph::DenseComplexMatrix::operator= ( const DenseComplexMatrix )
delete

Broken assignment operator.

◆ residual()

void oomph::DenseComplexMatrix::residual ( const Vector< std::complex< double >> &  x,
const Vector< std::complex< double >> &  rhs,
Vector< std::complex< double >> &  residual 
)
virtual

Find the residual of Ax=b, ie r=b-Ax for the "solution" x.

Find the residual of Ax=b, i.e. r=b-Ax.

Implements oomph::ComplexMatrixBase.

Definition at line 453 of file complex_matrices.cc.

References i, oomph::DenseMatrix< std::complex< double > >::M, oomph::DenseMatrix< std::complex< double > >::Matrixdata, and oomph::DenseMatrix< std::complex< double > >::N.

Member Data Documentation

◆ Index

Vector<long>* oomph::DenseComplexMatrix::Index
private

Pointer to storage for the index of permutations in the LU solve.

Definition at line 158 of file complex_matrices.h.

Referenced by lubksub(), ludecompose(), and ~DenseComplexMatrix().

◆ LU_factors

std::complex<double>* oomph::DenseComplexMatrix::LU_factors
private

Pointer to storage for the LU decomposition.

Definition at line 161 of file complex_matrices.h.

Referenced by delete_lu_factors(), lubksub(), ludecompose(), and ~DenseComplexMatrix().

◆ Overwrite_matrix_storage

bool oomph::DenseComplexMatrix::Overwrite_matrix_storage
private

Boolean flag used to decided whether the LU decomposition is stored separately, or not.

Definition at line 165 of file complex_matrices.h.

Referenced by delete_lu_factors(), and ludecompose().


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