From 7ca00c215a9823e619ccf6b332fc660237f24d40 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Wed, 16 May 2018 15:35:01 +0200 Subject: [PATCH] Check that level dofs are initialized when calling DoFHandler::locally_owned_mg_dofs --- include/deal.II/dofs/dof_handler.h | 7 ++- tests/multigrid/constrained_dofs_04.cc | 47 +++++++++++++++++++ .../constrained_dofs_04.debug.output | 2 + 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/multigrid/constrained_dofs_04.cc create mode 100644 tests/multigrid/constrained_dofs_04.debug.output diff --git a/include/deal.II/dofs/dof_handler.h b/include/deal.II/dofs/dof_handler.h index 86894f1a4f..88b369bf3f 100644 --- a/include/deal.II/dofs/dof_handler.h +++ b/include/deal.II/dofs/dof_handler.h @@ -1276,6 +1276,8 @@ DoFHandler::locally_owned_mg_dofs(const unsigned int level) const { Assert(level < this->get_triangulation().n_global_levels(), ExcMessage("invalid level in locally_owned_mg_dofs")); + Assert (mg_number_cache.size() == this->get_triangulation().n_global_levels(), + ExcMessage("The level dofs are not set up properly! Did you call distribute_mg_dofs()?")); return mg_number_cache[level].locally_owned_dofs; } @@ -1303,7 +1305,10 @@ template const std::vector & DoFHandler::locally_owned_mg_dofs_per_processor (const unsigned int level) const { - Assert(level < this->get_triangulation().n_global_levels(), ExcMessage("invalid level in locally_owned_mg_dofs_per_processor")); + Assert(level < this->get_triangulation().n_global_levels(), + ExcMessage("invalid level in locally_owned_mg_dofs_per_processor")); + Assert(mg_number_cache.size() == this->get_triangulation().n_global_levels(), + ExcMessage("The level dofs are not set up properly! Did you call distribute_mg_dofs()?")); return mg_number_cache[level].locally_owned_dofs_per_processor; } diff --git a/tests/multigrid/constrained_dofs_04.cc b/tests/multigrid/constrained_dofs_04.cc new file mode 100644 index 0000000000..9d90e83163 --- /dev/null +++ b/tests/multigrid/constrained_dofs_04.cc @@ -0,0 +1,47 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2018 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 at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// check that we get a reasonable error message when trying to call +// MGConstrainedDofs::initialize() with distributing level dofs. + +#include "../tests.h" +#include +#include +#include +#include + +#include + +int main(int argc, char *argv[]) +{ + initlog(); + deal_II_exceptions::disable_abort_on_exception(); + + constexpr int dim=2; + Triangulation tria; + GridGenerator::hyper_cube(tria); + DoFHandler dh (tria); + dh.distribute_dofs(FE_Q(1)); + MGConstrainedDoFs mg_dofs; + try + { + mg_dofs.initialize(dh); + } + catch (ExceptionBase &e) + { + deallog << e.get_exc_name() << std::endl; + } +} diff --git a/tests/multigrid/constrained_dofs_04.debug.output b/tests/multigrid/constrained_dofs_04.debug.output new file mode 100644 index 0000000000..19f9254a23 --- /dev/null +++ b/tests/multigrid/constrained_dofs_04.debug.output @@ -0,0 +1,2 @@ + +DEAL::ExcMessage("The level dofs are not set up properly! Did you call distribute_mg_dofs()?") -- 2.39.5