//////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// More...
#include <matrices.h>
Public Member Functions | |
CCDoubleMatrix () | |
Default constructor. More... | |
CCDoubleMatrix (const Vector< double > &value, const Vector< int > &row_index_, const Vector< int > &column_start_, const unsigned long &n, const unsigned long &m) | |
Constructor: Pass vector of values, vector of row indices, vector of column starts and number of rows (can be suppressed for square matrices). Number of nonzero entries is read off from value, so make sure the vector has been shrunk to its correct length. More... | |
CCDoubleMatrix (const CCDoubleMatrix &matrix)=delete | |
Broken copy constructor. More... | |
void | operator= (const CCDoubleMatrix &)=delete |
Broken assignment operator. More... | |
virtual | ~CCDoubleMatrix () |
Destructor: Kill the LU factors if they have been setup. 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... | |
double | operator() (const unsigned long &i, const unsigned long &j) const |
Overload the round-bracket access operator to provide read-only (const) access to the data. More... | |
virtual void | ludecompose () |
LU decomposition using SuperLU. More... | |
virtual void | lubksub (DoubleVector &rhs) |
LU back solve for given RHS. More... | |
void | multiply (const DoubleVector &x, DoubleVector &soln) const |
Multiply the matrix by the vector x: soln=Ax. More... | |
void | multiply_transpose (const DoubleVector &x, DoubleVector &soln) const |
Multiply the transposed matrix by the vector x: soln=A^T x. More... | |
void | multiply (const CCDoubleMatrix &matrix_in, CCDoubleMatrix &result) |
Function to multiply this matrix by the CCDoubleMatrix matrix_in The multiplication method used can be selected using the flag Matrix_matrix_multiply_method. By default Method 2 is used. 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... More... | |
void | matrix_reduction (const double &alpha, CCDoubleMatrix &reduced_matrix) |
For every row, find the maximum absolute value of the entries in this row. Set all values that are less than alpha times this maximum to zero and return the resulting matrix in reduced_matrix. Note: Diagonal entries are retained regardless of their size. More... | |
unsigned & | matrix_matrix_multiply_method () |
Access function to Matrix_matrix_multiply_method, the flag which determines the matrix matrix multiplication method used. 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... More... | |
Public Member Functions inherited from oomph::DoubleMatrixBase | |
DoubleMatrixBase () | |
(Empty) constructor. More... | |
DoubleMatrixBase (const DoubleMatrixBase &matrix)=delete | |
Broken copy constructor. More... | |
void | operator= (const DoubleMatrixBase &)=delete |
Broken assignment operator. More... | |
virtual | ~DoubleMatrixBase () |
virtual (empty) destructor More... | |
LinearSolver *& | linear_solver_pt () |
Return a pointer to the linear solver object. More... | |
LinearSolver *const & | linear_solver_pt () const |
Return a pointer to the linear solver object (const version) More... | |
void | solve (DoubleVector &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... | |
void | solve (const DoubleVector &rhs, DoubleVector &soln) |
Complete LU solve (Nothing gets overwritten!). The default should not need to be overwritten. More... | |
void | solve (Vector< 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... | |
void | solve (const Vector< double > &rhs, Vector< double > &soln) |
Complete LU solve (Nothing gets overwritten!). The default should not need to be overwritten. More... | |
virtual void | residual (const DoubleVector &x, const DoubleVector &b, DoubleVector &residual_) |
Find the residual, i.e. r=b-Ax the residual. More... | |
virtual double | max_residual (const DoubleVector &x, const DoubleVector &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::CCMatrix< double > | |
CCMatrix () | |
Default constructor. More... | |
CCMatrix (const Vector< double > &value, const Vector< int > &row_index_, const Vector< int > &column_start_, const unsigned long &n, const unsigned long &m) | |
Constructor: Pass vector of values, vector of row indices, vector of column starts and number of rows (can be suppressed for square matrices). Number of nonzero entries is read off from value, so make sure the vector has been shrunk to its correct length. More... | |
CCMatrix (const CCMatrix &source_matrix) | |
Copy constructor. More... | |
void | operator= (const CCMatrix &)=delete |
Broken assignment operator. More... | |
virtual | ~CCMatrix () |
Destructor, delete any allocated memory. More... | |
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... | |
double & | entry (const unsigned long &i, const unsigned long &j) |
Read-write access is not permitted for these matrices and is deliberately broken. More... | |
int * | column_start () |
Access to C-style column_start array. More... | |
const int * | column_start () const |
Access to C-style column_start array (const version) More... | |
int * | row_index () |
Access to C-style row index array. More... | |
const int * | row_index () const |
Access to C-style row 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< double > &value, const Vector< int > &row_index, const Vector< int > &column_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. More... | |
void | build_without_copy (double *value, int *row_index, int *column_start, const unsigned long &nnz, const unsigned long &n, const unsigned long &m) |
Function to build matrix from pointers to arrays which hold the column starts, row indices and non-zero values. The final parameters specifies 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 | 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... | |
Private Attributes | |
unsigned | Matrix_matrix_multiply_method |
Flag to determine which matrix-matrix multiplication method is used. 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::DoubleMatrixBase | |
LinearSolver * | Linear_solver_pt |
LinearSolver * | Default_linear_solver_pt |
Protected Attributes inherited from oomph::CCMatrix< double > | |
int * | Row_index |
Row index. More... | |
int * | Column_start |
Start index for column. 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... | |
Static Protected Attributes inherited from oomph::SparseMatrix< T, MATRIX_TYPE > | |
static T | Zero = T(0) |
Dummy zero. More... | |
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
A class for compressed column matrices that store doubles
Definition at line 2790 of file matrices.h.
oomph::CCDoubleMatrix::CCDoubleMatrix | ( | ) |
Default constructor.
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
Default constructor, set the default linear solver and matrix-matrix multiplication method.
Definition at line 572 of file matrices.cc.
References oomph::DoubleMatrixBase::Default_linear_solver_pt, oomph::DoubleMatrixBase::Linear_solver_pt, and Matrix_matrix_multiply_method.
oomph::CCDoubleMatrix::CCDoubleMatrix | ( | const Vector< double > & | value, |
const Vector< int > & | row_index_, | ||
const Vector< int > & | column_start_, | ||
const unsigned long & | n, | ||
const unsigned long & | m | ||
) |
Constructor: Pass vector of values, vector of row indices, vector of column starts and number of rows (can be suppressed for square matrices). Number of nonzero entries is read off from value, so make sure the vector has been shrunk to its correct length.
Definition at line 585 of file matrices.cc.
References oomph::DoubleMatrixBase::Default_linear_solver_pt, oomph::DoubleMatrixBase::Linear_solver_pt, and Matrix_matrix_multiply_method.
|
delete |
Broken copy constructor.
|
virtual |
Destructor: Kill the LU factors if they have been setup.
Destructor: delete the default linear solver.
Definition at line 597 of file matrices.cc.
References oomph::DoubleMatrixBase::Default_linear_solver_pt.
|
virtual |
LU back solve for given RHS.
Do the backsubstitution.
Definition at line 614 of file matrices.cc.
References oomph::DoubleMatrixBase::Default_linear_solver_pt.
|
virtual |
LU decomposition using SuperLU.
Perform LU decomposition. Return the sign of the determinant.
Definition at line 606 of file matrices.cc.
References oomph::DoubleMatrixBase::Default_linear_solver_pt.
|
inline |
Access function to Matrix_matrix_multiply_method, the flag which determines the matrix matrix multiplication method used. 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...
Definition at line 2886 of file matrices.h.
References Matrix_matrix_multiply_method.
void oomph::CCDoubleMatrix::matrix_reduction | ( | const double & | alpha, |
CCDoubleMatrix & | reduced_matrix | ||
) |
For every row, find the maximum absolute value of the entries in this row. Set all values that are less than alpha times this maximum to zero and return the resulting matrix in reduced_matrix. Note: Diagonal entries are retained regardless of their size.
Definition at line 1149 of file matrices.cc.
References oomph::CCMatrix< double >::build(), oomph::CCMatrix< double >::Column_start, i, ncol(), nrow(), oomph::CCMatrix< double >::Row_index, and oomph::SparseMatrix< T, MATRIX_TYPE >::Value.
void oomph::CCDoubleMatrix::multiply | ( | const CCDoubleMatrix & | matrix_in, |
CCDoubleMatrix & | result | ||
) |
Function to multiply this matrix by the CCDoubleMatrix matrix_in The multiplication method used can be selected using the flag Matrix_matrix_multiply_method. By default Method 2 is used. 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...
Definition at line 821 of file matrices.cc.
References oomph::CCMatrix< T >::build_without_copy(), oomph::CCMatrix< T >::column_start(), oomph::CCMatrix< double >::column_start(), oomph::CCMatrix< double >::Column_start, i, oomph::SparseMatrix< T, MATRIX_TYPE >::M, Matrix_matrix_multiply_method, oomph::SparseMatrix< T, MATRIX_TYPE >::N, ncol(), oomph::SparseMatrix< T, MATRIX_TYPE >::Nnz, nrow(), oomph::CCMatrix< T >::row_index(), oomph::CCMatrix< double >::row_index(), oomph::CCMatrix< double >::Row_index, oomph::SparseMatrix< T, MATRIX_TYPE >::Value, and oomph::SparseMatrix< T, MATRIX_TYPE >::value().
|
virtual |
Multiply the matrix by the vector x: soln=Ax.
Multiply the matrix by the vector x.
Implements oomph::DoubleMatrixBase.
Definition at line 622 of file matrices.cc.
References oomph::DoubleVector::build(), oomph::DoubleVector::built(), oomph::CCMatrix< double >::Column_start, oomph::LinearAlgebraDistribution::communicator_pt(), oomph::DistributableLinearAlgebraObject::distributed(), oomph::DistributableLinearAlgebraObject::distribution_pt(), i, oomph::DoubleVector::initialise(), oomph::SparseMatrix< T, MATRIX_TYPE >::N, ncol(), oomph::DistributableLinearAlgebraObject::nrow(), oomph::CCMatrix< double >::Row_index, oomph::SparseMatrix< T, MATRIX_TYPE >::Value, and oomph::DoubleVector::values_pt().
|
virtual |
Multiply the transposed matrix by the vector x: soln=A^T x.
Implements oomph::DoubleMatrixBase.
Definition at line 715 of file matrices.cc.
References oomph::DoubleVector::build(), oomph::DoubleVector::built(), oomph::CCMatrix< double >::Column_start, oomph::LinearAlgebraDistribution::communicator_pt(), oomph::DistributableLinearAlgebraObject::distributed(), oomph::DistributableLinearAlgebraObject::distribution_pt(), i, oomph::DoubleVector::initialise(), oomph::SparseMatrix< T, MATRIX_TYPE >::N, oomph::DistributableLinearAlgebraObject::nrow(), nrow(), oomph::CCMatrix< double >::Row_index, oomph::SparseMatrix< T, MATRIX_TYPE >::Value, and oomph::DoubleVector::values_pt().
Referenced by oomph::SuperLUSolver::solve(), and oomph::SuperLUSolver::solve_transpose().
|
inlinevirtual |
Return the number of columns of the matrix.
Implements oomph::DoubleMatrixBase.
Definition at line 2823 of file matrices.h.
References oomph::SparseMatrix< T, CCMatrix< T > >::ncol().
Referenced by matrix_reduction(), and multiply().
|
inlinevirtual |
Return the number of rows of the matrix.
Implements oomph::DoubleMatrixBase.
Definition at line 2817 of file matrices.h.
References oomph::SparseMatrix< T, CCMatrix< T > >::nrow().
Referenced by oomph::SuperLUSolver::factorise_distributed(), matrix_reduction(), multiply(), multiply_transpose(), and oomph::ILUZeroPreconditioner< CCDoubleMatrix >::setup().
|
inlinevirtual |
Overload the round-bracket access operator to provide read-only (const) access to the data.
Implements oomph::DoubleMatrixBase.
Definition at line 2830 of file matrices.h.
References oomph::CCMatrix< T >::get_entry(), and i.
|
delete |
Broken assignment operator.
|
private |
Flag to determine which matrix-matrix multiplication method is used.
Definition at line 2893 of file matrices.h.
Referenced by CCDoubleMatrix(), matrix_matrix_multiply_method(), and multiply().