diff --git a/MathLib/LinAlg/Eigen/EigenVector.h b/MathLib/LinAlg/Eigen/EigenVector.h index 667ff6ebfc1b3e1a46cbdea48da7ae661361515e..a4fe75fb063f2a1875f1cf09ff76b5094463ed9e 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 783e3f35593b7f7e1ca7923a4a9033e778701d34..74898df4db3d6106cda6fd49a7ebebfa0977375e 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