diff --git a/MathLib/LinAlg/PETSc/PETScVector.cpp b/MathLib/LinAlg/PETSc/PETScVector.cpp index a23f072be7029d505fa185fae3ecc7cf23ca87bb..52415470112ec59d900e6fc9d55dd6083655e8e5 100644 --- a/MathLib/LinAlg/PETSc/PETScVector.cpp +++ b/MathLib/LinAlg/PETSc/PETScVector.cpp @@ -44,8 +44,9 @@ PETScVector::PETScVector(const PetscInt vec_size, const bool is_global_size) PETScVector::PETScVector(const PetscInt vec_size, const std::vector<PetscInt>& ghost_ids, - const bool is_global_size) : - _size_ghosts(ghost_ids.size()), _has_ghost_id(true) + const bool is_global_size) + : _size_ghosts{ghost_ids.size()} + , _has_ghost_id{true} { _v.reset(new PETSc_Vec); @@ -77,6 +78,17 @@ PETScVector::PETScVector(const PETScVector &existing_vec, const bool deep_copy) } } +PETScVector::PETScVector(PETScVector &&other) + : _v{std::move(other._v)} + , _v_loc{std::move(other._v_loc)} + , _start_rank{other._start_rank} + , _end_rank{other._end_rank} + , _size{other._size} + , _size_loc{other._size_loc} + , _size_ghosts{other._size_ghosts} + , _has_ghost_id{other._has_ghost_id} +{} + void PETScVector::config() { VecSetFromOptions(*_v); @@ -232,10 +244,12 @@ void PETScVector::shallowCopy(const PETScVector &v) VecDuplicate(*v._v, _v.get()); - // TODO can't that be copied from v? - VecGetOwnershipRange(*_v, &_start_rank,&_end_rank); - VecGetLocalSize(*_v, &_size_loc); - VecGetSize(*_v, &_size); + _start_rank = v._start_rank; + _end_rank = v._end_rank; + _size = v._size; + _size_loc = v._size_loc; + _size_ghosts = v._size_ghosts; + _has_ghost_id = v._has_ghost_id; VecSetOption(*_v, VEC_IGNORE_NEGATIVE_INDICES, PETSC_TRUE); } diff --git a/MathLib/LinAlg/PETSc/PETScVector.h b/MathLib/LinAlg/PETSc/PETScVector.h index bf3f4e46f630c6708bf7baf30c96a8a27c754be0..ce15cbe8f4614dd990a96d24e8191f1644bfe091 100644 --- a/MathLib/LinAlg/PETSc/PETScVector.h +++ b/MathLib/LinAlg/PETSc/PETScVector.h @@ -72,7 +72,9 @@ class PETScVector \param deep_copy The flag for a deep copy, which means to copy the values as well, the default is true */ - PETScVector(const PETScVector &existing_vec, const bool deep_copy = true); + explicit PETScVector(const PETScVector &existing_vec, const bool deep_copy = true); + + PETScVector(PETScVector&& other); ~PETScVector() { @@ -221,12 +223,19 @@ class PETScVector void setZero() { *this = 0.0; } /// Overloaded operator: assign - void operator = (const PETScVector &v_in) + PETScVector& operator = (const PETScVector &v_in) { if (!_v) shallowCopy(v_in); VecCopy(*v_in._v, *_v); + + return *this; } + /// Disallow moving. + /// \todo This operator should be implemented properly when doing a + /// general cleanup of all matrix and vector classes. + PETScVector& operator = (PETScVector &&) = delete; + /// Overloaded operator: add void operator += (const PETScVector& v_in) { diff --git a/NumLib/ODESolver/MatrixTranslator.h b/NumLib/ODESolver/MatrixTranslator.h index 6df68880311403152646c2f83cc466a9d4e055a7..76970880311f22f24b019df4123cc7bef0d026c2 100644 --- a/NumLib/ODESolver/MatrixTranslator.h +++ b/NumLib/ODESolver/MatrixTranslator.h @@ -404,7 +404,7 @@ public: // Note: using x_old here is correct, since this method is called from within // CrankNicolson::pushState() __after__ x_old has been updated to the result // from the timestep just finished. - auto const x_old = _crank_nicolson.getXOld(); + auto const& x_old = _crank_nicolson.getXOld(); // _M_bar = (1.0-theta) * M; BLAS::copy(M, _M_bar); diff --git a/NumLib/ODESolver/TimeLoopSingleODE.h b/NumLib/ODESolver/TimeLoopSingleODE.h index dd69d77269297970ae877de696844827705db139..ff8f29d8e086bda2b65dc8b9b7c5fbfaff4f6a36 100644 --- a/NumLib/ODESolver/TimeLoopSingleODE.h +++ b/NumLib/ODESolver/TimeLoopSingleODE.h @@ -64,7 +64,7 @@ public: * \retval false otherwise */ template<typename Callback> - bool loop(const double t0, const Vector x0, + bool loop(const double t0, Vector const& x0, const double t_end, const double delta_t, Callback& post_timestep); @@ -81,7 +81,7 @@ template<typename Matrix, typename Vector, NonlinearSolverTag NLTag> template<typename Callback> bool TimeLoopSingleODE<Matrix, Vector, NLTag>:: -loop(const double t0, const Vector x0, const double t_end, const double delta_t, +loop(const double t0, Vector const& x0, const double t_end, const double delta_t, Callback& post_timestep) { // solution vector