]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Merge pull request #14866 from marcfehling/assert
authorWolfgang Bangerth <bangerth@colostate.edu>
Sat, 22 Apr 2023 00:06:39 +0000 (18:06 -0600)
committerGitHub <noreply@github.com>
Sat, 22 Apr 2023 00:06:39 +0000 (18:06 -0600)
Warn users about FE index mismatch instead of silently dropping them.

1  2 
include/deal.II/dofs/dof_accessor.templates.h
source/dofs/dof_handler.cc

index 57df3f28b81cd7399e6346debf28575026d18c14,88416b8278bbb6ef6163a2967bb986cfcbc59da3..c587a23412fc2380635680a3d017f0b1fa6c7431
@@@ -2154,20 -2149,34 +2154,39 @@@ DEAL_II_CXX20_REQUIRES((concepts::is_va
  void DoFHandler<dim, spacedim>::distribute_dofs(
    const hp::FECollection<dim, spacedim> &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<types::fe_index>::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
    //

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.