From fd67186cd43a8e456ba48eacac1b41864e9dd31b Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 17 Jan 2014 22:02:15 +0000 Subject: [PATCH] Disallow calling some functions in the hp context on non-active cells. git-svn-id: https://svn.dealii.org/trunk@32240 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/hp/get_interpolated_dof_values_01.cc | 107 ++++++++++++++++++ ...et_interpolated_dof_values_01.debug.output | 7 ++ tests/hp/set_dof_values_by_interpolation.cc | 107 ++++++++++++++++++ ...t_dof_values_by_interpolation.debug.output | 7 ++ 4 files changed, 228 insertions(+) create mode 100644 tests/hp/get_interpolated_dof_values_01.cc create mode 100644 tests/hp/get_interpolated_dof_values_01.debug.output create mode 100644 tests/hp/set_dof_values_by_interpolation.cc create mode 100644 tests/hp/set_dof_values_by_interpolation.debug.output diff --git a/tests/hp/get_interpolated_dof_values_01.cc b/tests/hp/get_interpolated_dof_values_01.cc new file mode 100644 index 0000000000..743e8a75ea --- /dev/null +++ b/tests/hp/get_interpolated_dof_values_01.cc @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define PRECISION 2 + + + + +template +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 tr; + GridGenerator::hyper_cube(tr, 0., 1.); + tr.refine_global (2); + + hp::FECollection fe; + for (unsigned int i=1; i<5; ++i) + fe.push_back (FE_Q(i)); + + hp::DoFHandler dof_handler(tr); + for (typename hp::DoFHandler::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 solution(dof_handler.n_dofs()); + for (unsigned int i=0; i::cell_iterator cell=dof_handler.begin(0); + Vector 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 index 0000000000..2aca68e01e --- /dev/null +++ b/tests/hp/get_interpolated_dof_values_01.debug.output @@ -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 index 0000000000..743e8a75ea --- /dev/null +++ b/tests/hp/set_dof_values_by_interpolation.cc @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define PRECISION 2 + + + + +template +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 tr; + GridGenerator::hyper_cube(tr, 0., 1.); + tr.refine_global (2); + + hp::FECollection fe; + for (unsigned int i=1; i<5; ++i) + fe.push_back (FE_Q(i)); + + hp::DoFHandler dof_handler(tr); + for (typename hp::DoFHandler::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 solution(dof_handler.n_dofs()); + for (unsigned int i=0; i::cell_iterator cell=dof_handler.begin(0); + Vector 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 index 0000000000..2aca68e01e --- /dev/null +++ b/tests/hp/set_dof_values_by_interpolation.debug.output @@ -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.") -- 2.39.5