]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Check that level dofs are initialized when calling DoFHandler<dim, spacedim>::locally... 6611/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 16 May 2018 13:35:01 +0000 (15:35 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 16 May 2018 15:13:04 +0000 (17:13 +0200)
include/deal.II/dofs/dof_handler.h
tests/multigrid/constrained_dofs_04.cc [new file with mode: 0644]
tests/multigrid/constrained_dofs_04.debug.output [new file with mode: 0644]

index 86894f1a4f91c95b942ae49932e32aac11f6e8ff..88b369bf3f9f2e9c08244062da3d724c3b71e3cf 100644 (file)
@@ -1276,6 +1276,8 @@ DoFHandler<dim, spacedim>::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 <int dim, int spacedim>
 const std::vector<IndexSet> &
 DoFHandler<dim, spacedim>::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 (file)
index 0000000..9d90e83
--- /dev/null
@@ -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 <deal.II/grid/tria.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/multigrid/mg_constrained_dofs.h>
+
+#include <algorithm>
+
+int main(int argc, char *argv[])
+{
+  initlog();
+  deal_II_exceptions::disable_abort_on_exception();
+
+  constexpr int dim=2;
+  Triangulation<dim> tria;
+  GridGenerator::hyper_cube(tria);
+  DoFHandler<dim> dh (tria);
+  dh.distribute_dofs(FE_Q<dim>(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 (file)
index 0000000..19f9254
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::ExcMessage("The level dofs are not set up properly! Did you call distribute_mg_dofs()?")

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.