]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix MatrixFreeTools::compute_diagonal 17428/head
authorPeter Munch <peterrmuench@gmail.com>
Sat, 3 Aug 2024 09:55:33 +0000 (11:55 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Sun, 4 Aug 2024 06:42:35 +0000 (08:42 +0200)
doc/news/changes/minor/20240803Munch [new file with mode: 0644]
include/deal.II/matrix_free/tools.h
tests/matrix_free/compute_diagonal_07.cc
tests/matrix_free/compute_diagonal_07.output

diff --git a/doc/news/changes/minor/20240803Munch b/doc/news/changes/minor/20240803Munch
new file mode 100644 (file)
index 0000000..106f832
--- /dev/null
@@ -0,0 +1,5 @@
+Fixed: MatrixFreeTools::compute_diagonal() used
+to use first_selected_component also for accessing
+(block) vectors. This has been fixed.
+<br>
+(Peter Munch, Nils Much, 2024/07/30)
index 6e3928a1aa3fa533dd8d3e7e5c9abeb77d4d779c..8b9c1f9f646e8577a552187349504d119b645c48 100644 (file)
@@ -76,6 +76,9 @@ namespace MatrixFreeTools
    *
    * The parameters @p dof_no, @p quad_no, and @p first_selected_component are
    * passed to the constructor of the FEEvaluation that is internally set up.
+   *
+   * The parameter @p first_vector_component is used to select the right
+   * starting block in a block vector.
    */
   template <int dim,
             int fe_degree,
@@ -97,7 +100,8 @@ namespace MatrixFreeTools
                       &cell_operation,
     const unsigned int dof_no                   = 0,
     const unsigned int quad_no                  = 0,
-    const unsigned int first_selected_component = 0);
+    const unsigned int first_selected_component = 0,
+    const unsigned int first_vector_component   = 0);
 
 
 
@@ -125,7 +129,8 @@ namespace MatrixFreeTools
     const CLASS       *owning_class,
     const unsigned int dof_no                   = 0,
     const unsigned int quad_no                  = 0,
-    const unsigned int first_selected_component = 0);
+    const unsigned int first_selected_component = 0,
+    const unsigned int first_vector_component   = 0);
 
 
 
@@ -179,7 +184,8 @@ namespace MatrixFreeTools
                       &boundary_operation,
     const unsigned int dof_no                   = 0,
     const unsigned int quad_no                  = 0,
-    const unsigned int first_selected_component = 0);
+    const unsigned int first_selected_component = 0,
+    const unsigned int first_vector_component   = 0);
 
 
 
@@ -227,7 +233,8 @@ namespace MatrixFreeTools
     const CLASS       *owning_class,
     const unsigned int dof_no                   = 0,
     const unsigned int quad_no                  = 0,
-    const unsigned int first_selected_component = 0);
+    const unsigned int first_selected_component = 0,
+    const unsigned int first_vector_component   = 0);
 
 
 
@@ -1352,7 +1359,8 @@ namespace MatrixFreeTools
                       &cell_operation,
     const unsigned int dof_no,
     const unsigned int quad_no,
-    const unsigned int first_selected_component)
+    const unsigned int first_selected_component,
+    const unsigned int first_vector_component)
   {
     compute_diagonal<dim,
                      fe_degree,
@@ -1367,7 +1375,8 @@ namespace MatrixFreeTools
                                  {},
                                  dof_no,
                                  quad_no,
-                                 first_selected_component);
+                                 first_selected_component,
+                                 first_vector_component);
   }
 
   template <typename CLASS,
@@ -1391,7 +1400,8 @@ namespace MatrixFreeTools
     const CLASS       *owning_class,
     const unsigned int dof_no,
     const unsigned int quad_no,
-    const unsigned int first_selected_component)
+    const unsigned int first_selected_component,
+    const unsigned int first_vector_component)
   {
     compute_diagonal<dim,
                      fe_degree,
@@ -1405,7 +1415,8 @@ namespace MatrixFreeTools
       [&](auto &phi) { (owning_class->*cell_operation)(phi); },
       dof_no,
       quad_no,
-      first_selected_component);
+      first_selected_component,
+      first_vector_component);
   }
 
   template <int dim,
@@ -1448,7 +1459,8 @@ namespace MatrixFreeTools
                       &boundary_operation,
     const unsigned int dof_no,
     const unsigned int quad_no,
-    const unsigned int first_selected_component)
+    const unsigned int first_selected_component,
+    const unsigned int first_vector_component)
   {
     int dummy = 0;
 
@@ -1461,7 +1473,7 @@ namespace MatrixFreeTools
     for (unsigned int d = 0; d < n_components; ++d)
       diagonal_global_components[d] = dealii::internal::
         BlockVectorSelector<VectorType, IsBlockVector<VectorType>::value>::
-          get_vector_component(diagonal_global, d + first_selected_component);
+          get_vector_component(diagonal_global, d + first_vector_component);
 
     const auto &dof_info = matrix_free.get_dof_info(dof_no);
 
@@ -1745,7 +1757,8 @@ namespace MatrixFreeTools
     const CLASS       *owning_class,
     const unsigned int dof_no,
     const unsigned int quad_no,
-    const unsigned int first_selected_component)
+    const unsigned int first_selected_component,
+    const unsigned int first_vector_component)
   {
     compute_diagonal<dim,
                      fe_degree,
@@ -1763,7 +1776,8 @@ namespace MatrixFreeTools
       [&](auto &phi) { (owning_class->*boundary_operation)(phi); },
       dof_no,
       quad_no,
-      first_selected_component);
+      first_selected_component,
+      first_vector_component);
   }
 
   namespace internal
index d134e59d9d54e179d6d74b39fbbeb48d69d2e9cb..94d72e5004871f8f1eac6a0c066dce6cc7744253 100644 (file)
@@ -29,7 +29,7 @@ template <int dim,
           typename Number              = double,
           typename VectorizedArrayType = VectorizedArray<Number>>
 void
-test()
+test(const unsigned int first_vector_component)
 {
   Triangulation<dim> tria;
   GridGenerator::hyper_ball(tria);
@@ -104,9 +104,10 @@ test()
 
   diagonal_global.print(deallog.get_file_stream());
 
-  LinearAlgebra::distributed::BlockVector<Number> diagonal_global_block(dim);
+  LinearAlgebra::distributed::BlockVector<Number> diagonal_global_block(
+    dim + first_vector_component);
 
-  for (unsigned int comp = 0; comp < dim; ++comp)
+  for (unsigned int comp = 0; comp < dim + first_vector_component; ++comp)
     matrix_free.initialize_dof_vector(diagonal_global_block.block(comp), 1);
 
   MatrixFreeTools::compute_diagonal<dim,
@@ -114,10 +115,14 @@ test()
                                     n_points,
                                     n_components,
                                     Number,
-                                    VectorizedArrayType>(matrix_free,
-                                                         diagonal_global_block,
-                                                         kernel,
-                                                         1);
+                                    VectorizedArrayType>(
+    matrix_free,
+    diagonal_global_block,
+    kernel,
+    1,
+    0,
+    0,
+    first_vector_component);
 
   diagonal_global_block.print(deallog.get_file_stream());
 }
@@ -128,5 +133,6 @@ main(int argc, char **argv)
   Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
   MPILogInitAll                    all;
 
-  test<2, 1>();
+  test<2, 1>(0);
+  test<2, 1>(1 /*test first vector component*/);
 }
index ecf899666775c79678ad982fc9972b67368cd1f2..fffb6018bf459b6d0a07d52a247b8757ab42c349 100644 (file)
@@ -11,3 +11,19 @@ Process #0
 Local range: [0, 8), global size: 8
 Vector data:
 0.000e+00 0.000e+00 4.621e+00 4.621e+00 0.000e+00 4.621e+00 4.621e+00 0.000e+00 
+Process #0
+Local range: [0, 16), global size: 16
+Vector data:
+0.000e+00 0.000e+00 0.000e+00 0.000e+00 4.621e+00 4.621e+00 4.621e+00 4.621e+00 0.000e+00 0.000e+00 4.621e+00 4.621e+00 4.621e+00 4.621e+00 0.000e+00 0.000e+00 
+Process #0
+Local range: [0, 8), global size: 8
+Vector data:
+0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 
+Process #0
+Local range: [0, 8), global size: 8
+Vector data:
+0.000e+00 0.000e+00 4.621e+00 4.621e+00 0.000e+00 4.621e+00 4.621e+00 0.000e+00 
+Process #0
+Local range: [0, 8), global size: 8
+Vector data:
+0.000e+00 0.000e+00 4.621e+00 4.621e+00 0.000e+00 4.621e+00 4.621e+00 0.000e+00 

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.