]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use automatic memory management, rather than doing it by hand. 5726/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 12 Jan 2018 18:12:08 +0000 (11:12 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 12 Jan 2018 18:12:08 +0000 (11:12 -0700)
source/fe/fe_raviart_thomas.cc
source/fe/fe_raviart_thomas_nodal.cc

index 4e7a0ba1800bb3d1be54ba3c2fd6b74c249298ca..95c16ec86aa7a6c987e25a7d4d4e454e8b17ecac 100644 (file)
@@ -193,9 +193,8 @@ FE_RaviartThomas<dim>::initialize_support_points (const unsigned int deg)
 
   if (deg==0) return;
 
-  // Create Legendre basis for the
-  // space D_xi Q_k
-  std::vector<AnisotropicPolynomials<dim>* > polynomials(dim);
+  // Create Legendre basis for the space D_xi Q_k
+  std::unique_ptr<AnisotropicPolynomials<dim>> polynomials[dim];
   for (unsigned int dd=0; dd<dim; ++dd)
     {
       std::vector<std::vector<Polynomials::Polynomial<double> > > poly(dim);
@@ -203,7 +202,7 @@ FE_RaviartThomas<dim>::initialize_support_points (const unsigned int deg)
         poly[d] = Polynomials::Legendre::generate_complete_basis(deg);
       poly[dd] = Polynomials::Legendre::generate_complete_basis(deg-1);
 
-      polynomials[dd] = new AnisotropicPolynomials<dim>(poly);
+      polynomials[dd] = std_cxx14::make_unique<AnisotropicPolynomials<dim>>(poly);
     }
 
   interior_weights.reinit(TableIndices<3>(n_interior_points, polynomials[0]->n(), dim));
@@ -217,9 +216,6 @@ FE_RaviartThomas<dim>::initialize_support_points (const unsigned int deg)
                                     * polynomials[d]->compute_value(i,cell_quadrature.point(k));
     }
 
-  for (unsigned int d=0; d<dim; ++d)
-    delete polynomials[d];
-
   Assert (current == this->generalized_support_points.size(),
           ExcInternalError());
 }
@@ -323,10 +319,9 @@ FE_RaviartThomas<dim>::initialize_restriction()
 
   if (this->degree == 1) return;
 
-  // Create Legendre basis for the
-  // space D_xi Q_k. Here, we cannot
+  // Create Legendre basis for the space D_xi Q_k. Here, we cannot
   // use the shape functions
-  std::vector<AnisotropicPolynomials<dim>* > polynomials(dim);
+  std::unique_ptr<AnisotropicPolynomials<dim>> polynomials[dim];
   for (unsigned int dd=0; dd<dim; ++dd)
     {
       std::vector<std::vector<Polynomials::Polynomial<double> > > poly(dim);
@@ -334,7 +329,7 @@ FE_RaviartThomas<dim>::initialize_restriction()
         poly[d] = Polynomials::Legendre::generate_complete_basis(this->degree-1);
       poly[dd] = Polynomials::Legendre::generate_complete_basis(this->degree-2);
 
-      polynomials[dd] = new AnisotropicPolynomials<dim>(poly);
+      polynomials[dd] = std_cxx14::make_unique<AnisotropicPolynomials<dim>>(poly);
     }
 
   QGauss<dim> q_cell(this->degree);
@@ -366,9 +361,6 @@ FE_RaviartThomas<dim>::initialize_restriction()
                    * polynomials[d]->compute_value(i_weight, q_sub.point(k));
               }
     }
-
-  for (unsigned int d=0; d<dim; ++d)
-    delete polynomials[d];
 }
 
 
index ad8a91ddb11b281c29094f9d37bc7183abb95eb1..802410e2c7d85b98514697a5d1fca7891b91b12d 100644 (file)
@@ -180,18 +180,27 @@ FE_RaviartThomasNodal<dim>::initialize_support_points (const unsigned int deg)
 
   for (unsigned int d=0; d<dim; ++d)
     {
-      QAnisotropic<dim> *quadrature;
-      if (dim == 1) quadrature = new QAnisotropic<dim>(high);
-      if (dim == 2) quadrature = new QAnisotropic<dim>(((d==0) ? low : high),
-                                                         ((d==1) ? low : high));
-      if (dim == 3) quadrature = new QAnisotropic<dim>(((d==0) ? low : high),
-                                                         ((d==1) ? low : high),
-                                                         ((d==2) ? low : high));
-      Assert(dim<=3, ExcNotImplemented());
+      std::unique_ptr<QAnisotropic<dim>> quadrature;
+      switch (dim)
+        {
+        case 1:
+          quadrature = std_cxx14::make_unique<QAnisotropic<dim>>(high);
+          break;
+        case 2:
+          quadrature = std_cxx14::make_unique<QAnisotropic<dim>>(((d==0) ? low : high),
+                                                                 ((d==1) ? low : high));
+          break;
+        case 3:
+          quadrature = std_cxx14::make_unique<QAnisotropic<dim>>(((d==0) ? low : high),
+                                                                 ((d==1) ? low : high),
+                                                                 ((d==2) ? low : high));
+          break;
+        default:
+          Assert(false, ExcNotImplemented());
+        }
 
       for (unsigned int k=0; k<quadrature->size(); ++k)
         this->generalized_support_points[current++] = quadrature->point(k);
-      delete quadrature;
     }
   Assert (current == this->dofs_per_cell, ExcInternalError());
 }

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.