]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Enable SolverIDR for block vectors 14232/head
authorPeter Munch <peterrmuench@gmail.com>
Tue, 30 Aug 2022 07:33:09 +0000 (09:33 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Sat, 3 Sep 2022 13:41:32 +0000 (15:41 +0200)
include/deal.II/lac/solver_idr.h

index 64bc3c679343af144bcf249784d6e9a32cbddbd1..3c6c66daba86d972c9311a13d8c7ae6ec6fe6d96 100644 (file)
@@ -24,6 +24,7 @@
 #include <deal.II/base/subscriptor.h>
 #include <deal.II/base/utilities.h>
 
+#include <deal.II/lac/block_vector_base.h>
 #include <deal.II/lac/full_matrix.h>
 #include <deal.II/lac/solver.h>
 #include <deal.II/lac/solver_control.h>
@@ -226,6 +227,53 @@ namespace internal
         }
       return *data[i];
     }
+
+
+
+    template <typename VectorType,
+              std::enable_if_t<!IsBlockVector<VectorType>::value, VectorType>
+                * = nullptr>
+    unsigned int
+    n_blocks(const VectorType &)
+    {
+      return 1;
+    }
+
+
+
+    template <typename VectorType,
+              std::enable_if_t<IsBlockVector<VectorType>::value, VectorType> * =
+                nullptr>
+    unsigned int
+    n_blocks(const VectorType &vector)
+    {
+      return vector.n_blocks();
+    }
+
+
+
+    template <typename VectorType,
+              std::enable_if_t<!IsBlockVector<VectorType>::value, VectorType>
+                * = nullptr>
+    VectorType &
+    block(VectorType &vector, const unsigned int b)
+    {
+      AssertDimension(b, 0);
+      (void)b;
+      return vector;
+    }
+
+
+
+    template <typename VectorType,
+              std::enable_if_t<IsBlockVector<VectorType>::value, VectorType> * =
+                nullptr>
+    typename VectorType::BlockType &
+    block(VectorType &vector, const unsigned int b)
+    {
+      return vector.block(b);
+    }
+
   } // namespace SolverIDRImplementation
 } // namespace internal
 
@@ -328,8 +376,13 @@ SolverIDR<VectorType>::solve(const MatrixType &        A,
       VectorType &tmp_q = Q(i, x);
       if (i != 0)
         {
-          for (auto indx : tmp_q.locally_owned_elements())
-            tmp_q(indx) = normal_distribution(rng);
+          for (unsigned int b = 0;
+               b < internal::SolverIDRImplementation::n_blocks(tmp_q);
+               ++b)
+            for (auto indx : internal::SolverIDRImplementation::block(tmp_q, b)
+                               .locally_owned_elements())
+              internal::SolverIDRImplementation::block(tmp_q, b)(indx) =
+                normal_distribution(rng);
           tmp_q.compress(VectorOperation::insert);
         }
       else

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.