From c5c08dcd9308ad19a6f2385c603bc79d1f0502a5 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 27 Apr 2018 16:09:23 -0600 Subject: [PATCH] Strengthen the guarantees by FiniteElement::operator==. This includes more fields of information. However, the operator now goes through fields in roughly increasing order of how expensive it is to compare things. --- include/deal.II/fe/fe.h | 25 ++++++++++++++++--------- source/fe/fe.cc | 19 +++++++++++++++---- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/include/deal.II/fe/fe.h b/include/deal.II/fe/fe.h index 273be3c05e..c519de1b0e 100644 --- a/include/deal.II/fe/fe.h +++ b/include/deal.II/fe/fe.h @@ -1335,17 +1335,24 @@ public: /** * Comparison operator. * - * The implementation in the current class checks for equality of the name - * returned by get_name() and for equality of the constraint matrix, as well - * as all of the fields in FiniteElementData. This covers most cases where - * elements can differ, but there are cases of derived elements that are - * different and for which the current function still returns @p true. - * For these cases, derived classes should overload this function. - * - * We do not compare the matrix arrays #restriction and #prolongation. + * The implementation in the current class checks for equality of the + * following pieces of information between the current object and the one + * given as argument, in this order: + * - the dynamic type (i.e., the type of the most derived class) of the + * current object and of the given object, + * - the name returned by get_name(), + * - as all of the fields in FiniteElementData, + * - constraint matrices, + * - restriction matrices, + * - prolongation matrices of this object and the argument. + * + * This covers most cases where elements can differ, but there are + * cases of derived elements that are different and for which the + * current function still returns @p true. For these cases, derived + * classes should overload this function. */ virtual - bool operator == (const FiniteElement &) const; + bool operator == (const FiniteElement &fe) const; /** * Non-equality comparison operator. Defined in terms of the equality comparison operator. diff --git a/source/fe/fe.cc b/source/fe/fe.cc index e877973aea..6c658766ca 100644 --- a/source/fe/fe.cc +++ b/source/fe/fe.cc @@ -27,6 +27,7 @@ #include #include #include +#include DEAL_II_NAMESPACE_OPEN @@ -937,10 +938,20 @@ template bool FiniteElement::operator == (const FiniteElement &f) const { - return ((static_cast&>(*this) == - static_cast&>(f)) && - (interface_constraints == f.interface_constraints) && - (this->get_name() == f.get_name())); + // Compare fields in roughly increasing order of how expensive the + // comparison is + return ((typeid(*this) == typeid(f)) + && + (this->get_name() == f.get_name()) + && + (static_cast&>(*this) == + static_cast&>(f)) + && + (interface_constraints == f.interface_constraints) + && + (restriction == f.restriction) + && + (prolongation == f.prolongation)); } -- 2.39.5