Skip to content
Snippets Groups Projects
Commit d50ea90d authored by Christoph Lehmann's avatar Christoph Lehmann Committed by Dmitri Naumov
Browse files

[MaL] copyValues resizes target vector

Update and unify documentation.
parent 9974a0a5
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include <Eigen/Eigen> #include <Eigen/Eigen>
#include <Eigen/Sparse> #include <Eigen/Sparse>
#include "EigenMapTools.h"
namespace MathLib namespace MathLib
{ {
/// Global vector based on Eigen vector /// Global vector based on Eigen vector
...@@ -90,11 +92,13 @@ public: ...@@ -90,11 +92,13 @@ public:
} }
} }
/// Copy vector values. /// Copy local entries to a vector.
/// \param u a vector for the values of local entries. It will be resized to
/// hold the current vector data.
void copyValues(std::vector<double>& u) const void copyValues(std::vector<double>& u) const
{ {
assert(u.size() == (std::size_t)vec_.size()); u.resize(size());
copy_n(vec_.data(), vec_.size(), u.begin()); toVector(u) = vec_;
} }
#ifndef NDEBUG #ifndef NDEBUG
......
...@@ -99,10 +99,12 @@ public: ...@@ -99,10 +99,12 @@ public:
} }
} }
/// Copy vector values. /// Copy local entries to a vector.
/// \param u a vector for the values of local entries. It will be resized to
/// hold the current vector data.
void copyValues(std::vector<double>& u) const void copyValues(std::vector<double>& u) const
{ {
assert(u.size() == size()); u.resize(size());
lis_vector_get_values(vec_, 0, size(), u.data()); lis_vector_get_values(vec_, 0, size(), u.data());
} }
......
...@@ -196,7 +196,7 @@ void PETScVector::setLocalAccessibleVector() const ...@@ -196,7 +196,7 @@ void PETScVector::setLocalAccessibleVector() const
void PETScVector::copyValues(std::vector<PetscScalar>& u) const void PETScVector::copyValues(std::vector<PetscScalar>& u) const
{ {
assert(u.size() == (std::size_t)(getLocalSize() + getGhostSize())); u.resize(getLocalSize() + getGhostSize());
PetscScalar* loc_x = getLocalVector(); PetscScalar* loc_x = getLocalVector();
std::copy_n(loc_x, getLocalSize() + getGhostSize(), u.begin()); std::copy_n(loc_x, getLocalSize() + getGhostSize(), u.begin());
......
...@@ -177,8 +177,9 @@ public: ...@@ -177,8 +177,9 @@ public:
*/ */
PETSc_Vec const& getRawVector() const { return v_; } PETSc_Vec const& getRawVector() const { return v_; }
/*! /*!
Copy local entries including ghost ones to an array Copy local entries including ghost ones to a vector.
\param u Preallocated vector for the values of local entries. \param u a vector for the values of local entries. It will be resized to
hold the current vector data.
*/ */
void copyValues(std::vector<PetscScalar>& u) const; void copyValues(std::vector<PetscScalar>& u) const;
......
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