Reference documentation for deal.II version 9.3.3
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
diagonal_matrix.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2016 - 2020 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dealii_diagonal_matrix_h
17#define dealii_diagonal_matrix_h
18
19
20#include <deal.II/base/config.h>
21
22#include <deal.II/lac/vector.h>
24
26
47template <typename VectorType = Vector<double>>
49{
50public:
51 using value_type = typename VectorType::value_type;
53
58 DiagonalMatrix() = default;
59
65 explicit DiagonalMatrix(const VectorType &vec);
66
71 void
72 reinit(const VectorType &vec);
73
80 void
82
87 VectorType &
89
93 void
95
99 const VectorType &
100 get_vector() const;
101
107 m() const;
108
114 n() const;
115
126 operator()(const size_type i, const size_type j) const;
127
137 value_type &
138 operator()(const size_type i, const size_type j);
139
151 template <typename number2>
152 void
153 add(const size_type row,
154 const size_type n_cols,
155 const size_type *col_indices,
156 const number2 * values,
157 const bool elide_zero_values = true,
158 const bool col_indices_are_sorted = false);
159
166 void
167 add(const size_type i, const size_type j, const value_type value);
168
172 void
173 vmult(VectorType &dst, const VectorType &src) const;
174
180 void
181 Tvmult(VectorType &dst, const VectorType &src) const;
182
188 void
189 vmult_add(VectorType &dst, const VectorType &src) const;
190
196 void
197 Tvmult_add(VectorType &dst, const VectorType &src) const;
198
206 void
207 initialize_dof_vector(VectorType &dst) const;
208
212 std::size_t
214
215private:
219 VectorType diagonal;
220};
221
222/* ---------------------------------- Inline functions ------------------- */
223
224#ifndef DOXYGEN
225
226template <typename VectorType>
228 : diagonal(vec)
229{}
230
231
232
233template <typename VectorType>
234void
236{
237 diagonal.reinit(0);
238}
239
240
241
242template <typename VectorType>
243std::size_t
245{
246 return diagonal.memory_consumption();
247}
248
249
250
251template <typename VectorType>
252void
253DiagonalMatrix<VectorType>::reinit(const VectorType &vec)
254{
255 diagonal = vec;
256}
257
258
259
260template <typename VectorType>
261void
263{
264 dst.reinit(diagonal);
265}
266
267
268
269template <typename VectorType>
270void
272{
273 diagonal.compress(operation);
274}
275
276
277
278template <typename VectorType>
279VectorType &
281{
282 return diagonal;
283}
284
285
286
287template <typename VectorType>
288const VectorType &
290{
291 return diagonal;
292}
293
294
295
296template <typename VectorType>
299{
300 return diagonal.size();
301}
302
303
304
305template <typename VectorType>
308{
309 return diagonal.size();
310}
311
312
313
314template <typename VectorType>
315typename VectorType::value_type
317 const size_type j) const
318{
319 Assert(i == j, ExcIndexRange(j, i, i + 1));
320 (void)j;
321 return diagonal(i);
322}
323
324
325
326template <typename VectorType>
327typename VectorType::value_type &
329{
330 Assert(i == j, ExcIndexRange(j, i, i + 1));
331 (void)j;
332 return diagonal(i);
333}
334
335
336
337template <typename VectorType>
338template <typename number2>
339void
341 const size_type n_cols,
342 const size_type *col_indices,
343 const number2 * values,
344 const bool,
345 const bool)
346{
347 for (size_type i = 0; i < n_cols; ++i)
348 if (col_indices[i] == row)
349 diagonal(row) += values[i];
350}
351
352
353
354template <typename VectorType>
355void
357 const size_type j,
358 const value_type value)
359{
360 if (i == j)
361 diagonal(i) += value;
362}
363
364
365
366template <typename VectorType>
367void
368DiagonalMatrix<VectorType>::vmult(VectorType &dst, const VectorType &src) const
369{
370 dst = src;
371 dst.scale(diagonal);
372}
373
374
375
376template <typename VectorType>
377void
378DiagonalMatrix<VectorType>::Tvmult(VectorType &dst, const VectorType &src) const
379{
380 vmult(dst, src);
381}
382
383
384
385template <typename VectorType>
386void
388 const VectorType &src) const
389{
390 VectorType tmp(src);
391 tmp.scale(diagonal);
392 dst += tmp;
393}
394
395
396
397template <typename VectorType>
398void
400 const VectorType &src) const
401{
402 vmult_add(dst, src);
403}
404
405
406#endif
407
409
410#endif
void initialize_dof_vector(VectorType &dst) const
size_type m() const
void Tvmult_add(VectorType &dst, const VectorType &src) const
VectorType diagonal
value_type & operator()(const size_type i, const size_type j)
VectorType & get_vector()
std::size_t memory_consumption() const
void add(const size_type i, const size_type j, const value_type value)
DiagonalMatrix(const VectorType &vec)
value_type operator()(const size_type i, const size_type j) const
typename VectorType::size_type size_type
void compress(VectorOperation::values operation)
const VectorType & get_vector() const
void vmult(VectorType &dst, const VectorType &src) const
size_type n() const
void reinit(const VectorType &vec)
void add(const size_type row, const size_type n_cols, const size_type *col_indices, const number2 *values, const bool elide_zero_values=true, const bool col_indices_are_sorted=false)
typename VectorType::value_type value_type
void vmult_add(VectorType &dst, const VectorType &src) const
DiagonalMatrix()=default
void Tvmult(VectorType &dst, const VectorType &src) const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:402
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
#define Assert(cond, exc)
Definition: exceptions.h:1465
@ diagonal
Matrix is diagonal.
types::global_dof_index size_type
Definition: cuda_kernels.h:45