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\}}\)
tridiagonal_matrix.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2005 - 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_tridiagonal_matrix_h
17#define dealii_tridiagonal_matrix_h
18
19#include <deal.II/base/config.h>
20
22
24
25#include <iomanip>
26#include <vector>
27
29
30// forward declarations
31#ifndef DOXYGEN
32template <typename number>
33class Vector;
34#endif
35
51template <typename number>
53{
54public:
56
57
61
68 TridiagonalMatrix(size_type n = 0, bool symmetric = false);
69
74 void
75 reinit(size_type n, bool symmetric = false);
76
77
79
81
82
88 m() const;
89
95 n() const;
96
102 bool
103 all_zero() const;
104
106
108
109
113 number
115
125 number &
127
129
131
132
142 void
144 const Vector<number> &v,
145 const bool adding = false) const;
146
153 void
154 vmult_add(Vector<number> &w, const Vector<number> &v) const;
155
165 void
167 const Vector<number> &v,
168 const bool adding = false) const;
169
177 void
178 Tvmult_add(Vector<number> &w, const Vector<number> &v) const;
179
185 number
186 matrix_scalar_product(const Vector<number> &u, const Vector<number> &v) const;
187
197 number
198 matrix_norm_square(const Vector<number> &v) const;
199
201
203
204
210 void
215 number
216 eigenvalue(const size_type i) const;
218
220
221
224 template <class OutputStream>
225 void
226 print(OutputStream & s,
227 const unsigned int width = 5,
228 const unsigned int precision = 2) const;
230
231private:
235 std::vector<number> diagonal;
245 std::vector<number> left;
251 std::vector<number> right;
252
258
266};
267
270//---------------------------------------------------------------------------
271#ifndef DOXYGEN
272
273template <typename number>
276{
277 return diagonal.size();
278}
279
280
281
282template <typename number>
285{
286 return diagonal.size();
287}
288
289
290template <typename number>
291inline number
293{
294 AssertIndexRange(i, n());
295 AssertIndexRange(j, n());
296 Assert(i <= j + 1, ExcIndexRange(i, j - 1, j + 2));
297 Assert(j <= i + 1, ExcIndexRange(j, i - 1, i + 2));
298
299 if (j == i)
300 return diagonal[i];
301 if (j == i - 1)
302 {
303 if (is_symmetric)
304 return right[i - 1];
305 else
306 return left[i];
307 }
308
309 if (j == i + 1)
310 return right[i];
311
312 Assert(false, ExcInternalError());
313 return 0;
314}
315
316
317template <typename number>
318inline number &
320{
321 AssertIndexRange(i, n());
322 AssertIndexRange(j, n());
323 Assert(i <= j + 1, ExcIndexRange(i, j - 1, j + 2));
324 Assert(j <= i + 1, ExcIndexRange(j, i - 1, i + 2));
325
326 if (j == i)
327 return diagonal[i];
328 if (j == i - 1)
329 {
330 if (is_symmetric)
331 return right[i - 1];
332 else
333 return left[i];
334 }
335
336 if (j == i + 1)
337 return right[i];
338
339 Assert(false, ExcInternalError());
340 return diagonal[0];
341}
342
343
344template <typename number>
345template <class OutputStream>
346void
347TridiagonalMatrix<number>::print(OutputStream & s,
348 const unsigned int width,
349 const unsigned int) const
350{
351 for (size_type i = 0; i < n(); ++i)
352 {
353 if (i > 0)
354 s << std::setw(width) << (*this)(i, i - 1);
355 else
356 s << std::setw(width) << "";
357
358 s << ' ' << (*this)(i, i) << ' ';
359
360 if (i < n() - 1)
361 s << std::setw(width) << (*this)(i, i + 1);
362
363 s << std::endl;
364 }
365}
366
367
368#endif // DOXYGEN
369
371
372#endif
number operator()(size_type i, size_type j) const
LAPACKSupport::State state
void Tvmult_add(Vector< number > &w, const Vector< number > &v) const
void vmult(Vector< number > &w, const Vector< number > &v, const bool adding=false) const
void print(OutputStream &s, const unsigned int width=5, const unsigned int precision=2) const
size_type n() const
number matrix_norm_square(const Vector< number > &v) const
std::vector< number > diagonal
void reinit(size_type n, bool symmetric=false)
void vmult_add(Vector< number > &w, const Vector< number > &v) const
std::vector< number > right
number & operator()(size_type i, size_type j)
void Tvmult(Vector< number > &w, const Vector< number > &v, const bool adding=false) const
size_type m() const
number eigenvalue(const size_type i) const
TridiagonalMatrix(size_type n=0, bool symmetric=false)
number matrix_scalar_product(const Vector< number > &u, const Vector< number > &v) const
std::vector< number > left
Definition: vector.h:110
#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
#define AssertIndexRange(index, range)
Definition: exceptions.h:1690
static ::ExceptionBase & ExcInternalError()
@ symmetric
Matrix is symmetric.
@ diagonal
Matrix is diagonal.
types::global_dof_index size_type
Definition: cuda_kernels.h:45
Tensor< 2, dim, Number > w(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
unsigned int global_dof_index
Definition: types.h:76