Skip to content

DirichletBoundaries should be a vector of unique_ptrs #3270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions include/base/dirichlet_boundaries.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<DirichletBoundary *>
class DirichletBoundaries : public std::vector<std::unique_ptr<DirichletBoundary>>
{
public:
DirichletBoundaries() {}

~DirichletBoundaries();
DirichletBoundaries() = default;
~DirichletBoundaries() = default;
};

} // namespace libMesh
Expand Down
23 changes: 8 additions & 15 deletions src/base/dof_map_constraints.C
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<DirichletBoundary>(dirichlet_boundary));
}


Expand All @@ -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<DirichletBoundary>(dirichlet_boundary));
}


Expand Down Expand Up @@ -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);
}

Expand All @@ -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
{
Expand Down