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

#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)
 Broken copy constructor. More...
 
void operator= (const SumOfMatrices &)
 Broken assignment operator. More...
 
 ~SumOfMatrices ()
 
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
 
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
 
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)
 Broken copy constructor. More...
 
void operator= (const DoubleMatrixBase &)
 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)
 Broken copy constructor. More...
 
void operator= (const Matrix &)
 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 266 of file sum_of_matrices.h.

Constructor & Destructor Documentation

oomph::SumOfMatrices::SumOfMatrices ( )
inline

Default constructor.

Definition at line 296 of file sum_of_matrices.h.

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

Constructor taking a pointer to the main matrix as input.

Definition at line 302 of file sum_of_matrices.h.

oomph::SumOfMatrices::SumOfMatrices ( const SumOfMatrices matrix)
inline

Broken copy constructor.

Definition at line 308 of file sum_of_matrices.h.

References oomph::BrokenCopy::broken_copy().

oomph::SumOfMatrices::~SumOfMatrices ( )
inline

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

Definition at line 317 of file sum_of_matrices.h.

Member Function Documentation

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 404 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().

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 464 of file sum_of_matrices.h.

References i.

Referenced by multiply().

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

Definition at line 470 of file sum_of_matrices.h.

References i.

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 508 of file sum_of_matrices.h.

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 381 of file sum_of_matrices.h.

References i.

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

Access to the main matrix.

Definition at line 331 of file sum_of_matrices.h.

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

Definition at line 332 of file sum_of_matrices.h.

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 45 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.

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 539 of file sum_of_matrices.h.

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

Return the number of added matrices in the sum.

Definition at line 500 of file sum_of_matrices.h.

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

Return the number of columns of the main matrix.

Implements oomph::DoubleMatrixBase.

Definition at line 487 of file sum_of_matrices.h.

Referenced by multiply().

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

Return the number of rows of the main matrix.

Implements oomph::DoubleMatrixBase.

Definition at line 474 of file sum_of_matrices.h.

Referenced by multiply().

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 517 of file sum_of_matrices.h.

References i.

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

Broken assignment operator.

Definition at line 312 of file sum_of_matrices.h.

References oomph::BrokenCopy::broken_assign().

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 343 of file sum_of_matrices.h.

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

Access to the maps.

Definition at line 468 of file sum_of_matrices.h.

References i.

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 336 of file sum_of_matrices.h.

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 360 of file sum_of_matrices.h.

References i.

Member Data Documentation

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

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

Definition at line 276 of file sum_of_matrices.h.

Referenced by multiply().

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 284 of file sum_of_matrices.h.

Referenced by multiply().

DoubleMatrixBase* oomph::SumOfMatrices::Main_matrix_pt
private

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

Definition at line 273 of file sum_of_matrices.h.

Referenced by multiply().

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 280 of file sum_of_matrices.h.

Referenced by multiply().

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

Should we delete the sub matrices when destructor is called?

Definition at line 287 of file sum_of_matrices.h.

bool oomph::SumOfMatrices::Should_delete_main_matrix
private

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

Definition at line 291 of file sum_of_matrices.h.


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