Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
pointer_matrix.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2002 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_pointer_matrix_h
17 #define dealii_pointer_matrix_h
18 
19 #include <deal.II/base/smartpointer.h>
20 #include <deal.II/base/subscriptor.h>
21 
22 #include <deal.II/lac/vector.h>
23 #include <deal.II/lac/vector_memory.h>
24 
25 DEAL_II_NAMESPACE_OPEN
26 
27 template <typename VectorType>
29 
30 class IdentityMatrix;
31 template <typename number>
32 class FullMatrix;
33 template <typename number>
34 class LAPACKFullMatrix;
35 template <typename number>
36 class SparseMatrix;
37 template <typename number>
38 class BlockSparseMatrix;
39 template <typename number>
41 template <typename number>
43 template <typename number>
45 template <typename number, typename BlockVectorType>
46 class BlockMatrixArray;
47 
62 template <typename VectorType>
63 class DEAL_II_DEPRECATED PointerMatrixBase : public Subscriptor
64 {
65 public:
74  using value_type = typename VectorType::value_type;
75 
81  virtual ~PointerMatrixBase() override = default;
82 
86  virtual void
87  clear() = 0;
88 
92  virtual void
93  vmult(VectorType &dst, const VectorType &src) const = 0;
94 
98  virtual void
99  Tvmult(VectorType &dst, const VectorType &src) const = 0;
100 
104  virtual void
105  vmult_add(VectorType &dst, const VectorType &src) const = 0;
106 
110  virtual void
111  Tvmult_add(VectorType &dst, const VectorType &src) const = 0;
112 };
113 
114 
127 template <typename MatrixType, typename VectorType>
128 class DEAL_II_DEPRECATED PointerMatrix : public PointerMatrixBase<VectorType>
129 {
130 public:
138  PointerMatrix(const MatrixType *M = nullptr);
139 
150  PointerMatrix(const char *name);
151 
163  PointerMatrix(const MatrixType *M, const char *name);
164 
165  // Use doc from base class
166  virtual void
167  clear() override;
168 
172  bool
173  empty() const;
174 
180  const PointerMatrix &
181  operator=(const MatrixType *M);
182 
186  virtual void
187  vmult(VectorType &dst, const VectorType &src) const override;
188 
192  virtual void
193  Tvmult(VectorType &dst, const VectorType &src) const override;
194 
198  virtual void
199  vmult_add(VectorType &dst, const VectorType &src) const override;
200 
204  virtual void
205  Tvmult_add(VectorType &dst, const VectorType &src) const override;
206 
207 private:
212 };
213 
214 
231 template <typename MatrixType, typename VectorType>
232 class DEAL_II_DEPRECATED PointerMatrixAux : public PointerMatrixBase<VectorType>
233 {
234 public:
244  PointerMatrixAux(VectorMemory<VectorType> *mem = 0, const MatrixType *M = 0);
245 
256  PointerMatrixAux(VectorMemory<VectorType> *mem, const char *name);
257 
270  const MatrixType * M,
271  const char * name);
272 
273  // Use doc from base class
274  virtual void
275  clear() override;
276 
280  bool
281  empty() const;
282 
286  void
287  set_memory(VectorMemory<VectorType> *mem);
288 
294  const PointerMatrixAux &
295  operator=(const MatrixType *M);
296 
300  virtual void
301  vmult(VectorType &dst, const VectorType &src) const override;
302 
306  virtual void
307  Tvmult(VectorType &dst, const VectorType &src) const override;
308 
312  virtual void
313  vmult_add(VectorType &dst, const VectorType &src) const override;
314 
318  virtual void
319  Tvmult_add(VectorType &dst, const VectorType &src) const override;
320 
321 private:
326 
333 
338 };
339 
340 
341 
354 template <typename number>
355 class DEAL_II_DEPRECATED PointerMatrixVector
356  : public PointerMatrixBase<Vector<number>>
357 {
358 public:
366  PointerMatrixVector(const Vector<number> *M = 0);
367 
378  PointerMatrixVector(const char *name);
379 
391  PointerMatrixVector(const Vector<number> *M, const char *name);
392 
393  // Use doc from base class
394  virtual void
395  clear();
396 
400  bool
401  empty() const;
402 
408  const PointerMatrixVector &
409  operator=(const Vector<number> *M);
410 
418  virtual void
419  vmult(Vector<number> &dst, const Vector<number> &src) const;
420 
428  virtual void
429  Tvmult(Vector<number> &dst, const Vector<number> &src) const;
430 
437  virtual void
438  vmult_add(Vector<number> &dst, const Vector<number> &src) const;
439 
446  virtual void
447  Tvmult_add(Vector<number> &dst, const Vector<number> &src) const;
448 
449 private:
454 };
455 
456 
457 
475 template <typename VectorType, typename MatrixType>
477 new_pointer_matrix_base(MatrixType &matrix,
478  const VectorType &,
479  const char *name = "PointerMatrixAux")
480 {
481  return new PointerMatrixAux<MatrixType, VectorType>(nullptr, &matrix, name);
482 }
483 
489 template <typename numberv>
492  const Vector<numberv> &,
493  const char *name = "PointerMatrix")
494 {
495  return new PointerMatrix<IdentityMatrix, Vector<numberv>>(&matrix, name);
496 }
497 
498 
504 template <typename numberv, typename numberm>
507  const Vector<numberv> &,
508  const char *name = "PointerMatrix")
509 {
510  return new PointerMatrix<FullMatrix<numberm>, Vector<numberv>>(&matrix, name);
511 }
512 
513 
519 template <typename numberv, typename numberm>
522  const Vector<numberv> &,
523  const char *name = "PointerMatrix")
524 {
525  return new PointerMatrix<LAPACKFullMatrix<numberm>, Vector<numberv>>(&matrix,
526  name);
527 }
528 
529 
535 template <typename numberv, typename numberm>
538  const Vector<numberv> &,
539  const char *name = "PointerMatrix")
540 {
541  return new PointerMatrix<SparseMatrix<numberm>, Vector<numberv>>(&matrix,
542  name);
543 }
544 
545 
551 template <typename VectorType, typename numberm>
554  const VectorType &,
555  const char *name = "PointerMatrix")
556 {
557  return new PointerMatrix<BlockSparseMatrix<numberm>, VectorType>(&matrix,
558  name);
559 }
560 
561 
567 template <typename numberv, typename numberm>
570  const Vector<numberv> &,
571  const char *name = "PointerMatrix")
572 {
573  return new PointerMatrix<SparseMatrixEZ<numberm>, Vector<numberv>>(&matrix,
574  name);
575 }
576 
577 
583 template <typename VectorType, typename numberm>
586  const VectorType &,
587  const char *name = "PointerMatrix")
588 {
589  return new PointerMatrix<BlockSparseMatrixEZ<numberm>, VectorType>(&matrix,
590  name);
591 }
592 
593 
599 template <typename numberv, typename numberm, typename BLOCK_VectorType>
603  const BLOCK_VectorType &,
604  const char *name = "PointerMatrix")
605 {
607  BlockVector<numberv>>(&matrix, name);
608 }
609 
610 
616 template <typename numberv, typename numberm>
619  const Vector<numberv> &,
620  const char *name = "PointerMatrix")
621 {
622  return new PointerMatrix<TridiagonalMatrix<numberm>, Vector<numberv>>(&matrix,
623  name);
624 }
625 
626 
627 
629 //---------------------------------------------------------------------------
630 
631 
632 template <typename MatrixType, typename VectorType>
634  : m(M, typeid(*this).name())
635 {}
636 
637 
638 template <typename MatrixType, typename VectorType>
640  : m(nullptr, name)
641 {}
642 
643 
644 template <typename MatrixType, typename VectorType>
646  const char * name)
647  : m(M, name)
648 {}
649 
650 
651 template <typename MatrixType, typename VectorType>
652 inline void
654 {
655  m = nullptr;
656 }
657 
658 
659 template <typename MatrixType, typename VectorType>
662 {
663  m = M;
664  return *this;
665 }
666 
667 
668 template <typename MatrixType, typename VectorType>
669 inline bool
671 {
672  if (m == nullptr)
673  return true;
674  return m->empty();
675 }
676 
677 template <typename MatrixType, typename VectorType>
678 inline void
680  const VectorType &src) const
681 {
682  Assert(m != nullptr, ExcNotInitialized());
683  m->vmult(dst, src);
684 }
685 
686 
687 template <typename MatrixType, typename VectorType>
688 inline void
690  const VectorType &src) const
691 {
692  Assert(m != nullptr, ExcNotInitialized());
693  m->Tvmult(dst, src);
694 }
695 
696 
697 template <typename MatrixType, typename VectorType>
698 inline void
700  const VectorType &src) const
701 {
702  Assert(m != nullptr, ExcNotInitialized());
703  m->vmult_add(dst, src);
704 }
705 
706 
707 template <typename MatrixType, typename VectorType>
708 inline void
710  const VectorType &src) const
711 {
712  Assert(m != nullptr, ExcNotInitialized());
713  m->Tvmult_add(dst, src);
714 }
715 
716 
717 
718 //----------------------------------------------------------------------//
719 
720 
721 template <typename MatrixType, typename VectorType>
724  const MatrixType * M)
725  : mem(mem, typeid(*this).name())
726  , m(M, typeid(*this).name())
727 {
728  if (mem == 0)
729  mem = &my_memory;
730 }
731 
732 
733 template <typename MatrixType, typename VectorType>
736  const char * name)
737  : mem(mem, name)
738  , m(0, name)
739 {
740  if (mem == 0)
741  mem = &my_memory;
742 }
743 
744 
745 template <typename MatrixType, typename VectorType>
748  const MatrixType * M,
749  const char * name)
750  : mem(mem, name)
751  , m(M, name)
752 {
753  if (mem == nullptr)
754  mem = &my_memory;
755 }
756 
757 
758 template <typename MatrixType, typename VectorType>
759 inline void
761 {
762  m = nullptr;
763 }
764 
765 
766 template <typename MatrixType, typename VectorType>
769 {
770  m = M;
771  return *this;
772 }
773 
774 
775 template <typename MatrixType, typename VectorType>
776 inline void
779 {
780  mem = M;
781  if (mem == 0)
782  mem = &my_memory;
783 }
784 
785 
786 template <typename MatrixType, typename VectorType>
787 inline bool
789 {
790  if (m == 0)
791  return true;
792  return m->empty();
793 }
794 
795 template <typename MatrixType, typename VectorType>
796 inline void
798  const VectorType &src) const
799 {
800  if (mem == nullptr)
801  mem = &my_memory;
802  Assert(mem != nullptr, ExcNotInitialized());
803  Assert(m != nullptr, ExcNotInitialized());
804  m->vmult(dst, src);
805 }
806 
807 
808 template <typename MatrixType, typename VectorType>
809 inline void
811  const VectorType &src) const
812 {
813  if (mem == nullptr)
814  mem = &my_memory;
815  Assert(mem != nullptr, ExcNotInitialized());
816  Assert(m != nullptr, ExcNotInitialized());
817  m->Tvmult(dst, src);
818 }
819 
820 
821 template <typename MatrixType, typename VectorType>
822 inline void
824  const VectorType &src) const
825 {
826  if (mem == nullptr)
827  mem = &my_memory;
828  Assert(mem != nullptr, ExcNotInitialized());
829  Assert(m != nullptr, ExcNotInitialized());
830  VectorType *v = mem->alloc();
831  v->reinit(dst);
832  m->vmult(*v, src);
833  dst += *v;
834  mem->free(v);
835 }
836 
837 
838 template <typename MatrixType, typename VectorType>
839 inline void
841  VectorType & dst,
842  const VectorType &src) const
843 {
844  if (mem == nullptr)
845  mem = &my_memory;
846  Assert(mem != nullptr, ExcNotInitialized());
847  Assert(m != nullptr, ExcNotInitialized());
848  VectorType *v = mem->alloc();
849  v->reinit(dst);
850  m->Tvmult(*v, src);
851  dst += *v;
852  mem->free(v);
853 }
854 
855 
856 //----------------------------------------------------------------------//
857 
858 
859 template <typename number>
861  : m(M, typeid(*this).name())
862 {}
863 
864 
865 template <typename number>
867  : m(0, name)
868 {}
869 
870 
871 template <typename number>
873  const char * name)
874  : m(M, name)
875 {}
876 
877 
878 template <typename number>
879 inline void
881 {
882  m = nullptr;
883 }
884 
885 
886 template <typename number>
887 inline const PointerMatrixVector<number> &
889 {
890  m = M;
891  return *this;
892 }
893 
894 
895 template <typename number>
896 inline bool
898 {
899  if (m == 0)
900  return true;
901  return m->empty();
902 }
903 
904 template <typename number>
905 inline void
907  const Vector<number> &src) const
908 {
909  Assert(m != nullptr, ExcNotInitialized());
910  Assert(dst.size() == 1, ExcDimensionMismatch(dst.size(), 1));
911 
912  dst(0) = *m * src;
913 }
914 
915 
916 template <typename number>
917 inline void
919  const Vector<number> &src) const
920 {
921  Assert(m != nullptr, ExcNotInitialized());
922  Assert(src.size() == 1, ExcDimensionMismatch(src.size(), 1));
923 
924  dst.equ(src(0), *m);
925 }
926 
927 
928 template <typename number>
929 inline void
931  const Vector<number> &src) const
932 {
933  Assert(m != nullptr, ExcNotInitialized());
934  Assert(dst.size() == 1, ExcDimensionMismatch(dst.size(), 1));
935 
936  dst(0) += *m * src;
937 }
938 
939 
940 template <typename number>
941 inline void
943  const Vector<number> &src) const
944 {
945  Assert(m != nullptr, ExcNotInitialized());
946  Assert(src.size() == 1, ExcDimensionMismatch(src.size(), 1));
947 
948  dst.add(src(0), *m);
949 }
950 
951 
952 DEAL_II_NAMESPACE_CLOSE
953 
954 #endif
virtual void clear() override
bool empty() const
SmartPointer< const MatrixType, PointerMatrixAux< MatrixType, VectorType > > m
virtual void Tvmult_add(VectorType &dst, const VectorType &src) const override
typename Vector< number > ::value_type value_type
Subscriptor & operator=(const Subscriptor &)
Definition: subscriptor.h:283
void equ(const Number a, const Vector< Number > &u)
virtual void vmult(Vector< number > &dst, const Vector< number > &src) const
PointerMatrix(const MatrixType *M=nullptr)
virtual void Tvmult_add(VectorType &dst, const VectorType &src) const override
static ::ExceptionBase & ExcNotInitialized()
SmartPointer< const Vector< number >, PointerMatrixVector< number > > m
virtual void Tvmult(VectorType &dst, const VectorType &src) const override
PointerMatrixVector(const Vector< number > *M=0)
const PointerMatrixAux & operator=(const MatrixType *M)
virtual void vmult_add(VectorType &dst, const VectorType &src) const =0
PointerMatrixBase< VectorType > * new_pointer_matrix_base(MatrixType &matrix, const VectorType &, const char *name="PointerMatrixAux")
void add(const std::vector< size_type > &indices, const std::vector< OtherNumber > &values)
virtual void vmult_add(Vector< number > &dst, const Vector< number > &src) const
virtual void vmult(VectorType &dst, const VectorType &src) const override
SmartPointer< VectorMemory< VectorType >, PointerMatrixAux< MatrixType, VectorType > > mem
virtual void Tvmult(Vector< number > &dst, const Vector< number > &src) const
#define Assert(cond, exc)
Definition: exceptions.h:1407
virtual void vmult(VectorType &dst, const VectorType &src) const =0
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
virtual void clear() override
const PointerMatrix & operator=(const MatrixType *M)
virtual void Tvmult_add(Vector< number > &dst, const Vector< number > &src) const
bool empty() const
GrowingVectorMemory< VectorType > my_memory
virtual void Tvmult_add(VectorType &dst, const VectorType &src) const =0
virtual void clear()=0
virtual void clear()
PointerMatrixAux(VectorMemory< VectorType > *mem=0, const MatrixType *M=0)
virtual void Tvmult(VectorType &dst, const VectorType &src) const override
const PointerMatrixVector & operator=(const Vector< number > *M)
size_type size() const
void set_memory(VectorMemory< VectorType > *mem)
virtual void Tvmult(VectorType &dst, const VectorType &src) const =0
virtual void vmult_add(VectorType &dst, const VectorType &src) const override
virtual void vmult_add(VectorType &dst, const VectorType &src) const override
virtual void vmult(VectorType &dst, const VectorType &src) const override
SmartPointer< const MatrixType, PointerMatrix< MatrixType, VectorType > > m