Chi-Tech
chi_math::SparseMatrix Class Reference

#include <chi_math_sparse_matrix.h>

Data Structures

struct  ConstEntryReference
 
class  ConstRowIteratorContext
 
class  EntriesIterator
 
struct  EntryReference
 
class  RowIteratorContext
 

Public Member Functions

 SparseMatrix (size_t num_rows, size_t num_cols)
 
 SparseMatrix (const SparseMatrix &in_matrix)
 
size_t NumRows () const
 
size_t NumCols () const
 
void Insert (size_t i, size_t j, double value)
 
void InsertAdd (size_t i, size_t j, double value)
 
double ValueIJ (size_t i, size_t j) const
 
void SetDiagonal (const std::vector< double > &diag)
 
void Compress ()
 
std::string PrintStr () const
 
virtual ~SparseMatrix ()=default
 
RowIteratorContext Row (size_t row_id)
 
ConstRowIteratorContext Row (size_t row_id) const
 
EntriesIterator begin ()
 
EntriesIterator end ()
 

Data Fields

std::vector< std::vector< size_t > > rowI_indices_
 
std::vector< std::vector< double > > rowI_values_
 

Private Member Functions

void CheckInitialized () const
 

Private Attributes

size_t row_size_
 Maximum number of rows for this matrix. More...
 
size_t col_size_
 Maximum number of columns for this matrix. More...
 

Detailed Description

Sparse matrix utility. This is a basic CSR type sparse matrix which allows efficient matrix storage and multiplication. It is not intended for solving linear systems (use PETSc for that instead). It was originally developed for the transfer matrices of transport cross-sections.

Definition at line 12 of file chi_math_sparse_matrix.h.

Constructor & Destructor Documentation

◆ SparseMatrix() [1/2]

chi_math::SparseMatrix::SparseMatrix ( size_t  num_rows,
size_t  num_cols 
)

Constructor with number of rows and columns constructor.

Definition at line 11 of file chi_math_sparse_matrix.cc.

◆ SparseMatrix() [2/2]

chi_math::SparseMatrix::SparseMatrix ( const SparseMatrix in_matrix)

Copy constructor.

Definition at line 21 of file chi_math_sparse_matrix.cc.

◆ ~SparseMatrix()

virtual chi_math::SparseMatrix::~SparseMatrix ( )
virtualdefault

Member Function Documentation

◆ begin()

SparseMatrix::EntriesIterator chi_math::SparseMatrix::begin ( )

Definition at line 270 of file chi_math_sparse_matrix.cc.

◆ CheckInitialized()

void chi_math::SparseMatrix::CheckInitialized ( ) const
private

Constructor with number of rows constructor.

Definition at line 250 of file chi_math_sparse_matrix.cc.

◆ Compress()

void chi_math::SparseMatrix::Compress ( )

Sorts the column indices of each row for faster lookup.

Definition at line 166 of file chi_math_sparse_matrix.cc.

◆ end()

SparseMatrix::EntriesIterator chi_math::SparseMatrix::end ( )

Definition at line 281 of file chi_math_sparse_matrix.cc.

◆ Insert()

void chi_math::SparseMatrix::Insert ( size_t  i,
size_t  j,
double  value 
)

Inserts a value into the matrix.

Definition at line 38 of file chi_math_sparse_matrix.cc.

◆ InsertAdd()

void chi_math::SparseMatrix::InsertAdd ( size_t  i,
size_t  j,
double  value 
)

Inserts-Adds a value into the matrix with duplicate check.

Definition at line 69 of file chi_math_sparse_matrix.cc.

◆ NumCols()

size_t chi_math::SparseMatrix::NumCols ( ) const
inline

Definition at line 31 of file chi_math_sparse_matrix.h.

◆ NumRows()

size_t chi_math::SparseMatrix::NumRows ( ) const
inline

Definition at line 30 of file chi_math_sparse_matrix.h.

◆ PrintStr()

std::string chi_math::SparseMatrix::PrintStr ( ) const

Prints the sparse matrix to string.

Definition at line 211 of file chi_math_sparse_matrix.cc.

◆ Row() [1/2]

SparseMatrix::RowIteratorContext chi_math::SparseMatrix::Row ( size_t  row_id)

Definition at line 264 of file chi_math_sparse_matrix.cc.

◆ Row() [2/2]

SparseMatrix::ConstRowIteratorContext chi_math::SparseMatrix::Row ( size_t  row_id) const

Definition at line 267 of file chi_math_sparse_matrix.cc.

◆ SetDiagonal()

void chi_math::SparseMatrix::SetDiagonal ( const std::vector< double > &  diag)

Sets the diagonal of the matrix using a vector.

Definition at line 100 of file chi_math_sparse_matrix.cc.

◆ ValueIJ()

double chi_math::SparseMatrix::ValueIJ ( size_t  i,
size_t  j 
) const

Returns the value in the matrix at the given location. This is a rather inefficient routine. Use the columns and values rather than directly this function.

Definition at line 138 of file chi_math_sparse_matrix.cc.

Field Documentation

◆ col_size_

size_t chi_math::SparseMatrix::col_size_
private

Maximum number of columns for this matrix.

Definition at line 16 of file chi_math_sparse_matrix.h.

◆ row_size_

size_t chi_math::SparseMatrix::row_size_
private

Maximum number of rows for this matrix.

Definition at line 15 of file chi_math_sparse_matrix.h.

◆ rowI_indices_

std::vector<std::vector<size_t> > chi_math::SparseMatrix::rowI_indices_

rowI_indices[i] is a vector indices j for the non-zero columns.

Definition at line 21 of file chi_math_sparse_matrix.h.

◆ rowI_values_

std::vector<std::vector<double> > chi_math::SparseMatrix::rowI_values_

rowI_values[i] corresponds to column indices and contains the non-zero value.

Definition at line 24 of file chi_math_sparse_matrix.h.


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