From 3af1779a2ad4640a6eb7cffdf1675a4ac30b4053 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 30 Nov 2020 18:59:16 -0700 Subject: [PATCH] Simplify the computation of the diagonal. --- .../deal.II/grid/tria_accessor.templates.h | 57 +++++++++++-------- 1 file changed, 34 insertions(+), 23 deletions(-) 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; -- 2.39.5