From c5b3e9c3364cc6eb095cb3d475fb6e7b10cda64b Mon Sep 17 00:00:00 2001 From: Christoph Lehmann <christoph.lehmann@ufz.de> Date: Wed, 6 Jul 2016 20:10:12 +0200 Subject: [PATCH] [MaL] added get method --- MathLib/LinAlg/Eigen/EigenVector.h | 13 +++++++++++++ MathLib/LinAlg/PETSc/PETScVector.h | 16 +++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/MathLib/LinAlg/Eigen/EigenVector.h b/MathLib/LinAlg/Eigen/EigenVector.h index 667ff6ebfc1..a4fe75fb063 100644 --- a/MathLib/LinAlg/Eigen/EigenVector.h +++ b/MathLib/LinAlg/Eigen/EigenVector.h @@ -65,6 +65,19 @@ public: return _vec[rowId]; } + /// get entries + std::vector<double> get(std::vector<IndexType> const& indices) const + { + std::vector<double> local_x; + local_x.reserve(indices.size()); + + for (auto i : indices) { + local_x.emplace_back(_vec[i]); + } + + return local_x; + } + /// set entry void set(IndexType rowId, double v) { diff --git a/MathLib/LinAlg/PETSc/PETScVector.h b/MathLib/LinAlg/PETSc/PETScVector.h index 783e3f35593..74898df4db3 100644 --- a/MathLib/LinAlg/PETSc/PETScVector.h +++ b/MathLib/LinAlg/PETSc/PETScVector.h @@ -158,16 +158,14 @@ class PETScVector VecSetValues(_v, e_idxs.size(), &e_idxs[0], &sub_vec[0], INSERT_VALUES); } - /*! - Get several entries - \param e_idxs Indicies of entries to be gotten. - Note: std::size_t cannot be the type of e_idxs template argument - \param sub_vec Values of entries - */ - template<class T_SUBVEC> void get(const std::vector<PetscInt> &e_idxs, - T_SUBVEC &sub_vec) + //! Get several entries + std::vector<double> get(std::vector<IndexType> const& indices) const { - VecGetValues(_v, e_idxs.size(), &e_idxs[0], &sub_vec[0]); + std::vector<double> local_x(indices.size()); + + VecGetValues(_v, indices.size(), indices.data(), local_x.data()); + + return local_x; } // TODO preliminary -- GitLab