Reference documentation for deal.II version 9.2.0
\(\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 - 2019 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 
49 template <typename VectorType = Vector<double>>
51 {
52 public:
53  using value_type = typename VectorType::value_type;
54  using size_type = typename VectorType::size_type;
55 
60  DiagonalMatrix() = default;
61 
67  explicit DiagonalMatrix(const VectorType &vec);
68 
73  void
74  reinit(const VectorType &vec);
75 
82  void
84 
89  VectorType &
90  get_vector();
91 
95  void
96  clear();
97 
101  const VectorType &
102  get_vector() const;
103 
108  size_type
109  m() const;
110 
115  size_type
116  n() const;
117 
127  value_type
128  operator()(const size_type i, const size_type j) const;
129 
139  value_type &
140  operator()(const size_type i, const size_type j);
141 
153  template <typename number2>
154  void
155  add(const size_type row,
156  const size_type n_cols,
157  const size_type *col_indices,
158  const number2 * values,
159  const bool elide_zero_values = true,
160  const bool col_indices_are_sorted = false);
161 
168  void
169  add(const size_type i, const size_type j, const value_type value);
170 
174  void
175  vmult(VectorType &dst, const VectorType &src) const;
176 
182  void
183  Tvmult(VectorType &dst, const VectorType &src) const;
184 
190  void
191  vmult_add(VectorType &dst, const VectorType &src) const;
192 
198  void
199  Tvmult_add(VectorType &dst, const VectorType &src) const;
200 
208  void
209  initialize_dof_vector(VectorType &dst) const;
210 
214  std::size_t
215  memory_consumption() const;
216 
217 private:
222 };
223 
224 /* ---------------------------------- Inline functions ------------------- */
225 
226 #ifndef DOXYGEN
227 
228 template <typename VectorType>
230  : diagonal(vec)
231 {}
232 
233 
234 
235 template <typename VectorType>
236 void
238 {
239  diagonal.reinit(0);
240 }
241 
242 
243 
244 template <typename VectorType>
245 std::size_t
247 {
248  return diagonal.memory_consumption();
249 }
250 
251 
252 
253 template <typename VectorType>
254 void
256 {
257  diagonal = vec;
258 }
259 
260 
261 
262 template <typename VectorType>
263 void
265 {
266  dst.reinit(diagonal);
267 }
268 
269 
270 
271 template <typename VectorType>
272 void
274 {
275  diagonal.compress(operation);
276 }
277 
278 
279 
280 template <typename VectorType>
281 VectorType &
283 {
284  return diagonal;
285 }
286 
287 
288 
289 template <typename VectorType>
290 const VectorType &
292 {
293  return diagonal;
294 }
295 
296 
297 
298 template <typename VectorType>
299 typename VectorType::size_type
301 {
302  return diagonal.size();
303 }
304 
305 
306 
307 template <typename VectorType>
308 typename VectorType::size_type
310 {
311  return diagonal.size();
312 }
313 
314 
315 
316 template <typename VectorType>
317 typename VectorType::value_type
319  const size_type j) const
320 {
321  Assert(i == j, ExcIndexRange(j, i, i + 1));
322  (void)j;
323  return diagonal(i);
324 }
325 
326 
327 
328 template <typename VectorType>
329 typename VectorType::value_type &
331 {
332  Assert(i == j, ExcIndexRange(j, i, i + 1));
333  (void)j;
334  return diagonal(i);
335 }
336 
337 
338 
339 template <typename VectorType>
340 template <typename number2>
341 void
343  const size_type n_cols,
344  const size_type *col_indices,
345  const number2 * values,
346  const bool,
347  const bool)
348 {
349  for (size_type i = 0; i < n_cols; ++i)
350  if (col_indices[i] == row)
351  diagonal(row) += values[i];
352 }
353 
354 
355 
356 template <typename VectorType>
357 void
359  const size_type j,
360  const value_type value)
361 {
362  if (i == j)
363  diagonal(i) += value;
364 }
365 
366 
367 
368 template <typename VectorType>
369 void
371 {
372  dst = src;
373  dst.scale(diagonal);
374 }
375 
376 
377 
378 template <typename VectorType>
379 void
381 {
382  vmult(dst, src);
383 }
384 
385 
386 
387 template <typename VectorType>
388 void
390  const VectorType &src) const
391 {
392  VectorType tmp(src);
393  tmp.scale(diagonal);
394  dst += tmp;
395 }
396 
397 
398 
399 template <typename VectorType>
400 void
402  const VectorType &src) const
403 {
404  vmult_add(dst, src);
405 }
406 
407 
408 #endif
409 
411 
412 #endif
std::size_t memory_consumption() const
types::global_dof_index size_type
Definition: cuda_kernels.h:45
VectorType & get_vector()
void Tvmult(VectorType &dst, const VectorType &src) const
void compress(VectorOperation::values operation)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
typename VectorType::size_type size_type
value_type operator()(const size_type i, const size_type j) const
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)
size_type n() const
void vmult(VectorType &dst, const VectorType &src) const
#define Assert(cond, exc)
Definition: exceptions.h:1419
size_type m() const
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
VectorType diagonal
DiagonalMatrix()=default
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
void initialize_dof_vector(VectorType &dst) const
void reinit(const VectorType &vec)
void vmult_add(VectorType &dst, const VectorType &src) const
typename VectorType::value_type value_type
void Tvmult_add(VectorType &dst, const VectorType &src) const
static const bool value