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>
130 unsigned int size()
const;
135 template <
typename number2>
141 template <
typename number2>
273 template <
typename number>
279 n_diagonal_blocks(0),
280 var_store_diagonals(store),
281 var_same_diagonal(false),
282 var_inverses_ready(false)
286 template <
typename number>
291 if (var_inverse_full.size()!=0)
292 var_inverse_full.erase(var_inverse_full.begin(), var_inverse_full.end());
293 if (var_inverse_householder.size()!=0)
294 var_inverse_householder.erase(var_inverse_householder.begin(), var_inverse_householder.end());
295 if (var_inverse_svd.size()!=0)
296 var_inverse_svd.erase(var_inverse_svd.begin(), var_inverse_svd.end());
297 if (var_diagonal.size()!=0)
298 var_diagonal.erase(var_diagonal.begin(), var_diagonal.end());
299 var_same_diagonal =
false;
300 var_inverses_ready =
false;
301 n_diagonal_blocks = 0;
304 template <
typename number>
311 var_same_diagonal = compress;
312 var_inverses_ready =
false;
313 n_diagonal_blocks = n;
320 var_inverse_full.resize(1);
321 var_inverse_full[0].reinit(b,b);
324 var_inverse_householder.resize(1);
327 var_inverse_svd.resize(1);
328 var_inverse_svd[0].reinit(b,b);
334 if (store_diagonals())
336 var_diagonal.resize(1);
337 var_diagonal[0].reinit(b,b);
350 if (store_diagonals())
352 std::vector<FullMatrix<number> >
354 var_diagonal.swap (tmp);
361 std::vector<FullMatrix<number> >
363 var_inverse_full.swap (tmp);
367 var_inverse_householder.resize(n);
371 std::vector<LAPACKFullMatrix<number> >
373 var_inverse_svd.swap (tmp);
383 template <
typename number>
388 return n_diagonal_blocks;
391 template <
typename number>
392 template <
typename number2>
396 size_type i, Vector<number2> &dst,
const Vector<number2> &src)
const 398 const size_type ii = same_diagonal() ? 0U : i;
404 var_inverse_full[ii].vmult(dst, src);
408 var_inverse_householder[ii].vmult(dst, src);
412 var_inverse_svd[ii].vmult(dst, src);
420 template <
typename number>
421 template <
typename number2>
425 size_type i, Vector<number2> &dst,
const Vector<number2> &src)
const 427 const size_type ii = same_diagonal() ? 0U : i;
433 var_inverse_full[ii].Tvmult(dst, src);
437 var_inverse_householder[ii].Tvmult(dst, src);
441 var_inverse_svd[ii].Tvmult(dst, src);
449 template <
typename number>
455 return var_inverse_full[0];
458 return var_inverse_full[i];
462 template <
typename number>
468 return var_inverse_householder[0];
471 return var_inverse_householder[i];
475 template <
typename number>
481 return var_inverse_svd[0];
484 return var_inverse_svd[i];
488 template <
typename number>
493 Assert(store_diagonals(), ExcDiagonalsNotStored());
496 return var_diagonal[0];
499 return var_diagonal[i];
503 template <
typename number>
508 Assert(var_inverse_full.size() != 0, ExcInverseNotAvailable());
511 return var_inverse_full[0];
514 return var_inverse_full[i];
518 template <
typename number>
523 Assert(var_inverse_householder.size() != 0, ExcInverseNotAvailable());
526 return var_inverse_householder[0];
529 return var_inverse_householder[i];
533 template <
typename number>
538 Assert(var_inverse_svd.size() != 0, ExcInverseNotAvailable());
541 return var_inverse_svd[0];
544 return var_inverse_svd[i];
548 template <
typename number>
553 Assert(store_diagonals(), ExcDiagonalsNotStored());
556 return var_diagonal[0];
559 return var_diagonal[i];
563 template <
typename number>
567 return var_same_diagonal;
571 template <
typename number>
575 return var_store_diagonals;
579 template <
typename number>
583 var_inverses_ready = x;
587 template <
typename number>
591 return var_inverses_ready;
595 template <
typename number>
599 deallog <<
"PreconditionBlockBase: " << size() <<
" blocks; ";
601 if (inversion == svd)
603 unsigned int kermin = 100000000, kermax = 0;
604 double sigmin = 1.e300, sigmax= -1.e300;
605 double kappamin = 1.e300, kappamax= -1.e300;
611 while (k <= matrix.n_cols() && matrix.singular_value(matrix.n_cols()-k) == 0)
613 const double s0 = matrix.singular_value(0);
614 const double sm = matrix.singular_value(matrix.n_cols()-k);
615 const double co = sm/s0;
617 if (kermin > k) kermin = k-1;
618 if (kermax < k) kermax = k-1;
619 if (s0 < sigmin) sigmin = s0;
620 if (sm > sigmax) sigmax = sm;
621 if (co < kappamin) kappamin = co;
622 if (co > kappamax) kappamax = co;
624 deallog <<
"dim ker [" << kermin <<
':' << kermax
625 <<
"] sigma [" << sigmin <<
':' << sigmax
626 <<
"] kappa [" << kappamin <<
':' << kappamax <<
']' << std::endl;
629 else if (inversion == householder)
632 else if (inversion == gauss_jordan)
642 template <
typename number>
647 std::size_t mem =
sizeof(*this);
648 for (
size_type i=0; i<var_inverse_full.size(); ++i)
650 for (
size_type i=0; i<var_diagonal.size(); ++i)
656 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)
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
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