From 60d37981715cc70ec51bc9c4b54f3e53faeacf51 Mon Sep 17 00:00:00 2001 From: David Wells Date: Sat, 7 May 2016 19:34:19 -0400 Subject: [PATCH] Use index sets to simplify some assertions. GCC 6.1 now warns (-Waddress) that (since the dynamic cast of an object back to its own type always succeeds) the address of an object is always nonzero. Fortunately these dynamic casts are not needed anymore due to better support for generic programming in the library. Since local_size is not available for scalar vectors, perform (stricter) checks with index sets instead. Regardless of the new GCC warning, these assertions are useful for all distributed vectors (and may be run now for sequential vectors too) and dof handler type, so they should always be checked. --- source/fe/fe_tools_interpolate.cc | 110 ++++++++++++------------------ 1 file changed, 42 insertions(+), 68 deletions(-) diff --git a/source/fe/fe_tools_interpolate.cc b/source/fe/fe_tools_interpolate.cc index 1a611c6521..88b4fcee3c 100644 --- a/source/fe/fe_tools_interpolate.cc +++ b/source/fe/fe_tools_interpolate.cc @@ -85,24 +85,19 @@ namespace FETools Assert(u2.size()==dof2.n_dofs(), ExcDimensionMismatch(u2.size(), dof2.n_dofs())); -#ifdef DEAL_II_WITH_PETSC - if (dynamic_cast(&u1) != 0) - if (dynamic_cast*>(&dof1) != 0) - { - // if u1 is a parallel distributed - // PETSc vector, we check the local - // size of u1 for safety - Assert(dynamic_cast(&u1)->local_size() == dof1.n_locally_owned_dofs(), - ExcDimensionMismatch(dynamic_cast(&u1)->local_size(), dof1.n_locally_owned_dofs())); - }; - - if (dynamic_cast(&u2) != 0) - if (dynamic_cast*>(&dof2) != 0) - { - Assert(dynamic_cast(&u2)->local_size() == dof2.n_locally_owned_dofs(), - ExcDimensionMismatch(dynamic_cast(&u2)->local_size(), dof2.n_locally_owned_dofs())); - }; +#ifdef DEBUG + const IndexSet &dof1_local_dofs = dof1.locally_owned_dofs(); + const IndexSet &dof2_local_dofs = dof2.locally_owned_dofs(); + const IndexSet u1_elements = u1.locally_owned_elements(); + const IndexSet u2_elements = u2.locally_owned_elements(); + Assert(u1_elements == dof1_local_dofs, + ExcMessage("The provided vector and DoF handler should have the same" + " index sets.")); + Assert(u2_elements == dof2_local_dofs, + ExcMessage("The provided vector and DoF handler should have the same" + " index sets.")); #endif + // allocate vectors at maximal // size. will be reinited in inner // cell, but Vector makes sure that @@ -248,23 +243,16 @@ namespace FETools Assert(u1_interpolated.size()==dof1.n_dofs(), ExcDimensionMismatch(u1_interpolated.size(), dof1.n_dofs())); -#ifdef DEAL_II_WITH_PETSC - if (dynamic_cast(&u1) != 0) - if (dynamic_cast*>(&dof1) != 0) - { - // if u1 is a parallel distributed - // PETSc vector, we check the local - // size of u1 for safety - Assert(dynamic_cast(&u1)->local_size() == dof1.n_locally_owned_dofs(), - ExcDimensionMismatch(dynamic_cast(&u1)->local_size(), dof1.n_locally_owned_dofs())); - }; - - if (dynamic_cast(&u1_interpolated) != 0) - if (dynamic_cast*>(&dof1) != 0) - { - Assert(dynamic_cast(&u1_interpolated)->local_size() == dof1.n_locally_owned_dofs(), - ExcDimensionMismatch(dynamic_cast(&u1_interpolated)->local_size(), dof1.n_locally_owned_dofs())); - }; +#ifdef DEBUG + const IndexSet &dof1_local_dofs = dof1.locally_owned_dofs(); + const IndexSet u1_elements = u1.locally_owned_elements(); + const IndexSet u1_interpolated_elements = u1_interpolated.locally_owned_elements(); + Assert(u1_elements == dof1_local_dofs, + ExcMessage("The provided vector and DoF handler should have the same" + " index sets.")); + Assert(u1_interpolated_elements == dof1_local_dofs, + ExcMessage("The provided vector and DoF handler should have the same" + " index sets.")); #endif // For continuous elements on grids @@ -328,23 +316,16 @@ namespace FETools Assert(u1_interpolated.size() == dof1.n_dofs(), ExcDimensionMismatch(u1_interpolated.size(), dof1.n_dofs())); -#ifdef DEAL_II_WITH_PETSC - if (dynamic_cast(&u1) != 0) - if (dynamic_cast*>(&dof1) != 0) - { - // if u1 is a parallel distributed - // PETSc vector, we check the local - // size of u1 for safety - Assert(dynamic_cast(&u1)->local_size() == dof1.n_locally_owned_dofs(), - ExcDimensionMismatch(dynamic_cast(&u1)->local_size(), dof1.n_locally_owned_dofs())); - }; - - if (dynamic_cast(&u1_interpolated) != 0) - if (dynamic_cast*>(&dof1) != 0) - { - Assert(dynamic_cast(&u1_interpolated)->local_size() == dof1.n_locally_owned_dofs(), - ExcDimensionMismatch(dynamic_cast(&u1_interpolated)->local_size(), dof1.n_locally_owned_dofs())); - }; +#ifdef DEBUG + const IndexSet &dof1_local_dofs = dof1.locally_owned_dofs(); + const IndexSet u1_elements = u1.locally_owned_elements(); + const IndexSet u1_interpolated_elements = u1_interpolated.locally_owned_elements(); + Assert(u1_elements == dof1_local_dofs, + ExcMessage("The provided vector and DoF handler should have the same" + " index sets.")); + Assert(u1_interpolated_elements == dof1_local_dofs, + ExcMessage("The provided vector and DoF handler should have the same" + " index sets.")); #endif Vector u1_local(DoFTools::max_dofs_per_cell(dof1)); @@ -560,23 +541,16 @@ namespace FETools Assert(u1_difference.size()==dof1.n_dofs(), ExcDimensionMismatch(u1_difference.size(), dof1.n_dofs())); -#ifdef DEAL_II_WITH_PETSC - if (dynamic_cast(&u1) != 0) - if (dynamic_cast*>(&dof1) != 0) - { - // if u1 is a parallel distributed - // PETSc vector, we check the local - // size of u1 for safety - Assert(dynamic_cast(&u1)->local_size() == dof1.n_locally_owned_dofs(), - ExcDimensionMismatch(dynamic_cast(&u1)->local_size(), dof1.n_locally_owned_dofs())); - }; - - if (dynamic_cast(&u1_difference) != 0) - if (dynamic_cast*>(&dof1) != 0) - { - Assert(dynamic_cast(&u1_difference)->local_size() == dof1.n_locally_owned_dofs(), - ExcDimensionMismatch(dynamic_cast(&u1_difference)->local_size(), dof1.n_locally_owned_dofs())); - }; +#ifdef DEBUG + const IndexSet &dof1_local_dofs = dof1.locally_owned_dofs(); + const IndexSet u1_elements = u1.locally_owned_elements(); + const IndexSet u1_difference_elements = u1_difference.locally_owned_elements(); + Assert(u1_elements == dof1_local_dofs, + ExcMessage("The provided vector and DoF handler should have the same" + " index sets.")); + Assert(u1_difference_elements == dof1_local_dofs, + ExcMessage("The provided vector and DoF handler should have the same" + " index sets.")); #endif // For continuous elements on grids -- 2.39.5