]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Simplify the computation of the diagonal. 11284/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 1 Dec 2020 01:59:16 +0000 (18:59 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 1 Dec 2020 01:59:16 +0000 (18:59 -0700)
include/deal.II/grid/tria_accessor.templates.h

index 1653dd49b010bf280637f4f98ea47f40a1fccb93..7d7b3f049d2a56fabb3333b79d5bdb6ca72e449a 100644 (file)
@@ -1888,35 +1888,46 @@ TriaAccessor<structdim, dim, spacedim>::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;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.