]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid raw pointers in favor of VectorMemory::Pointer.
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 12 Sep 2017 01:03:29 +0000 (19:03 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 13 Sep 2017 15:33:29 +0000 (09:33 -0600)
include/deal.II/lac/solver_richardson.h

index 37f7b95a7ac925e9d8230e660de1c48c71b1d534..71253f0ff18fb80be917bbb5cff7fd69fc149750 100644 (file)
@@ -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<VectorType>::SolverRichardson(SolverControl            &cn,
                                                const AdditionalData     &data)
   :
   Solver<VectorType> (cn,mem),
-  Vr(nullptr),
-  Vd(nullptr),
   additional_data(data)
 {}
 
@@ -201,8 +187,6 @@ SolverRichardson<VectorType>::SolverRichardson(SolverControl        &cn,
                                                const AdditionalData &data)
   :
   Solver<VectorType> (cn),
-  Vr(nullptr),
-  Vd(nullptr),
   additional_data(data)
 {}
 
@@ -227,11 +211,14 @@ SolverRichardson<VectorType>::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<VectorType>::Pointer Vr (this->memory);
+  typename VectorMemory<VectorType>::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<VectorType>::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<VectorType>::solve (const MatrixType         &A,
 }
 
 
+
 template <class VectorType>
 template <typename MatrixType, typename PreconditionerType>
 void
@@ -294,11 +278,14 @@ SolverRichardson<VectorType>::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<VectorType>::Pointer Vr (this->memory);
+  typename VectorMemory<VectorType>::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<VectorType>::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)

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.