16 #ifndef dealii__precondition_block_base_h 17 #define dealii__precondition_block_base_h 20 #include <deal.II/base/config.h> 21 #include <deal.II/base/exceptions.h> 22 #include <deal.II/base/subscriptor.h> 23 #include <deal.II/base/smartpointer.h> 24 #include <deal.II/base/memory_consumption.h> 25 #include <deal.II/lac/householder.h> 26 #include <deal.II/lac/lapack_full_matrix.h> 30 DEAL_II_NAMESPACE_OPEN
33 template <
typename number>
class Vector;
53 template <
typename number>
145 unsigned int size()
const;
156 template <
typename number2>
162 template <
typename number2>
294 template <
typename number>
300 n_diagonal_blocks(0),
301 var_store_diagonals(store),
302 var_same_diagonal(false),
303 var_inverses_ready(false)
307 template <
typename number>
312 if (var_inverse_full.size()!=0)
313 var_inverse_full.erase(var_inverse_full.begin(), var_inverse_full.end());
314 if (var_inverse_householder.size()!=0)
315 var_inverse_householder.erase(var_inverse_householder.begin(), var_inverse_householder.end());
316 if (var_inverse_svd.size()!=0)
317 var_inverse_svd.erase(var_inverse_svd.begin(), var_inverse_svd.end());
318 if (var_diagonal.size()!=0)
319 var_diagonal.erase(var_diagonal.begin(), var_diagonal.end());
320 var_same_diagonal =
false;
321 var_inverses_ready =
false;
322 n_diagonal_blocks = 0;
325 template <
typename number>
332 var_same_diagonal = compress;
333 var_inverses_ready =
false;
334 n_diagonal_blocks = n;
341 var_inverse_full.resize(1);
342 var_inverse_full[0].reinit(b,b);
345 var_inverse_householder.resize(1);
348 var_inverse_svd.resize(1);
349 var_inverse_svd[0].reinit(b,b);
355 if (store_diagonals())
357 var_diagonal.resize(1);
358 var_diagonal[0].reinit(b,b);
371 if (store_diagonals())
373 std::vector<FullMatrix<number> >
375 var_diagonal.swap (tmp);
382 std::vector<FullMatrix<number> >
384 var_inverse_full.swap (tmp);
388 var_inverse_householder.resize(n);
392 std::vector<LAPACKFullMatrix<number> >
394 var_inverse_svd.swap (tmp);
404 template <
typename number>
409 return n_diagonal_blocks;
412 template <
typename number>
413 template <
typename number2>
419 const size_type ii = same_diagonal() ? 0U : i;
425 var_inverse_full[ii].vmult(dst, src);
429 var_inverse_householder[ii].vmult(dst, src);
433 var_inverse_svd[ii].vmult(dst, src);
441 template <
typename number>
442 template <
typename number2>
448 const size_type ii = same_diagonal() ? 0U : i;
454 var_inverse_full[ii].Tvmult(dst, src);
458 var_inverse_householder[ii].Tvmult(dst, src);
462 var_inverse_svd[ii].Tvmult(dst, src);
470 template <
typename number>
476 return var_inverse_full[0];
479 return var_inverse_full[i];
483 template <
typename number>
489 return var_inverse_householder[0];
492 return var_inverse_householder[i];
496 template <
typename number>
502 return var_inverse_svd[0];
505 return var_inverse_svd[i];
509 template <
typename number>
514 Assert(store_diagonals(), ExcDiagonalsNotStored());
517 return var_diagonal[0];
520 return var_diagonal[i];
524 template <
typename number>
529 Assert(var_inverse_full.size() != 0, ExcInverseNotAvailable());
532 return var_inverse_full[0];
535 return var_inverse_full[i];
539 template <
typename number>
544 Assert(var_inverse_householder.size() != 0, ExcInverseNotAvailable());
547 return var_inverse_householder[0];
550 return var_inverse_householder[i];
554 template <
typename number>
559 Assert(var_inverse_svd.size() != 0, ExcInverseNotAvailable());
562 return var_inverse_svd[0];
565 return var_inverse_svd[i];
569 template <
typename number>
574 Assert(store_diagonals(), ExcDiagonalsNotStored());
577 return var_diagonal[0];
580 return var_diagonal[i];
584 template <
typename number>
588 return var_same_diagonal;
592 template <
typename number>
596 return var_store_diagonals;
600 template <
typename number>
604 var_inverses_ready = x;
608 template <
typename number>
612 return var_inverses_ready;
616 template <
typename number>
620 deallog <<
"PreconditionBlockBase: " << size() <<
" blocks; ";
622 if (inversion == svd)
624 unsigned int kermin = 100000000, kermax = 0;
625 double sigmin = 1.e300, sigmax= -1.e300;
626 double kappamin = 1.e300, kappamax= -1.e300;
632 while (k <= matrix.n_cols() && matrix.singular_value(matrix.n_cols()-k) == 0)
634 const double s0 = matrix.singular_value(0);
635 const double sm = matrix.singular_value(matrix.n_cols()-k);
636 const double co = sm/s0;
638 if (kermin > k) kermin = k-1;
639 if (kermax < k) kermax = k-1;
640 if (s0 < sigmin) sigmin = s0;
641 if (sm > sigmax) sigmax = sm;
642 if (co < kappamin) kappamin = co;
643 if (co > kappamax) kappamax = co;
645 deallog <<
"dim ker [" << kermin <<
':' << kermax
646 <<
"] sigma [" << sigmin <<
':' << sigmax
647 <<
"] kappa [" << kappamin <<
':' << kappamax <<
']' << std::endl;
650 else if (inversion == householder)
653 else if (inversion == gauss_jordan)
663 template <
typename number>
668 std::size_t mem =
sizeof(*this);
669 for (
size_type i=0; i<var_inverse_full.size(); ++i)
671 for (
size_type i=0; i<var_diagonal.size(); ++i)
677 DEAL_II_NAMESPACE_CLOSE
types::global_dof_index size_type
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
void inverses_computed(bool are_they)
void inverse_vmult(size_type i, Vector< number2 > &dst, const Vector< number2 > &src) const
std::vector< FullMatrix< number > > var_diagonal
FullMatrix< number > & inverse(size_type i)
PreconditionBlockBase(bool store_diagonals=false, Inversion method=gauss_jordan)
unsigned int global_dof_index
#define Assert(cond, exc)
bool store_diagonals() const
#define DeclException0(Exception0)
std::vector< FullMatrix< number > > var_inverse_full
void reinit(unsigned int nblocks, size_type blocksize, bool compress, Inversion method=gauss_jordan)
unsigned int n_diagonal_blocks
void log_statistics() const
void inverse_Tvmult(size_type i, Vector< number2 > &dst, const Vector< number2 > &src) const
number el(size_type i, size_type j) const
std_cxx11::enable_if< std_cxx11::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
unsigned int size() const
static ::ExceptionBase & ExcDiagonalsNotStored()
std::vector< LAPACKFullMatrix< number > > var_inverse_svd
LAPACKFullMatrix< number > & inverse_svd(size_type i)
Householder< number > & inverse_householder(size_type i)
static ::ExceptionBase & ExcNotImplemented()
bool inverses_ready() const
std::size_t memory_consumption() const
std::vector< Householder< number > > var_inverse_householder
FullMatrix< number > & diagonal(size_type i)
static ::ExceptionBase & ExcInverseNotAvailable()
bool same_diagonal() const