From fe0e7be934821b6d453cd284944da904ffa46774 Mon Sep 17 00:00:00 2001 From: David Wells Date: Sun, 26 Feb 2023 16:58:50 -0500 Subject: [PATCH] Fix an array index warning. --- source/base/geometric_utilities.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/source/base/geometric_utilities.cc b/source/base/geometric_utilities.cc index e55034af86..7eed9996fc 100644 --- a/source/base/geometric_utilities.cc +++ b/source/base/geometric_utilities.cc @@ -46,18 +46,22 @@ namespace GeometricUtilities std::array to_spherical(const Point &position) { - std::array scoord; + std::array 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::min()) -- 2.39.5