From: Marc Fehling Date: Thu, 9 Mar 2023 13:52:22 +0000 (+0100) Subject: Warn users about FE index mismatch instead of silently dropping them. X-Git-Tag: v9.5.0-rc1~301^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=346a09d6d1d9c75b330d758cd70cc95298dbceda;p=dealii.git Warn users about FE index mismatch instead of silently dropping them. --- diff --git a/source/dofs/dof_handler.cc b/source/dofs/dof_handler.cc index 62fc1523ea..88416b8278 100644 --- a/source/dofs/dof_handler.cc +++ b/source/dofs/dof_handler.cc @@ -2158,6 +2158,25 @@ void DoFHandler::distribute_dofs( ExcMessage("The Triangulation you are using is empty!")); Assert(ff.size() > 0, ExcMessage("The given hp::FECollection is empty!")); +#ifdef DEBUG + // make sure that the provided FE collection is large enough to + // cover all FE indices presently in use on the mesh + if ((hp_cell_active_fe_indices.size() > 0) && + (hp_cell_future_fe_indices.size() > 0)) + { + Assert(hp_capability_enabled, ExcInternalError()); + + for (const auto &cell : + this->active_cell_iterators() | IteratorFilters::LocallyOwnedCell()) + { + Assert(cell->active_fe_index() < ff.size(), + ExcInvalidFEIndex(cell->active_fe_index(), ff.size())); + Assert(cell->future_fe_index() < ff.size(), + ExcInvalidFEIndex(cell->future_fe_index(), ff.size())); + } + } +#endif + // // register the new finite element collection // @@ -2205,22 +2224,6 @@ void DoFHandler::distribute_dofs( // on both its own cells and all ghost cells internal::hp::DoFHandlerImplementation::Implementation:: communicate_active_fe_indices(*this); - -#ifdef DEBUG - // make sure that the FE collection is large enough to - // cover all FE indices presently in use on the mesh - for (const auto &cell : this->active_cell_iterators()) - { - if (!cell->is_artificial()) - Assert(cell->active_fe_index() < this->fe_collection.size(), - ExcInvalidFEIndex(cell->active_fe_index(), - this->fe_collection.size())); - if (cell->is_locally_owned()) - Assert(cell->future_fe_index() < this->fe_collection.size(), - ExcInvalidFEIndex(cell->future_fe_index(), - this->fe_collection.size())); - } -#endif } { diff --git a/tests/hp/non_hp_mode.cc b/tests/hp/non_hp_mode.cc new file mode 100644 index 0000000000..e6ec60bff0 --- /dev/null +++ b/tests/hp/non_hp_mode.cc @@ -0,0 +1,65 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2023 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. +// +// --------------------------------------------------------------------- + + +// warn users that they should have nonzero active FE indices in non-hp mode + + +#include + +#include + +#include +#include + +#include "../tests.h" + + +template +void +test() +{ + Triangulation triangulation; + GridGenerator::hyper_cube(triangulation); + + FE_Q fe(1); + + DoFHandler dof_handler(triangulation); + + // Choose index out of range here. + dof_handler.begin_active()->set_active_fe_index(1); + + try + { + dof_handler.distribute_dofs(fe); + } + catch (ExceptionBase &e) + { + deallog << e.what() << std::endl; + } +} + + +int +main() +{ + deal_II_exceptions::disable_abort_on_exception(); + + initlog(); + + test<2>(); + + deallog << "OK" << std::endl; +} diff --git a/tests/hp/non_hp_mode.debug.output b/tests/hp/non_hp_mode.debug.output new file mode 100644 index 0000000000..4f97b17266 --- /dev/null +++ b/tests/hp/non_hp_mode.debug.output @@ -0,0 +1,13 @@ + +DEAL:: +-------------------------------------------------------- +An error occurred in file in function + void dealii::DoFHandler::distribute_dofs(const dealii::hp::FECollection&) [with int dim = 2; int spacedim = 2] +The violated condition was: + cell->active_fe_index() < ff.size() +Additional information: + The mesh contains a cell with an active FE index of 1, but the finite + element collection only has 1 elements +-------------------------------------------------------- + +DEAL::OK