From 18ac2afc4ee3833efe2754d8a81f1cc4c8098dff Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Mon, 29 Jul 2013 13:26:12 +0200 Subject: [PATCH] Replace all addSubVector(), addValue() with add(). This helps with generalization when using essentially same concept of addition. --- MathLib/LinAlg/Dense/DenseVector.h | 2 +- MathLib/LinAlg/Dense/GlobalDenseMatrix.h | 8 ++++---- MathLib/LinAlg/Dense/GlobalDenseMatrix.tpp | 6 +++--- MathLib/LinAlg/Lis/LisMatrix.cpp | 2 +- MathLib/LinAlg/Lis/LisMatrix.h | 18 ++++++++++++++---- MathLib/LinAlg/Lis/LisVector.h | 2 +- Tests/MathLib/TestGlobalMatrixInterface.cpp | 4 ++-- Tests/MathLib/TestGlobalVectorInterface.cpp | 2 +- Tests/MathLib/TestLinearSolver.cpp | 2 +- 9 files changed, 28 insertions(+), 18 deletions(-) diff --git a/MathLib/LinAlg/Dense/DenseVector.h b/MathLib/LinAlg/Dense/DenseVector.h index 31a6ff7c8e7..1cf0f44c512 100644 --- a/MathLib/LinAlg/Dense/DenseVector.h +++ b/MathLib/LinAlg/Dense/DenseVector.h @@ -66,7 +66,7 @@ public: * @param sub_vec sub-vector */ template<class T_SUBVEC> - void addSubVector(const std::vector<std::size_t> &pos, const T_SUBVEC &sub_vec) + void add(const std::vector<std::size_t> &pos, const T_SUBVEC &sub_vec) { for (std::size_t i=0; i<pos.size(); ++i) { this->add(pos[i], sub_vec[i]); diff --git a/MathLib/LinAlg/Dense/GlobalDenseMatrix.h b/MathLib/LinAlg/Dense/GlobalDenseMatrix.h index 0c9bc24f243..35d3d656054 100644 --- a/MathLib/LinAlg/Dense/GlobalDenseMatrix.h +++ b/MathLib/LinAlg/Dense/GlobalDenseMatrix.h @@ -67,21 +67,21 @@ public: * @param val The value that shoud be added. * @return False if row index or column index are to large, else true. */ - virtual bool addValue(IDX_TYPE row, IDX_TYPE col, FP_TYPE val); + virtual bool add(IDX_TYPE row, IDX_TYPE col, FP_TYPE val); /// Add sub-matrix at positions \c row_pos and same column positions as the /// given row positions. template<class T_DENSE_MATRIX> - void addSubMatrix(std::vector<IDX_TYPE> const& row_pos, + void add(std::vector<IDX_TYPE> const& row_pos, const T_DENSE_MATRIX &sub_matrix, FP_TYPE fkt = static_cast<FP_TYPE>(1.0)) { - this->addSubMatrix(row_pos, row_pos, sub_matrix, fkt); + this->add(row_pos, row_pos, sub_matrix, fkt); } template<class T_DENSE_MATRIX> - void addSubMatrix(std::vector<IDX_TYPE> const& row_pos, + void add(std::vector<IDX_TYPE> const& row_pos, std::vector<IDX_TYPE> const& col_pos, const T_DENSE_MATRIX &sub_matrix, FP_TYPE fkt = static_cast<FP_TYPE>(1.0)); diff --git a/MathLib/LinAlg/Dense/GlobalDenseMatrix.tpp b/MathLib/LinAlg/Dense/GlobalDenseMatrix.tpp index a0b71ef6eee..2fbf20a3c86 100644 --- a/MathLib/LinAlg/Dense/GlobalDenseMatrix.tpp +++ b/MathLib/LinAlg/Dense/GlobalDenseMatrix.tpp @@ -50,7 +50,7 @@ GlobalDenseMatrix<FP_TYPE, IDX_TYPE>::setValue(IDX_TYPE row, IDX_TYPE col, FP_TY template<typename FP_TYPE, typename IDX_TYPE> bool -GlobalDenseMatrix<FP_TYPE, IDX_TYPE>::addValue(IDX_TYPE row, IDX_TYPE col, FP_TYPE val) +GlobalDenseMatrix<FP_TYPE, IDX_TYPE>::add(IDX_TYPE row, IDX_TYPE col, FP_TYPE val) { if (row >= this->_n_rows || col >= this->_n_cols) return false; @@ -61,7 +61,7 @@ GlobalDenseMatrix<FP_TYPE, IDX_TYPE>::addValue(IDX_TYPE row, IDX_TYPE col, FP_TY template<typename FP_TYPE, typename IDX_TYPE> template<class T_DENSE_MATRIX> void -GlobalDenseMatrix<FP_TYPE, IDX_TYPE>::addSubMatrix(std::vector<IDX_TYPE> const& row_pos, std::vector<IDX_TYPE> const& col_pos, +GlobalDenseMatrix<FP_TYPE, IDX_TYPE>::add(std::vector<IDX_TYPE> const& row_pos, std::vector<IDX_TYPE> const& col_pos, const T_DENSE_MATRIX &sub_matrix, FP_TYPE fkt) { if (row_pos.size() != sub_matrix.getNRows() || col_pos.size() != sub_matrix.getNCols()) @@ -73,7 +73,7 @@ GlobalDenseMatrix<FP_TYPE, IDX_TYPE>::addSubMatrix(std::vector<IDX_TYPE> const& const IDX_TYPE row = row_pos[i]; for (std::size_t j = 0; j < n_cols; j++) { const IDX_TYPE col = col_pos[j]; - addValue(row, col, fkt * sub_matrix(i, j)); + add(row, col, fkt * sub_matrix(i, j)); } } } diff --git a/MathLib/LinAlg/Lis/LisMatrix.cpp b/MathLib/LinAlg/Lis/LisMatrix.cpp index 1bd85c440d8..b5c3877681a 100644 --- a/MathLib/LinAlg/Lis/LisMatrix.cpp +++ b/MathLib/LinAlg/Lis/LisMatrix.cpp @@ -67,7 +67,7 @@ int LisMatrix::setValue(std::size_t rowId, std::size_t colId, double v) return 0; } -int LisMatrix::addValue(std::size_t rowId, std::size_t colId, double v) +int LisMatrix::add(std::size_t rowId, std::size_t colId, double v) { lis_matrix_set_value(LIS_ADD_VALUE, rowId, colId, v, _AA); if (rowId==colId) diff --git a/MathLib/LinAlg/Lis/LisMatrix.h b/MathLib/LinAlg/Lis/LisMatrix.h index 110d43543ee..415a4a5d627 100644 --- a/MathLib/LinAlg/Lis/LisMatrix.h +++ b/MathLib/LinAlg/Lis/LisMatrix.h @@ -68,7 +68,7 @@ public: 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); + int add(std::size_t rowId, std::size_t colId, double v); /// printout this equation for debugging void write(const std::string &filename) const; @@ -82,9 +82,19 @@ public: /// y = mat * x void matvec(const LisVector &x, LisVector &y) const; + /// Add sub-matrix at positions \c row_pos and same column positions as the + /// given row positions. + template<class T_DENSE_MATRIX> + void add(std::vector<std::size_t> const& row_pos, + const T_DENSE_MATRIX &sub_matrix, + double fkt = 1.0) + { + this->add(row_pos, row_pos, sub_matrix, fkt); + } + /// template <class T_DENSE_MATRIX> - void addSubMatrix(std::vector<std::size_t> const& row_pos, + void add(std::vector<std::size_t> const& row_pos, std::vector<std::size_t> const& col_pos, const T_DENSE_MATRIX &sub_matrix, double fkt = 1.0); @@ -109,7 +119,7 @@ private: template<class T_DENSE_MATRIX> void -LisMatrix::addSubMatrix(std::vector<std::size_t> const& row_pos, std::vector<std::size_t> const& col_pos, +LisMatrix::add(std::vector<std::size_t> const& row_pos, std::vector<std::size_t> const& col_pos, const T_DENSE_MATRIX &sub_matrix, double fkt) { if (row_pos.size() != sub_matrix.getNRows() || col_pos.size() != sub_matrix.getNCols()) @@ -121,7 +131,7 @@ LisMatrix::addSubMatrix(std::vector<std::size_t> const& row_pos, std::vector<std const std::size_t row = row_pos[i]; for (std::size_t j = 0; j < n_cols; j++) { const std::size_t col = col_pos[j]; - addValue(row, col, fkt * sub_matrix(i, j)); + add(row, col, fkt * sub_matrix(i, j)); } } }; diff --git a/MathLib/LinAlg/Lis/LisVector.h b/MathLib/LinAlg/Lis/LisVector.h index 99c8c25b351..3dfc8210318 100644 --- a/MathLib/LinAlg/Lis/LisVector.h +++ b/MathLib/LinAlg/Lis/LisVector.h @@ -96,7 +96,7 @@ public: /// template<class T_SUBVEC> - void addSubVector(const std::vector<std::size_t> &pos, const T_SUBVEC &sub_vec) + void add(const std::vector<std::size_t> &pos, const T_SUBVEC &sub_vec) { for (std::size_t i=0; i<pos.size(); ++i) { this->add(pos[i], sub_vec[i]); diff --git a/Tests/MathLib/TestGlobalMatrixInterface.cpp b/Tests/MathLib/TestGlobalMatrixInterface.cpp index 4a7c7805733..af254e9b99f 100644 --- a/Tests/MathLib/TestGlobalMatrixInterface.cpp +++ b/Tests/MathLib/TestGlobalMatrixInterface.cpp @@ -33,14 +33,14 @@ void checkGlobalMatrixInterface(T_MATRIX &m) ASSERT_EQ(10u, m.getRangeEnd()); m.setValue(0, 0, 1.0); - m.addValue(0, 0, 1.0); + m.add(0, 0, 1.0); m.setZero(); MathLib::DenseMatrix<double> local_m(2,2, 1.0); std::vector<std::size_t> vec_pos(2); vec_pos[0] = 1; vec_pos[1] = 3; - m.addSubMatrix(vec_pos, vec_pos, local_m); + m.add(vec_pos, vec_pos, local_m); ASSERT_TRUE(finalizeMatrixAssembly(m)); } diff --git a/Tests/MathLib/TestGlobalVectorInterface.cpp b/Tests/MathLib/TestGlobalVectorInterface.cpp index 2c494bb447d..8798b3c05fa 100644 --- a/Tests/MathLib/TestGlobalVectorInterface.cpp +++ b/Tests/MathLib/TestGlobalVectorInterface.cpp @@ -54,7 +54,7 @@ void checkGlobalVectorInterface() std::vector<std::size_t> vec_pos(2); vec_pos[0] = 0; vec_pos[1] = 3; - y.addSubVector(vec_pos, local_vec); + y.add(vec_pos, local_vec); ASSERT_EQ(3.0, y.get(0)); ASSERT_EQ(0.0, y.get(1)); ASSERT_EQ(1.0, y.get(3)); diff --git a/Tests/MathLib/TestLinearSolver.cpp b/Tests/MathLib/TestLinearSolver.cpp index d0754f8798b..f2e36064505 100644 --- a/Tests/MathLib/TestLinearSolver.cpp +++ b/Tests/MathLib/TestLinearSolver.cpp @@ -91,7 +91,7 @@ void checkLinearSolverInterface(T_MATRIX &A, boost::property_tree::ptree &ls_opt for (size_t j=0; j<ex1.dim_eqs; j++) { double v = ex1.mat(i, j); if (v!=.0) - A.addValue(i, j, v); + A.add(i, j, v); } } -- GitLab