A class for compressed row matrices. More...
#include <complex_matrices.h>
Public Types | |
enum class | SerialMatrixMultiplyMethod { Memory_efficient = 0 , Fastest = 1 , Vector_of_vectors = 2 } |
Serial matrix multiply method enumeration. More... | |
Public Member Functions | |
CRComplexMatrix () | |
Default constructor. More... | |
CRComplexMatrix (const Vector< std::complex< double >> &value, const Vector< int > &column_index, const Vector< int > &row_start, const unsigned long &n, const unsigned long &m) | |
Constructor: Pass vector of values, vector of column indices, vector of row starts and number of columns (can be suppressed for square matrices) More... | |
CRComplexMatrix (const CRComplexMatrix &matrix)=delete | |
Broken copy constructor. More... | |
void | operator= (const CRComplexMatrix &)=delete |
Broken assignment operator. More... | |
virtual | ~CRComplexMatrix () |
Destructor: Kill the LU decomposition if it has been computed. More... | |
void | enable_doc_stats () |
Set flag to indicate that stats are to be displayed during solution of linear system with SuperLU. More... | |
void | disable_doc_stats () |
the solve 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 round-bracket access operator for read-only access. More... | |
int | ludecompose () |
LU decomposition using SuperLU. More... | |
void | lubksub (Vector< std::complex< double >> &rhs) |
LU back solve for given RHS. More... | |
void | clean_up_memory () |
LU clean up (perhaps this should happen in the destructor) More... | |
void | residual (const Vector< std::complex< double >> &x, const Vector< std::complex< double >> &b, Vector< std::complex< double >> &residual) |
Find the residual to x of Ax=b, i.e. r=b-Ax. 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... | |
void | add (const CRDoubleMatrix &matrix_in, CRComplexMatrix &result_matrix) const |
Element-wise addition of this matrix with matrix_in. More... | |
void | add (const CRComplexMatrix &matrix_in, CRComplexMatrix &result_matrix) const |
Element-wise addition of this matrix with matrix_in. More... | |
void | multiply (const CRComplexMatrix &matrix_in, CRComplexMatrix &result) const |
Function to multiply this matrix by the CRComplexMatrix matrix_in. In a serial matrix, there are 3 methods available: Method 1: First runs through this matrix and matrix_in to find the storage requirements for result - arrays of the correct size are then allocated before performing the calculation. Minimises memory requirements but more costly. Method 2: Grows storage for values and column indices of result 'on the fly' using an array of maps. Faster but more memory intensive. Method 3: Grows storage for values and column indices of result 'on the fly' using a vector of vectors. Not particularly impressive on the platforms we tried... Method 2 is employed by default. See also CRDoubleMatrix::multiply(...) More... | |
SerialMatrixMultiplyMethod & | serial_matrix_matrix_multiply_method () |
Access function to Serial_matrix_matrix_multiply_method, the flag which determines the matrix matrix multiplication method used for serial matrices. More... | |
SerialMatrixMultiplyMethod | serial_matrix_matrix_multiply_method () const |
Read only access function (const version) to Serial_matrix_matrix_multiply_method, the flag which determines the matrix matrix multiplication method used for serial matrices. More... | |
Public Member Functions inherited from oomph::CRMatrix< std::complex< double > > | |
CRMatrix () | |
Default constructor. More... | |
CRMatrix (const Vector< std::complex< double > > &value, const Vector< int > &column_index_, const Vector< int > &row_start_, const unsigned long &n, const unsigned long &m) | |
Constructor: Pass vector of values, vector of column indices, vector of row starts and number of rows and columns Number of nonzero entries is read off from value, so make sure the vector has been shrunk to its correct length. More... | |
CRMatrix (const CRMatrix &source_matrix) | |
Copy constructor. More... | |
void | operator= (const CRMatrix &)=delete |
Broken assignment operator. More... | |
virtual | ~CRMatrix () |
Destructor, delete any allocated memory. More... | |
std::complex< double > | get_entry (const unsigned long &i, const unsigned long &j) const |
Access function that will be called by the read-only round-bracket operator (const) More... | |
std::complex< double > & | entry (const unsigned long &i, const unsigned long &j) |
The read-write access function is deliberately broken. More... | |
int * | row_start () |
Access to C-style row_start array. More... | |
const int * | row_start () const |
Access to C-style row_start array (const version) More... | |
int * | column_index () |
Access to C-style column index array. More... | |
const int * | column_index () const |
Access to C-style column index array (const version) 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... | |
void | clean_up_memory () |
Wipe matrix data and set all values to 0. More... | |
void | build (const Vector< std::complex< double > > &value, const Vector< int > &column_index, const Vector< int > &row_start, const unsigned long &n, const unsigned long &m) |
Build matrix from compressed representation. Number of nonzero entries is read off from value, so make sure the vector has been shrunk to its correct length. This matrix forms the storage for CRDoubleMatrices which are distributable. The argument n should be the number of local rows. The argument m is the number of columns. More... | |
void | build_without_copy (std::complex< double > *value, int *column_index, int *row_start, const unsigned long &nnz, const unsigned long &n, const unsigned long &m) |
Function to build matrix from pointers to arrays which hold the row starts, column indices and non-zero values. The final two arguments are the number of rows and columns. Note that, as the name suggests, this function does not make a copy of the data pointed to by the first three arguments! More... | |
Public Member Functions inherited from oomph::SparseMatrix< T, MATRIX_TYPE > | |
SparseMatrix () | |
Default constructor. More... | |
SparseMatrix (const SparseMatrix &source_matrix) | |
Copy constructor. More... | |
void | operator= (const SparseMatrix &)=delete |
Broken assignment operator. More... | |
virtual | ~SparseMatrix () |
Destructor, delete the memory associated with the values. More... | |
T * | value () |
Access to C-style value array. More... | |
const T * | value () const |
Access to C-style value array (const version) 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... | |
unsigned long | nnz () const |
Return the number of nonzero entries. 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... | |
T | 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... | |
virtual void | output (std::ostream &outfile) const |
Output function to print a matrix row-by-row, in the form a(0,0) a(0,1) ... a(1,0) a(1,1) ... ... to the stream outfile. Broken virtual since it might not be sensible to implement this for some sparse matrices. 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... | |
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... | |
Protected Attributes | |
bool | Doc_stats_during_solve |
Flag to indicate if stats are to be displayed during solution of linear system with SuperLU. More... | |
Protected Attributes inherited from oomph::CRMatrix< std::complex< double > > | |
int * | Column_index |
Column index. More... | |
int * | Row_start |
Start index for row. More... | |
Protected Attributes inherited from oomph::SparseMatrix< T, MATRIX_TYPE > | |
T * | Value |
Internal representation of the matrix values, a pointer. More... | |
unsigned long | N |
Number of rows. More... | |
unsigned long | M |
Number of columns. More... | |
unsigned long | Nnz |
Number of non-zero values (i.e. size of Value array) More... | |
Private Attributes | |
void * | F_factors |
Storage for the LU factors as required by SuperLU. More... | |
int | Info |
Info flag for the SuperLU solver. More... | |
SerialMatrixMultiplyMethod | Serial_matrix_matrix_multiply_method |
A switch variable for selecting the matrix multiply method for serial (non-parallel) runs. Note that the parallel case hasn't been implemented, so this is used in both cases. 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... | |
Static Protected Attributes inherited from oomph::SparseMatrix< T, MATRIX_TYPE > | |
static T | Zero = T(0) |
Dummy zero. More... | |
A class for compressed row matrices.
Definition at line 277 of file complex_matrices.h.
Serial matrix multiply method enumeration.
Enumerator | |
---|---|
Memory_efficient | |
Fastest | |
Vector_of_vectors |
Definition at line 282 of file complex_matrices.h.
|
inline |
Default constructor.
Definition at line 291 of file complex_matrices.h.
References Doc_stats_during_solve, Fastest, and Serial_matrix_matrix_multiply_method.
|
inline |
Constructor: Pass vector of values, vector of column indices, vector of row starts and number of columns (can be suppressed for square matrices)
Definition at line 304 of file complex_matrices.h.
References Doc_stats_during_solve, Fastest, and Serial_matrix_matrix_multiply_method.
|
delete |
Broken copy constructor.
|
inlinevirtual |
Destructor: Kill the LU decomposition if it has been computed.
Definition at line 329 of file complex_matrices.h.
References clean_up_memory().
void oomph::CRComplexMatrix::add | ( | const CRComplexMatrix & | matrix_in, |
CRComplexMatrix & | result_matrix | ||
) | const |
Element-wise addition of this matrix with matrix_in.
Definition at line 867 of file complex_matrices.cc.
References oomph::CRMatrix< T >::build(), oomph::CRMatrix< T >::column_index(), oomph::CRMatrix< std::complex< double > >::column_index(), i, ncol(), nrow(), oomph::CRMatrix< T >::row_start(), oomph::CRMatrix< std::complex< double > >::row_start(), and oomph::SparseMatrix< T, MATRIX_TYPE >::value().
void oomph::CRComplexMatrix::add | ( | const CRDoubleMatrix & | matrix_in, |
CRComplexMatrix & | result_matrix | ||
) | const |
Element-wise addition of this matrix with matrix_in.
Definition at line 967 of file complex_matrices.cc.
References oomph::CRMatrix< T >::build(), oomph::CRDoubleMatrix::built(), oomph::CRMatrix< std::complex< double > >::column_index(), oomph::CRDoubleMatrix::column_index(), i, ncol(), oomph::CRDoubleMatrix::ncol(), nrow(), oomph::CRDoubleMatrix::nrow(), oomph::CRMatrix< std::complex< double > >::row_start(), oomph::CRDoubleMatrix::row_start(), oomph::SparseMatrix< T, MATRIX_TYPE >::value(), and oomph::CRDoubleMatrix::value().
void oomph::CRComplexMatrix::clean_up_memory | ( | ) |
LU clean up (perhaps this should happen in the destructor)
Cleanup memory.
Definition at line 1616 of file complex_matrices.cc.
References oomph::CRMatrix< std::complex< double > >::Column_index, oomph::LeakCheckNames::doc(), Doc_stats_during_solve, F_factors, i, Info, oomph::SparseMatrix< T, MATRIX_TYPE >::N, oomph::SparseMatrix< T, MATRIX_TYPE >::Nnz, oomph::CRMatrix< std::complex< double > >::Row_start, oomph::superlu_complex(), and oomph::SparseMatrix< T, MATRIX_TYPE >::Value.
Referenced by ~CRComplexMatrix().
|
inline |
|
inline |
Set flag to indicate that stats are to be displayed during solution of linear system with SuperLU.
Definition at line 336 of file complex_matrices.h.
References Doc_stats_during_solve.
|
virtual |
LU back solve for given RHS.
Do back-substitution.
RHS vector
Reimplemented from oomph::ComplexMatrixBase.
Definition at line 1535 of file complex_matrices.cc.
References oomph::CRMatrix< std::complex< double > >::Column_index, oomph::LeakCheckNames::doc(), Doc_stats_during_solve, F_factors, i, Info, oomph::SparseMatrix< T, MATRIX_TYPE >::M, oomph::SparseMatrix< T, MATRIX_TYPE >::N, oomph::SparseMatrix< T, MATRIX_TYPE >::Nnz, oomph::CRMatrix< std::complex< double > >::Row_start, oomph::superlu_complex(), and oomph::SparseMatrix< T, MATRIX_TYPE >::Value.
|
virtual |
LU decomposition using SuperLU.
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
Do LU decomposition and return sign of determinant
Reimplemented from oomph::ComplexMatrixBase.
Definition at line 1482 of file complex_matrices.cc.
References oomph::CRMatrix< std::complex< double > >::Column_index, oomph::LeakCheckNames::doc(), Doc_stats_during_solve, F_factors, i, Info, oomph::SparseMatrix< T, MATRIX_TYPE >::M, oomph::SparseMatrix< T, MATRIX_TYPE >::N, oomph::SparseMatrix< T, MATRIX_TYPE >::Nnz, oomph::CRMatrix< std::complex< double > >::Row_start, oomph::superlu_complex(), and oomph::SparseMatrix< T, MATRIX_TYPE >::Value.
void oomph::CRComplexMatrix::multiply | ( | const CRComplexMatrix & | matrix_in, |
CRComplexMatrix & | result | ||
) | const |
Function to multiply this matrix by the CRComplexMatrix matrix_in. In a serial matrix, there are 3 methods available: Method 1: First runs through this matrix and matrix_in to find the storage requirements for result - arrays of the correct size are then allocated before performing the calculation. Minimises memory requirements but more costly. Method 2: Grows storage for values and column indices of result 'on the fly' using an array of maps. Faster but more memory intensive. Method 3: Grows storage for values and column indices of result 'on the fly' using a vector of vectors. Not particularly impressive on the platforms we tried... Method 2 is employed by default. See also CRDoubleMatrix::multiply(...)
Definition at line 559 of file complex_matrices.cc.
References oomph::CRMatrix< T >::build_without_copy(), oomph::CRMatrix< std::complex< double > >::column_index(), oomph::CRMatrix< T >::column_index(), Fastest, i, Memory_efficient, ncol(), oomph::SparseMatrix< T, MATRIX_TYPE >::nnz(), nrow(), oomph::CRMatrix< std::complex< double > >::row_start(), oomph::CRMatrix< T >::row_start(), Serial_matrix_matrix_multiply_method, oomph::SparseMatrix< T, MATRIX_TYPE >::value(), and Vector_of_vectors.
|
virtual |
Multiply the matrix by the vector x: soln=Ax.
Multiply the matrix by the vector x.
Implements oomph::ComplexMatrixBase.
Definition at line 1706 of file complex_matrices.cc.
References oomph::CRMatrix< std::complex< double > >::Column_index, i, oomph::SparseMatrix< T, MATRIX_TYPE >::M, oomph::SparseMatrix< T, MATRIX_TYPE >::N, oomph::CRMatrix< std::complex< double > >::Row_start, and oomph::SparseMatrix< T, MATRIX_TYPE >::Value.
|
virtual |
Multiply the transposed matrix by the vector x: soln=A^T x.
Implements oomph::ComplexMatrixBase.
Definition at line 1745 of file complex_matrices.cc.
References oomph::CRMatrix< std::complex< double > >::Column_index, i, oomph::SparseMatrix< T, MATRIX_TYPE >::M, oomph::SparseMatrix< T, MATRIX_TYPE >::N, oomph::CRMatrix< std::complex< double > >::Row_start, and oomph::SparseMatrix< T, MATRIX_TYPE >::Value.
|
inlinevirtual |
Return the number of columns of the matrix.
Implements oomph::ComplexMatrixBase.
Definition at line 355 of file complex_matrices.h.
Referenced by add(), and multiply().
|
inlinevirtual |
Return the number of rows of the matrix.
Implements oomph::ComplexMatrixBase.
Definition at line 349 of file complex_matrices.h.
Referenced by add(), and multiply().
|
inlinevirtual |
Overload the round-bracket access operator for read-only access.
Implements oomph::ComplexMatrixBase.
Definition at line 361 of file complex_matrices.h.
References oomph::CRMatrix< std::complex< double > >::get_entry(), and i.
|
delete |
Broken assignment operator.
|
virtual |
Find the residual to x of Ax=b, i.e. r=b-Ax.
Find the residulal to x of Ax=b, ie r=b-Ax.
Implements oomph::ComplexMatrixBase.
Definition at line 1656 of file complex_matrices.cc.
References oomph::CRMatrix< std::complex< double > >::Column_index, i, oomph::SparseMatrix< T, MATRIX_TYPE >::M, oomph::SparseMatrix< T, MATRIX_TYPE >::N, oomph::CRMatrix< std::complex< double > >::Row_start, and oomph::SparseMatrix< T, MATRIX_TYPE >::Value.
|
inline |
Access function to Serial_matrix_matrix_multiply_method, the flag which determines the matrix matrix multiplication method used for serial matrices.
Definition at line 408 of file complex_matrices.h.
References Serial_matrix_matrix_multiply_method.
|
inline |
Read only access function (const version) to Serial_matrix_matrix_multiply_method, the flag which determines the matrix matrix multiplication method used for serial matrices.
Definition at line 417 of file complex_matrices.h.
References Serial_matrix_matrix_multiply_method.
|
protected |
Flag to indicate if stats are to be displayed during solution of linear system with SuperLU.
Definition at line 425 of file complex_matrices.h.
Referenced by clean_up_memory(), CRComplexMatrix(), disable_doc_stats(), enable_doc_stats(), lubksub(), and ludecompose().
|
private |
Storage for the LU factors as required by SuperLU.
Definition at line 429 of file complex_matrices.h.
Referenced by clean_up_memory(), lubksub(), and ludecompose().
|
private |
Info flag for the SuperLU solver.
Definition at line 432 of file complex_matrices.h.
Referenced by clean_up_memory(), lubksub(), and ludecompose().
|
private |
A switch variable for selecting the matrix multiply method for serial (non-parallel) runs. Note that the parallel case hasn't been implemented, so this is used in both cases.
Definition at line 437 of file complex_matrices.h.
Referenced by CRComplexMatrix(), multiply(), and serial_matrix_matrix_multiply_method().