diff --git a/MathLib/LinAlg/Lis/LisMatrix.cpp b/MathLib/LinAlg/Lis/LisMatrix.cpp index 99047c400214b94f1440ec48a215e35652fc59e7..1bd85c440d84ead22b1fecb4819f20f98fe49ff0 100644 --- a/MathLib/LinAlg/Lis/LisMatrix.cpp +++ b/MathLib/LinAlg/Lis/LisMatrix.cpp @@ -23,15 +23,15 @@ namespace MathLib { LisMatrix::LisMatrix(std::size_t n_rows, LisOption::MatrixType mat_type) - : _n_rows(n_rows), _mat_type(mat_type), _is_assembled(false) + : _n_rows(n_rows), _mat_type(mat_type), _is_assembled(false) { 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); - ierr = lis_vector_duplicate(_AA, &_diag); - checkLisError(ierr); + ierr = lis_vector_duplicate(_AA, &_diag); + checkLisError(ierr); } LisMatrix::~LisMatrix() @@ -44,83 +44,83 @@ LisMatrix::~LisMatrix() void LisMatrix::setZero() { - // A matrix has to be destroyed and created again because Lis doesn't provide a - // function to set matrix entries to zero - 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); - ierr = lis_vector_set_all(0.0, _diag); - checkLisError(ierr); - - _is_assembled = false; + // A matrix has to be destroyed and created again because Lis doesn't provide a + // function to set matrix entries to zero + 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); + ierr = lis_vector_set_all(0.0, _diag); + checkLisError(ierr); + + _is_assembled = false; } int LisMatrix::setValue(std::size_t rowId, std::size_t colId, double v) { - lis_matrix_set_value(LIS_INS_VALUE, rowId, colId, v, _AA); - if (rowId==colId) - lis_vector_set_value(LIS_INS_VALUE, rowId, v, _diag); - _is_assembled = false; - return 0; + lis_matrix_set_value(LIS_INS_VALUE, rowId, colId, v, _AA); + if (rowId==colId) + lis_vector_set_value(LIS_INS_VALUE, rowId, v, _diag); + _is_assembled = false; + return 0; } int LisMatrix::addValue(std::size_t rowId, std::size_t colId, double v) { - lis_matrix_set_value(LIS_ADD_VALUE, rowId, colId, v, _AA); - if (rowId==colId) - lis_vector_set_value(LIS_ADD_VALUE, rowId, v, _diag); - _is_assembled = false; - return 0; + lis_matrix_set_value(LIS_ADD_VALUE, rowId, colId, v, _AA); + if (rowId==colId) + lis_vector_set_value(LIS_ADD_VALUE, rowId, v, _diag); + _is_assembled = false; + return 0; } void LisMatrix::write(const std::string &filename) const { - if (!_is_assembled) - throw std::logic_error("LisMatrix::write(): matrix not assembled."); + if (!_is_assembled) + throw std::logic_error("LisMatrix::write(): matrix not assembled."); lis_output_matrix(_AA, LIS_FMT_MM, const_cast<char*>(filename.c_str())); } double LisMatrix::getMaxDiagCoeff() { - double abs_max_entry; - int ierr = lis_vector_get_value(_diag, 0, &abs_max_entry); - checkLisError(ierr); - abs_max_entry = std::abs(abs_max_entry); - for (std::size_t k(1); k<_n_rows; ++k) { - double tmp; - ierr = lis_vector_get_value(_diag, k, &tmp); - checkLisError(ierr); - if (abs_max_entry < std::abs(tmp)) { - abs_max_entry = std::abs(tmp); - } - } - - return abs_max_entry; + double abs_max_entry; + int ierr = lis_vector_get_value(_diag, 0, &abs_max_entry); + checkLisError(ierr); + abs_max_entry = std::abs(abs_max_entry); + for (std::size_t k(1); k<_n_rows; ++k) { + double tmp; + ierr = lis_vector_get_value(_diag, k, &tmp); + checkLisError(ierr); + if (abs_max_entry < std::abs(tmp)) { + abs_max_entry = std::abs(tmp); + } + } + + return abs_max_entry; } void LisMatrix::matvec (const LisVector &x, LisVector &y) const { - if (!_is_assembled) - throw std::logic_error("LisMatrix::matvec(): matrix not assembled."); + if (!_is_assembled) + throw std::logic_error("LisMatrix::matvec(): matrix not assembled."); int ierr = lis_matvec(_AA, const_cast<LisVector*>(&x)->getRawVector(), y.getRawVector()); checkLisError(ierr); } bool finalizeMatrixAssembly(LisMatrix &mat) { - LIS_MATRIX &A = mat.getRawMatrix(); - - if (!mat.isAssembled()) { - 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; - } - return true; + LIS_MATRIX &A = mat.getRawMatrix(); + + if (!mat.isAssembled()) { + 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; + } + return true; } diff --git a/MathLib/LinAlg/Lis/LisMatrix.h b/MathLib/LinAlg/Lis/LisMatrix.h index a362638e52f6fb35c72312b8f1882a8db7799f7b..110d43543ee82419624c56d86051fb785001f06a 100644 --- a/MathLib/LinAlg/Lis/LisMatrix.h +++ b/MathLib/LinAlg/Lis/LisMatrix.h @@ -98,7 +98,7 @@ private: std::size_t const _n_rows; LisOption::MatrixType const _mat_type; LIS_MATRIX _AA; - LIS_VECTOR _diag; + LIS_VECTOR _diag; bool _is_assembled; int _is; ///< location where the partial matrix _AA starts in global matrix. int _ie; ///< location where the partial matrix _AA ends in global matrix.