From 8024ba49e18512e103cc75168faca49c848fbdcc Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 2 May 2006 22:41:06 +0000 Subject: [PATCH] Fix an off-by-one bug in a number of places. git-svn-id: https://svn.dealii.org/trunk@12989 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/dofs/hp_dof_handler.h | 17 +++++-- deal.II/deal.II/source/dofs/hp_dof_levels.cc | 12 ++--- tests/hp/crash_05/cmp/generic | 44 +++++++++++++++++++ 3 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 tests/hp/crash_05/cmp/generic diff --git a/deal.II/deal.II/include/dofs/hp_dof_handler.h b/deal.II/deal.II/include/dofs/hp_dof_handler.h index 4976f2d357..5a87c03894 100644 --- a/deal.II/deal.II/include/dofs/hp_dof_handler.h +++ b/deal.II/deal.II/include/dofs/hp_dof_handler.h @@ -1364,7 +1364,7 @@ namespace hp if (this_fe_index == fe_index) return *(pointer + 1 + local_index); else - pointer += (*finite_elements)[this_fe_index].dofs_per_vertex; + pointer += (*finite_elements)[this_fe_index].dofs_per_vertex + 1; } } @@ -1388,6 +1388,8 @@ namespace hp Assert (local_index < (*finite_elements)[fe_index].dofs_per_vertex, ExcIndexRange(local_index, 0, (*finite_elements)[fe_index].dofs_per_vertex)); + Assert (fe_index < finite_elements->size(), + ExcInternalError()); // hop along the list of index // sets until we find the one @@ -1400,15 +1402,22 @@ namespace hp unsigned int *pointer = &vertex_dofs[starting_offset]; while (true) { - Assert (*pointer != deal_II_numbers::invalid_unsigned_int, + Assert (pointer <= &vertex_dofs.back(), ExcInternalError()); + + const unsigned int this_fe_index = *pointer; + + Assert (this_fe_index != deal_II_numbers::invalid_unsigned_int, ExcInternalError()); - if (*pointer == fe_index) + Assert (this_fe_index < finite_elements->size(), + ExcInternalError()); + + if (this_fe_index == fe_index) { *(pointer + 1 + local_index) = global_index; return; } else - pointer += (*finite_elements)[*pointer].dofs_per_vertex; + pointer += (*finite_elements)[this_fe_index].dofs_per_vertex + 1; } } diff --git a/deal.II/deal.II/source/dofs/hp_dof_levels.cc b/deal.II/deal.II/source/dofs/hp_dof_levels.cc index f1df5b1105..9c3db4143e 100644 --- a/deal.II/deal.II/source/dofs/hp_dof_levels.cc +++ b/deal.II/deal.II/source/dofs/hp_dof_levels.cc @@ -79,7 +79,7 @@ namespace internal if (*pointer == fe_index) return *(pointer + 1 + local_index); else - pointer += dof_handler.get_fe()[*pointer].dofs_per_line; + pointer += dof_handler.get_fe()[*pointer].dofs_per_line + 1; } } } @@ -147,7 +147,7 @@ namespace internal return; } else - pointer += dof_handler.get_fe()[*pointer].dofs_per_line; + pointer += dof_handler.get_fe()[*pointer].dofs_per_line + 1; } } } @@ -212,7 +212,7 @@ namespace internal if (*pointer == fe_index) return *(pointer + 1 + local_index); else - pointer += dof_handler.get_fe()[*pointer].dofs_per_quad; + pointer += dof_handler.get_fe()[*pointer].dofs_per_quad + 1; } } } @@ -281,7 +281,7 @@ namespace internal return; } else - pointer += dof_handler.get_fe()[*pointer].dofs_per_quad; + pointer += dof_handler.get_fe()[*pointer].dofs_per_quad + 1; } } } @@ -346,7 +346,7 @@ namespace internal if (*pointer == fe_index) return *(pointer + 1 + local_index); else - pointer += dof_handler.get_fe()[*pointer].dofs_per_hex; + pointer += dof_handler.get_fe()[*pointer].dofs_per_hex + 1; } } } @@ -415,7 +415,7 @@ namespace internal return; } else - pointer += dof_handler.get_fe()[*pointer].dofs_per_hex; + pointer += dof_handler.get_fe()[*pointer].dofs_per_hex + 1; } } } diff --git a/tests/hp/crash_05/cmp/generic b/tests/hp/crash_05/cmp/generic new file mode 100644 index 0000000000..f8b76209b4 --- /dev/null +++ b/tests/hp/crash_05/cmp/generic @@ -0,0 +1,44 @@ + +DEAL::Setting fe_index=0 on cell 1.0 +DEAL::Setting fe_index=1 on cell 1.1 +DEAL::1.0 +DEAL::0 1 +DEAL::1.1 +DEAL::2 3 +DEAL::Setting fe_index=0 on cell 1.0 +DEAL::Setting fe_index=1 on cell 1.1 +DEAL::Setting fe_index=2 on cell 1.2 +DEAL::Setting fe_index=3 on cell 1.3 +DEAL::1.0 +DEAL::0 1 2 3 +DEAL::1.1 +DEAL::4 5 6 7 +DEAL::1.2 +DEAL::8 9 10 11 +DEAL::1.3 +DEAL::12 13 14 15 +DEAL::Setting fe_index=0 on cell 1.0 +DEAL::Setting fe_index=1 on cell 1.1 +DEAL::Setting fe_index=2 on cell 1.2 +DEAL::Setting fe_index=3 on cell 1.3 +DEAL::Setting fe_index=4 on cell 1.4 +DEAL::Setting fe_index=5 on cell 1.5 +DEAL::Setting fe_index=6 on cell 1.6 +DEAL::Setting fe_index=7 on cell 1.7 +DEAL::1.0 +DEAL::0 1 2 3 4 5 6 7 +DEAL::1.1 +DEAL::8 9 10 11 12 13 14 15 +DEAL::1.2 +DEAL::16 17 18 19 20 21 22 23 +DEAL::1.3 +DEAL::24 25 26 27 28 29 30 31 +DEAL::1.4 +DEAL::32 33 34 35 36 37 38 39 +DEAL::1.5 +DEAL::40 41 42 43 44 45 46 47 +DEAL::1.6 +DEAL::48 49 50 51 52 53 54 55 +DEAL::1.7 +DEAL::56 57 58 59 60 61 62 63 +DEAL::OK -- 2.39.5