deal.II version GIT relicensing-2287-g6548a49e0a 2024-12-20 18:30:00+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
precondition_block.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 1999 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_precondition_block_h
16#define dealii_precondition_block_h
17
18
19#include <deal.II/base/config.h>
20
24
26
27#include <vector>
28
30
79template <typename MatrixType,
80 typename inverse_type = typename MatrixType::value_type>
82 protected PreconditionBlockBase<inverse_type>
83{
84private:
88 using number = typename MatrixType::value_type;
89
93 using value_type = inverse_type;
94
95public:
100
105 {
106 public:
112 const double relaxation = 1.,
113 const bool invert_diagonal = true,
114 const bool same_diagonal = false);
115
120
125
130
139
145 double threshold;
146 };
147
148
153
157 ~PreconditionBlock() override = default;
158
166 void
167 initialize(const MatrixType &A, const AdditionalData parameters);
168
169protected:
181 void
182 initialize(const MatrixType &A,
183 const std::vector<size_type> &permutation,
184 const std::vector<size_type> &inverse_permutation,
185 const AdditionalData parameters);
186
210 void
211 set_permutation(const std::vector<size_type> &permutation,
212 const std::vector<size_type> &inverse_permutation);
213
217 void
219
220public:
226 void
228
232 bool
233 empty() const;
234
240 el(size_type i, size_type j) const;
241
257 void
259
271 template <typename number2>
272 void
274 const Vector<number2> &prev,
275 const Vector<number2> &src,
276 const bool transpose_diagonal) const;
277
289 template <typename number2>
290 void
292 const Vector<number2> &prev,
293 const Vector<number2> &src,
294 const bool transpose_diagonal) const;
295
296
301 block_size() const;
302
307 std::size_t
309
320 int,
321 int,
322 << "The blocksize " << arg1 << " and the size of the matrix "
323 << arg2 << " do not match.");
324
329
332protected:
338
351
355 std::vector<size_type> permutation;
356
360 std::vector<size_type> inverse_permutation;
361};
362
363
364
376template <typename MatrixType,
377 typename inverse_type = typename MatrixType::value_type>
379 : public virtual EnableObserverPointer,
380 private PreconditionBlock<MatrixType, inverse_type>
381{
382private:
386 using number = typename MatrixType::value_type;
387
388public:
393
398 {
399 private:
404 {
405 public:
411 const size_type row);
412
417 row() const;
418
423 column() const;
424
428 inverse_type
429 value() const;
430
431 protected:
436
441
446
451
456
457 // Make enclosing class a friend.
458 friend class const_iterator;
459 };
460
461 public:
467 const size_type row);
468
474
478 const Accessor &
479 operator*() const;
480
484 const Accessor *
485 operator->() const;
486
490 bool
495 bool
497
502 bool
503 operator<(const const_iterator &) const;
504
505 private:
510 };
511
516 using PreconditionBlock<MatrixType, inverse_type>::initialize;
517 using PreconditionBlock<MatrixType, inverse_type>::clear;
518 using PreconditionBlock<MatrixType, inverse_type>::empty;
519 using PreconditionBlock<MatrixType, inverse_type>::el;
520 using PreconditionBlock<MatrixType, inverse_type>::invert_diagblocks;
521 using PreconditionBlock<MatrixType, inverse_type>::block_size;
522 using PreconditionBlockBase<inverse_type>::size;
523 using PreconditionBlockBase<inverse_type>::inverse;
525 using PreconditionBlockBase<inverse_type>::inverse_svd;
526 using PreconditionBlockBase<inverse_type>::log_statistics;
527 using PreconditionBlock<MatrixType, inverse_type>::set_permutation;
528
536 template <typename number2>
537 void
539
543 template <typename number2>
544 void
553 template <typename number2>
554 void
556
560 template <typename number2>
561 void
563
567 template <typename number2>
568 void
569 step(Vector<number2> &dst, const Vector<number2> &rhs) const;
570
574 template <typename number2>
575 void
576 Tstep(Vector<number2> &dst, const Vector<number2> &rhs) const;
577
582 begin() const;
583
588 end() const;
589
594 begin(const size_type r) const;
595
600 end(const size_type r) const;
601
602
603private:
610 template <typename number2>
611 void
612 do_vmult(Vector<number2> &, const Vector<number2> &, bool adding) const;
613
614 friend class Accessor;
615 friend class const_iterator;
616};
617
618
619
653template <typename MatrixType,
654 typename inverse_type = typename MatrixType::value_type>
656 : public virtual EnableObserverPointer,
657 protected PreconditionBlock<MatrixType, inverse_type>
658{
659public:
664
669
673 using number = typename MatrixType::value_type;
674
679 using PreconditionBlock<MatrixType, inverse_type>::initialize;
680 using PreconditionBlock<MatrixType, inverse_type>::clear;
681 using PreconditionBlockBase<inverse_type>::size;
682 using PreconditionBlockBase<inverse_type>::inverse;
684 using PreconditionBlockBase<inverse_type>::inverse_svd;
685 using PreconditionBlock<MatrixType, inverse_type>::invert_diagblocks;
686 using PreconditionBlock<MatrixType, inverse_type>::set_permutation;
687 using PreconditionBlockBase<inverse_type>::log_statistics;
688
699 template <typename number2>
700 void
702
710 template <typename number2>
711 void
713
722 template <typename number2>
723 void
725
733 template <typename number2>
734 void
736
740 template <typename number2>
741 void
742 step(Vector<number2> &dst, const Vector<number2> &rhs) const;
743
747 template <typename number2>
748 void
749 Tstep(Vector<number2> &dst, const Vector<number2> &rhs) const;
750
751protected:
756
766 template <typename number2>
767 void
769 const Vector<number2> &,
770 const bool transpose_diagonal,
771 const bool adding) const;
772
782 template <typename number2>
783 void
785 const Vector<number2> &,
786 const bool transpose_diagonal,
787 const bool adding) const;
788};
789
790
810template <typename MatrixType,
811 typename inverse_type = typename MatrixType::value_type>
813 : public virtual EnableObserverPointer,
814 private PreconditionBlockSOR<MatrixType, inverse_type>
815{
816public:
821
825 using number = typename MatrixType::value_type;
826
831
832 // Keep AdditionalData accessible
834
835 // The following are the
836 // functions of the base classes
837 // which we want to keep
838 // accessible.
842 using PreconditionBlockSOR<MatrixType, inverse_type>::initialize;
843 using PreconditionBlockSOR<MatrixType, inverse_type>::clear;
844 using PreconditionBlockBase<inverse_type>::size;
845 using PreconditionBlockBase<inverse_type>::inverse;
847 using PreconditionBlockBase<inverse_type>::inverse_svd;
848 using PreconditionBlockBase<inverse_type>::log_statistics;
849 using PreconditionBlockSOR<MatrixType, inverse_type>::set_permutation;
850 using PreconditionBlockSOR<MatrixType, inverse_type>::empty;
851 using PreconditionBlockSOR<MatrixType, inverse_type>::el;
852 using PreconditionBlockSOR<MatrixType, inverse_type>::invert_diagblocks;
853
861 template <typename number2>
862 void
864
868 template <typename number2>
869 void
871
875 template <typename number2>
876 void
877 step(Vector<number2> &dst, const Vector<number2> &rhs) const;
878
882 template <typename number2>
883 void
884 Tstep(Vector<number2> &dst, const Vector<number2> &rhs) const;
885};
886
888//---------------------------------------------------------------------------
889
890#ifndef DOXYGEN
891
892template <typename MatrixType, typename inverse_type>
893inline bool
895{
896 if (A == nullptr)
897 return true;
898 return A->empty();
899}
900
901
902template <typename MatrixType, typename inverse_type>
903inline inverse_type
904PreconditionBlock<MatrixType, inverse_type>::el(size_type i, size_type j) const
905{
906 const size_type bs = blocksize;
907 const unsigned int nb = i / bs;
908
909 const FullMatrix<inverse_type> &B = this->inverse(nb);
910
911 const size_type ib = i % bs;
912 const size_type jb = j % bs;
913
914 if (jb + nb * bs != j)
915 {
916 return 0.;
917 }
918
919 return B(ib, jb);
920}
921
922//---------------------------------------------------------------------------
923
924template <typename MatrixType, typename inverse_type>
928 const size_type row)
929 : matrix(matrix)
930 , bs(matrix->block_size())
931 , a_block(row / bs)
932 , b_iterator(&matrix->inverse(0), 0, 0)
933 , b_end(&matrix->inverse(0), 0, 0)
934{
935 // This is the end accessor, which
936 // does not have a valid block.
937 if (a_block == matrix->size())
938 return;
939
940 const size_type r = row % bs;
941
942 b_iterator = matrix->inverse(a_block).begin(r);
943 b_end = matrix->inverse(a_block).end();
944
945 AssertIndexRange(a_block, matrix->size());
946}
947
948
949template <typename MatrixType, typename inverse_type>
952 inverse_type>::const_iterator::Accessor::row() const
953{
954 Assert(a_block < matrix->size(), ExcIteratorPastEnd());
955
956 return bs * a_block + b_iterator->row();
957}
958
959
960template <typename MatrixType, typename inverse_type>
963 inverse_type>::const_iterator::Accessor::column() const
964{
965 Assert(a_block < matrix->size(), ExcIteratorPastEnd());
966
967 return bs * a_block + b_iterator->column();
968}
969
970
971template <typename MatrixType, typename inverse_type>
972inline inverse_type
974 inverse_type>::const_iterator::Accessor::value() const
975{
976 Assert(a_block < matrix->size(), ExcIteratorPastEnd());
977
978 return b_iterator->value();
979}
980
981
982template <typename MatrixType, typename inverse_type>
986 const size_type row)
987 : accessor(matrix, row)
988{}
989
990
991template <typename MatrixType, typename inverse_type>
992inline typename PreconditionBlockJacobi<MatrixType,
993 inverse_type>::const_iterator &
995{
997
1000 {
1001 ++accessor.a_block;
1002
1004 {
1008 }
1009 }
1010 return *this;
1011}
1012
1013
1014template <typename MatrixType, typename inverse_type>
1016 const_iterator::Accessor &
1018 const
1019{
1020 return accessor;
1021}
1022
1023
1024template <typename MatrixType, typename inverse_type>
1026 const_iterator::Accessor *
1028 inverse_type>::const_iterator::operator->() const
1029{
1030 return &accessor;
1031}
1032
1033
1034template <typename MatrixType, typename inverse_type>
1035inline bool
1037 const const_iterator &other) const
1038{
1039 if (accessor.a_block == accessor.matrix->size() &&
1040 accessor.a_block == other.accessor.a_block)
1041 return true;
1042
1043 if (accessor.a_block != other.accessor.a_block)
1044 return false;
1045
1046 return (accessor.row() == other.accessor.row() &&
1047 accessor.column() == other.accessor.column());
1048}
1049
1050
1051template <typename MatrixType, typename inverse_type>
1052inline bool
1054 const const_iterator &other) const
1055{
1056 return !(*this == other);
1057}
1058
1059
1060template <typename MatrixType, typename inverse_type>
1061inline bool
1063 const const_iterator &other) const
1064{
1065 return (accessor.row() < other.accessor.row() ||
1066 (accessor.row() == other.accessor.row() &&
1067 accessor.column() < other.accessor.column()));
1068}
1069
1070
1071template <typename MatrixType, typename inverse_type>
1072inline
1075{
1076 return const_iterator(this, 0);
1077}
1078
1079
1080template <typename MatrixType, typename inverse_type>
1081inline
1084{
1085 return const_iterator(this, this->size() * this->block_size());
1086}
1087
1088
1089template <typename MatrixType, typename inverse_type>
1090inline
1093 const size_type r) const
1094{
1095 AssertIndexRange(r, this->A->m());
1096 return const_iterator(this, r);
1097}
1098
1099
1100
1101template <typename MatrixType, typename inverse_type>
1102inline
1105 const size_type r) const
1106{
1107 AssertIndexRange(r, this->A->m());
1108 return const_iterator(this, r + 1);
1109}
1110
1111#endif // DOXYGEN
1112
1114
1115#endif
typename Table< 2, number >::const_iterator const_iterator
iterator begin(const size_type r)
iterator end(const size_type r)
Householder< number > & inverse_householder(size_type i)
FullMatrix< number > & inverse(size_type i)
LAPACKFullMatrix< number > & inverse_svd(size_type i)
const PreconditionBlockJacobi< MatrixType, inverse_type > * matrix
FullMatrix< inverse_type >::const_iterator b_end
FullMatrix< inverse_type >::const_iterator b_iterator
Accessor(const PreconditionBlockJacobi< MatrixType, inverse_type > *matrix, const size_type row)
bool operator!=(const const_iterator &) const
const_iterator(const PreconditionBlockJacobi< MatrixType, inverse_type > *matrix, const size_type row)
bool operator==(const const_iterator &) const
bool operator<(const const_iterator &) const
const Accessor & operator*() const
const Accessor * operator->() const
void vmult(Vector< number2 > &, const Vector< number2 > &) const
void step(Vector< number2 > &dst, const Vector< number2 > &rhs) const
void vmult_add(Vector< number2 > &, const Vector< number2 > &) const
const_iterator begin(const size_type r) const
const_iterator end() const
void Tvmult(Vector< number2 > &, const Vector< number2 > &) const
void do_vmult(Vector< number2 > &, const Vector< number2 > &, bool adding) const
void Tvmult_add(Vector< number2 > &, const Vector< number2 > &) const
typename MatrixType::value_type number
const_iterator begin() const
const_iterator end(const size_type r) const
void Tstep(Vector< number2 > &dst, const Vector< number2 > &rhs) const
types::global_dof_index size_type
PreconditionBlockSOR(bool store)
void vmult_add(Vector< number2 > &, const Vector< number2 > &) const
void vmult(Vector< number2 > &, const Vector< number2 > &) const
typename MatrixType::value_type number
void step(Vector< number2 > &dst, const Vector< number2 > &rhs) const
void Tstep(Vector< number2 > &dst, const Vector< number2 > &rhs) const
void forward(Vector< number2 > &, const Vector< number2 > &, const bool transpose_diagonal, const bool adding) const
void backward(Vector< number2 > &, const Vector< number2 > &, const bool transpose_diagonal, const bool adding) const
void Tvmult(Vector< number2 > &, const Vector< number2 > &) const
void Tvmult_add(Vector< number2 > &, const Vector< number2 > &) const
void vmult(Vector< number2 > &, const Vector< number2 > &) const
void step(Vector< number2 > &dst, const Vector< number2 > &rhs) const
typename MatrixType::value_type number
void Tstep(Vector< number2 > &dst, const Vector< number2 > &rhs) const
types::global_dof_index size_type
void Tvmult(Vector< number2 > &, const Vector< number2 > &) const
AdditionalData(const size_type block_size, const double relaxation=1., const bool invert_diagonal=true, const bool same_diagonal=false)
PreconditionBlockBase< inverse_type >::Inversion inversion
PreconditionBlock(bool store_diagonals=false)
~PreconditionBlock() override=default
value_type el(size_type i, size_type j) const
void forward_step(Vector< number2 > &dst, const Vector< number2 > &prev, const Vector< number2 > &src, const bool transpose_diagonal) const
bool empty() const
void initialize(const MatrixType &A, const AdditionalData parameters)
ObserverPointer< const MatrixType, PreconditionBlock< MatrixType, inverse_type > > A
void invert_diagblocks()
void invert_permuted_diagblocks()
void backward_step(Vector< number2 > &dst, const Vector< number2 > &prev, const Vector< number2 > &src, const bool transpose_diagonal) const
std::size_t memory_consumption() const
std::vector< size_type > inverse_permutation
void set_permutation(const std::vector< size_type > &permutation, const std::vector< size_type > &inverse_permutation)
std::vector< size_type > permutation
size_type block_size() const
typename MatrixType::value_type number
void initialize(const MatrixType &A, const std::vector< size_type > &permutation, const std::vector< size_type > &inverse_permutation, const AdditionalData parameters)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:498
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499
#define DeclException0(Exception0)
Definition exceptions.h:466
static ::ExceptionBase & ExcInverseMatricesAlreadyExist()
#define Assert(cond, exc)
static ::ExceptionBase & ExcIteratorPastEnd()
#define DeclException2(Exception2, type1, type2, outsequence)
Definition exceptions.h:534
static ::ExceptionBase & ExcWrongBlockSize(int arg1, int arg2)
#define AssertIndexRange(index, range)
std::size_t size
Definition mpi.cc:734
@ matrix
Contents is actually a matrix.
Tpetra::CrsMatrix< Number, LO, GO, NodeType< MemorySpace > > MatrixType
unsigned int global_dof_index
Definition types.h:81