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

Class for a matrix of the form M = S + G + H + ... where S is the main matrix and G,H etc. are matrices of size S or smaller. This may be useful if, for example, G,H etc. are subblocks of M that must be stored in a different format to S. More...

#include <sum_of_matrices.h>

+ Inheritance diagram for oomph::SumOfMatrices:

Public Member Functions

 SumOfMatrices ()
 Default constructor. More...
 
 SumOfMatrices (DoubleMatrixBase *main_matrix_pt)
 Constructor taking a pointer to the main matrix as input. More...
 
 SumOfMatrices (const SumOfMatrices &matrix)=delete
 Broken copy constructor. More...
 
void operator= (const SumOfMatrices &)=delete
 Broken assignment operator. More...
 
 ~SumOfMatrices ()
 Destructor: delete matrices as instructed by Should_delete_added_matrix vector and Should_delete_main_matrix. More...
 
const DoubleMatrixBasemain_matrix_pt () const
 Access to the main matrix. More...
 
DoubleMatrixBase *& main_matrix_pt ()
 
void set_delete_main_matrix ()
 Set the main matrix to be deleted by the destructor of the SumOfMatrices (default is to not delete it). 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
 Output the matrix in sparse format. Note that this is going to be slow because we have to check every entry of every matrix for non-zeros. More...
 
void get_as_indices (Vector< int > &row, Vector< int > &col, Vector< double > &values)
 Get a list of row/col indices and total entry for non-zeros in the matrix. e.g. for use as input to other matrix classes. Warning this is SLOW! for sparse matrices. More...
 
void add_matrix (DoubleMatrixBase *added_matrix_pt_in, const AddedMainNumberingLookup *main_to_added_rows_pt, const AddedMainNumberingLookup *main_to_added_cols_pt, bool should_delete_matrix=false)
 Add a new matrix to the sum by giving a matrix pointer and a mapping from the main matrix numbering to the added matrix's numbering. More...
 
DoubleMatrixBaseadded_matrix_pt (const unsigned &i) const
 Access function for ith added matrix (main matrix not included in numbering). More...
 
const AddedMainNumberingLookuprow_map_pt (const unsigned &i) const
 Access to the maps. More...
 
const AddedMainNumberingLookupcol_map_pt (const unsigned &i) const
 
unsigned long nrow () const
 Return the number of rows of the main matrix. More...
 
unsigned long ncol () const
 Return the number of columns of the main matrix. More...
 
unsigned n_added_matrix () const
 Return the number of added matrices in the sum. More...
 
void multiply (const DoubleVector &x, DoubleVector &soln) const
 Multiply: just call multiply on each of the matrices and add up the results (with appropriate bookeeping of the relative positions). More...
 
double & entry (const unsigned long &i, const unsigned long &j) const
 Broken operator() because it does not make sense to return anything by reference. More...
 
double operator() (const unsigned long &i, const unsigned long &j) const
 Access function to get the total value of entries in position (i,j). Warning: this way of getting entries is far too slow to use inside of loops. More...
 
virtual void multiply_transpose (const DoubleVector &x, DoubleVector &soln) const
 Dummy overload of a pure virtual function. I'm not sure how best to implement this and I don't think I need it. 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::Matrix< double, SumOfMatrices >
 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...
 
double 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...
 
double & 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

DoubleMatrixBaseMain_matrix_pt
 Pointer to the matrix which we are adding the others to. More...
 
Vector< DoubleMatrixBase * > Added_matrix_pt
 List of pointers to the matrices that are added to the main matrix. More...
 
Vector< const AddedMainNumberingLookup * > Row_map_pt
 List of maps between row numbers of the main matrix and the added matrices. More...
 
Vector< const AddedMainNumberingLookup * > Col_map_pt
 List of maps between col numbers of the main matrix and the added matrices. More...
 
Vector< unsigned > Should_delete_added_matrix
 Should we delete the sub matrices when destructor is called? More...
 
bool Should_delete_main_matrix
 Should we delete the main matrix when destructor is called? Default is no. More...
 

Additional Inherited Members

- Protected Member Functions inherited from oomph::Matrix< double, SumOfMatrices >
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
LinearSolverLinear_solver_pt
 
LinearSolverDefault_linear_solver_pt
 

Detailed Description

Class for a matrix of the form M = S + G + H + ... where S is the main matrix and G,H etc. are matrices of size S or smaller. This may be useful if, for example, G,H etc. are subblocks of M that must be stored in a different format to S.

Maps mut be provided which gives a map from the rows/cols of the main matrix to the rows/cols of each of the added matrices.

Definition at line 260 of file sum_of_matrices.h.

Constructor & Destructor Documentation

◆ SumOfMatrices() [1/3]

oomph::SumOfMatrices::SumOfMatrices ( )
inline

Default constructor.

Definition at line 287 of file sum_of_matrices.h.

◆ SumOfMatrices() [2/3]

oomph::SumOfMatrices::SumOfMatrices ( DoubleMatrixBase main_matrix_pt)
inline

Constructor taking a pointer to the main matrix as input.

Definition at line 298 of file sum_of_matrices.h.

◆ SumOfMatrices() [3/3]

oomph::SumOfMatrices::SumOfMatrices ( const SumOfMatrices matrix)
delete

Broken copy constructor.

◆ ~SumOfMatrices()

oomph::SumOfMatrices::~SumOfMatrices ( )
inline

Destructor: delete matrices as instructed by Should_delete_added_matrix vector and Should_delete_main_matrix.

Definition at line 316 of file sum_of_matrices.h.

Member Function Documentation

◆ add_matrix()

void oomph::SumOfMatrices::add_matrix ( DoubleMatrixBase added_matrix_pt_in,
const AddedMainNumberingLookup main_to_added_rows_pt,
const AddedMainNumberingLookup main_to_added_cols_pt,
bool  should_delete_matrix = false 
)
inline

Add a new matrix to the sum by giving a matrix pointer and a mapping from the main matrix numbering to the added matrix's numbering.

Definition at line 415 of file sum_of_matrices.h.

References oomph::AddedMainNumberingLookup::added_to_main_mapping_pt(), oomph::AddedMainNumberingLookup::main_to_added_mapping_pt(), oomph::DoubleMatrixBase::ncol(), oomph::DoubleMatrixBase::nrow(), oomph::Global_string_for_annotation::string(), and oomph::StringConversion::to_string().

◆ added_matrix_pt()

DoubleMatrixBase* oomph::SumOfMatrices::added_matrix_pt ( const unsigned &  i) const
inline

Access function for ith added matrix (main matrix not included in numbering).

Definition at line 485 of file sum_of_matrices.h.

References i.

Referenced by multiply().

◆ col_map_pt()

const AddedMainNumberingLookup* oomph::SumOfMatrices::col_map_pt ( const unsigned &  i) const
inline

Definition at line 495 of file sum_of_matrices.h.

References i.

◆ entry()

double& oomph::SumOfMatrices::entry ( const unsigned long &  i,
const unsigned long &  j 
) const
inline

Broken operator() because it does not make sense to return anything by reference.

Definition at line 540 of file sum_of_matrices.h.

◆ get_as_indices()

void oomph::SumOfMatrices::get_as_indices ( Vector< int > &  row,
Vector< int > &  col,
Vector< double > &  values 
)
inline

Get a list of row/col indices and total entry for non-zeros in the matrix. e.g. for use as input to other matrix classes. Warning this is SLOW! for sparse matrices.

Definition at line 389 of file sum_of_matrices.h.

References i.

◆ main_matrix_pt() [1/2]

DoubleMatrixBase*& oomph::SumOfMatrices::main_matrix_pt ( )
inline

Definition at line 337 of file sum_of_matrices.h.

◆ main_matrix_pt() [2/2]

const DoubleMatrixBase* oomph::SumOfMatrices::main_matrix_pt ( ) const
inline

Access to the main matrix.

Definition at line 333 of file sum_of_matrices.h.

◆ multiply()

void oomph::SumOfMatrices::multiply ( const DoubleVector x,
DoubleVector soln 
) const
virtual

Multiply: just call multiply on each of the matrices and add up the results (with appropriate bookeeping of the relative positions).

Matrix-vector multiplication for a sumofmatrices class. Just delegate each multiplication to the appropriate class then add up the results.

Implements oomph::DoubleMatrixBase.

Definition at line 40 of file sum_of_matrices.cc.

References Added_matrix_pt, added_matrix_pt(), oomph::LinearAlgebraDistribution::build(), Col_map_pt, Main_matrix_pt, oomph::DoubleMatrixBase::multiply(), ncol(), nrow(), and Row_map_pt.

◆ multiply_transpose()

virtual void oomph::SumOfMatrices::multiply_transpose ( const DoubleVector x,
DoubleVector soln 
) const
inlinevirtual

Dummy overload of a pure virtual function. I'm not sure how best to implement this and I don't think I need it.

Implements oomph::DoubleMatrixBase.

Definition at line 573 of file sum_of_matrices.h.

◆ n_added_matrix()

unsigned oomph::SumOfMatrices::n_added_matrix ( ) const
inline

Return the number of added matrices in the sum.

Definition at line 529 of file sum_of_matrices.h.

◆ ncol()

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

Return the number of columns of the main matrix.

Implements oomph::DoubleMatrixBase.

Definition at line 515 of file sum_of_matrices.h.

References oomph::DoubleMatrixBase::ncol().

Referenced by multiply().

◆ nrow()

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

Return the number of rows of the main matrix.

Implements oomph::DoubleMatrixBase.

Definition at line 501 of file sum_of_matrices.h.

References oomph::DoubleMatrixBase::nrow().

Referenced by multiply().

◆ operator()()

double oomph::SumOfMatrices::operator() ( const unsigned long &  i,
const unsigned long &  j 
) const
inlinevirtual

Access function to get the total value of entries in position (i,j). Warning: this way of getting entries is far too slow to use inside of loops.

Implements oomph::DoubleMatrixBase.

Definition at line 552 of file sum_of_matrices.h.

References i.

◆ operator=()

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

Broken assignment operator.

◆ output_bottom_right_zero_helper()

void oomph::SumOfMatrices::output_bottom_right_zero_helper ( std::ostream &  outfile) const
inlinevirtual

Output the "bottom right" entry regardless of it being zero or not (this allows automatic detection of matrix size in e.g. matlab, python).

Implements oomph::Matrix< double, SumOfMatrices >.

Definition at line 353 of file sum_of_matrices.h.

◆ row_map_pt()

const AddedMainNumberingLookup* oomph::SumOfMatrices::row_map_pt ( const unsigned &  i) const
inline

Access to the maps.

Definition at line 491 of file sum_of_matrices.h.

References i.

◆ set_delete_main_matrix()

void oomph::SumOfMatrices::set_delete_main_matrix ( )
inline

Set the main matrix to be deleted by the destructor of the SumOfMatrices (default is to not delete it).

Definition at line 344 of file sum_of_matrices.h.

◆ sparse_indexed_output_helper()

void oomph::SumOfMatrices::sparse_indexed_output_helper ( std::ostream &  outfile) const
inlinevirtual

Output the matrix in sparse format. Note that this is going to be slow because we have to check every entry of every matrix for non-zeros.

Implements oomph::Matrix< double, SumOfMatrices >.

Definition at line 369 of file sum_of_matrices.h.

References i.

Member Data Documentation

◆ Added_matrix_pt

Vector<DoubleMatrixBase*> oomph::SumOfMatrices::Added_matrix_pt
private

List of pointers to the matrices that are added to the main matrix.

Definition at line 268 of file sum_of_matrices.h.

Referenced by multiply().

◆ Col_map_pt

Vector<const AddedMainNumberingLookup*> oomph::SumOfMatrices::Col_map_pt
private

List of maps between col numbers of the main matrix and the added matrices.

Definition at line 276 of file sum_of_matrices.h.

Referenced by multiply().

◆ Main_matrix_pt

DoubleMatrixBase* oomph::SumOfMatrices::Main_matrix_pt
private

Pointer to the matrix which we are adding the others to.

Definition at line 265 of file sum_of_matrices.h.

Referenced by multiply().

◆ Row_map_pt

Vector<const AddedMainNumberingLookup*> oomph::SumOfMatrices::Row_map_pt
private

List of maps between row numbers of the main matrix and the added matrices.

Definition at line 272 of file sum_of_matrices.h.

Referenced by multiply().

◆ Should_delete_added_matrix

Vector<unsigned> oomph::SumOfMatrices::Should_delete_added_matrix
private

Should we delete the sub matrices when destructor is called?

Definition at line 279 of file sum_of_matrices.h.

◆ Should_delete_main_matrix

bool oomph::SumOfMatrices::Should_delete_main_matrix
private

Should we delete the main matrix when destructor is called? Default is no.

Definition at line 283 of file sum_of_matrices.h.


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