From: Wolfgang Bangerth Date: Sat, 22 Apr 2023 00:06:39 +0000 (-0600) Subject: Merge pull request #14866 from marcfehling/assert X-Git-Tag: v9.5.0-rc1~301 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96b51adf0a1ffef76f51c3c47dcb062ab7accccb;p=dealii.git Merge pull request #14866 from marcfehling/assert Warn users about FE index mismatch instead of silently dropping them. --- 96b51adf0a1ffef76f51c3c47dcb062ab7accccb diff --cc source/dofs/dof_handler.cc index 57df3f28b8,88416b8278..c587a23412 --- a/source/dofs/dof_handler.cc +++ b/source/dofs/dof_handler.cc @@@ -2154,20 -2149,34 +2154,39 @@@ DEAL_II_CXX20_REQUIRES((concepts::is_va void DoFHandler::distribute_dofs( const hp::FECollection &ff) { - Assert( - this->tria != nullptr, - ExcMessage( - "You need to set the Triangulation in the DoFHandler using reinit() or " - "in the constructor before you can distribute DoFs.")); + Assert(this->tria != nullptr, + ExcMessage( + "You need to set the Triangulation in the DoFHandler using reinit() " + "or in the constructor before you can distribute DoFs.")); Assert(this->tria->n_levels() > 0, ExcMessage("The Triangulation you are using is empty!")); + + // verify size of provided FE collection Assert(ff.size() > 0, ExcMessage("The given hp::FECollection is empty!")); + Assert((ff.size() <= std::numeric_limits::max()) && + (ff.size() != numbers::invalid_fe_index), + ExcMessage("The given hp::FECollection contains more finite elements " + "than the DoFHandler can cover with active FE indices.")); + #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 //