From: David Wells Date: Thu, 24 Dec 2020 02:14:45 +0000 (-0500) Subject: Clean up FE_Nothing::get_name(). X-Git-Tag: v9.3.0-rc1~699^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1981e3ec3de7a194bbcb55dff4304392ca764b17;p=dealii.git Clean up FE_Nothing::get_name(). --- diff --git a/include/deal.II/fe/fe_nothing.h b/include/deal.II/fe/fe_nothing.h index b3b83ec8d3..dd779d1ee3 100644 --- a/include/deal.II/fe/fe_nothing.h +++ b/include/deal.II/fe/fe_nothing.h @@ -158,8 +158,17 @@ public: clone() const override; /** - * Return a string that uniquely identifies a finite element. In this case - * it is FE_Nothing@. + * Return a string that uniquely identifies a finite element. The name is + * FE_Nothing@(type, n_components, dominating) where + * dim, spacedim, type, and n_components + * are all specified by the constructor or type signature with the following + * exceptions: + *
    + *
  1. If spacedim == dim then that field is not printed.
  2. + *
  3. If type is a hypercube then that field is not printed.
  4. + *
  5. If n_components == 1 then that field is not printed.
  6. + *
  7. If dominate == false then that field is not printed.
  8. + *
*/ virtual std::string get_name() const override; @@ -323,16 +332,6 @@ public: bool is_dominating() const; - /** - * Comparison operator. In addition to the fields already checked by - * FiniteElement::operator==(), this operator also checks for equality - * of the arguments passed to the constructors of the current object - * as well as the object against which the comparison is done (which - * for this purpose obviously also needs to be of type FE_Nothing). - */ - virtual bool - operator==(const FiniteElement &fe) const override; - private: /** * If true, this element will dominate any other apart from itself in diff --git a/include/deal.II/grid/reference_cell.h b/include/deal.II/grid/reference_cell.h index 2bfa0943b1..2cd1399533 100644 --- a/include/deal.II/grid/reference_cell.h +++ b/include/deal.II/grid/reference_cell.h @@ -70,6 +70,39 @@ namespace ReferenceCell } } + /** + * Convert the given reference cell type to a string. + */ + inline std::string + to_string(const Type &type) + { + switch (type) + { + case Type::Vertex: + return "Vertex"; + case Type::Line: + return "Line"; + case Type::Tri: + return "Tri"; + case Type::Quad: + return "Quad"; + case Type::Tet: + return "Tet"; + case Type::Pyramid: + return "Pyramid"; + case Type::Wedge: + return "Wedge"; + case Type::Hex: + return "Hex"; + case Type::Invalid: + return "Invalid"; + default: + Assert(false, ExcNotImplemented()); + } + + return "Invalid"; + } + /** * Return the correct simplex reference cell type for the given dimension * @p dim. diff --git a/source/fe/fe_nothing.cc b/source/fe/fe_nothing.cc index 5cba50338d..44009a9e48 100644 --- a/source/fe/fe_nothing.cc +++ b/source/fe/fe_nothing.cc @@ -72,16 +72,25 @@ std::string FE_Nothing::get_name() const { std::ostringstream namebuf; - namebuf << "FE_Nothing<" << dim << ">("; + namebuf << "FE_Nothing<" << Utilities::dim_string(dim, spacedim) << ">("; + + std::vector name_components; + if (this->reference_cell_type() != ReferenceCell::get_hypercube(dim)) + name_components.push_back( + ReferenceCell::to_string(this->reference_cell_type())); if (this->n_components() > 1) + name_components.push_back(std::to_string(this->n_components())); + if (dominate) + name_components.emplace_back("dominating"); + + for (const std::string &comp : name_components) { - namebuf << this->n_components(); - if (dominate) - namebuf << ", dominating"; + namebuf << comp; + if (comp != name_components.back()) + namebuf << ", "; } - else if (dominate) - namebuf << "dominating"; namebuf << ")"; + return namebuf.str(); } @@ -199,29 +208,6 @@ FE_Nothing::is_dominating() const -template -bool -FE_Nothing:: -operator==(const FiniteElement &f) const -{ - // Compare fields stored in the base class - if (!(this->FiniteElement::operator==(f))) - return false; - - // Then make sure the other object is really of type FE_Nothing, - // and compare the data that has been passed to both objects' - // constructors. - if (const FE_Nothing *fe_nothing = - dynamic_cast *>(&f)) - return ((dominate == fe_nothing->dominate) && - (this->components == fe_nothing->components) && - (this->reference_cell_type() == fe_nothing->reference_cell_type())); - else - return false; -} - - - template FiniteElementDomination::Domination FE_Nothing::compare_for_domination( diff --git a/tests/fe/get_fe_by_name_01.output b/tests/fe/get_fe_by_name_01.output index 096155d2c0..f2249c8265 100644 --- a/tests/fe/get_fe_by_name_01.output +++ b/tests/fe/get_fe_by_name_01.output @@ -271,16 +271,16 @@ DEAL::Generated : DEAL::FE_Nothing<1>() DEAL::Read FE_Nothing() DEAL::Generated : -DEAL::FE_Nothing<1>() +DEAL::FE_Nothing<1,2>() DEAL::Read FE_Nothing() DEAL::Generated : DEAL::FE_Nothing<2>() DEAL::Read FE_Nothing() DEAL::Generated : -DEAL::FE_Nothing<1>() +DEAL::FE_Nothing<1,3>() DEAL::Read FE_Nothing() DEAL::Generated : -DEAL::FE_Nothing<2>() +DEAL::FE_Nothing<2,3>() DEAL::Read FE_Nothing() DEAL::Generated : DEAL::FE_Nothing<3>() diff --git a/tests/hp/fe_nothing_22.cc b/tests/hp/fe_nothing_22.cc index 7bc1cc828d..eb24c88f85 100644 --- a/tests/hp/fe_nothing_22.cc +++ b/tests/hp/fe_nothing_22.cc @@ -15,27 +15,11 @@ -// Test FE_Nothing::operator==() - - -#include -#include - -#include -#include -#include +// Test FE_Nothing::operator==(). The base clase operator should suffice #include -#include -#include - -#include -#include -#include -#include -#include -#include +#include #include "../tests.h" @@ -45,6 +29,7 @@ template void test() { + deallog << "dim = " << dim << std::endl; deallog << std::boolalpha; deallog << (FE_Nothing(1) == FE_Nothing(1, false)) << std::endl; deallog << (FE_Nothing(1) == FE_Nothing(2)) << std::endl; @@ -52,6 +37,30 @@ test() << std::endl; deallog << (FE_Nothing(1, true) == FE_Nothing(2, true)) << std::endl; + if (dim == 2) + { + deallog << (FE_Nothing(ReferenceCell::Type::Quad, 2, true) == + FE_Nothing(2, true)) + << std::endl; + deallog << (FE_Nothing(ReferenceCell::Type::Tri, 2, true) == + FE_Nothing(2, true)) + << std::endl; + } + if (dim == 3) + { + deallog << (FE_Nothing(ReferenceCell::Type::Hex, 2, true) == + FE_Nothing(2, true)) + << std::endl; + deallog << (FE_Nothing(ReferenceCell::Type::Tet, 2, true) == + FE_Nothing(2, true)) + << std::endl; + deallog << (FE_Nothing(ReferenceCell::Type::Wedge, 1, false) == + FE_Nothing(ReferenceCell::Type::Pyramid, 1, false)) + << std::endl; + deallog << (FE_Nothing(ReferenceCell::Type::Wedge, 3) == + FE_Nothing(3)) + << std::endl; + } } diff --git a/tests/hp/fe_nothing_22.output b/tests/hp/fe_nothing_22.output index 9ce031bab8..17d12fbb37 100644 --- a/tests/hp/fe_nothing_22.output +++ b/tests/hp/fe_nothing_22.output @@ -1,8 +1,17 @@ +DEAL::dim = 1 DEAL::true DEAL::false DEAL::false DEAL::false +DEAL::dim = 2 +DEAL::true +DEAL::false +DEAL::false +DEAL::false +DEAL::true +DEAL::false +DEAL::dim = 3 DEAL::true DEAL::false DEAL::false