From: Wolfgang Bangerth Date: Sun, 18 Jun 2017 00:52:15 +0000 (-0600) Subject: Use std::unique_ptrs instead of raw pointers for level/face objects in class DoFHandler. X-Git-Tag: v9.0.0-rc1~1487^2~16 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e73b3f7955e4e10ee907fbac76ab7eceefbf1f89;p=dealii.git Use std::unique_ptrs instead of raw pointers for level/face objects in class DoFHandler. --- diff --git a/include/deal.II/dofs/dof_handler.h b/include/deal.II/dofs/dof_handler.h index c4fe7509d2..eb298faae6 100644 --- a/include/deal.II/dofs/dof_handler.h +++ b/include/deal.II/dofs/dof_handler.h @@ -1070,18 +1070,18 @@ private: * Space to store the DoF numbers for the different levels. Analogous to the * levels[] tree of the Triangulation objects. */ - std::vector*> levels; + std::vector > > levels; - std::vector*> mg_levels; + std::vector > > mg_levels; /** * Space to store DoF numbers of faces. They are not stored in * levels since faces are not organized hierarchically, but in a * flat array. */ - dealii::internal::DoFHandler::DoFFaces *faces; + std::unique_ptr > faces; - dealii::internal::DoFHandler::DoFFaces *mg_faces; + std::unique_ptr > mg_faces; /** * Make accessor objects friends. @@ -1300,11 +1300,8 @@ void DoFHandler::load (Archive &ar, // pointer object still points to something useful, that object is not // destroyed and we end up with a memory leak. consequently, first delete // previous content before re-loading stuff - for (unsigned int i=0; i const unsigned int DoFHandler::dimension; @@ -280,8 +276,7 @@ namespace internal for (unsigned int i=0; in_levels(); ++i) { - dof_handler.levels - .push_back (new internal::DoFHandler::DoFLevel<1>); + dof_handler.levels.emplace_back (new internal::DoFHandler::DoFLevel<1>); dof_handler.levels.back()->dof_object.dofs .resize (dof_handler.tria->n_raw_cells(i) * @@ -307,7 +302,7 @@ namespace internal for (unsigned int i=0; in_levels(); ++i) { - dof_handler.levels.push_back (new internal::DoFHandler::DoFLevel<2>); + dof_handler.levels.emplace_back (new internal::DoFHandler::DoFLevel<2>); dof_handler.levels.back()->dof_object.dofs .resize (dof_handler.tria->n_raw_cells(i) * @@ -320,7 +315,7 @@ namespace internal DoFHandler<2,spacedim>::invalid_dof_index); } - dof_handler.faces = new internal::DoFHandler::DoFFaces<2>; + dof_handler.faces.reset (new internal::DoFHandler::DoFFaces<2>); // avoid access to n_raw_lines when there are no cells if (dof_handler.tria->n_cells() > 0) { @@ -343,7 +338,7 @@ namespace internal for (unsigned int i=0; in_levels(); ++i) { - dof_handler.levels.push_back (new internal::DoFHandler::DoFLevel<3>); + dof_handler.levels.emplace_back (new internal::DoFHandler::DoFLevel<3>); dof_handler.levels.back()->dof_object.dofs .resize (dof_handler.tria->n_raw_cells(i) * @@ -355,7 +350,7 @@ namespace internal dof_handler.selected_fe->dofs_per_cell, DoFHandler<3,spacedim>::invalid_dof_index); } - dof_handler.faces = new internal::DoFHandler::DoFFaces<3>; + dof_handler.faces.reset (new internal::DoFHandler::DoFFaces<3>); // avoid access to n_raw_lines when there are no cells if (dof_handler.tria->n_cells() > 0) @@ -384,7 +379,7 @@ namespace internal for (unsigned int i = 0; i < n_levels; ++i) { - dof_handler.mg_levels.push_back (new internal::DoFHandler::DoFLevel<1>); + dof_handler.mg_levels.emplace_back (new internal::DoFHandler::DoFLevel<1>); dof_handler.mg_levels.back ()->dof_object.dofs = std::vector (tria.n_raw_lines (i) * dofs_per_line, DoFHandler<1>::invalid_dof_index); } @@ -440,11 +435,11 @@ namespace internal for (unsigned int i = 0; i < n_levels; ++i) { - dof_handler.mg_levels.push_back (new internal::DoFHandler::DoFLevel<2>); + dof_handler.mg_levels.emplace_back (new internal::DoFHandler::DoFLevel<2>); dof_handler.mg_levels.back ()->dof_object.dofs = std::vector (tria.n_raw_quads (i) * fe.dofs_per_quad, DoFHandler<2>::invalid_dof_index); } - dof_handler.mg_faces = new internal::DoFHandler::DoFFaces<2>; + dof_handler.mg_faces.reset (new internal::DoFHandler::DoFFaces<2>); dof_handler.mg_faces->lines.dofs = std::vector (tria.n_raw_lines () * fe.dofs_per_line, DoFHandler<2>::invalid_dof_index); const unsigned int &n_vertices = tria.n_vertices (); @@ -499,11 +494,11 @@ namespace internal for (unsigned int i = 0; i < n_levels; ++i) { - dof_handler.mg_levels.push_back (new internal::DoFHandler::DoFLevel<3>); + dof_handler.mg_levels.emplace_back (new internal::DoFHandler::DoFLevel<3>); dof_handler.mg_levels.back ()->dof_object.dofs = std::vector (tria.n_raw_hexs (i) * fe.dofs_per_hex, DoFHandler<3>::invalid_dof_index); } - dof_handler.mg_faces = new internal::DoFHandler::DoFFaces<3>; + dof_handler.mg_faces.reset (new internal::DoFHandler::DoFFaces<3>); dof_handler.mg_faces->lines.dofs = std::vector (tria.n_raw_lines () * fe.dofs_per_line, DoFHandler<3>::invalid_dof_index); dof_handler.mg_faces->quads.dofs = std::vector (tria.n_raw_quads () * fe.dofs_per_quad, DoFHandler<3>::invalid_dof_index); @@ -678,9 +673,7 @@ template DoFHandler::DoFHandler () : tria(nullptr, typeid(*this).name()), - selected_fe(nullptr, typeid(*this).name()), - faces(nullptr), - mg_faces (nullptr) + selected_fe(nullptr, typeid(*this).name()) {} @@ -1144,21 +1137,21 @@ void DoFHandler::distribute_mg_dofs (const FiniteElement void DoFHandler::reserve_space () { //TODO: move this to distribute_mg_dofs and remove function } + + template void DoFHandler::clear_mg_space () { - for (unsigned int i = 0; i < mg_levels.size (); ++i) - delete mg_levels[i]; - mg_levels.clear (); - delete mg_faces; - mg_faces = nullptr; + mg_faces.reset (); std::vector tmp; @@ -1477,12 +1470,8 @@ DoFHandler::max_couplings_between_boundary_dofs () const template void DoFHandler::clear_space () { - for (unsigned int i=0; i tmp; std::swap (vertex_dofs, tmp);