deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+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: Apache-2.0 WITH LLVM-exception OR 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// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_tridiagonal_matrix_h
14#define dealii_tridiagonal_matrix_h
15
16#include <deal.II/base/config.h>
17
19
21
22#include <iomanip>
23#include <vector>
24
26
27// forward declarations
28#ifndef DOXYGEN
29template <typename number>
30class Vector;
31#endif
32
49template <typename number>
51{
52public:
54
59
66 TridiagonalMatrix(size_type n = 0, bool symmetric = false);
67
72 void
73 reinit(size_type n, bool symmetric = false);
74
75
79
86 m() const;
87
93 n() const;
94
100 bool
101 all_zero() const;
102
106
111 number
113
123 number &
125
129
140 void
142 const Vector<number> &v,
143 const bool adding = false) const;
144
151 void
152 vmult_add(Vector<number> &w, const Vector<number> &v) const;
153
163 void
165 const Vector<number> &v,
166 const bool adding = false) const;
167
175 void
176 Tvmult_add(Vector<number> &w, const Vector<number> &v) const;
177
183 number
184 matrix_scalar_product(const Vector<number> &u, const Vector<number> &v) const;
185
195 number
196 matrix_norm_square(const Vector<number> &v) const;
197
201
208 void
213 number
214 eigenvalue(const size_type i) const;
218
222 template <class OutputStream>
223 void
224 print(OutputStream &s,
225 const unsigned int width = 5,
226 const unsigned int precision = 2) const;
229private:
233 std::vector<number> diagonal;
243 std::vector<number> left;
249 std::vector<number> right;
250
256
264};
265
268//---------------------------------------------------------------------------
269#ifndef DOXYGEN
270
271template <typename number>
274{
275 return diagonal.size();
276}
277
278
279
280template <typename number>
283{
284 return diagonal.size();
285}
286
287
288template <typename number>
289inline number
290TridiagonalMatrix<number>::operator()(size_type i, size_type j) const
291{
292 AssertIndexRange(i, n());
293 AssertIndexRange(j, n());
294 Assert(i <= j + 1, ExcIndexRange(i, j - 1, j + 2));
295 Assert(j <= i + 1, ExcIndexRange(j, i - 1, i + 2));
296
297 if (j == i)
298 return diagonal[i];
299 if (j == i - 1)
300 {
301 if (is_symmetric)
302 return right[i - 1];
303 else
304 return left[i];
305 }
306
307 if (j == i + 1)
308 return right[i];
309
311 return 0;
312}
313
314
315template <typename number>
316inline number &
317TridiagonalMatrix<number>::operator()(size_type i, size_type j)
318{
319 AssertIndexRange(i, n());
320 AssertIndexRange(j, n());
321 Assert(i <= j + 1, ExcIndexRange(i, j - 1, j + 2));
322 Assert(j <= i + 1, ExcIndexRange(j, i - 1, i + 2));
323
324 if (j == i)
325 return diagonal[i];
326 if (j == i - 1)
327 {
328 if (is_symmetric)
329 return right[i - 1];
330 else
331 return left[i];
332 }
333
334 if (j == i + 1)
335 return right[i];
336
338 return diagonal[0];
339}
340
341
342template <typename number>
343template <class OutputStream>
344void
346 const unsigned int width,
347 const unsigned int) const
348{
349 for (size_type i = 0; i < n(); ++i)
350 {
351 if (i > 0)
352 s << std::setw(width) << (*this)(i, i - 1);
353 else
354 s << std::setw(width) << "";
355
356 s << ' ' << (*this)(i, i) << ' ';
357
358 if (i < n() - 1)
359 s << std::setw(width) << (*this)(i, i + 1);
360
361 s << std::endl;
362 }
363}
364
365
366#endif // DOXYGEN
367
369
370#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:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DEAL_II_ASSERT_UNREACHABLE()
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcIndexRange(std::size_t arg1, std::size_t arg2, std::size_t arg3)
@ diagonal
Matrix is diagonal.
unsigned int global_dof_index
Definition types.h:92