From 65bb99e41f9d4c7c363e514e8bf07e74cd6c70d7 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 22 Aug 2017 12:46:36 -0600 Subject: [PATCH] Use automatic pointers for temporary vectors in SolverCG. --- include/deal.II/lac/solver_cg.h | 56 +++++++++------------------------ 1 file changed, 14 insertions(+), 42 deletions(-) diff --git a/include/deal.II/lac/solver_cg.h b/include/deal.II/lac/solver_cg.h index 3207990ad5..f487ba678b 100644 --- a/include/deal.II/lac/solver_cg.h +++ b/include/deal.II/lac/solver_cg.h @@ -186,14 +186,6 @@ protected: const boost::signals2::signal &)> &eigenvalues_signal, const boost::signals2::signal &cond_signal); - /** - * Temporary vectors, allocated through the @p VectorMemory object at the - * start of the actual solution process and deallocated at the end. - */ - VectorType *Vr; - VectorType *Vp; - VectorType *Vz; - /** * Additional parameters. */ @@ -227,9 +219,6 @@ protected: * iteration. */ boost::signals2::signal &)> all_eigenvalues_signal; - -private: - void cleanup(); }; /*@}*/ @@ -244,9 +233,6 @@ SolverCG::SolverCG (SolverControl &cn, const AdditionalData &data) : Solver(cn,mem), - Vr(nullptr), - Vp(nullptr), - Vz(nullptr), additional_data(data) {} @@ -257,9 +243,6 @@ SolverCG::SolverCG (SolverControl &cn, const AdditionalData &data) : Solver(cn), - Vr(nullptr), - Vp(nullptr), - Vz(nullptr), additional_data(data) {} @@ -271,18 +254,6 @@ SolverCG::~SolverCG () -template -void -SolverCG::cleanup() -{ - this->memory.free(Vr); - this->memory.free(Vp); - this->memory.free(Vz); - deallog.pop(); -} - - - template void SolverCG::print_vectors(const unsigned int, @@ -348,11 +319,16 @@ SolverCG::solve (const MatrixType &A, deallog.push("cg"); // Memory allocation - Vr = this->memory.alloc(); - Vz = this->memory.alloc(); - Vp = this->memory.alloc(); - // Should we build the matrix for - // eigenvalue computations? + typename VectorMemory::Pointer g_pointer(this->memory); + typename VectorMemory::Pointer d_pointer(this->memory); + typename VectorMemory::Pointer h_pointer(this->memory); + + // define some aliases for simpler access + VectorType &g = *g_pointer; + VectorType &d = *d_pointer; + VectorType &h = *h_pointer; + + // Should we build the matrix for eigenvalue computations? const bool do_eigenvalues = !condition_number_signal.empty() ||!all_condition_numbers_signal.empty() ||!eigenvalues_signal.empty() @@ -370,10 +346,6 @@ SolverCG::solve (const MatrixType &A, { double eigen_beta_alpha = 0; - // define some aliases for simpler access - VectorType &g = *Vr; - VectorType &d = *Vz; - VectorType &h = *Vp; // resize the vectors, but do not set // the values since they'd be overwritten // soon anyway. @@ -398,7 +370,7 @@ SolverCG::solve (const MatrixType &A, conv = this->iteration_status(0, res, x); if (conv != SolverControl::iterate) { - cleanup(); + deallog.pop(); return; } @@ -470,14 +442,14 @@ SolverCG::solve (const MatrixType &A, } catch (...) { - cleanup(); + deallog.pop(); throw; } compute_eigs_and_cond(diagonal,offdiagonal,eigenvalues_signal, condition_number_signal); - // Deallocate Memory - cleanup(); + deallog.pop(); + // in case of failure: throw exception if (conv != SolverControl::success) AssertThrow(false, SolverControl::NoConvergence (it, res)); -- 2.39.5