]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Step-81: Avoid using 1.0i literal when multiplying dealii::Tensor<>
authorMatthias Maier <tamiko@43-1.org>
Thu, 26 May 2022 01:52:24 +0000 (20:52 -0500)
committerMatthias Maier <tamiko@43-1.org>
Thu, 26 May 2022 05:16:02 +0000 (00:16 -0500)
examples/step-81/step-81.cc

index 0cb2dfeaf22620d6dcffd3f5ccace14ee57b2da5..22bf2e8acd5a561fa27156cf2fa13c83407c07c2 100644 (file)
@@ -671,21 +671,23 @@ namespace Step81
 
             for (const auto i : fe_values.dof_indices())
               {
+                constexpr std::complex<double> imag{0., 1.};
+
                 const auto phi_i = real_part.value(i, q_point) -
-                                   1.0i * imag_part.value(i, q_point);
+                                   imag * imag_part.value(i, q_point);
                 const auto curl_phi_i = real_part.curl(i, q_point) -
-                                        1.0i * imag_part.curl(i, q_point);
+                                        imag * imag_part.curl(i, q_point);
 
                 const auto rhs_value =
-                  (1.0i * scalar_product(J_a, phi_i)) * fe_values.JxW(q_point);
+                  (imag * scalar_product(J_a, phi_i)) * fe_values.JxW(q_point);
                 cell_rhs(i) += rhs_value.real();
 
                 for (const auto j : fe_values.dof_indices())
                   {
                     const auto phi_j = real_part.value(j, q_point) +
-                                       1.0i * imag_part.value(j, q_point);
+                                       imag * imag_part.value(j, q_point);
                     const auto curl_phi_j = real_part.curl(j, q_point) +
-                                            1.0i * imag_part.curl(j, q_point);
+                                            imag * imag_part.curl(j, q_point);
 
                     const auto temp =
                       (scalar_product(mu_inv * curl_phi_j, curl_phi_i) -
@@ -739,16 +741,18 @@ namespace Step81
 
                         for (const auto i : fe_face_values.dof_indices())
                           {
+                            constexpr std::complex<double> imag{0., 1.};
+
                             const auto phi_i =
                               real_part.value(i, q_point) -
-                              1.0i * imag_part.value(i, q_point);
+                              imag * imag_part.value(i, q_point);
                             const auto phi_i_T = tangential_part(phi_i, normal);
 
                             for (const auto j : fe_face_values.dof_indices())
                               {
                                 const auto phi_j =
                                   real_part.value(j, q_point) +
-                                  1.0i * imag_part.value(j, q_point);
+                                  imag * imag_part.value(j, q_point);
                                 const auto phi_j_T =
                                   tangential_part(phi_j, normal) *
                                   fe_face_values.JxW(q_point);
@@ -757,7 +761,7 @@ namespace Step81
                                 const auto sqrt_prod = prod;
 
                                 const auto temp =
-                                  -1.0i * scalar_product((sqrt_prod * phi_j_T),
+                                  -imag * scalar_product((sqrt_prod * phi_j_T),
                                                          phi_i_T);
                                 cell_matrix(i, j) += temp.real();
                               } /* j */
@@ -795,19 +799,21 @@ namespace Step81
 
                     for (const auto i : fe_face_values.dof_indices())
                       {
+                        constexpr std::complex<double> imag{0., 1.};
+
                         const auto phi_i = real_part.value(i, q_point) -
-                                           1.0i * imag_part.value(i, q_point);
+                                           imag * imag_part.value(i, q_point);
                         const auto phi_i_T = tangential_part(phi_i, normal);
 
                         for (const auto j : fe_face_values.dof_indices())
                           {
                             const auto phi_j =
                               real_part.value(j, q_point) +
-                              1.0i * imag_part.value(j, q_point);
+                              imag * imag_part.value(j, q_point);
                             const auto phi_j_T = tangential_part(phi_j, normal);
 
                             const auto temp =
-                              -1.0i *
+                              -imag *
                               scalar_product((sigma * phi_j_T), phi_i_T) *
                               fe_face_values.JxW(q_point);
                             cell_matrix(i, j) += temp.real();

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.