Reference documentation for deal.II version GIT relicensing-1182-g1782d71672 2024-07-22 00:00:02+00:00
\(\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\}}\)
Loading...
Searching...
No Matches
tridiagonal_matrix.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2005 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_tridiagonal_matrix_h
16#define dealii_tridiagonal_matrix_h
17
18#include <deal.II/base/config.h>
19
21
23
24#include <iomanip>
25#include <vector>
26
28
29// forward declarations
30#ifndef DOXYGEN
31template <typename number>
32class Vector;
33#endif
34
51template <typename number>
53{
54public:
56
61
68 TridiagonalMatrix(size_type n = 0, bool symmetric = false);
69
74 void
75 reinit(size_type n, bool symmetric = false);
76
77
81
88 m() const;
89
95 n() const;
96
102 bool
103 all_zero() const;
104
108
113 number
115
125 number &
127
131
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
187
197 number
198 matrix_norm_square(const Vector<number> &v) const;
199
203
210 void
215 number
216 eigenvalue(const size_type i) const;
220
224 template <class OutputStream>
225 void
227 const unsigned int width = 5,
228 const unsigned int precision = 2) const;
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
292TridiagonalMatrix<number>::operator()(size_type i, size_type j) const
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
313 return 0;
314}
315
316
317template <typename number>
318inline number &
319TridiagonalMatrix<number>::operator()(size_type i, size_type j)
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
340 return diagonal[0];
341}
342
343
344template <typename number>
345template <class OutputStream>
346void
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
number matrix_scalar_product(const Vector< number > &u, const Vector< number > &v) const
std::vector< number > left
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:503
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcIndexRange(std::size_t arg1, std::size_t arg2, std::size_t arg3)
#define DEAL_II_ASSERT_UNREACHABLE()
@ diagonal
Matrix is diagonal.
unsigned int global_dof_index
Definition types.h:81