]> https://gitweb.dealii.org/ - dealii.git/commitdiff
PolynomialsRannacherTurek: remove some reinterpret_casts. 17518/head
authorDavid Wells <drwells@email.unc.edu>
Tue, 13 Aug 2024 22:18:50 +0000 (16:18 -0600)
committerDavid Wells <drwells@email.unc.edu>
Wed, 14 Aug 2024 03:52:04 +0000 (21:52 -0600)
include/deal.II/base/polynomials_rannacher_turek.h

index e1a86358105ccfd342eab0e4088db8da506c5690..65557afb38d1cd352e8c377ee205a7ea2a08469d 100644 (file)
@@ -153,78 +153,76 @@ namespace internal
     {
       const unsigned int dim = 2;
 
-      Tensor<order, dim> derivative;
-      switch (order)
+      if constexpr (order == 1)
         {
-          case 1:
+          Tensor<1, dim> derivative;
+          if (i == 0)
             {
-              Tensor<1, dim> &grad =
-                *reinterpret_cast<Tensor<1, dim> *>(&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<Tensor<2, dim> *>(&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<order, dim>();
+              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

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.