diff --git a/include/base/dirichlet_boundaries.h b/include/base/dirichlet_boundaries.h index 1edf2e488bb..07cd211f100 100644 --- a/include/base/dirichlet_boundaries.h +++ b/include/base/dirichlet_boundaries.h @@ -211,12 +211,11 @@ class DirichletBoundary * \note \p std::map has no virtual destructor, so downcasting here * would be dangerous. */ -class DirichletBoundaries : public std::vector +class DirichletBoundaries : public std::vector> { public: - DirichletBoundaries() {} - - ~DirichletBoundaries(); + DirichletBoundaries() = default; + ~DirichletBoundaries() = default; }; } // namespace libMesh diff --git a/src/base/dof_map_constraints.C b/src/base/dof_map_constraints.C index f5c12f9e06b..d2339400da8 100644 --- a/src/base/dof_map_constraints.C +++ b/src/base/dof_map_constraints.C @@ -1585,7 +1585,7 @@ public: // Construct mapping from boundary_id -> (dirichlet_id, DirichletBoundary) for (const auto & b_id : dirichlet->b) - boundary_id_to_ordered_dirichlet_boundaries[b_id].emplace(dirichlet_id, dirichlet); + boundary_id_to_ordered_dirichlet_boundaries[b_id].emplace(dirichlet_id, dirichlet.get()); for (const auto & var : dirichlet->variables) { @@ -5238,7 +5238,7 @@ void DofMap::constrain_p_dofs (unsigned int var, #ifdef LIBMESH_ENABLE_DIRICHLET void DofMap::add_dirichlet_boundary (const DirichletBoundary & dirichlet_boundary) { - _dirichlet_boundaries->push_back(new DirichletBoundary(dirichlet_boundary)); + _dirichlet_boundaries->push_back(std::make_unique(dirichlet_boundary)); } @@ -5250,8 +5250,9 @@ void DofMap::add_adjoint_dirichlet_boundary (const DirichletBoundary & dirichlet for (unsigned int i = old_size; i <= qoi_index; ++i) _adjoint_dirichlet_boundaries.push_back(new DirichletBoundaries()); + // Make copy of DirichletBoundary, owned by _adjoint_dirichlet_boundaries _adjoint_dirichlet_boundaries[qoi_index]->push_back - (new DirichletBoundary(dirichlet_boundary)); + (std::make_unique(dirichlet_boundary)); } @@ -5287,14 +5288,13 @@ DofMap::get_adjoint_dirichlet_boundaries(unsigned int q) void DofMap::remove_dirichlet_boundary (const DirichletBoundary & boundary_to_remove) { // Find a boundary condition matching the one to be removed - auto lam = [&boundary_to_remove](const DirichletBoundary * bdy) + auto lam = [&boundary_to_remove](const auto & bdy) {return bdy->b == boundary_to_remove.b && bdy->variables == boundary_to_remove.variables;}; auto it = std::find_if(_dirichlet_boundaries->begin(), _dirichlet_boundaries->end(), lam); - // Delete it and remove it + // Assert it was actually found and remove it from the vector libmesh_assert (it != _dirichlet_boundaries->end()); - delete *it; _dirichlet_boundaries->erase(it); } @@ -5305,26 +5305,19 @@ void DofMap::remove_adjoint_dirichlet_boundary (const DirichletBoundary & bounda libmesh_assert_greater(_adjoint_dirichlet_boundaries.size(), qoi_index); - auto lam = [&boundary_to_remove](const DirichletBoundary * bdy) + auto lam = [&boundary_to_remove](const auto & bdy) {return bdy->b == boundary_to_remove.b && bdy->variables == boundary_to_remove.variables;}; auto it = std::find_if(_adjoint_dirichlet_boundaries[qoi_index]->begin(), _adjoint_dirichlet_boundaries[qoi_index]->end(), lam); - // Delete it and remove it + // Assert it was actually found and remove it from the vector libmesh_assert (it != _adjoint_dirichlet_boundaries[qoi_index]->end()); - delete *it; _adjoint_dirichlet_boundaries[qoi_index]->erase(it); } -DirichletBoundaries::~DirichletBoundaries() -{ - for (auto & item : *this) - delete item; -} - void DofMap::check_dirichlet_bcid_consistency (const MeshBase & mesh, const DirichletBoundary & boundary) const {