]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Disallow calling some functions in the hp context on non-active cells.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 17 Jan 2014 22:02:15 +0000 (22:02 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 17 Jan 2014 22:02:15 +0000 (22:02 +0000)
git-svn-id: https://svn.dealii.org/trunk@32240 0785d39b-7218-0410-832d-ea1e28bc413d

tests/hp/get_interpolated_dof_values_01.cc [new file with mode: 0644]
tests/hp/get_interpolated_dof_values_01.debug.output [new file with mode: 0644]
tests/hp/set_dof_values_by_interpolation.cc [new file with mode: 0644]
tests/hp/set_dof_values_by_interpolation.debug.output [new file with mode: 0644]

diff --git a/tests/hp/get_interpolated_dof_values_01.cc b/tests/hp/get_interpolated_dof_values_01.cc
new file mode 100644 (file)
index 0000000..743e8a7
--- /dev/null
@@ -0,0 +1,107 @@
+// ---------------------------------------------------------------------
+// $Id$
+//
+// Copyright (C) 1998 - 2014 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.
+//
+// ---------------------------------------------------------------------
+
+
+// cell->get_interpolated_dof_values can not work properly in the hp
+// context when called on non-active cells because these do not have a
+// finite element associated with them
+
+#include "../tests.h"
+#include <deal.II/base/quadrature_lib.h>
+#include <deal.II/base/logstream.h>
+#include <deal.II/lac/vector.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/tria_iterator.h>
+#include <deal.II/dofs/dof_accessor.h>
+#include <deal.II/hp/dof_handler.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_tools.h>
+#include <deal.II/fe/fe_q.h>
+
+#include <vector>
+#include <fstream>
+#include <string>
+
+#define PRECISION 2
+
+
+
+
+template <int dim>
+void test ()
+{
+  // create a hp::DoFHandler with different finite elements on the
+  // cells. note that we assign active_fe_indices also to inactive
+  // elements
+  Triangulation<dim> tr;
+  GridGenerator::hyper_cube(tr, 0., 1.);
+  tr.refine_global (2);
+
+  hp::FECollection<dim> fe;
+  for (unsigned int i=1; i<5; ++i)
+    fe.push_back (FE_Q<dim>(i));
+
+  hp::DoFHandler<dim> dof_handler(tr);
+  for (typename hp::DoFHandler<dim>::cell_iterator cell=dof_handler.begin();
+       cell!=dof_handler.end(); ++cell)
+    cell->set_active_fe_index (cell->index() % fe.size());
+
+  dof_handler.distribute_dofs (fe);
+
+  // create a mostly arbitrary FE field
+  Vector<double> solution(dof_handler.n_dofs());
+  for (unsigned int i=0; i<solution.size(); ++i)
+    solution(i) = i;
+
+  // try to interpolate from the active cell onto the coarsest cell,
+  // which is definitely not active. this can't work, so expect an
+  // exception
+  typename hp::DoFHandler<dim>::cell_iterator cell=dof_handler.begin(0);
+  Vector<double> local (cell->get_fe().dofs_per_cell);
+
+  try
+    {
+      cell->get_interpolated_dof_values (solution, local);
+    }
+  catch (const ExceptionBase &e)
+    {
+      deallog << "Yes, exception!" << std::endl;
+      deallog << e.get_exc_name() << std::endl;
+    }
+}
+
+
+int
+main()
+{
+  std::ofstream logfile ("output");
+  logfile.precision (PRECISION);
+  logfile.setf(std::ios::fixed);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  deal_II_exceptions::disable_abort_on_exception();
+
+  test<1>();
+  test<2>();
+  test<3>();
+
+  return 0;
+}
+
+
+
diff --git a/tests/hp/get_interpolated_dof_values_01.debug.output b/tests/hp/get_interpolated_dof_values_01.debug.output
new file mode 100644 (file)
index 0000000..2aca68e
--- /dev/null
@@ -0,0 +1,7 @@
+
+DEAL::Yes, exception!
+DEAL::ExcMessage ("You cannot call this function on non-active cells " "of hp::DoFHandler objects because they do not have " "associated finite element spaces associated: degrees " "of freedom are only distributed on active cells for which " "the active_fe_index has been set.")
+DEAL::Yes, exception!
+DEAL::ExcMessage ("You cannot call this function on non-active cells " "of hp::DoFHandler objects because they do not have " "associated finite element spaces associated: degrees " "of freedom are only distributed on active cells for which " "the active_fe_index has been set.")
+DEAL::Yes, exception!
+DEAL::ExcMessage ("You cannot call this function on non-active cells " "of hp::DoFHandler objects because they do not have " "associated finite element spaces associated: degrees " "of freedom are only distributed on active cells for which " "the active_fe_index has been set.")
diff --git a/tests/hp/set_dof_values_by_interpolation.cc b/tests/hp/set_dof_values_by_interpolation.cc
new file mode 100644 (file)
index 0000000..743e8a7
--- /dev/null
@@ -0,0 +1,107 @@
+// ---------------------------------------------------------------------
+// $Id$
+//
+// Copyright (C) 1998 - 2014 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.
+//
+// ---------------------------------------------------------------------
+
+
+// cell->get_interpolated_dof_values can not work properly in the hp
+// context when called on non-active cells because these do not have a
+// finite element associated with them
+
+#include "../tests.h"
+#include <deal.II/base/quadrature_lib.h>
+#include <deal.II/base/logstream.h>
+#include <deal.II/lac/vector.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/tria_iterator.h>
+#include <deal.II/dofs/dof_accessor.h>
+#include <deal.II/hp/dof_handler.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_tools.h>
+#include <deal.II/fe/fe_q.h>
+
+#include <vector>
+#include <fstream>
+#include <string>
+
+#define PRECISION 2
+
+
+
+
+template <int dim>
+void test ()
+{
+  // create a hp::DoFHandler with different finite elements on the
+  // cells. note that we assign active_fe_indices also to inactive
+  // elements
+  Triangulation<dim> tr;
+  GridGenerator::hyper_cube(tr, 0., 1.);
+  tr.refine_global (2);
+
+  hp::FECollection<dim> fe;
+  for (unsigned int i=1; i<5; ++i)
+    fe.push_back (FE_Q<dim>(i));
+
+  hp::DoFHandler<dim> dof_handler(tr);
+  for (typename hp::DoFHandler<dim>::cell_iterator cell=dof_handler.begin();
+       cell!=dof_handler.end(); ++cell)
+    cell->set_active_fe_index (cell->index() % fe.size());
+
+  dof_handler.distribute_dofs (fe);
+
+  // create a mostly arbitrary FE field
+  Vector<double> solution(dof_handler.n_dofs());
+  for (unsigned int i=0; i<solution.size(); ++i)
+    solution(i) = i;
+
+  // try to interpolate from the active cell onto the coarsest cell,
+  // which is definitely not active. this can't work, so expect an
+  // exception
+  typename hp::DoFHandler<dim>::cell_iterator cell=dof_handler.begin(0);
+  Vector<double> local (cell->get_fe().dofs_per_cell);
+
+  try
+    {
+      cell->get_interpolated_dof_values (solution, local);
+    }
+  catch (const ExceptionBase &e)
+    {
+      deallog << "Yes, exception!" << std::endl;
+      deallog << e.get_exc_name() << std::endl;
+    }
+}
+
+
+int
+main()
+{
+  std::ofstream logfile ("output");
+  logfile.precision (PRECISION);
+  logfile.setf(std::ios::fixed);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  deal_II_exceptions::disable_abort_on_exception();
+
+  test<1>();
+  test<2>();
+  test<3>();
+
+  return 0;
+}
+
+
+
diff --git a/tests/hp/set_dof_values_by_interpolation.debug.output b/tests/hp/set_dof_values_by_interpolation.debug.output
new file mode 100644 (file)
index 0000000..2aca68e
--- /dev/null
@@ -0,0 +1,7 @@
+
+DEAL::Yes, exception!
+DEAL::ExcMessage ("You cannot call this function on non-active cells " "of hp::DoFHandler objects because they do not have " "associated finite element spaces associated: degrees " "of freedom are only distributed on active cells for which " "the active_fe_index has been set.")
+DEAL::Yes, exception!
+DEAL::ExcMessage ("You cannot call this function on non-active cells " "of hp::DoFHandler objects because they do not have " "associated finite element spaces associated: degrees " "of freedom are only distributed on active cells for which " "the active_fe_index has been set.")
+DEAL::Yes, exception!
+DEAL::ExcMessage ("You cannot call this function on non-active cells " "of hp::DoFHandler objects because they do not have " "associated finite element spaces associated: degrees " "of freedom are only distributed on active cells for which " "the active_fe_index has been set.")

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.