]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix an array index warning. 14834/head
authorDavid Wells <drwells@email.unc.edu>
Sun, 26 Feb 2023 21:58:50 +0000 (16:58 -0500)
committerDavid Wells <drwells@email.unc.edu>
Sun, 26 Feb 2023 21:58:50 +0000 (16:58 -0500)
source/base/geometric_utilities.cc

index e55034af864614683c3497f462ec1c5e523a6819..7eed9996fc7e7719245d71ed13a184790594e26b 100644 (file)
@@ -46,18 +46,22 @@ namespace GeometricUtilities
     std::array<double, dim>
     to_spherical(const Point<dim> &position)
     {
-      std::array<double, dim> scoord;
+      std::array<double, dim> scoord{};
+      Assert(dim > 1, ExcNotImplemented());
 
       // radius
-      scoord[0] = position.norm();
-      // azimuth angle \theta:
-      scoord[1] = std::atan2(position(1), position(0));
-      // correct to [0,2*pi)
-      if (scoord[1] < 0.0)
-        scoord[1] += 2.0 * numbers::PI;
+      if DEAL_II_CONSTEXPR_IN_CONDITIONAL (dim > 1)
+        {
+          scoord[0] = position.norm();
+          // azimuth angle \theta:
+          scoord[1] = std::atan2(position(1), position(0));
+          // correct to [0,2*pi)
+          if (scoord[1] < 0.0)
+            scoord[1] += 2.0 * numbers::PI;
+        }
 
       // polar angle \phi:
-      if (dim == 3)
+      if DEAL_II_CONSTEXPR_IN_CONDITIONAL (dim == 3)
         {
           // acos returns the angle in the range [0,\pi]
           if (scoord[0] > std::numeric_limits<double>::min())

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.