From: David Wells Date: Tue, 13 Aug 2024 22:18:50 +0000 (-0600) Subject: PolynomialsRannacherTurek: remove some reinterpret_casts. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F17518%2Fhead;p=dealii.git PolynomialsRannacherTurek: remove some reinterpret_casts. --- diff --git a/include/deal.II/base/polynomials_rannacher_turek.h b/include/deal.II/base/polynomials_rannacher_turek.h index e1a8635810..65557afb38 100644 --- a/include/deal.II/base/polynomials_rannacher_turek.h +++ b/include/deal.II/base/polynomials_rannacher_turek.h @@ -153,78 +153,76 @@ namespace internal { const unsigned int dim = 2; - Tensor derivative; - switch (order) + if constexpr (order == 1) { - case 1: + Tensor<1, dim> derivative; + if (i == 0) { - Tensor<1, dim> &grad = - *reinterpret_cast *>(&derivative); - if (i == 0) - { - grad[0] = -2.5 + 3 * p[0]; - grad[1] = 1.5 - 3 * p[1]; - } - else if (i == 1) - { - grad[0] = -0.5 + 3.0 * p[0]; - grad[1] = 1.5 - 3.0 * p[1]; - } - else if (i == 2) - { - grad[0] = 1.5 - 3.0 * p[0]; - grad[1] = -2.5 + 3.0 * p[1]; - } - else if (i == 3) - { - grad[0] = 1.5 - 3.0 * p[0]; - grad[1] = -0.5 + 3.0 * p[1]; - } - else - { - DEAL_II_NOT_IMPLEMENTED(); - } - return derivative; + derivative[0] = -2.5 + 3 * p[0]; + derivative[1] = 1.5 - 3 * p[1]; } - case 2: + else if (i == 1) { - Tensor<2, dim> &grad_grad = - *reinterpret_cast *>(&derivative); - if (i == 0) - { - grad_grad[0][0] = 3; - grad_grad[0][1] = 0; - grad_grad[1][0] = 0; - grad_grad[1][1] = -3; - } - else if (i == 1) - { - grad_grad[0][0] = 3; - grad_grad[0][1] = 0; - grad_grad[1][0] = 0; - grad_grad[1][1] = -3; - } - else if (i == 2) - { - grad_grad[0][0] = -3; - grad_grad[0][1] = 0; - grad_grad[1][0] = 0; - grad_grad[1][1] = 3; - } - else if (i == 3) - { - grad_grad[0][0] = -3; - grad_grad[0][1] = 0; - grad_grad[1][0] = 0; - grad_grad[1][1] = 3; - } - return derivative; + derivative[0] = -0.5 + 3.0 * p[0]; + derivative[1] = 1.5 - 3.0 * p[1]; } - default: + else if (i == 2) { - // higher derivatives are all zero - return Tensor(); + derivative[0] = 1.5 - 3.0 * p[0]; + derivative[1] = -2.5 + 3.0 * p[1]; } + else if (i == 3) + { + derivative[0] = 1.5 - 3.0 * p[0]; + derivative[1] = -0.5 + 3.0 * p[1]; + } + else + { + DEAL_II_NOT_IMPLEMENTED(); + } + return derivative; + } + else if constexpr (order == 2) + { + Tensor<2, dim> derivative; + if (i == 0) + { + derivative[0][0] = 3; + derivative[0][1] = 0; + derivative[1][0] = 0; + derivative[1][1] = -3; + } + else if (i == 1) + { + derivative[0][0] = 3; + derivative[0][1] = 0; + derivative[1][0] = 0; + derivative[1][1] = -3; + } + else if (i == 2) + { + derivative[0][0] = -3; + derivative[0][1] = 0; + derivative[1][0] = 0; + derivative[1][1] = 3; + } + else if (i == 3) + { + derivative[0][0] = -3; + derivative[0][1] = 0; + derivative[1][0] = 0; + derivative[1][1] = 3; + } + else + { + DEAL_II_NOT_IMPLEMENTED(); + } + return derivative; + } + else + { + // higher derivatives are all zero + return {}; } } } // namespace PolynomialsRannacherTurekImplementation