]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Reduce run time of matrix-free RT tests 13878/head
authorMartin Kronbichler <martin.kronbichler@uni-a.de>
Tue, 31 May 2022 19:23:47 +0000 (21:23 +0200)
committerMartin Kronbichler <martin.kronbichler@uni-a.de>
Tue, 31 May 2022 19:30:55 +0000 (21:30 +0200)
tests/matrix_free/matrix_vector_rt_common.h
tests/matrix_free/matrix_vector_rt_face_common.h

index 9f2ee3d0e212537b30285791dfac291e2101700c..90ea0b41c8bc24a19408a7ae85fb5fab404e7f69 100644 (file)
@@ -160,13 +160,14 @@ protected:
 };
 
 
-template <int dim, int fe_degree, typename Number>
+template <int dim, int, typename Number>
 void
 do_test(const DoFHandler<dim> &          dof,
         const AffineConstraints<double> &constraints,
         const TestType                   test_type)
 {
   deallog << "Testing " << enum_to_string(test_type) << std::endl;
+  const unsigned int fe_degree = dof.get_fe().degree - 1;
 
   //   constraints.distribute(solution);
   MatrixFree<dim, Number> mf_data;
@@ -192,7 +193,7 @@ do_test(const DoFHandler<dim> &          dof,
     }
 
   // MatrixFree solution
-  MatrixFreeTest<dim, fe_degree, fe_degree + 2, Number> mf(mf_data, test_type);
+  MatrixFreeTest<dim, -1, 0, Number> mf(mf_data, test_type);
   mf.test_functions(solution, initial_condition);
 
 
@@ -212,6 +213,9 @@ do_test(const DoFHandler<dim> &          dof,
   std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
   FullMatrix<double> local_matrix(dofs_per_cell, dofs_per_cell);
 
+  std::vector<Tensor<1, dim>> phi_val(dofs_per_cell);
+  std::vector<Tensor<2, dim>> phi_grad(dofs_per_cell);
+  std::vector<double>         phi_div(dofs_per_cell);
 
   const FEValuesExtractors::Vector velocities(0);
 
@@ -222,29 +226,27 @@ do_test(const DoFHandler<dim> &          dof,
       local_matrix = 0;
 
       for (const auto q : fe_val.quadrature_point_indices())
-        for (unsigned int i = 0; i < dofs_per_cell; ++i)
-          {
-            const Tensor<1, dim> phi_i = fe_val[velocities].value(i, q) * 10.;
-            const Tensor<2, dim> grad_phi_i = fe_val[velocities].gradient(i, q);
-            const Number div_phi_i = fe_val[velocities].divergence(i, q);
-
+        {
+          const double JxW = fe_val.JxW(q);
+          for (unsigned int i = 0; i < dofs_per_cell; ++i)
+            {
+              phi_val[i]  = fe_val[velocities].value(i, q);
+              phi_grad[i] = fe_val[velocities].gradient(i, q);
+              phi_div[i]  = fe_val[velocities].divergence(i, q);
+            }
+          for (unsigned int i = 0; i < dofs_per_cell; ++i)
             for (unsigned int j = 0; j < dofs_per_cell; ++j)
               {
-                const Tensor<1, dim> phi_j = fe_val[velocities].value(j, q);
-                const Tensor<2, dim> grad_phi_j =
-                  fe_val[velocities].gradient(j, q);
-                const Number div_phi_j = fe_val[velocities].divergence(j, q);
-
                 if (test_type < TestType::gradients)
-                  local_matrix(i, j) += phi_j * phi_i * fe_val.JxW(q);
+                  local_matrix(i, j) += 10. * (phi_val[j] * phi_val[i]) * JxW;
                 if (test_type == TestType::gradients ||
                     test_type == TestType::values_gradients)
                   local_matrix(i, j) +=
-                    scalar_product(grad_phi_i, grad_phi_j) * fe_val.JxW(q);
+                    scalar_product(phi_grad[i], phi_grad[j]) * JxW;
                 else if (test_type == TestType::divergence)
-                  local_matrix(i, j) += div_phi_i * div_phi_j * fe_val.JxW(q);
+                  local_matrix(i, j) += phi_div[i] * phi_div[j] * JxW;
               }
-          }
+        }
       cell->get_dof_indices(local_dof_indices);
       for (unsigned int i = 0; i < dofs_per_cell; ++i)
         for (unsigned int j = 0; j < dofs_per_cell; ++j)
index b9a1cd1ceff511c5592e2c0b02355e3125a489ff..dd65b7f3917bfb5bd80a0c3891f82f2dd0c9483c 100644 (file)
@@ -252,7 +252,7 @@ do_test(const DoFHandler<dim> &          dof,
       initial_condition[i] = random_value<Number>();
     }
 
-  MatrixFreeTest<dim, fe_degree, fe_degree + 2, Number> mf(mf_data, test_type);
+  MatrixFreeTest<dim, -1, 0, Number> mf(mf_data, test_type);
   mf.test_functions(solution, initial_condition);
 
 
@@ -273,6 +273,9 @@ do_test(const DoFHandler<dim> &          dof,
   std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
   FullMatrix<double> local_matrix(dofs_per_cell, dofs_per_cell);
 
+  std::vector<Tensor<1, dim>> phi_val(dofs_per_cell);
+  std::vector<Tensor<2, dim>> phi_grad(dofs_per_cell);
+  std::vector<double>         phi_div(dofs_per_cell);
 
   const FEValuesExtractors::Vector velocities(0);
   // Assemble matrix
@@ -283,30 +286,27 @@ do_test(const DoFHandler<dim> &          dof,
         local_matrix = 0;
 
         for (const auto q : fe_val.quadrature_point_indices())
-          for (unsigned int i = 0; i < dofs_per_cell; ++i)
-            {
-              const Tensor<1, dim> phi_i = fe_val[velocities].value(i, q) * 10.;
-              const Tensor<2, dim> grad_phi_i =
-                fe_val[velocities].gradient(i, q);
-              const Number div_phi_i = fe_val[velocities].divergence(i, q);
-
+          {
+            const double JxW = fe_val.JxW(q);
+            for (unsigned int i = 0; i < dofs_per_cell; ++i)
+              {
+                phi_val[i]  = fe_val[velocities].value(i, q);
+                phi_grad[i] = fe_val[velocities].gradient(i, q);
+                phi_div[i]  = fe_val[velocities].divergence(i, q);
+              }
+            for (unsigned int i = 0; i < dofs_per_cell; ++i)
               for (unsigned int j = 0; j < dofs_per_cell; ++j)
                 {
-                  const Tensor<1, dim> phi_j = fe_val[velocities].value(j, q);
-                  const Tensor<2, dim> grad_phi_j =
-                    fe_val[velocities].gradient(j, q);
-                  const Number div_phi_j = fe_val[velocities].divergence(j, q);
-
                   if (test_type < TestType::gradients)
-                    local_matrix(i, j) += phi_j * phi_i * fe_val.JxW(q);
+                    local_matrix(i, j) += 10. * (phi_val[j] * phi_val[i]) * JxW;
                   if (test_type == TestType::gradients ||
                       test_type == TestType::values_gradients)
                     local_matrix(i, j) +=
-                      scalar_product(grad_phi_i, grad_phi_j) * fe_val.JxW(q);
+                      scalar_product(phi_grad[i], phi_grad[j]) * JxW;
                   else if (test_type == TestType::divergence)
-                    local_matrix(i, j) += div_phi_i * div_phi_j * fe_val.JxW(q);
+                    local_matrix(i, j) += phi_div[i] * phi_div[j] * JxW;
                 }
-            }
+          }
         cell->get_dof_indices(local_dof_indices);
         for (unsigned int i = 0; i < dofs_per_cell; ++i)
           for (unsigned int j = 0; j < dofs_per_cell; ++j)

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.