From: David Wells Date: Sun, 26 Feb 2023 21:58:50 +0000 (-0500) Subject: Fix an array index warning. X-Git-Tag: v9.5.0-rc1~518^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe0e7be934821b6d453cd284944da904ffa46774;p=dealii.git Fix an array index warning. --- 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())