16 #ifndef dealii_precondition_block_base_h 17 #define dealii_precondition_block_base_h 20 #include <deal.II/base/config.h> 22 #include <deal.II/base/exceptions.h> 23 #include <deal.II/base/memory_consumption.h> 24 #include <deal.II/base/smartpointer.h> 25 #include <deal.II/base/subscriptor.h> 27 #include <deal.II/lac/householder.h> 28 #include <deal.II/lac/lapack_full_matrix.h> 32 DEAL_II_NAMESPACE_OPEN
34 template <
typename number>
36 template <
typename number>
57 template <
typename number>
110 reinit(
unsigned int nblocks,
148 template <
typename number2>
151 Vector<number2> & dst,
152 const Vector<number2> &src)
const;
157 template <
typename number2>
160 Vector<number2> & dst,
161 const Vector<number2> &src)
const;
302 template <
typename number>
306 , n_diagonal_blocks(0)
307 , var_store_diagonals(store)
308 , var_same_diagonal(false)
309 , var_inverses_ready(false)
313 template <
typename number>
317 if (var_inverse_full.size() != 0)
318 var_inverse_full.erase(var_inverse_full.begin(), var_inverse_full.end());
319 if (var_inverse_householder.size() != 0)
320 var_inverse_householder.erase(var_inverse_householder.begin(),
321 var_inverse_householder.end());
322 if (var_inverse_svd.size() != 0)
323 var_inverse_svd.erase(var_inverse_svd.begin(), var_inverse_svd.end());
324 if (var_diagonal.size() != 0)
325 var_diagonal.erase(var_diagonal.begin(), var_diagonal.end());
326 var_same_diagonal =
false;
327 var_inverses_ready =
false;
328 n_diagonal_blocks = 0;
331 template <
typename number>
339 var_same_diagonal = compress;
340 var_inverses_ready =
false;
341 n_diagonal_blocks = n;
348 var_inverse_full.resize(1);
349 var_inverse_full[0].reinit(b, b);
352 var_inverse_householder.resize(1);
355 var_inverse_svd.resize(1);
356 var_inverse_svd[0].reinit(b, b);
362 if (store_diagonals())
364 var_diagonal.resize(1);
365 var_diagonal[0].reinit(b, b);
378 if (store_diagonals())
381 var_diagonal.swap(tmp);
389 var_inverse_full.swap(tmp);
393 var_inverse_householder.resize(n);
397 std::vector<LAPACKFullMatrix<number>> tmp(
399 var_inverse_svd.swap(tmp);
409 template <
typename number>
413 return n_diagonal_blocks;
416 template <
typename number>
417 template <
typename number2>
420 Vector<number2> & dst,
421 const Vector<number2> &src)
const 423 const size_type ii = same_diagonal() ? 0U : i;
429 var_inverse_full[ii].vmult(dst, src);
433 var_inverse_householder[ii].vmult(dst, src);
437 var_inverse_svd[ii].vmult(dst, src);
445 template <
typename number>
446 template <
typename number2>
449 Vector<number2> & dst,
450 const Vector<number2> &src)
const 452 const size_type ii = same_diagonal() ? 0U : i;
458 var_inverse_full[ii].Tvmult(dst, src);
462 var_inverse_householder[ii].Tvmult(dst, src);
466 var_inverse_svd[ii].Tvmult(dst, src);
474 template <
typename number>
479 return var_inverse_full[0];
481 Assert(i < var_inverse_full.size(),
483 return var_inverse_full[i];
487 template <
typename number>
492 return var_inverse_householder[0];
495 return var_inverse_householder[i];
499 template <
typename number>
504 return var_inverse_svd[0];
507 return var_inverse_svd[i];
511 template <
typename number>
515 Assert(store_diagonals(), ExcDiagonalsNotStored());
518 return var_diagonal[0];
521 return var_diagonal[i];
525 template <
typename number>
529 Assert(var_inverse_full.size() != 0, ExcInverseNotAvailable());
532 return var_inverse_full[0];
534 Assert(i < var_inverse_full.size(),
536 return var_inverse_full[i];
540 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>
558 Assert(var_inverse_svd.size() != 0, ExcInverseNotAvailable());
561 return var_inverse_svd[0];
564 return var_inverse_svd[i];
568 template <
typename number>
572 Assert(store_diagonals(), ExcDiagonalsNotStored());
575 return var_diagonal[0];
578 return var_diagonal[i];
582 template <
typename number>
586 return var_same_diagonal;
590 template <
typename number>
594 return var_store_diagonals;
598 template <
typename number>
602 var_inverses_ready = x;
606 template <
typename number>
610 return var_inverses_ready;
614 template <
typename number>
618 deallog <<
"PreconditionBlockBase: " << size() <<
" blocks; ";
620 if (inversion == svd)
622 unsigned int kermin = 100000000, kermax = 0;
623 double sigmin = 1.e300, sigmax = -1.e300;
624 double kappamin = 1.e300, kappamax = -1.e300;
630 while (k <= matrix.n_cols() &&
631 matrix.singular_value(matrix.n_cols() - k) == 0)
633 const double s0 = matrix.singular_value(0);
634 const double sm = matrix.singular_value(matrix.n_cols() - k);
635 const double co = sm / s0;
650 deallog <<
"dim ker [" << kermin <<
':' << kermax <<
"] sigma [" << sigmin
651 <<
':' << sigmax <<
"] kappa [" << kappamin <<
':' << kappamax
654 else if (inversion == householder)
656 else if (inversion == gauss_jordan)
665 template <
typename number>
669 std::size_t mem =
sizeof(*this);
670 for (
size_type i = 0; i < var_inverse_full.size(); ++i)
672 for (
size_type i = 0; i < var_diagonal.size(); ++i)
678 DEAL_II_NAMESPACE_CLOSE
types::global_dof_index size_type
#define AssertIndexRange(index, range)
~PreconditionBlockBase()=default
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
LinearAlgebra::distributed::Vector< Number > Vector
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)
#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
unsigned int global_dof_index
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()
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
bool same_diagonal() const