From: Daniel Arndt Date: Fri, 27 Apr 2018 09:22:04 +0000 (+0200) Subject: Comparison operator for FiniteElement and FECollection X-Git-Tag: v9.0.0-rc1~94^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07f5bac11269550c1ca3cfa589b41f6570c3fc7b;p=dealii.git Comparison operator for FiniteElement and FECollection --- diff --git a/doc/news/changes/minor/20180425DanielArndt b/doc/news/changes/minor/20180425DanielArndt new file mode 100644 index 0000000000..040b1e98ee --- /dev/null +++ b/doc/news/changes/minor/20180425DanielArndt @@ -0,0 +1,4 @@ +New: FECollection gained an equality comparison operator. Both FiniteElement +and FECollcetion have a non-equality comparison operator now. +
+(Daniel Arndt, 2018/04/25) diff --git a/include/deal.II/fe/fe.h b/include/deal.II/fe/fe.h index e09610521b..fac7ca852b 100644 --- a/include/deal.II/fe/fe.h +++ b/include/deal.II/fe/fe.h @@ -1333,16 +1333,20 @@ public: //@} /** - * Comparison operator. We also check for equality of the constraint matrix, - * which is quite an expensive operation. Do therefore use this function - * with care, if possible only for debugging purposes. + * Comparison operator. We also check for equality of the name returned by + * get_name() and for equality of the constraint matrix, which is quite an + * expensive operation. Do therefore use this function with care, if + * possible only for debugging purposes. * - * Since this function is not that important, we avoid an implementational - * question about comparing arrays and do not compare the matrix arrays - * #restriction and #prolongation. + * We do not compare the matrix arrays #restriction and #prolongation. */ bool operator == (const FiniteElement &) const; + /** + * Non-equality comparison operator. Defined in terms of the equality comparison operator. + */ + bool operator != (const FiniteElement &) const; + /** * @name Index computations * @{ diff --git a/include/deal.II/hp/fe_collection.h b/include/deal.II/hp/fe_collection.h index 4751b4efcf..7dbf3265f4 100644 --- a/include/deal.II/hp/fe_collection.h +++ b/include/deal.II/hp/fe_collection.h @@ -100,6 +100,18 @@ namespace hp FECollection & operator= (FECollection &&) = default; // NOLINT + /** + * Equality comparison operator. All stored FiniteElement objects are compared in order. + */ + bool + operator== (const FECollection &fe_collection) const; + + /** + * Non-equality comparison operator. All stored FiniteElement objects are compared in order. + */ + bool + operator!= (const FECollection &fe_collection) const; + /** * Add a finite element. This function generates a copy of the given * element, i.e. you can do things like push_back(FE_Q(1));. @@ -495,6 +507,35 @@ namespace hp } + + template + inline + bool + FECollection::operator== (const FECollection &fe_collection) const + { + const unsigned int n_elements = size(); + if (n_elements != fe_collection.size()) + return false; + + for (unsigned int i=0; i + inline + bool + FECollection::operator != (const FECollection &fe_collection) const + { + return !(*this == fe_collection); + } + + + template inline const FiniteElement & diff --git a/source/fe/fe.cc b/source/fe/fe.cc index dabb42ea53..e877973aea 100644 --- a/source/fe/fe.cc +++ b/source/fe/fe.cc @@ -939,7 +939,17 @@ FiniteElement::operator == (const FiniteElement &f) { return ((static_cast&>(*this) == static_cast&>(f)) && - (interface_constraints == f.interface_constraints)); + (interface_constraints == f.interface_constraints) && + (this->get_name() == f.get_name())); +} + + + +template +bool +FiniteElement::operator != (const FiniteElement &f) const +{ + return !(*this == f); }