From 70c3b32e09243a0e4563ea495f97e1f39067cdc0 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 11 Sep 2017 19:03:29 -0600 Subject: [PATCH] Avoid raw pointers in favor of VectorMemory::Pointer. --- include/deal.II/lac/solver_richardson.h | 46 ++++++++----------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/include/deal.II/lac/solver_richardson.h b/include/deal.II/lac/solver_richardson.h index 37f7b95a7a..71253f0ff1 100644 --- a/include/deal.II/lac/solver_richardson.h +++ b/include/deal.II/lac/solver_richardson.h @@ -149,18 +149,6 @@ protected: virtual typename VectorType::value_type criterion(const VectorType &r, const VectorType &d) const; - /** - * Residual. Temporary vector allocated through the VectorMemory object at - * the start of the actual solution process and deallocated at the end. - */ - VectorType *Vr; - /** - * Preconditioned residual. Temporary vector allocated through the - * VectorMemory object at the start of the actual solution process and - * deallocated at the end. - */ - VectorType *Vd; - /** * Control parameters. */ @@ -189,8 +177,6 @@ SolverRichardson::SolverRichardson(SolverControl &cn, const AdditionalData &data) : Solver (cn,mem), - Vr(nullptr), - Vd(nullptr), additional_data(data) {} @@ -201,8 +187,6 @@ SolverRichardson::SolverRichardson(SolverControl &cn, const AdditionalData &data) : Solver (cn), - Vr(nullptr), - Vd(nullptr), additional_data(data) {} @@ -227,11 +211,14 @@ SolverRichardson::solve (const MatrixType &A, unsigned int iter = 0; - // Memory allocation - Vr = this->memory.alloc(); + // Memory allocation. + // 'Vr' holds the residual, 'Vd' the preconditioned residual + typename VectorMemory::Pointer Vr (this->memory); + typename VectorMemory::Pointer Vd (this->memory); + VectorType &r = *Vr; r.reinit(x); - Vd = this->memory.alloc(); + VectorType &d = *Vd; d.reinit(x); @@ -263,14 +250,10 @@ SolverRichardson::solve (const MatrixType &A, } catch (...) { - this->memory.free(Vr); - this->memory.free(Vd); deallog.pop(); throw; } - // Deallocate Memory - this->memory.free(Vr); - this->memory.free(Vd); + deallog.pop(); // in case of failure: throw exception @@ -281,6 +264,7 @@ SolverRichardson::solve (const MatrixType &A, } + template template void @@ -294,11 +278,14 @@ SolverRichardson::Tsolve (const MatrixType &A, unsigned int iter = 0; - // Memory allocation - Vr = this->memory.alloc(); + // Memory allocation. + // 'Vr' holds the residual, 'Vd' the preconditioned residual + typename VectorMemory::Pointer Vr (this->memory); + typename VectorMemory::Pointer Vd (this->memory); + VectorType &r = *Vr; r.reinit(x); - Vd = this-> memory.alloc(); + VectorType &d = *Vd; d.reinit(x); @@ -328,15 +315,10 @@ SolverRichardson::Tsolve (const MatrixType &A, } catch (...) { - this->memory.free(Vr); - this->memory.free(Vd); deallog.pop(); throw; } - // Deallocate Memory - this->memory.free(Vr); - this->memory.free(Vd); deallog.pop(); // in case of failure: throw exception if (conv != SolverControl::success) -- 2.39.5