Class of matrices containing doubles, and stored as a DenseMatrix<double>, but with solving functionality inherited from the abstract DoubleMatrix class. More...
#include <matrices.h>
Public Member Functions | |
DenseDoubleMatrix () | |
Constructor, set the default linear solver. More... | |
DenseDoubleMatrix (const unsigned long &n) | |
Constructor to build a square n by n matrix. More... | |
DenseDoubleMatrix (const unsigned long &n, const unsigned long &m) | |
Constructor to build a matrix with n rows and m columns. More... | |
DenseDoubleMatrix (const unsigned long &n, const unsigned long &m, const double &initial_val) | |
Constructor to build a matrix with n rows and m columns, with initial value initial_val. More... | |
DenseDoubleMatrix (const DenseDoubleMatrix &matrix)=delete | |
Broken copy constructor. More... | |
void | operator= (const DenseDoubleMatrix &)=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... | |
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... | |
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 | ~DenseDoubleMatrix () |
Destructor. More... | |
virtual void | ludecompose () |
LU decomposition using DenseLU (default linea solver) More... | |
virtual void | lubksub (DoubleVector &rhs) |
LU backsubstitution. More... | |
virtual void | lubksub (Vector< double > &rhs) |
LU backsubstitution. More... | |
void | eigenvalues_by_jacobi (Vector< double > &eigen_val, DenseMatrix< double > &eigen_vect) const |
Determine eigenvalues and eigenvectors, using Jacobi rotations. Only for symmetric matrices. Nothing gets overwritten! 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 | matrix_reduction (const double &alpha, DenseDoubleMatrix &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... | |
void | multiply (const DenseDoubleMatrix &matrix_in, DenseDoubleMatrix &result) |
Function to multiply this matrix by a DenseDoubleMatrix matrix_in. 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::DenseMatrix< 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 double &initial_val) | |
Constructor to build a matrix with n rows and m columns, with initial value initial_val. More... | |
DenseMatrix & | operator= (const DenseMatrix &source_matrix) |
Copy assignment. More... | |
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... | |
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 double &initial_value) |
Resize to a non-square n x m matrix and initialize the new values to initial_value. More... | |
void | initialise (const 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... | |
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... | |
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... | |
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::DenseMatrix< double > | |
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... | |
Class of matrices containing doubles, and stored as a DenseMatrix<double>, but with solving functionality inherited from the abstract DoubleMatrix class.
Definition at line 1270 of file matrices.h.
oomph::DenseDoubleMatrix::DenseDoubleMatrix | ( | ) |
Constructor, set the default linear solver.
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
Constructor, set the default linear solver to be the DenseLU solver
Definition at line 139 of file matrices.cc.
References oomph::DoubleMatrixBase::Default_linear_solver_pt, and oomph::DoubleMatrixBase::Linear_solver_pt.
oomph::DenseDoubleMatrix::DenseDoubleMatrix | ( | const unsigned long & | n | ) |
Constructor to build a square n by n matrix.
Constructor to build a square n by n matrix. Set the default linear solver to be DenseLU.
Definition at line 148 of file matrices.cc.
References oomph::DoubleMatrixBase::Default_linear_solver_pt, and oomph::DoubleMatrixBase::Linear_solver_pt.
oomph::DenseDoubleMatrix::DenseDoubleMatrix | ( | const unsigned long & | n, |
const unsigned long & | m | ||
) |
Constructor to build a matrix with n rows and m columns.
Constructor to build a matrix with n rows and m columns. Set the default linear solver to be DenseLU.
Definition at line 159 of file matrices.cc.
References oomph::DoubleMatrixBase::Default_linear_solver_pt, and oomph::DoubleMatrixBase::Linear_solver_pt.
oomph::DenseDoubleMatrix::DenseDoubleMatrix | ( | const unsigned long & | n, |
const unsigned long & | m, | ||
const double & | initial_val | ||
) |
Constructor to build a matrix with n rows and m columns, with initial value initial_val.
Constructor to build a matrix with n rows and m columns, with initial value initial_val Set the default linear solver to be DenseLU.
Definition at line 171 of file matrices.cc.
References oomph::DoubleMatrixBase::Default_linear_solver_pt, and oomph::DoubleMatrixBase::Linear_solver_pt.
|
delete |
Broken copy constructor.
|
virtual |
Destructor.
Destructor delete the default linear solver.
Definition at line 182 of file matrices.cc.
References oomph::DoubleMatrixBase::Default_linear_solver_pt.
void oomph::DenseDoubleMatrix::eigenvalues_by_jacobi | ( | Vector< double > & | eigen_vals, |
DenseMatrix< double > & | eigen_vect | ||
) | const |
Determine eigenvalues and eigenvectors, using Jacobi rotations. Only for symmetric matrices. Nothing gets overwritten!
eigen_vect(i,j)
= j-th component of i-th eigenvector.eigen_val(i)
is the i-th eigenvalue; same ordering as in eigenvectorseigen_vect(i,j)
= j-th component of i-th eigenvector.eigen_val
[i] is the i-th eigenvalue; same ordering as in eigenvectors Definition at line 224 of file matrices.cc.
References i, oomph::DenseMatrix< double >::M, oomph::DenseMatrix< double >::Matrixdata, oomph::DenseMatrix< double >::N, oomph::DenseMatrix< T >::ncol(), oomph::DenseMatrix< T >::nrow(), and oomph::DenseMatrix< T >::resize().
Referenced by oomph::PVDEquationsBase< DIM >::get_principal_stress().
|
virtual |
LU backsubstitution.
Back substitute an LU decomposed matrix.
Definition at line 202 of file matrices.cc.
References oomph::DoubleMatrixBase::Default_linear_solver_pt.
Referenced by oomph::DGElement::get_inverse_mass_matrix_times_residuals(), oomph::Z2ErrorEstimator::get_recovered_flux_in_patch(), and oomph::VorticitySmoother< ELEMENT >::get_recovered_vorticity_in_patch().
|
virtual |
LU backsubstitution.
Back substitute an LU decomposed matrix.
Definition at line 211 of file matrices.cc.
References oomph::DoubleMatrixBase::Default_linear_solver_pt.
|
virtual |
LU decomposition using DenseLU (default linea solver)
LU decompose a matrix, by using the default linear solver (DenseLU)
Definition at line 192 of file matrices.cc.
References oomph::DoubleMatrixBase::Default_linear_solver_pt.
Referenced by oomph::DGElement::get_inverse_mass_matrix_times_residuals(), oomph::Z2ErrorEstimator::get_recovered_flux_in_patch(), oomph::VorticitySmoother< ELEMENT >::get_recovered_vorticity_in_patch(), and oomph::DGElement::pre_compute_mass_matrix().
void oomph::DenseDoubleMatrix::matrix_reduction | ( | const double & | alpha, |
DenseDoubleMatrix & | 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 481 of file matrices.cc.
References i, oomph::DenseMatrix< double >::M, oomph::DenseMatrix< double >::Matrixdata, oomph::DenseMatrix< double >::N, and oomph::DenseMatrix< T >::resize().
void oomph::DenseDoubleMatrix::multiply | ( | const DenseDoubleMatrix & | matrix_in, |
DenseDoubleMatrix & | result | ||
) |
Function to multiply this matrix by a DenseDoubleMatrix matrix_in.
Function to multiply this matrix by the DenseDoubleMatrix matrix_in.
Definition at line 521 of file matrices.cc.
References i, oomph::DenseMatrix< double >::Matrixdata, ncol(), nrow(), and oomph::DenseMatrix< T >::resize().
|
virtual |
Multiply the matrix by the vector x: soln=Ax.
Implements oomph::DoubleMatrixBase.
Definition at line 294 of file matrices.cc.
References oomph::DoubleVector::build(), oomph::DoubleVector::built(), oomph::LinearAlgebraDistribution::communicator_pt(), oomph::DistributableLinearAlgebraObject::distributed(), oomph::DistributableLinearAlgebraObject::distribution_pt(), i, oomph::DoubleVector::initialise(), oomph::DenseMatrix< double >::M, oomph::DenseMatrix< double >::Matrixdata, oomph::DenseMatrix< double >::N, ncol(), oomph::DistributableLinearAlgebraObject::nrow(), and oomph::DoubleVector::values_pt().
|
virtual |
Multiply the transposed matrix by the vector x: soln=A^T x.
Implements oomph::DoubleMatrixBase.
Definition at line 385 of file matrices.cc.
References oomph::DoubleVector::build(), oomph::DoubleVector::built(), oomph::LinearAlgebraDistribution::communicator_pt(), oomph::DistributableLinearAlgebraObject::distributed(), oomph::DistributableLinearAlgebraObject::distribution_pt(), i, oomph::DoubleVector::initialise(), oomph::DenseMatrix< double >::M, oomph::DenseMatrix< double >::Matrixdata, oomph::DenseMatrix< double >::N, oomph::DistributableLinearAlgebraObject::nrow(), nrow(), and oomph::DoubleVector::values_pt().
|
inlinevirtual |
Return the number of columns of the matrix.
Implements oomph::DoubleMatrixBase.
Definition at line 1301 of file matrices.h.
References oomph::DenseMatrix< T >::ncol().
Referenced by multiply().
|
inlinevirtual |
Return the number of rows of the matrix.
Implements oomph::DoubleMatrixBase.
Definition at line 1295 of file matrices.h.
References oomph::DenseMatrix< T >::nrow().
Referenced by multiply(), and multiply_transpose().
|
inline |
Overload the non-const version of the round-bracket access operator for read-write access.
Definition at line 1316 of file matrices.h.
References oomph::DenseMatrix< T >::entry(), and i.
|
inlinevirtual |
Overload the const version of the round-bracket access operator for read-only access.
Implements oomph::DoubleMatrixBase.
Definition at line 1308 of file matrices.h.
References oomph::DenseMatrix< T >::get_entry(), and i.
|
delete |
Broken assignment operator.