ryujin 2.1.1 revision 0348cbb53a3e4b1da2a4c037e81f88f2d21ce219
diagonal_preconditioner.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3// Copyright (C) 2022 - 2023 by the ryujin authors
4//
5
6#pragma once
7
8#include "state_vector.h"
9
10#include <deal.II/lac/la_parallel_block_vector.h>
11
12namespace ryujin
13{
20 template <typename Number>
22 {
23 public:
28
33
38
42 void reinit(const std::shared_ptr<const dealii::Utilities::MPI::Partitioner>
43 &scalar_partitioner)
44 {
45 diagonal_.reinit(scalar_partitioner);
46 }
47
52 {
53 return diagonal_;
54 }
55
59 void vmult(ScalarVector &dst, const ScalarVector &src) const
60 {
61 const auto n_owned = diagonal_.get_partitioner()->locally_owned_size();
62 AssertDimension(n_owned, src.get_partitioner()->locally_owned_size());
63 AssertDimension(n_owned, dst.get_partitioner()->locally_owned_size());
64
65 DEAL_II_OPENMP_SIMD_PRAGMA
66 for (unsigned int i = 0; i < n_owned; ++i)
67 dst.local_element(i) =
68 diagonal_.local_element(i) * src.local_element(i);
69 }
70
74 void vmult(BlockVector &dst, const BlockVector &src) const
75 {
76 const auto n_blocks = src.n_blocks();
77 AssertDimension(n_blocks, dst.n_blocks());
78
79 const auto n_owned = diagonal_.get_partitioner()->locally_owned_size();
80
81 for (unsigned int d = 0; d < n_blocks; ++d) {
82 AssertDimension(n_owned,
83 src.block(d).get_partitioner()->locally_owned_size());
84 AssertDimension(n_owned,
85 dst.block(d).get_partitioner()->locally_owned_size());
86
87 DEAL_II_OPENMP_SIMD_PRAGMA
88 for (unsigned int i = 0; i < n_owned; ++i)
89 dst.block(d).local_element(i) =
90 diagonal_.local_element(i) * src.block(d).local_element(i);
91 }
92 }
93
94 private:
95 ScalarVector diagonal_;
96 };
97
98} /* namespace ryujin */
void reinit(const std::shared_ptr< const dealii::Utilities::MPI::Partitioner > &scalar_partitioner)
typename Vectors::ScalarVector< Number > ScalarVector
void vmult(BlockVector &dst, const BlockVector &src) const
void vmult(ScalarVector &dst, const ScalarVector &src) const
typename Vectors::BlockVector< Number > BlockVector
dealii::LinearAlgebra::distributed::Vector< Number > ScalarVector
Definition: state_vector.h:31
dealii::LinearAlgebra::distributed::BlockVector< Number > BlockVector
Definition: state_vector.h:37