Skip to content
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

Fix tria::has_hanging_nodes for anisotropically refined meshes #14150

Merged
merged 3 commits into from
Jul 28, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions source/grid/tria.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13979,10 +13979,19 @@ template <int dim, int spacedim>
bool
Triangulation<dim, spacedim>::has_hanging_nodes() const
{
for (unsigned int lvl = 0; lvl < n_global_levels() - 1; ++lvl)
if (n_active_cells(lvl) != 0)
return true;

if (anisotropic_refinement == false)
{
for (unsigned int lvl = 0; lvl < n_global_levels() - 1; ++lvl)
if (n_active_cells(lvl) != 0)
return true;
}
else
{
for (const auto &cell : active_cell_iterators())
for (const auto &i : cell->face_indices())
if (cell->face(i)->has_children())
return true;
}
return false;
}

Expand Down
42 changes: 42 additions & 0 deletions tests/grid/grid_has_hanging_nodes.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// ---------------------------------------------------------------------
//
// Copyright (C) 2022 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE.md at
// the top level directory of deal.II.
//
// ---------------------------------------------------------------------

// Check that has hanging nodes works correctly for anysotropic refinement

#include <deal.II/grid/grid_generator.h>
#include <deal.II/grid/tria.h>

#include "../tests.h"

int
main()
{
initlog();
Triangulation<2> tria;
GridGenerator::hyper_cube(tria);
tria.begin_active()->set_refine_flag(RefinementCase<2>::cut_x);
tria.execute_coarsening_and_refinement();
tria.begin_active()->set_refine_flag(RefinementCase<2>::cut_x);
tria.execute_coarsening_and_refinement();

if (tria.has_hanging_nodes() == false)
{
deallog << "OK" << std::endl;
}
else
{
deallog << "NOT OK" << std::endl;
}
}
2 changes: 2 additions & 0 deletions tests/grid/grid_has_hanging_nodes.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

DEAL::OK