Skip to content
Snippets Groups Projects
Commit c38cbb1b authored by Tom Fischer's avatar Tom Fischer
Browse files

Changes to cleanup class LisMatrix.

- Reformatted code
- Made docu more meaningful
- Changed name of first parameter of constructor
- Moved implementation of setValue() and getValue() from header into cpp-file
parent 664e6976
No related branches found
No related tags found
No related merge requests found
......@@ -20,33 +20,52 @@
namespace MathLib
{
LisMatrix::LisMatrix(std::size_t dimension, LisOption::MatrixType mat_type)
: _n_rows(dimension), _max_diag_coeff(.0), _mat_type(mat_type), _is_assembled(false)
LisMatrix::LisMatrix(std::size_t n_rows, LisOption::MatrixType mat_type)
: _n_rows(n_rows), _max_diag_coeff(.0), _mat_type(mat_type), _is_assembled(false)
{
int ierr = 0;
ierr = lis_matrix_create(0, &_AA); checkLisError(ierr);
ierr = lis_matrix_set_size(_AA, 0, dimension); checkLisError(ierr);
int ierr = lis_matrix_create(0, &_AA);
checkLisError(ierr);
ierr = lis_matrix_set_size(_AA, 0, n_rows);
checkLisError(ierr);
lis_matrix_get_range(_AA, &_is, &_ie);
}
LisMatrix::~LisMatrix()
{
int ierr = 0;
ierr = lis_matrix_destroy(_AA); checkLisError(ierr);
int ierr = lis_matrix_destroy(_AA);
checkLisError(ierr);
}
void LisMatrix::setZero()
{
int ierr = 0;
// A matrix has to be destroyed and created again because Lis doesn't provide a
// function to set matrix entries to zero
ierr = lis_matrix_destroy(_AA); checkLisError(ierr);
ierr = lis_matrix_create(0, &_AA); checkLisError(ierr);
ierr = lis_matrix_set_size(_AA, 0, _n_rows); checkLisError(ierr);
int ierr = lis_matrix_destroy(_AA);
checkLisError(ierr);
ierr = lis_matrix_create(0, &_AA);
checkLisError(ierr);
ierr = lis_matrix_set_size(_AA, 0, _n_rows);
checkLisError(ierr);
_max_diag_coeff = .0;
}
int LisMatrix::setValue(std::size_t rowId, std::size_t colId, double v)
{
if (rowId==colId)
_max_diag_coeff = std::max(_max_diag_coeff, std::abs(v));
lis_matrix_set_value(LIS_INS_VALUE, rowId, colId, v, _AA);
return 0;
}
int LisMatrix::addValue(std::size_t rowId, std::size_t colId, double v)
{
if (rowId==colId)
_max_diag_coeff = std::max(_max_diag_coeff, std::abs(v));
lis_matrix_set_value(LIS_ADD_VALUE, rowId, colId, v, _AA);
return 0;
}
void LisMatrix::write(const std::string &filename) const
{
lis_output_matrix(_AA, LIS_FMT_MM, const_cast<char*>(filename.c_str()));
......@@ -54,7 +73,8 @@ void LisMatrix::write(const std::string &filename) const
void LisMatrix::matvec (const LisVector &x, LisVector &y) const
{
int ierr = lis_matvec(_AA, const_cast<LisVector*>(&x)->getRawVector(), y.getRawVector()); checkLisError(ierr);
int ierr = lis_matvec(_AA, const_cast<LisVector*>(&x)->getRawVector(), y.getRawVector());
checkLisError(ierr);
}
bool finalizeMatrixAssembly(LisMatrix &mat)
......@@ -63,7 +83,8 @@ bool finalizeMatrixAssembly(LisMatrix &mat)
// commented out below because lis_matrix_is_assembled() always returns the same value.
// if (LIS_SUCCESS!=lis_matrix_is_assembled(A)) {
if (!mat.isAssembled()) {
int ierr = lis_matrix_set_type(A, static_cast<int>(mat.getMatrixType())); checkLisError(ierr);
int ierr = lis_matrix_set_type(A, static_cast<int>(mat.getMatrixType()));
checkLisError(ierr);
ierr = lis_matrix_assemble(A); //checkLisError(ierr);
mat._is_assembled = true;
}
......
......@@ -28,20 +28,21 @@ namespace MathLib
class LisVector;
/**
* \brief Lis matrix wrapper class
* \brief LisMatrix is a wrapper class for matrix types of the
* linear iterative solvers library.
*
* Lis matrix only supports a regular matrix, i.e. the number of
* rows should equal to the number of columns.
* LisMatrix only supports square matrices, i.e. the number of
* rows have to be equal to the number of columns.
*/
class LisMatrix
{
public:
/**
* constructor
* @param length
* @param n_rows the number of rows (that is equal to the number of columns)
* @param mat_type default 1 CRS
*/
LisMatrix(std::size_t length, LisOption::MatrixType mat_type = LisOption::MatrixType::CRS);
LisMatrix(std::size_t n_rows, LisOption::MatrixType mat_type = LisOption::MatrixType::CRS);
/**
*
......@@ -64,22 +65,10 @@ public:
void setZero();
/// set entry
int setValue(std::size_t rowId, std::size_t colId, double v)
{
if (rowId==colId)
_max_diag_coeff = std::max(_max_diag_coeff, std::abs(v));
lis_matrix_set_value(LIS_INS_VALUE, rowId, colId, v, _AA);
return 0;
}
int setValue(std::size_t rowId, std::size_t colId, double v);
/// add value
int addValue(std::size_t rowId, std::size_t colId, double v)
{
if (rowId==colId)
_max_diag_coeff = std::max(_max_diag_coeff, std::abs(v));
lis_matrix_set_value(LIS_ADD_VALUE, rowId, colId, v, _AA);
return 0;
}
int addValue(std::size_t rowId, std::size_t colId, double v);
/// printout this equation for debugging
void write(const std::string &filename) const;
......@@ -91,7 +80,7 @@ public:
LIS_MATRIX& getRawMatrix() { return _AA; };
/// y = mat * x
void matvec ( const LisVector &x, LisVector &y) const;
void matvec(const LisVector &x, LisVector &y) const;
///
template <class T_DENSE_MATRIX>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment