]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Convert more places to VectorMemory::Pointer. 4987/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 28 Aug 2017 19:23:42 +0000 (13:23 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 29 Aug 2017 13:23:24 +0000 (07:23 -0600)
include/deal.II/lac/eigen.h
include/deal.II/lac/filtered_matrix.h
include/deal.II/lac/householder.h
include/deal.II/lac/solver_bicgstab.h
source/lac/trilinos_sparse_matrix.cc

index ddd9e9a2dd22efb46b4b2dd1468e69e4c10287cc..e9da6fa6c2e73d2f4cc31a10620d19c642eca9c7 100644 (file)
@@ -345,10 +345,10 @@ EigenInverse<VectorType>::solve (double           &value,
   unsigned int goal = additional_data.start_adaption;
 
   // Auxiliary vector
-  VectorType *Vy = this->memory.alloc ();
+  typename VectorMemory<VectorType>::Pointer Vy (this->memory);
   VectorType &y = *Vy;
   y.reinit (x);
-  VectorType *Vr = this->memory.alloc ();
+  typename VectorMemory<VectorType>::Pointer Vr (this->memory);
   VectorType &r = *Vr;
   r.reinit (x);
 
@@ -416,9 +416,6 @@ EigenInverse<VectorType>::solve (double           &value,
       old_value = value;
     }
 
-  this->memory.free(Vy);
-  this->memory.free(Vr);
-
   deallog.pop();
 
   // in case of failure: throw
index 22802333638fb820c03c8f67ecbbcf4efba420c6..bb946d6509c47e498dd66d6ad326441a22f05bac 100644 (file)
@@ -900,7 +900,7 @@ FilteredMatrix<VectorType>::vmult (VectorType &dst, const VectorType &src) const
   if (!expect_constrained_source)
     {
       GrowingVectorMemory<VectorType> mem;
-      VectorType *tmp_vector = mem.alloc();
+      typename VectorMemory<VectorType>::Pointer tmp_vector (mem);
       // first copy over src vector and
       // pre-filter
       tmp_vector->reinit(src, true);
@@ -908,7 +908,6 @@ FilteredMatrix<VectorType>::vmult (VectorType &dst, const VectorType &src) const
       pre_filter (*tmp_vector);
       // then let matrix do its work
       matrix->vmult (dst, *tmp_vector);
-      mem.free(tmp_vector);
     }
   else
     {
@@ -929,7 +928,7 @@ FilteredMatrix<VectorType>::Tvmult (VectorType &dst, const VectorType &src) cons
   if (!expect_constrained_source)
     {
       GrowingVectorMemory<VectorType> mem;
-      VectorType *tmp_vector = mem.alloc();
+      typename VectorMemory<VectorType>::Pointer tmp_vector (mem);
       // first copy over src vector and
       // pre-filter
       tmp_vector->reinit(src, true);
@@ -937,7 +936,6 @@ FilteredMatrix<VectorType>::Tvmult (VectorType &dst, const VectorType &src) cons
       pre_filter (*tmp_vector);
       // then let matrix do its work
       matrix->Tvmult (dst, *tmp_vector);
-      mem.free(tmp_vector);
     }
   else
     {
@@ -958,7 +956,7 @@ FilteredMatrix<VectorType>::vmult_add (VectorType &dst, const VectorType &src) c
   if (!expect_constrained_source)
     {
       GrowingVectorMemory<VectorType> mem;
-      VectorType *tmp_vector = mem.alloc();
+      typename VectorMemory<VectorType>::Pointer tmp_vector (mem);
       // first copy over src vector and
       // pre-filter
       tmp_vector->reinit(src, true);
@@ -966,7 +964,6 @@ FilteredMatrix<VectorType>::vmult_add (VectorType &dst, const VectorType &src) c
       pre_filter (*tmp_vector);
       // then let matrix do its work
       matrix->vmult_add (dst, *tmp_vector);
-      mem.free(tmp_vector);
     }
   else
     {
@@ -987,7 +984,7 @@ FilteredMatrix<VectorType>::Tvmult_add (VectorType &dst, const VectorType &src)
   if (!expect_constrained_source)
     {
       GrowingVectorMemory<VectorType> mem;
-      VectorType *tmp_vector = mem.alloc();
+      typename VectorMemory<VectorType>::Pointer tmp_vector (mem);
       // first copy over src vector and
       // pre-filter
       tmp_vector->reinit(src, true);
@@ -995,7 +992,6 @@ FilteredMatrix<VectorType>::Tvmult_add (VectorType &dst, const VectorType &src)
       pre_filter (*tmp_vector);
       // then let matrix do its work
       matrix->Tvmult_add (dst, *tmp_vector);
-      mem.free(tmp_vector);
     }
   else
     {
index cec7b58eb58b02132bdea5ef434c47a3d9ae889a..d1272117fce3b71a73a3c1207f6a98bee2ba96a2 100644 (file)
@@ -208,7 +208,7 @@ Householder<number>::least_squares (Vector<number2> &dst,
   const size_type m = this->m(), n = this->n();
 
   GrowingVectorMemory<Vector<number2> > mem;
-  Vector<number2> *aux = mem.alloc();
+  typename VectorMemory<Vector<number2> >::Pointer aux (mem);
   aux->reinit(src, true);
   *aux = src;
   // m > n, m = src.n, n = dst.n
@@ -235,11 +235,11 @@ Householder<number>::least_squares (Vector<number2> &dst,
   // Compute solution
   this->backward(dst, *aux);
 
-  mem.free(aux);
-
   return std::sqrt(sum);
 }
 
+
+
 template <typename number>
 template <typename number2>
 double
@@ -253,7 +253,7 @@ Householder<number>::least_squares (BlockVector<number2> &dst,
   const size_type m = this->m(), n = this->n();
 
   GrowingVectorMemory<BlockVector<number2> > mem;
-  BlockVector<number2> *aux = mem.alloc();
+  typename VectorMemory<BlockVector<number2> >::Pointer aux (mem);
   aux->reinit(src, true);
   *aux = src;
   // m > n, m = src.n, n = dst.n
@@ -289,8 +289,6 @@ Householder<number>::least_squares (BlockVector<number2> &dst,
   //to the BlockVector
   dst = v_dst;
 
-  mem.free(aux);
-
   return std::sqrt(sum);
 }
 
index be4aaa246748b0b75f25a4bc51eba3a2c115c921..ede0758a68bdee9ea74ac7b1eb0afb58e0600e38 100644 (file)
@@ -160,31 +160,31 @@ protected:
   /**
    * Auxiliary vector.
    */
-  VectorType *Vr;
+  typename VectorMemory<VectorType>::Pointer Vr;
   /**
    * Auxiliary vector.
    */
-  VectorType *Vrbar;
+  typename VectorMemory<VectorType>::Pointer Vrbar;
   /**
    * Auxiliary vector.
    */
-  VectorType *Vp;
+  typename VectorMemory<VectorType>::Pointer Vp;
   /**
    * Auxiliary vector.
    */
-  VectorType *Vy;
+  typename VectorMemory<VectorType>::Pointer Vy;
   /**
    * Auxiliary vector.
    */
-  VectorType *Vz;
+  typename VectorMemory<VectorType>::Pointer Vz;
   /**
    * Auxiliary vector.
    */
-  VectorType *Vt;
+  typename VectorMemory<VectorType>::Pointer Vt;
   /**
    * Auxiliary vector.
    */
-  VectorType *Vv;
+  typename VectorMemory<VectorType>::Pointer Vv;
   /**
    * Right hand side vector.
    */
@@ -296,15 +296,6 @@ SolverBicgstab<VectorType>::SolverBicgstab (SolverControl        &cn,
                                             const AdditionalData &data)
   :
   Solver<VectorType>(cn),
-  Vx(nullptr),
-  Vr(nullptr),
-  Vrbar(nullptr),
-  Vp(nullptr),
-  Vy(nullptr),
-  Vz(nullptr),
-  Vt(nullptr),
-  Vv(nullptr),
-  Vb(nullptr),
   alpha(0.),
   beta(0.),
   omega(0.),
@@ -459,19 +450,20 @@ SolverBicgstab<VectorType>::solve(const MatrixType         &A,
                                   const PreconditionerType &preconditioner)
 {
   deallog.push("Bicgstab");
-  Vr    = this->memory.alloc();
+  Vr    = typename VectorMemory<VectorType>::Pointer(this->memory);
+  Vrbar = typename VectorMemory<VectorType>::Pointer(this->memory);
+  Vp    = typename VectorMemory<VectorType>::Pointer(this->memory);
+  Vy    = typename VectorMemory<VectorType>::Pointer(this->memory);
+  Vz    = typename VectorMemory<VectorType>::Pointer(this->memory);
+  Vt    = typename VectorMemory<VectorType>::Pointer(this->memory);
+  Vv    = typename VectorMemory<VectorType>::Pointer(this->memory);
+
   Vr->reinit(x, true);
-  Vrbar = this->memory.alloc();
   Vrbar->reinit(x, true);
-  Vp    = this->memory.alloc();
   Vp->reinit(x, true);
-  Vy    = this->memory.alloc();
   Vy->reinit(x, true);
-  Vz    = this->memory.alloc();
   Vz->reinit(x, true);
-  Vt    = this->memory.alloc();
   Vt->reinit(x, true);
-  Vv    = this->memory.alloc();
   Vv->reinit(x, true);
 
   Vx = &x;
@@ -496,14 +488,6 @@ SolverBicgstab<VectorType>::solve(const MatrixType         &A,
     }
   while (state.breakdown == true);
 
-  this->memory.free(Vr);
-  this->memory.free(Vrbar);
-  this->memory.free(Vp);
-  this->memory.free(Vy);
-  this->memory.free(Vz);
-  this->memory.free(Vt);
-  this->memory.free(Vv);
-
   deallog.pop();
 
   // in case of failure: throw exception
index 3a4e0086759a307027a6d486b94c52e72f23096e..c23306384330873ac8bec0f776347e55857bcde1 100644 (file)
@@ -2973,7 +2973,7 @@ namespace TrilinosWrappers
           // Duplicated from LinearOperator::operator*
           // TODO: Template the constructor on GrowingVectorMemory vector type?
           GrowingVectorMemory<GVMVectorType> vector_memory;
-          GVMVectorType *i = vector_memory.alloc();
+          VectorMemory<GVMVectorType>::Pointer i (vector_memory);
 
           // Initialize intermediate vector
           const Epetra_Map &first_op_init_map = first_op.OperatorDomainMap();
@@ -2997,8 +2997,6 @@ namespace TrilinosWrappers
           first_op.Apply(tril_src, tril_dst);
           const int ierr = tril_dst.Update (1.0, tril_int, 1.0);
           AssertThrow (ierr == 0, ExcTrilinosError(ierr));
-
-          vector_memory.free(i);
         };
 
         return_op.Tvmult = [first_op, second_op](Domain &tril_dst,
@@ -3007,7 +3005,7 @@ namespace TrilinosWrappers
           // Duplicated from LinearOperator::operator*
           // TODO: Template the constructor on GrowingVectorMemory vector type?
           GrowingVectorMemory<GVMVectorType> vector_memory;
-          GVMVectorType *i = vector_memory.alloc();
+          VectorMemory<GVMVectorType>::Pointer i (vector_memory);
 
           // These operators may themselves be transposed or not, so we let them
           // decide what the intended outcome is
@@ -3042,8 +3040,6 @@ namespace TrilinosWrappers
           // Reset transpose flag
           const_cast<TrilinosPayload &>(first_op).transpose();
           const_cast<TrilinosPayload &>(second_op).transpose();
-
-          vector_memory.free(i);
         };
 
         return_op.inv_vmult = [first_op, second_op](Domain &tril_dst,
@@ -3052,7 +3048,7 @@ namespace TrilinosWrappers
           // Duplicated from LinearOperator::operator*
           // TODO: Template the constructor on GrowingVectorMemory vector type?
           GrowingVectorMemory<GVMVectorType> vector_memory;
-          GVMVectorType *i = vector_memory.alloc();
+          VectorMemory<GVMVectorType>::Pointer i (vector_memory);
 
           // Initialize intermediate vector
           const Epetra_Map &first_op_init_map = first_op.OperatorRangeMap();
@@ -3076,8 +3072,6 @@ namespace TrilinosWrappers
           first_op.ApplyInverse(tril_src, tril_dst);
           const int ierr = tril_dst.Update (1.0, tril_int, 1.0);
           AssertThrow (ierr == 0, ExcTrilinosError(ierr));
-
-          vector_memory.free(i);
         };
 
         return_op.inv_Tvmult = [first_op, second_op](Range &tril_dst,
@@ -3086,7 +3080,7 @@ namespace TrilinosWrappers
           // Duplicated from LinearOperator::operator*
           // TODO: Template the constructor on GrowingVectorMemory vector type?
           GrowingVectorMemory<GVMVectorType> vector_memory;
-          GVMVectorType *i = vector_memory.alloc();
+          VectorMemory<GVMVectorType>::Pointer i (vector_memory);
 
           // These operators may themselves be transposed or not, so we let them
           // decide what the intended outcome is
@@ -3121,8 +3115,6 @@ namespace TrilinosWrappers
           // Reset transpose flag
           const_cast<TrilinosPayload &>(first_op).transpose();
           const_cast<TrilinosPayload &>(second_op).transpose();
-
-          vector_memory.free(i);
         };
 
         return return_op;
@@ -3150,7 +3142,7 @@ namespace TrilinosWrappers
           // Duplicated from LinearOperator::operator*
           // TODO: Template the constructor on GrowingVectorMemory vector type?
           GrowingVectorMemory<GVMVectorType> vector_memory;
-          GVMVectorType *i = vector_memory.alloc();
+          VectorMemory<GVMVectorType>::Pointer i (vector_memory);
 
           // Initialize intermediate vector
           const Epetra_Map &first_op_init_map = first_op.OperatorDomainMap();
@@ -3172,8 +3164,6 @@ namespace TrilinosWrappers
           // decide what the intended outcome is
           second_op.Apply(tril_src, tril_int);
           first_op.Apply(tril_int, tril_dst);
-
-          vector_memory.free(i);
         };
 
         return_op.Tvmult = [first_op, second_op](Domain &tril_dst,
@@ -3182,7 +3172,7 @@ namespace TrilinosWrappers
           // Duplicated from LinearOperator::operator*
           // TODO: Template the constructor on GrowingVectorMemory vector type?
           GrowingVectorMemory<GVMVectorType> vector_memory;
-          GVMVectorType *i = vector_memory.alloc();
+          VectorMemory<GVMVectorType>::Pointer i (vector_memory);
 
           // These operators may themselves be transposed or not, so we let them
           // decide what the intended outcome is
@@ -3214,8 +3204,6 @@ namespace TrilinosWrappers
           // Reset transpose flag
           const_cast<TrilinosPayload &>(first_op).transpose();
           const_cast<TrilinosPayload &>(second_op).transpose();
-
-          vector_memory.free(i);
         };
 
         return_op.inv_vmult = [first_op, second_op](Domain &tril_dst,
@@ -3224,7 +3212,7 @@ namespace TrilinosWrappers
           // Duplicated from LinearOperator::operator*
           // TODO: Template the constructor on GrowingVectorMemory vector type?
           GrowingVectorMemory<GVMVectorType> vector_memory;
-          GVMVectorType *i = vector_memory.alloc();
+          VectorMemory<GVMVectorType>::Pointer i (vector_memory);
 
           // Initialize intermediate vector
           const Epetra_Map &first_op_init_map = first_op.OperatorRangeMap();
@@ -3246,8 +3234,6 @@ namespace TrilinosWrappers
           // and the same order as Tvmult
           first_op.ApplyInverse(tril_src, tril_int);
           second_op.ApplyInverse(tril_int, tril_dst);
-
-          vector_memory.free(i);
         };
 
         return_op.inv_Tvmult = [first_op, second_op](Range &tril_dst,
@@ -3256,7 +3242,7 @@ namespace TrilinosWrappers
           // Duplicated from LinearOperator::operator*
           // TODO: Template the constructor on GrowingVectorMemory vector type?
           GrowingVectorMemory<GVMVectorType> vector_memory;
-          GVMVectorType *i = vector_memory.alloc();
+          VectorMemory<GVMVectorType>::Pointer i (vector_memory);
 
           // These operators may themselves be transposed or not, so we let them
           // decide what the intended outcome is
@@ -3291,8 +3277,6 @@ namespace TrilinosWrappers
           // Reset transpose flag
           const_cast<TrilinosPayload &>(first_op).transpose();
           const_cast<TrilinosPayload &>(second_op).transpose();
-
-          vector_memory.free(i);
         };
 
         return return_op;

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.