From ffda44559a6ade8f6e2ad1f8c8ee65c5271a083f Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 26 Jun 2017 17:43:47 -0600 Subject: [PATCH] Use std::unique_ptr in hp::DoFHandler. This replaces raw pointers. A similar change was made last week to the ::DoFHandler class already. --- include/deal.II/hp/dof_handler.h | 53 ++++++++++++++++++-------------- source/hp/dof_handler.cc | 33 ++++++++------------ 2 files changed, 42 insertions(+), 44 deletions(-) diff --git a/include/deal.II/hp/dof_handler.h b/include/deal.II/hp/dof_handler.h index 93925d423c..81e4da9484 100644 --- a/include/deal.II/hp/dof_handler.h +++ b/include/deal.II/hp/dof_handler.h @@ -249,11 +249,27 @@ namespace hp */ DoFHandler (const Triangulation &tria); + /** + * Copy constructor. DoFHandler objects are large and expensive. + * They should not be copied, in particular not by accident, but + * rather deliberately constructed. As a consequence, this constructor + * is explicitly removed from the interface of this class. + */ + DoFHandler (const DoFHandler &) = delete; + /** * Destructor. */ virtual ~DoFHandler (); + /** + * Copy operator. DoFHandler objects are large and expensive. + * They should not be copied, in particular not by accident, but + * rather deliberately constructed. As a consequence, this operator + * is explicitly removed from the interface of this class. + */ + DoFHandler &operator = (const DoFHandler &) = delete; + /** * Go through the triangulation and "distribute" the degrees of freedoms * needed for the given finite element. "Distributing" degrees of freedom @@ -720,32 +736,23 @@ namespace hp private: - /** - * Copy constructor. I can see no reason why someone might want to use it, - * so I don't provide it. Since this class has pointer members, making it - * private prevents the compiler to provide it's own, incorrect one if - * anyone chose to copy such an object. - */ - DoFHandler (const DoFHandler &); - - /** - * Copy operator. I can see no reason why someone might want to use it, so - * I don't provide it. Since this class has pointer members, making it - * private prevents the compiler to provide it's own, incorrect one if - * anyone chose to copy such an object. - */ - DoFHandler &operator = (const DoFHandler &); - /** * Free all used memory. */ void clear_space (); - template - types::global_dof_index get_dof_index (const unsigned int obj_level, const unsigned int obj_index, const unsigned int fe_index, const unsigned int local_index) const; + template + types::global_dof_index get_dof_index (const unsigned int obj_level, + const unsigned int obj_index, + const unsigned int fe_index, + const unsigned int local_index) const; - template - void set_dof_index (const unsigned int obj_level, const unsigned int obj_index, const unsigned int fe_index, const unsigned int local_index, const types::global_dof_index global_index) const; + template + void set_dof_index (const unsigned int obj_level, + const unsigned int obj_index, + const unsigned int fe_index, + const unsigned int local_index, + const types::global_dof_index global_index) const; /** * Create default tables for the active_fe_indices in the @@ -814,13 +821,13 @@ namespace hp * 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; /** * Space to store the DoF numbers for the faces. Analogous to the * faces pointer of the Triangulation objects. */ - dealii::internal::hp::DoFIndicesOnFaces *faces; + std::unique_ptr > faces; /** * A structure that contains all sorts of numbers that characterize the @@ -865,7 +872,7 @@ namespace hp * refinement, i.e. from between when pre_refinement_action is called and * when post_refinement_action runs. */ - std::vector *> has_children; + std::vector > > has_children; /** * A list of connections with which this object connects to the diff --git a/source/hp/dof_handler.cc b/source/hp/dof_handler.cc index 3bc530f435..e9fa9c081b 100644 --- a/source/hp/dof_handler.cc +++ b/source/hp/dof_handler.cc @@ -571,7 +571,7 @@ namespace internal for (unsigned int level=0; leveln_levels(); ++level) { - dof_handler.levels.push_back (new internal::hp::DoFLevel); + dof_handler.levels.emplace_back (new internal::hp::DoFLevel); std::swap (active_fe_backup[level], dof_handler.levels[level]->active_fe_indices); } @@ -699,11 +699,11 @@ namespace internal for (unsigned int level=0; leveln_levels(); ++level) { - dof_handler.levels.push_back (new internal::hp::DoFLevel); + dof_handler.levels.emplace_back (new internal::hp::DoFLevel); std::swap (active_fe_backup[level], dof_handler.levels[level]->active_fe_indices); } - dof_handler.faces = new internal::hp::DoFIndicesOnFaces<2>; + dof_handler.faces.reset (new internal::hp::DoFIndicesOnFaces<2>); } // QUAD (CELL) DOFs @@ -1076,11 +1076,11 @@ namespace internal for (unsigned int level=0; leveln_levels(); ++level) { - dof_handler.levels.push_back (new internal::hp::DoFLevel); + dof_handler.levels.emplace_back (new internal::hp::DoFLevel); std::swap (active_fe_backup[level], dof_handler.levels[level]->active_fe_indices); } - dof_handler.faces = new internal::hp::DoFIndicesOnFaces<3>; + dof_handler.faces.reset (new internal::hp::DoFIndicesOnFaces<3>); } // HEX (CELL) DOFs @@ -3148,7 +3148,7 @@ namespace hp // Create sufficiently many // hp::DoFLevels. while (levels.size () < tria->n_levels ()) - levels.push_back (new dealii::internal::hp::DoFLevel); + levels.emplace_back (new dealii::internal::hp::DoFLevel); // then make sure that on each // level we have the appropriate @@ -3199,8 +3199,7 @@ namespace hp for (unsigned int i=0; in_raw_cells(i); - std::vector *has_children_level = - new std::vector (cells_on_level); + std::unique_ptr > has_children_level(new std::vector (cells_on_level)); // Check for each cell, if it has children. in 1d, // we don't store refinement cases, so use the 'children' @@ -3220,7 +3219,7 @@ namespace hp std::placeholders::_1, static_cast(RefinementCase::no_refinement))); - has_children.push_back (has_children_level); + has_children.emplace_back (std::move(has_children_level)); } } @@ -3235,13 +3234,13 @@ namespace hp // Normally only one level is added, but if this Triangulation // is created by copy_triangulation, it can be more than one level. while (levels.size () < tria->n_levels ()) - levels.push_back (new dealii::internal::hp::DoFLevel); + levels.emplace_back (new dealii::internal::hp::DoFLevel); // Coarsening can lead to the loss // of levels. Hence remove them. while (levels.size () > tria->n_levels ()) { - delete levels[levels.size ()-1]; + // drop the last element. that also releases the memory pointed to levels.pop_back (); } @@ -3306,11 +3305,6 @@ namespace hp } // Free buffer objects - std::vector *>::iterator children_level; - for (children_level = has_children.begin (); - children_level != has_children.end (); - ++children_level) - delete (*children_level); has_children.clear (); } @@ -3344,11 +3338,8 @@ namespace hp template void DoFHandler::clear_space () { - for (unsigned int i=0; i tmp; -- 2.39.5