From: Wolfgang Bangerth <bangerth@colostate.edu>
Date: Fri, 27 Apr 2018 22:09:23 +0000 (-0600)
Subject: Strengthen the guarantees by FiniteElement::operator==.
X-Git-Tag: v9.0.0-rc1~30^2~1
X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c5c08dcd9308ad19a6f2385c603bc79d1f0502a5;p=dealii.git

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.
---

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<dim,spacedim> &) const;
+  bool operator == (const FiniteElement<dim,spacedim> &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 <algorithm>
 #include <functional>
 #include <numeric>
+#include <typeinfo>
 
 DEAL_II_NAMESPACE_OPEN
 
@@ -937,10 +938,20 @@ template <int dim, int spacedim>
 bool
 FiniteElement<dim,spacedim>::operator == (const FiniteElement<dim,spacedim> &f) const
 {
-  return ((static_cast<const FiniteElementData<dim>&>(*this) ==
-           static_cast<const FiniteElementData<dim>&>(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<const FiniteElementData<dim>&>(*this) ==
+           static_cast<const FiniteElementData<dim>&>(f))
+          &&
+          (interface_constraints == f.interface_constraints)
+          &&
+          (restriction == f.restriction)
+          &&
+          (prolongation == f.prolongation));
 }