Reference documentation for deal.II version 8.5.1
tridiagonal_matrix.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2016 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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__tridiagonal_matrix_h
17 #define dealii__tridiagonal_matrix_h
18 
19 #include <deal.II/base/config.h>
20 #include <deal.II/base/subscriptor.h>
21 #include <deal.II/lac/lapack_support.h>
22 
23 #include <vector>
24 #include <iomanip>
25 
26 DEAL_II_NAMESPACE_OPEN
27 
28 // forward declarations
29 template<typename number> class Vector;
30 
31 
48 template<typename number>
50 {
51 public:
53 
54 
58 
66  bool symmetric = false);
67 
72  void reinit(size_type n,
73  bool symmetric = false);
74 
75 
77 
79 
84  size_type m () const;
85 
90  size_type n () const;
91 
97  bool all_zero () const;
98 
99 
100 
102 
104 
108  number operator()(size_type i, size_type j) const;
109 
119  number &operator()(size_type i, size_type j);
120 
122 
124 
134  void vmult (Vector<number> &w,
135  const Vector<number> &v,
136  const bool adding=false) const;
137 
144  void vmult_add (Vector<number> &w,
145  const Vector<number> &v) const;
146 
156  void Tvmult (Vector<number> &w,
157  const Vector<number> &v,
158  const bool adding=false) const;
159 
167  void Tvmult_add (Vector<number> &w,
168  const Vector<number> &v) const;
169 
175  number matrix_scalar_product (const Vector<number> &u,
176  const Vector<number> &v) const;
177 
187  number matrix_norm_square (const Vector<number> &v) const;
188 
190 
192 
199  number l1_norm () const;
200 
207  number linfty_norm () const;
208 
213  number frobenius_norm () const;
214 
223  number relative_symmetry_norm2 () const;
225 
227 
233  void compute_eigenvalues();
237  number eigenvalue(const size_type i) const;
239 
241 
244  template <class OutputStream>
245  void print(OutputStream &s,
246  const unsigned int width=5,
247  const unsigned int precision=2) const;
248 
253  std::size_t memory_consumption () const;
255 
256 private:
260  std::vector<number> diagonal;
270  std::vector<number> left;
276  std::vector<number> right;
277 
283 
290  LAPACKSupport::State state;
291 };
292 
295 //---------------------------------------------------------------------------
296 #ifndef DOXYGEN
297 
298 template<typename number>
301 {
302  return diagonal.size();
303 }
304 
305 
306 
307 template<typename number>
310 {
311  return diagonal.size();
312 }
313 
314 
315 template<typename number>
316 inline
317 number
318 TridiagonalMatrix<number>::operator()(size_type i, size_type j) const
319 {
320  Assert(i<n(), ExcIndexRange(i,0,n()));
321  Assert(j<n(), ExcIndexRange(j,0,n()));
322  Assert (i<=j+1, ExcIndexRange(i,j-1,j+2));
323  Assert (j<=i+1, ExcIndexRange(j,i-1,i+2));
324 
325  if (j==i)
326  return diagonal[i];
327  if (j==i-1)
328  {
329  if (is_symmetric)
330  return right[i-1];
331  else
332  return left[i];
333  }
334 
335  if (j==i+1)
336  return right[i];
337 
338  Assert (false, ExcInternalError());
339  return 0;
340 }
341 
342 
343 template<typename number>
344 inline
345 number &
346 TridiagonalMatrix<number>::operator()(size_type i, size_type j)
347 {
348  Assert(i<n(), ExcIndexRange(i,0,n()));
349  Assert(j<n(), ExcIndexRange(j,0,n()));
350  Assert (i<=j+1, ExcIndexRange(i,j-1,j+2));
351  Assert (j<=i+1, ExcIndexRange(j,i-1,i+2));
352 
353  if (j==i)
354  return diagonal[i];
355  if (j==i-1)
356  {
357  if (is_symmetric)
358  return right[i-1];
359  else
360  return left[i];
361  }
362 
363  if (j==i+1)
364  return right[i];
365 
366  Assert (false, ExcInternalError());
367  return diagonal[0];
368 }
369 
370 
371 template <typename number>
372 template <class OutputStream>
373 void
375  OutputStream &s,
376  const unsigned int width,
377  const unsigned int) const
378 {
379  for (size_type i=0; i<n(); ++i)
380  {
381  if (i>0)
382  s << std::setw(width) << (*this)(i,i-1);
383  else
384  s << std::setw(width) << "";
385 
386  s << ' ' << (*this)(i,i) << ' ';
387 
388  if (i<n()-1)
389  s << std::setw(width) << (*this)(i,i+1);
390 
391  s << std::endl;
392  }
393 }
394 
395 
396 #endif // DOXYGEN
397 
398 DEAL_II_NAMESPACE_CLOSE
399 
400 #endif
void compute_eigenvalues()
std::vector< number > left
void print(OutputStream &s, const unsigned int width=5, const unsigned int precision=2) const
number l1_norm() const
number linfty_norm() const
void vmult(Vector< number > &w, const Vector< number > &v, const bool adding=false) const
number relative_symmetry_norm2() const
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
void Tvmult_add(Vector< number > &w, const Vector< number > &v) const
std::size_t memory_consumption() const
unsigned int global_dof_index
Definition: types.h:88
#define Assert(cond, exc)
Definition: exceptions.h:313
std::vector< number > right
number matrix_scalar_product(const Vector< number > &u, const Vector< number > &v) const
number frobenius_norm() const
TridiagonalMatrix(size_type n=0, bool symmetric=false)
types::global_dof_index size_type
number matrix_norm_square(const Vector< number > &v) const
size_type n() const
number eigenvalue(const size_type i) const
void Tvmult(Vector< number > &w, const Vector< number > &v, const bool adding=false) const
number operator()(size_type i, size_type j) const
LAPACKSupport::State state
std::vector< number > diagonal
size_type m() const
void reinit(size_type n, bool symmetric=false)
void vmult_add(Vector< number > &w, const Vector< number > &v) const
static ::ExceptionBase & ExcInternalError()