From: Wolfgang Bangerth Date: Tue, 1 Dec 2020 01:59:16 +0000 (-0700) Subject: Simplify the computation of the diagonal. X-Git-Tag: v9.3.0-rc1~830^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F11284%2Fhead;p=dealii.git Simplify the computation of the diagonal. --- diff --git a/include/deal.II/grid/tria_accessor.templates.h b/include/deal.II/grid/tria_accessor.templates.h index 1653dd49b0..7d7b3f049d 100644 --- a/include/deal.II/grid/tria_accessor.templates.h +++ b/include/deal.II/grid/tria_accessor.templates.h @@ -1888,35 +1888,46 @@ TriaAccessor::diameter() const switch (this->reference_cell_type()) { case ReferenceCell::Type::Line: + // Return the distance between the two vertices return (this->vertex(1) - this->vertex(0)).norm(); + case ReferenceCell::Type::Tri: - return std::max(std::max((this->vertex(1) - this->vertex(0)).norm(), - (this->vertex(2) - this->vertex(1)).norm()), - (this->vertex(2) - this->vertex(0)).norm()); + // Return the longest of the three edges + return std::max({(this->vertex(1) - this->vertex(0)).norm(), + (this->vertex(2) - this->vertex(1)).norm(), + (this->vertex(2) - this->vertex(0)).norm()}); + case ReferenceCell::Type::Quad: - return std::max((this->vertex(3) - this->vertex(0)).norm(), - (this->vertex(2) - this->vertex(1)).norm()); + // Return the longer one of the two diagonals of the quadrilateral + return std::max({(this->vertex(3) - this->vertex(0)).norm(), + (this->vertex(2) - this->vertex(1)).norm()}); + case ReferenceCell::Type::Tet: - return std::max( - std::max(std::max((this->vertex(1) - this->vertex(0)).norm(), - (this->vertex(2) - this->vertex(0)).norm()), - std::max((this->vertex(2) - this->vertex(1)).norm(), - (this->vertex(3) - this->vertex(0)).norm())), - std::max((this->vertex(3) - this->vertex(1)).norm(), - (this->vertex(3) - this->vertex(2)).norm())); + // Return the longest of the six edges of the tetrahedron + return std::max({(this->vertex(1) - this->vertex(0)).norm(), + (this->vertex(2) - this->vertex(0)).norm(), + (this->vertex(2) - this->vertex(1)).norm(), + (this->vertex(3) - this->vertex(0)).norm(), + (this->vertex(3) - this->vertex(1)).norm(), + (this->vertex(3) - this->vertex(2)).norm()}); + case ReferenceCell::Type::Wedge: - return std::max( - std::max(std::max((this->vertex(4) - this->vertex(0)).norm(), - (this->vertex(3) - this->vertex(1)).norm()), - std::max((this->vertex(5) - this->vertex(1)).norm(), - (this->vertex(4) - this->vertex(2)).norm())), - std::max((this->vertex(5) - this->vertex(0)).norm(), - (this->vertex(3) - this->vertex(2)).norm())); + // Return the longest of the 2*3=6 diagonals of the three quadrilateral + // sides of the wedge + return std::max({(this->vertex(4) - this->vertex(0)).norm(), + (this->vertex(3) - this->vertex(1)).norm(), + (this->vertex(5) - this->vertex(1)).norm(), + (this->vertex(4) - this->vertex(2)).norm(), + (this->vertex(5) - this->vertex(0)).norm(), + (this->vertex(3) - this->vertex(2)).norm()}); + case ReferenceCell::Type::Hex: - return std::max(std::max((this->vertex(7) - this->vertex(0)).norm(), - (this->vertex(6) - this->vertex(1)).norm()), - std::max((this->vertex(2) - this->vertex(5)).norm(), - (this->vertex(3) - this->vertex(4)).norm())); + // Return the longest of the four diagonals of the hexahedron + return std::max({(this->vertex(7) - this->vertex(0)).norm(), + (this->vertex(6) - this->vertex(1)).norm(), + (this->vertex(2) - this->vertex(5)).norm(), + (this->vertex(3) - this->vertex(4)).norm()}); + default: Assert(false, ExcNotImplemented()); return -1e10;