Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
tridiagonal_matrix.h
1 // ---------------------------------------------------------------------
2 // @f$Id: tridiagonal_matrix.h 30036 2013-07-18 16:55:32Z maier @f$
3 //
4 // Copyright (C) 2005 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__tridiagonal_matrix_h
18 #define __deal2__tridiagonal_matrix_h
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/subscriptor.h>
22 #include <deal.II/lac/lapack_support.h>
23 
24 #include <vector>
25 #include <iomanip>
26 
28 
29 // forward declarations
30 template<typename number> class Vector;
31 
32 
49 template<typename number>
51 {
52 public:
57 
66  TridiagonalMatrix(size_type n = 0,
67  bool symmetric = false);
68 
75  void reinit(size_type n,
76  bool symmetric = false);
77 
78 
80 
82 
88  size_type m () const;
89 
95  size_type n () const;
96 
107  bool all_zero () const;
108 
109 
110 
112 
114 
120  number operator()(size_type i, size_type j) const;
121 
137  number &operator()(size_type i, size_type j);
138 
140 
142 
156  void vmult (Vector<number> &w,
157  const Vector<number> &v,
158  const bool adding=false) const;
159 
171  void vmult_add (Vector<number> &w,
172  const Vector<number> &v) const;
173 
189  void Tvmult (Vector<number> &w,
190  const Vector<number> &v,
191  const bool adding=false) const;
192 
204  void Tvmult_add (Vector<number> &w,
205  const Vector<number> &v) const;
206 
214  number matrix_scalar_product (const Vector<number> &u,
215  const Vector<number> &v) const;
216 
236  number matrix_norm_square (const Vector<number> &v) const;
237 
239 
241 
252  number l1_norm () const;
253 
265  number linfty_norm () const;
266 
272  number frobenius_norm () const;
273 
287  number relative_symmetry_norm2 () const;
289 
291 
301  void compute_eigenvalues();
307  number eigenvalue(const size_type i) const;
309 
311 
315  template <class OUT>
316  void print (OUT &s,
317  const unsigned int width=5,
318  const unsigned int precision=2) const;
319 
325  std::size_t memory_consumption () const;
327 
328 private:
332  std::vector<number> diagonal;
348  std::vector<number> left;
358  std::vector<number> right;
359 
367 
379  LAPACKSupport::State state;
380 };
381 
384 //---------------------------------------------------------------------------
385 #ifndef DOXYGEN
386 
387 template<typename number>
390 {
391  return diagonal.size();
392 }
393 
394 
395 
396 template<typename number>
399 {
400  return diagonal.size();
401 }
402 
403 
404 template<typename number>
405 inline
406 number
408 {
409  Assert(i<n(), ExcIndexRange(i,0,n()));
410  Assert(j<n(), ExcIndexRange(j,0,n()));
411  Assert (i<=j+1, ExcIndexRange(i,j-1,j+2));
412  Assert (j<=i+1, ExcIndexRange(j,i-1,i+2));
413 
414  if (j==i)
415  return diagonal[i];
416  if (j==i-1)
417  {
418  if (is_symmetric)
419  return right[i-1];
420  else
421  return left[i];
422  }
423 
424  if (j==i+1)
425  return right[i];
426 
427  Assert (false, ExcInternalError());
428  return 0;
429 }
430 
431 
432 template<typename number>
433 inline
434 number &
436 {
437  Assert(i<n(), ExcIndexRange(i,0,n()));
438  Assert(j<n(), ExcIndexRange(j,0,n()));
439  Assert (i<=j+1, ExcIndexRange(i,j-1,j+2));
440  Assert (j<=i+1, ExcIndexRange(j,i-1,i+2));
441 
442  if (j==i)
443  return diagonal[i];
444  if (j==i-1)
445  {
446  if (is_symmetric)
447  return right[i-1];
448  else
449  return left[i];
450  }
451 
452  if (j==i+1)
453  return right[i];
454 
455  Assert (false, ExcInternalError());
456  return diagonal[0];
457 }
458 
459 
460 template <typename number>
461 template <class OUT>
462 void
464  OUT &s,
465  const unsigned int width,
466  const unsigned int) const
467 {
468  for (size_type i=0; i<n(); ++i)
469  {
470  if (i>0)
471  s << std::setw(width) << (*this)(i,i-1);
472  else
473  s << std::setw(width) << "";
474 
475  s << ' ' << (*this)(i,i) << ' ';
476 
477  if (i<n()-1)
478  s << std::setw(width) << (*this)(i,i+1);
479 
480  s << std::endl;
481  }
482 }
483 
484 
485 #endif // DOXYGEN
486 
487 DEAL_II_NAMESPACE_CLOSE
488 
489 #endif
490 
void Tvmult_add(Vector< number > &w, const Vector< number > &v) const
void compute_eigenvalues()
void Tvmult(Vector< number > &w, const Vector< number > &v, const bool adding=false) const
void vmult(Vector< number > &w, const Vector< number > &v, const bool adding=false) const
std::vector< number > left
number l1_norm() const
size_type n() const
number linfty_norm() const
number matrix_scalar_product(const Vector< number > &u, const Vector< number > &v) const
unsigned int global_dof_index
Definition: types.h:100
#define Assert(cond, exc)
Definition: exceptions.h:299
std::vector< number > right
::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
bool all_zero() const
TridiagonalMatrix(size_type n=0, bool symmetric=false)
types::global_dof_index size_type
number frobenius_norm() const
void print(OUT &s, const unsigned int width=5, const unsigned int precision=2) const
std::size_t memory_consumption() const
number relative_symmetry_norm2() const
LAPACKSupport::State state
std::vector< number > diagonal
number matrix_norm_square(const Vector< number > &v) const
void vmult_add(Vector< number > &w, const Vector< number > &v) const
void reinit(size_type n, bool symmetric=false)
number eigenvalue(const size_type i) const
::ExceptionBase & ExcInternalError()
size_type m() const
number operator()(size_type i, size_type j) const