Reference documentation for deal.II version Git 9e617570d7 2020-09-22 20:39:52 -0400
\(\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 
47 template <typename VectorType = Vector<double>>
49 {
50 public:
51  using value_type = typename VectorType::value_type;
52  using size_type = typename VectorType::size_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 &
88  get_vector();
89 
93  void
94  clear();
95 
99  const VectorType &
100  get_vector() const;
101 
106  size_type
107  m() const;
108 
113  size_type
114  n() const;
115 
125  value_type
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
213  memory_consumption() const;
214 
215 private:
220 };
221 
222 /* ---------------------------------- Inline functions ------------------- */
223 
224 #ifndef DOXYGEN
225 
226 template <typename VectorType>
228  : diagonal(vec)
229 {}
230 
231 
232 
233 template <typename VectorType>
234 void
236 {
237  diagonal.reinit(0);
238 }
239 
240 
241 
242 template <typename VectorType>
243 std::size_t
245 {
246  return diagonal.memory_consumption();
247 }
248 
249 
250 
251 template <typename VectorType>
252 void
254 {
255  diagonal = vec;
256 }
257 
258 
259 
260 template <typename VectorType>
261 void
263 {
264  dst.reinit(diagonal);
265 }
266 
267 
268 
269 template <typename VectorType>
270 void
272 {
273  diagonal.compress(operation);
274 }
275 
276 
277 
278 template <typename VectorType>
279 VectorType &
281 {
282  return diagonal;
283 }
284 
285 
286 
287 template <typename VectorType>
288 const VectorType &
290 {
291  return diagonal;
292 }
293 
294 
295 
296 template <typename VectorType>
297 typename VectorType::size_type
299 {
300  return diagonal.size();
301 }
302 
303 
304 
305 template <typename VectorType>
306 typename VectorType::size_type
308 {
309  return diagonal.size();
310 }
311 
312 
313 
314 template <typename VectorType>
315 typename 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 
326 template <typename VectorType>
327 typename VectorType::value_type &
329 {
330  Assert(i == j, ExcIndexRange(j, i, i + 1));
331  (void)j;
332  return diagonal(i);
333 }
334 
335 
336 
337 template <typename VectorType>
338 template <typename number2>
339 void
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 
354 template <typename VectorType>
355 void
357  const size_type j,
358  const value_type value)
359 {
360  if (i == j)
361  diagonal(i) += value;
362 }
363 
364 
365 
366 template <typename VectorType>
367 void
369 {
370  dst = src;
371  dst.scale(diagonal);
372 }
373 
374 
375 
376 template <typename VectorType>
377 void
379 {
380  vmult(dst, src);
381 }
382 
383 
384 
385 template <typename VectorType>
386 void
388  const VectorType &src) const
389 {
390  VectorType tmp(src);
391  tmp.scale(diagonal);
392  dst += tmp;
393 }
394 
395 
396 
397 template <typename VectorType>
398 void
400  const VectorType &src) const
401 {
402  vmult_add(dst, src);
403 }
404 
405 
406 #endif
407 
409 
410 #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:1411
size_type m() const
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:363
VectorType diagonal
DiagonalMatrix()=default
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:362
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