oomph::SparseMatrix< T, MATRIX_TYPE > Class Template Reference

#include <matrices.h>

+ Inheritance diagram for oomph::SparseMatrix< T, MATRIX_TYPE >:

Public Member Functions

 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...
 
Tvalue ()
 Access to C-style value array. More...
 
const Tvalue () 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...
 
virtual void output_bottom_right_zero_helper (std::ostream &outfile) const
 
virtual void sparse_indexed_output_helper (std::ostream &outfile) const
 
- 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
 
Toperator() (const unsigned long &i, const unsigned long &j)
 
virtual void output (std::ostream &outfile) const
 
void sparse_indexed_output (std::ostream &outfile, const unsigned &precision=0, const bool &output_bottom_right_zero=false) const
 
void sparse_indexed_output (std::string filename, const unsigned &precision=0, const bool &output_bottom_right_zero=false) const
 

Protected Attributes

TValue
 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

static T Zero = T(0)
 Dummy zero. 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
 

Detailed Description

template<class T, class MATRIX_TYPE>
class oomph::SparseMatrix< T, MATRIX_TYPE >

//////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// Class for sparse matrices, that store only the non-zero values in a linear array in memory. The details of the array indexing vary depending on the storage scheme used. The MATRIX_TYPE template parameter for use in the curious recursive template pattern is included and passed directly to the base Matrix class.

Constructor & Destructor Documentation

◆ SparseMatrix() [1/2]

template<class T , class MATRIX_TYPE >
oomph::SparseMatrix< T, MATRIX_TYPE >::SparseMatrix ( )
inline

Default constructor.

581 : Value(0), N(0), M(0), Nnz(0) {}
unsigned long Nnz
Number of non-zero values (i.e. size of Value array)
Definition: matrices.h:574
T * Value
Internal representation of the matrix values, a pointer.
Definition: matrices.h:565
unsigned long N
Number of rows.
Definition: matrices.h:568
unsigned long M
Number of columns.
Definition: matrices.h:571

◆ SparseMatrix() [2/2]

template<class T , class MATRIX_TYPE >
oomph::SparseMatrix< T, MATRIX_TYPE >::SparseMatrix ( const SparseMatrix< T, MATRIX_TYPE > &  source_matrix)
inline

Copy constructor.

585  {
586  // Number of nonzero entries
587  Nnz = source_matrix.nnz();
588 
589  // Number of rows
590  N = source_matrix.nrow();
591 
592  // Number of columns
593  M = source_matrix.ncol();
594 
595  // Values stored in C-style array
596  Value = new T[Nnz];
597 
598  // Assign the values
599  for (unsigned long i = 0; i < Nnz; i++)
600  {
601  Value[i] = source_matrix.value()[i];
602  }
603  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
const Scalar & value() const
Definition: SparseUtil.h:200

References i, oomph::SparseMatrix< T, MATRIX_TYPE >::N, oomph::SparseMatrix< T, MATRIX_TYPE >::ncol(), oomph::SparseMatrix< T, MATRIX_TYPE >::Nnz, oomph::SparseMatrix< T, MATRIX_TYPE >::nnz(), oomph::SparseMatrix< T, MATRIX_TYPE >::nrow(), oomph::SparseMatrix< T, MATRIX_TYPE >::Value, and oomph::SparseMatrix< T, MATRIX_TYPE >::value().

◆ ~SparseMatrix()

template<class T , class MATRIX_TYPE >
virtual oomph::SparseMatrix< T, MATRIX_TYPE >::~SparseMatrix ( )
inlinevirtual

Destructor, delete the memory associated with the values.

610  {
611  delete[] Value;
612  Value = 0;
613  }

References oomph::SparseMatrix< T, MATRIX_TYPE >::Value.

Member Function Documentation

◆ ncol()

template<class T , class MATRIX_TYPE >
unsigned long oomph::SparseMatrix< T, MATRIX_TYPE >::ncol ( ) const
inlinevirtual

Return the number of columns of the matrix.

Implements oomph::Matrix< T, MATRIX_TYPE >.

Reimplemented in oomph::CCDoubleMatrix.

635  {
636  return M;
637  }

References oomph::SparseMatrix< T, MATRIX_TYPE >::M.

Referenced by oomph::CRDoubleMatrix::ncol(), and oomph::SparseMatrix< T, MATRIX_TYPE >::SparseMatrix().

◆ nnz()

template<class T , class MATRIX_TYPE >
unsigned long oomph::SparseMatrix< T, MATRIX_TYPE >::nnz ( ) const
inline

◆ nrow()

template<class T , class MATRIX_TYPE >
unsigned long oomph::SparseMatrix< T, MATRIX_TYPE >::nrow ( ) const
inlinevirtual

Return the number of rows of the matrix.

Implements oomph::Matrix< T, MATRIX_TYPE >.

Reimplemented in oomph::CCDoubleMatrix.

629  {
630  return N;
631  }

References oomph::SparseMatrix< T, MATRIX_TYPE >::N.

Referenced by oomph::SparseMatrix< T, MATRIX_TYPE >::SparseMatrix().

◆ operator=()

template<class T , class MATRIX_TYPE >
void oomph::SparseMatrix< T, MATRIX_TYPE >::operator= ( const SparseMatrix< T, MATRIX_TYPE > &  )
delete

Broken assignment operator.

◆ output_bottom_right_zero_helper()

template<class T , class MATRIX_TYPE >
virtual void oomph::SparseMatrix< T, MATRIX_TYPE >::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< T, MATRIX_TYPE >.

Reimplemented in oomph::CCMatrix< T >, oomph::CCMatrix< double >, oomph::CCMatrix< std::complex< double > >, oomph::CRMatrix< T >, oomph::CRMatrix< double >, and oomph::CRMatrix< std::complex< double > >.

649  {
650  std::string error_message = "SparseMatrix::output_bottom_right_zero_"
651  "helper() is a virtual function.\n";
652  error_message +=
653  "It must be overloaded for specific sparse matrix storage formats\n";
654 
655  throw OomphLibError(
657  }
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and oomph::Global_string_for_annotation::string().

◆ sparse_indexed_output_helper()

template<class T , class MATRIX_TYPE >
virtual void oomph::SparseMatrix< T, MATRIX_TYPE >::sparse_indexed_output_helper ( std::ostream &  outfile) const
inlinevirtual

Indexed output function to print a matrix to the stream outfile as i,j,a(i,j) for a(i,j)!=0 only.

Implements oomph::Matrix< T, MATRIX_TYPE >.

Reimplemented in oomph::CCMatrix< T >, oomph::CCMatrix< double >, oomph::CCMatrix< std::complex< double > >, oomph::CRMatrix< T >, oomph::CRMatrix< double >, and oomph::CRMatrix< std::complex< double > >.

662  {
663  std::string error_message =
664  "SparseMatrix::sparse_indexed_output_helper() is a virtual function.\n";
665  error_message +=
666  "It must be overloaded for specific sparse matrix storage formats\n";
667 
668  throw OomphLibError(
670  }

References OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and oomph::Global_string_for_annotation::string().

◆ value() [1/2]

◆ value() [2/2]

template<class T , class MATRIX_TYPE >
const T* oomph::SparseMatrix< T, MATRIX_TYPE >::value ( ) const
inline

Access to C-style value array (const version)

623  {
624  return Value;
625  }

References oomph::SparseMatrix< T, MATRIX_TYPE >::Value.

Member Data Documentation

◆ M

◆ N

◆ Nnz

◆ Value

◆ Zero

template<class T , class MATRIX_TYPE >
T oomph::SparseMatrix< T, MATRIX_TYPE >::Zero = T(0)
staticprotected

Dummy zero.


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