OGS
MathLib::LisMatrix Class Reference

Detailed Description

LisMatrix is a wrapper class for matrix types of the linear iterative solvers library.

LisMatrix only supports square matrices, i.e. the number of rows have to be equal to the number of columns.

Definition at line 43 of file LisMatrix.h.

#include <LisMatrix.h>

Public Types

enum class  MatrixType : int {
  CRS = 1 , CCS = 2 , MSR = 3 , DIA = 4 ,
  ELL = 5 , JDS = 6 , BSR = 7 , BSC = 8 ,
  VBR = 9 , COO = 10 , DNS = 11
}
 Matrix type. More...
 
using IndexType = LIS_INT
 

Public Member Functions

 LisMatrix (std::size_t n_rows, MatrixType mat_type=MatrixType::CRS)
 
 LisMatrix (std::size_t n_rows, int nonzero, IndexType *row_ptr, IndexType *col_idx, double *data)
 
virtual ~LisMatrix ()
 
std::size_t getNumberOfRows () const
 return the number of rows
 
std::size_t getNumberOfColumns () const
 return the number of columns
 
std::size_t getRangeBegin () const
 return a start index of the active data range
 
std::size_t getRangeEnd () const
 return an end index of the active data range
 
void setZero ()
 reset this matrix with keeping its original dimension
 
int setValue (IndexType rowId, IndexType colId, double v)
 set entry
 
int add (IndexType rowId, IndexType colId, double v)
 add value
 
void write (const std::string &filename) const
 printout this equation for debugging
 
LIS_MATRIX & getRawMatrix ()
 return a raw Lis matrix object
 
template<class T_DENSE_MATRIX >
void add (std::vector< IndexType > const &row_pos, const T_DENSE_MATRIX &sub_matrix, double fkt=1.0)
 
template<class T_DENSE_MATRIX >
void add (RowColumnIndices< IndexType > const &indices, const T_DENSE_MATRIX &sub_matrix, double fkt=1.0)
 Add sub-matrix at positions given by indices.
 
template<class T_DENSE_MATRIX >
void add (std::vector< IndexType > const &row_pos, std::vector< IndexType > const &col_pos, const T_DENSE_MATRIX &sub_matrix, double fkt=1.0)
 
MatrixType getMatrixType () const
 get this matrix type
 
bool isAssembled () const
 return if this matrix is already assembled or not
 

Private Attributes

std::size_t const n_rows_
 
MatrixType const mat_type_
 
LIS_MATRIX AA_
 
LIS_VECTOR diag_
 
bool is_assembled_
 
IndexType is_
 
IndexType ie_
 location where the partial matrix AA_ ends in global matrix.
 
bool use_external_arrays_
 

Friends

template<typename MATRIX , typename SPARSITY_PATTERN >
struct SetMatrixSparsity
 
bool finalizeMatrixAssembly (LisMatrix &mat)
 finish assembly to make this matrix be ready for use
 

Member Typedef Documentation

◆ IndexType

Definition at line 62 of file LisMatrix.h.

Member Enumeration Documentation

◆ MatrixType

enum class MathLib::LisMatrix::MatrixType : int
strong

Matrix type.

Enumerator
CRS 
CCS 
MSR 
DIA 
ELL 
JDS 
BSR 
BSC 
VBR 
COO 
DNS 

Definition at line 47 of file LisMatrix.h.

Constructor & Destructor Documentation

◆ LisMatrix() [1/2]

MathLib::LisMatrix::LisMatrix ( std::size_t n_rows,
MatrixType mat_type = MatrixType::CRS )

constructor

Parameters
n_rowsthe number of rows (that is equal to the number of columns)
mat_typedefault 1 CRS

Definition at line 26 of file LisMatrix.cpp.

27 : n_rows_(n_rows),
28 mat_type_(mat_type),
29 is_assembled_(false),
31{
32 int ierr = lis_matrix_create(0, &AA_);
33 checkLisError(ierr);
34 ierr = lis_matrix_set_size(AA_, 0, n_rows);
35 checkLisError(ierr);
36 lis_matrix_get_range(AA_, &is_, &ie_);
37 ierr = lis_vector_duplicate(AA_, &diag_);
38 checkLisError(ierr);
39}
IndexType ie_
location where the partial matrix AA_ ends in global matrix.
Definition LisMatrix.h:155
std::size_t const n_rows_
Definition LisMatrix.h:147
LIS_VECTOR diag_
Definition LisMatrix.h:150
MatrixType const mat_type_
Definition LisMatrix.h:148
bool checkLisError(int err)
Definition LisCheck.h:31

References AA_, MathLib::checkLisError(), diag_, ie_, and is_.

◆ LisMatrix() [2/2]

MathLib::LisMatrix::LisMatrix ( std::size_t n_rows,
int nonzero,
IndexType * row_ptr,
IndexType * col_idx,
double * data )

constructor using raw CRS data

Note that the given CRS data will not be deleted in this class.

Parameters
n_rowsthe number of rows
nonzerothe number of non zero entries
row_ptrarray of row pointer indexes
col_idxarray of column indexes
datathe non-zero entry values

Definition at line 41 of file LisMatrix.cpp.

43 : n_rows_(n_rows),
45 is_assembled_(false),
47{
48 int ierr = lis_matrix_create(0, &AA_);
49 checkLisError(ierr);
50 ierr = lis_matrix_set_size(AA_, 0, n_rows);
51 checkLisError(ierr);
52 ierr = lis_matrix_set_csr(nnz, row_ptr, col_idx, data, AA_);
53 checkLisError(ierr);
54 ierr = lis_matrix_assemble(AA_);
55 checkLisError(ierr);
56 is_assembled_ = true;
57 lis_matrix_get_range(AA_, &is_, &ie_);
58 ierr = lis_vector_duplicate(AA_, &diag_);
59 checkLisError(ierr);
60}

References AA_, MathLib::checkLisError(), diag_, ie_, is_, and is_assembled_.

◆ ~LisMatrix()

MathLib::LisMatrix::~LisMatrix ( )
virtual

Definition at line 62 of file LisMatrix.cpp.

63{
64 int ierr = 0;
66 {
67 ierr = lis_matrix_unset(AA_);
68 checkLisError(ierr);
69 }
70 ierr = lis_matrix_destroy(AA_);
71 checkLisError(ierr);
72 ierr = lis_vector_destroy(diag_);
73 checkLisError(ierr);
74}

References AA_, MathLib::checkLisError(), diag_, and use_external_arrays_.

Member Function Documentation

◆ add() [1/4]

int MathLib::LisMatrix::add ( IndexType rowId,
IndexType colId,
double v )

add value

Definition at line 103 of file LisMatrix.cpp.

104{
105 if (v == 0.0)
106 return 0;
107 lis_matrix_set_value(LIS_ADD_VALUE, rowId, colId, v, AA_);
108 if (rowId == colId)
109 lis_vector_set_value(LIS_ADD_VALUE, rowId, v, diag_);
110 is_assembled_ = false;
111 return 0;
112}
static const double v

References AA_, diag_, is_assembled_, and MathLib::v.

Referenced by add(), add(), and add().

◆ add() [2/4]

template<class T_DENSE_MATRIX >
void MathLib::LisMatrix::add ( RowColumnIndices< IndexType > const & indices,
const T_DENSE_MATRIX & sub_matrix,
double fkt = 1.0 )
inline

Add sub-matrix at positions given by indices.

Definition at line 128 of file LisMatrix.h.

131 {
132 this->add(indices.rows, indices.columns, sub_matrix, fkt);
133 }
int add(IndexType rowId, IndexType colId, double v)
add value

References add(), MathLib::RowColumnIndices< IDX_TYPE >::columns, and MathLib::RowColumnIndices< IDX_TYPE >::rows.

◆ add() [3/4]

template<class T_DENSE_MATRIX >
void MathLib::LisMatrix::add ( std::vector< IndexType > const & row_pos,
const T_DENSE_MATRIX & sub_matrix,
double fkt = 1.0 )
inline

Add sub-matrix at positions row_pos and same column positions as the given row positions.

Definition at line 119 of file LisMatrix.h.

122 {
123 this->add(row_pos, row_pos, sub_matrix, fkt);
124 }

References add().

◆ add() [4/4]

template<class T_DENSE_MATRIX >
void MathLib::LisMatrix::add ( std::vector< IndexType > const & row_pos,
std::vector< IndexType > const & col_pos,
const T_DENSE_MATRIX & sub_matrix,
double fkt = 1.0 )

Definition at line 166 of file LisMatrix.h.

169{
170 auto const n_rows = row_pos.size();
171 auto const n_cols = col_pos.size();
172 for (auto i = decltype(n_rows){0}; i < n_rows; i++)
173 {
174 auto const row = row_pos[i];
175 for (auto j = decltype(n_cols){0}; j < n_cols; j++)
176 {
177 auto const col = col_pos[j];
178 add(row, col, fkt * sub_matrix(i, j));
179 }
180 }
181};

References add().

◆ getMatrixType()

MatrixType MathLib::LisMatrix::getMatrixType ( ) const
inline

get this matrix type

Definition at line 141 of file LisMatrix.h.

141{ return mat_type_; }

References mat_type_.

◆ getNumberOfColumns()

std::size_t MathLib::LisMatrix::getNumberOfColumns ( ) const
inline

return the number of columns

Definition at line 93 of file LisMatrix.h.

93{ return getNumberOfRows(); }
std::size_t getNumberOfRows() const
return the number of rows
Definition LisMatrix.h:90

References getNumberOfRows().

◆ getNumberOfRows()

std::size_t MathLib::LisMatrix::getNumberOfRows ( ) const
inline

return the number of rows

Definition at line 90 of file LisMatrix.h.

90{ return n_rows_; }

References n_rows_.

Referenced by getNumberOfColumns(), and MathLib::SetMatrixSparsity< LisMatrix, SPARSITY_PATTERN >::operator()().

◆ getRangeBegin()

std::size_t MathLib::LisMatrix::getRangeBegin ( ) const
inline

return a start index of the active data range

Definition at line 96 of file LisMatrix.h.

96{ return is_; }

References is_.

◆ getRangeEnd()

std::size_t MathLib::LisMatrix::getRangeEnd ( ) const
inline

return an end index of the active data range

Definition at line 99 of file LisMatrix.h.

99{ return ie_; }

References ie_.

◆ getRawMatrix()

LIS_MATRIX & MathLib::LisMatrix::getRawMatrix ( )
inline

return a raw Lis matrix object

Definition at line 114 of file LisMatrix.h.

114{ return AA_; }

References AA_.

Referenced by MathLib::EigenLisLinearSolver::solve().

◆ isAssembled()

bool MathLib::LisMatrix::isAssembled ( ) const
inline

return if this matrix is already assembled or not

Definition at line 144 of file LisMatrix.h.

144{ return is_assembled_; }

References is_assembled_.

◆ setValue()

int MathLib::LisMatrix::setValue ( IndexType rowId,
IndexType colId,
double v )

set entry

Definition at line 92 of file LisMatrix.cpp.

93{
94 if (v == 0.0)
95 return 0;
96 lis_matrix_set_value(LIS_INS_VALUE, rowId, colId, v, AA_);
97 if (rowId == colId)
98 lis_vector_set_value(LIS_INS_VALUE, rowId, v, diag_);
99 is_assembled_ = false;
100 return 0;
101}

References AA_, diag_, is_assembled_, and MathLib::v.

◆ setZero()

void MathLib::LisMatrix::setZero ( )

reset this matrix with keeping its original dimension

Definition at line 76 of file LisMatrix.cpp.

77{
78 // A matrix has to be destroyed and created again because Lis doesn't
79 // provide a function to set matrix entries to zero
80 int ierr = lis_matrix_destroy(AA_);
81 checkLisError(ierr);
82 ierr = lis_matrix_create(0, &AA_);
83 checkLisError(ierr);
84 ierr = lis_matrix_set_size(AA_, 0, n_rows_);
85 checkLisError(ierr);
86 ierr = lis_vector_set_all(0.0, diag_);
87 checkLisError(ierr);
88
89 is_assembled_ = false;
90}

References AA_, MathLib::checkLisError(), diag_, is_assembled_, and n_rows_.

◆ write()

void MathLib::LisMatrix::write ( const std::string & filename) const

printout this equation for debugging

Definition at line 114 of file LisMatrix.cpp.

115{
116 if (!is_assembled_)
117 {
118 OGS_FATAL("LisMatrix::write(): matrix not assembled.");
119 }
120 lis_output_matrix(AA_, LIS_FMT_MM, const_cast<char*>(filename.c_str()));
121}
#define OGS_FATAL(...)
Definition Error.h:26

References AA_, is_assembled_, and OGS_FATAL.

Friends And Related Symbol Documentation

◆ finalizeMatrixAssembly

bool finalizeMatrixAssembly ( LisMatrix & mat)
friend

finish assembly to make this matrix be ready for use

Definition at line 123 of file LisMatrix.cpp.

124{
125 LIS_MATRIX& A = mat.getRawMatrix();
126
127 if (!mat.isAssembled())
128 {
129 int ierr =
130 lis_matrix_set_type(A, static_cast<int>(mat.getMatrixType()));
131 checkLisError(ierr);
132 ierr = lis_matrix_assemble(A);
133 checkLisError(ierr);
134 mat.is_assembled_ = true;
135 }
136 return true;
137}

◆ SetMatrixSparsity

template<typename MATRIX , typename SPARSITY_PATTERN >
friend struct SetMatrixSparsity
friend

Definition at line 162 of file LisMatrix.h.

Member Data Documentation

◆ AA_

LIS_MATRIX MathLib::LisMatrix::AA_
private

◆ diag_

LIS_VECTOR MathLib::LisMatrix::diag_
private

Definition at line 150 of file LisMatrix.h.

Referenced by LisMatrix(), LisMatrix(), ~LisMatrix(), add(), setValue(), and setZero().

◆ ie_

IndexType MathLib::LisMatrix::ie_
private

location where the partial matrix AA_ ends in global matrix.

Definition at line 155 of file LisMatrix.h.

Referenced by LisMatrix(), LisMatrix(), and getRangeEnd().

◆ is_

IndexType MathLib::LisMatrix::is_
private

location where the partial matrix AA_ starts in global matrix.

Definition at line 152 of file LisMatrix.h.

Referenced by LisMatrix(), LisMatrix(), and getRangeBegin().

◆ is_assembled_

bool MathLib::LisMatrix::is_assembled_
private

Definition at line 151 of file LisMatrix.h.

Referenced by LisMatrix(), add(), isAssembled(), setValue(), setZero(), and write().

◆ mat_type_

MatrixType const MathLib::LisMatrix::mat_type_
private

Definition at line 148 of file LisMatrix.h.

Referenced by getMatrixType().

◆ n_rows_

std::size_t const MathLib::LisMatrix::n_rows_
private

Definition at line 147 of file LisMatrix.h.

Referenced by getNumberOfRows(), and setZero().

◆ use_external_arrays_

bool MathLib::LisMatrix::use_external_arrays_
private

Definition at line 156 of file LisMatrix.h.

Referenced by ~LisMatrix().


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