Reference documentation for deal.II version Git cb0bd54b52 2019-09-21 16:31:22 -0400
\(\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 // Forward declarations
28 #ifndef DOXYGEN
29 template <typename VectorType>
30 class VectorMemory;
31 
32 class IdentityMatrix;
33 template <typename number>
34 class FullMatrix;
35 template <typename number>
36 class LAPACKFullMatrix;
37 template <typename number>
38 class SparseMatrix;
39 template <typename number>
40 class BlockSparseMatrix;
41 template <typename number>
42 class SparseMatrixEZ;
43 template <typename number>
45 template <typename number>
46 class TridiagonalMatrix;
47 template <typename number, typename BlockVectorType>
48 class BlockMatrixArray;
49 #endif
50 
65 template <typename VectorType>
66 class DEAL_II_DEPRECATED PointerMatrixBase : public Subscriptor
67 {
68 public:
77  using value_type = typename VectorType::value_type;
78 
84  virtual ~PointerMatrixBase() override = default;
85 
89  virtual void
90  clear() = 0;
91 
95  virtual void
96  vmult(VectorType &dst, const VectorType &src) const = 0;
97 
101  virtual void
102  Tvmult(VectorType &dst, const VectorType &src) const = 0;
103 
107  virtual void
108  vmult_add(VectorType &dst, const VectorType &src) const = 0;
109 
113  virtual void
114  Tvmult_add(VectorType &dst, const VectorType &src) const = 0;
115 };
116 
117 
130 template <typename MatrixType, typename VectorType>
131 class DEAL_II_DEPRECATED PointerMatrix : public PointerMatrixBase<VectorType>
132 {
133 public:
141  PointerMatrix(const MatrixType *M = nullptr);
142 
153  PointerMatrix(const char *name);
154 
166  PointerMatrix(const MatrixType *M, const char *name);
167 
168  // Use doc from base class
169  virtual void
170  clear() override;
171 
175  bool
176  empty() const;
177 
183  const PointerMatrix &
184  operator=(const MatrixType *M);
185 
189  virtual void
190  vmult(VectorType &dst, const VectorType &src) const override;
191 
195  virtual void
196  Tvmult(VectorType &dst, const VectorType &src) const override;
197 
201  virtual void
202  vmult_add(VectorType &dst, const VectorType &src) const override;
203 
207  virtual void
208  Tvmult_add(VectorType &dst, const VectorType &src) const override;
209 
210 private:
215 };
216 
217 
234 template <typename MatrixType, typename VectorType>
235 class DEAL_II_DEPRECATED PointerMatrixAux : public PointerMatrixBase<VectorType>
236 {
237 public:
247  PointerMatrixAux(VectorMemory<VectorType> *mem = 0, const MatrixType *M = 0);
248 
259  PointerMatrixAux(VectorMemory<VectorType> *mem, const char *name);
260 
273  const MatrixType * M,
274  const char * name);
275 
276  // Use doc from base class
277  virtual void
278  clear() override;
279 
283  bool
284  empty() const;
285 
289  void
290  set_memory(VectorMemory<VectorType> *mem);
291 
297  const PointerMatrixAux &
298  operator=(const MatrixType *M);
299 
303  virtual void
304  vmult(VectorType &dst, const VectorType &src) const override;
305 
309  virtual void
310  Tvmult(VectorType &dst, const VectorType &src) const override;
311 
315  virtual void
316  vmult_add(VectorType &dst, const VectorType &src) const override;
317 
321  virtual void
322  Tvmult_add(VectorType &dst, const VectorType &src) const override;
323 
324 private:
329 
336 
341 };
342 
343 
344 
357 template <typename number>
358 class DEAL_II_DEPRECATED PointerMatrixVector
359  : public PointerMatrixBase<Vector<number>>
360 {
361 public:
369  PointerMatrixVector(const Vector<number> *M = 0);
370 
381  PointerMatrixVector(const char *name);
382 
394  PointerMatrixVector(const Vector<number> *M, const char *name);
395 
396  // Use doc from base class
397  virtual void
398  clear();
399 
403  bool
404  empty() const;
405 
411  const PointerMatrixVector &
412  operator=(const Vector<number> *M);
413 
421  virtual void
422  vmult(Vector<number> &dst, const Vector<number> &src) const;
423 
431  virtual void
432  Tvmult(Vector<number> &dst, const Vector<number> &src) const;
433 
440  virtual void
441  vmult_add(Vector<number> &dst, const Vector<number> &src) const;
442 
449  virtual void
450  Tvmult_add(Vector<number> &dst, const Vector<number> &src) const;
451 
452 private:
457 };
458 
459 
460 
478 template <typename VectorType, typename MatrixType>
480 new_pointer_matrix_base(MatrixType &matrix,
481  const VectorType &,
482  const char *name = "PointerMatrixAux")
483 {
484  return new PointerMatrixAux<MatrixType, VectorType>(nullptr, &matrix, name);
485 }
486 
492 template <typename numberv>
495  const Vector<numberv> &,
496  const char *name = "PointerMatrix")
497 {
498  return new PointerMatrix<IdentityMatrix, Vector<numberv>>(&matrix, name);
499 }
500 
501 
507 template <typename numberv, typename numberm>
510  const Vector<numberv> &,
511  const char *name = "PointerMatrix")
512 {
513  return new PointerMatrix<FullMatrix<numberm>, Vector<numberv>>(&matrix, name);
514 }
515 
516 
522 template <typename numberv, typename numberm>
525  const Vector<numberv> &,
526  const char *name = "PointerMatrix")
527 {
528  return new PointerMatrix<LAPACKFullMatrix<numberm>, Vector<numberv>>(&matrix,
529  name);
530 }
531 
532 
538 template <typename numberv, typename numberm>
541  const Vector<numberv> &,
542  const char *name = "PointerMatrix")
543 {
544  return new PointerMatrix<SparseMatrix<numberm>, Vector<numberv>>(&matrix,
545  name);
546 }
547 
548 
554 template <typename VectorType, typename numberm>
557  const VectorType &,
558  const char *name = "PointerMatrix")
559 {
560  return new PointerMatrix<BlockSparseMatrix<numberm>, VectorType>(&matrix,
561  name);
562 }
563 
564 
570 template <typename numberv, typename numberm>
573  const Vector<numberv> &,
574  const char *name = "PointerMatrix")
575 {
576  return new PointerMatrix<SparseMatrixEZ<numberm>, Vector<numberv>>(&matrix,
577  name);
578 }
579 
580 
586 template <typename VectorType, typename numberm>
589  const VectorType &,
590  const char *name = "PointerMatrix")
591 {
592  return new PointerMatrix<BlockSparseMatrixEZ<numberm>, VectorType>(&matrix,
593  name);
594 }
595 
596 
602 template <typename numberv, typename numberm, typename BLOCK_VectorType>
606  const BLOCK_VectorType &,
607  const char *name = "PointerMatrix")
608 {
610  BlockVector<numberv>>(&matrix, name);
611 }
612 
613 
619 template <typename numberv, typename numberm>
622  const Vector<numberv> &,
623  const char *name = "PointerMatrix")
624 {
625  return new PointerMatrix<TridiagonalMatrix<numberm>, Vector<numberv>>(&matrix,
626  name);
627 }
628 
629 
630 
632 //---------------------------------------------------------------------------
633 
634 
635 template <typename MatrixType, typename VectorType>
637  : m(M, typeid(*this).name())
638 {}
639 
640 
641 template <typename MatrixType, typename VectorType>
643  : m(nullptr, name)
644 {}
645 
646 
647 template <typename MatrixType, typename VectorType>
649  const char * name)
650  : m(M, name)
651 {}
652 
653 
654 template <typename MatrixType, typename VectorType>
655 inline void
657 {
658  m = nullptr;
659 }
660 
661 
662 template <typename MatrixType, typename VectorType>
665 {
666  m = M;
667  return *this;
668 }
669 
670 
671 template <typename MatrixType, typename VectorType>
672 inline bool
674 {
675  if (m == nullptr)
676  return true;
677  return m->empty();
678 }
679 
680 template <typename MatrixType, typename VectorType>
681 inline void
683  const VectorType &src) const
684 {
685  Assert(m != nullptr, ExcNotInitialized());
686  m->vmult(dst, src);
687 }
688 
689 
690 template <typename MatrixType, typename VectorType>
691 inline void
693  const VectorType &src) const
694 {
695  Assert(m != nullptr, ExcNotInitialized());
696  m->Tvmult(dst, src);
697 }
698 
699 
700 template <typename MatrixType, typename VectorType>
701 inline void
703  const VectorType &src) const
704 {
705  Assert(m != nullptr, ExcNotInitialized());
706  m->vmult_add(dst, src);
707 }
708 
709 
710 template <typename MatrixType, typename VectorType>
711 inline void
713  const VectorType &src) const
714 {
715  Assert(m != nullptr, ExcNotInitialized());
716  m->Tvmult_add(dst, src);
717 }
718 
719 
720 
721 //----------------------------------------------------------------------//
722 
723 
724 template <typename MatrixType, typename VectorType>
727  const MatrixType * M)
728  : mem(mem, typeid(*this).name())
729  , m(M, typeid(*this).name())
730 {
731  if (mem == 0)
732  mem = &my_memory;
733 }
734 
735 
736 template <typename MatrixType, typename VectorType>
739  const char * name)
740  : mem(mem, name)
741  , m(0, name)
742 {
743  if (mem == 0)
744  mem = &my_memory;
745 }
746 
747 
748 template <typename MatrixType, typename VectorType>
751  const MatrixType * M,
752  const char * name)
753  : mem(mem, name)
754  , m(M, name)
755 {
756  if (mem == nullptr)
757  mem = &my_memory;
758 }
759 
760 
761 template <typename MatrixType, typename VectorType>
762 inline void
764 {
765  m = nullptr;
766 }
767 
768 
769 template <typename MatrixType, typename VectorType>
772 {
773  m = M;
774  return *this;
775 }
776 
777 
778 template <typename MatrixType, typename VectorType>
779 inline void
782 {
783  mem = M;
784  if (mem == 0)
785  mem = &my_memory;
786 }
787 
788 
789 template <typename MatrixType, typename VectorType>
790 inline bool
792 {
793  if (m == 0)
794  return true;
795  return m->empty();
796 }
797 
798 template <typename MatrixType, typename VectorType>
799 inline void
801  const VectorType &src) const
802 {
803  if (mem == nullptr)
804  mem = &my_memory;
805  Assert(mem != nullptr, ExcNotInitialized());
806  Assert(m != nullptr, ExcNotInitialized());
807  m->vmult(dst, src);
808 }
809 
810 
811 template <typename MatrixType, typename VectorType>
812 inline void
814  const VectorType &src) const
815 {
816  if (mem == nullptr)
817  mem = &my_memory;
818  Assert(mem != nullptr, ExcNotInitialized());
819  Assert(m != nullptr, ExcNotInitialized());
820  m->Tvmult(dst, src);
821 }
822 
823 
824 template <typename MatrixType, typename VectorType>
825 inline void
827  const VectorType &src) const
828 {
829  if (mem == nullptr)
830  mem = &my_memory;
831  Assert(mem != nullptr, ExcNotInitialized());
832  Assert(m != nullptr, ExcNotInitialized());
833  VectorType *v = mem->alloc();
834  v->reinit(dst);
835  m->vmult(*v, src);
836  dst += *v;
837  mem->free(v);
838 }
839 
840 
841 template <typename MatrixType, typename VectorType>
842 inline void
844  VectorType & dst,
845  const VectorType &src) const
846 {
847  if (mem == nullptr)
848  mem = &my_memory;
849  Assert(mem != nullptr, ExcNotInitialized());
850  Assert(m != nullptr, ExcNotInitialized());
851  VectorType *v = mem->alloc();
852  v->reinit(dst);
853  m->Tvmult(*v, src);
854  dst += *v;
855  mem->free(v);
856 }
857 
858 
859 //----------------------------------------------------------------------//
860 
861 
862 template <typename number>
864  : m(M, typeid(*this).name())
865 {}
866 
867 
868 template <typename number>
870  : m(0, name)
871 {}
872 
873 
874 template <typename number>
876  const char * name)
877  : m(M, name)
878 {}
879 
880 
881 template <typename number>
882 inline void
884 {
885  m = nullptr;
886 }
887 
888 
889 template <typename number>
890 inline const PointerMatrixVector<number> &
892 {
893  m = M;
894  return *this;
895 }
896 
897 
898 template <typename number>
899 inline bool
901 {
902  if (m == 0)
903  return true;
904  return m->empty();
905 }
906 
907 template <typename number>
908 inline void
910  const Vector<number> &src) const
911 {
912  Assert(m != nullptr, ExcNotInitialized());
913  Assert(dst.size() == 1, ExcDimensionMismatch(dst.size(), 1));
914 
915  dst(0) = *m * src;
916 }
917 
918 
919 template <typename number>
920 inline void
922  const Vector<number> &src) const
923 {
924  Assert(m != nullptr, ExcNotInitialized());
925  Assert(src.size() == 1, ExcDimensionMismatch(src.size(), 1));
926 
927  dst.equ(src(0), *m);
928 }
929 
930 
931 template <typename number>
932 inline void
934  const Vector<number> &src) const
935 {
936  Assert(m != nullptr, ExcNotInitialized());
937  Assert(dst.size() == 1, ExcDimensionMismatch(dst.size(), 1));
938 
939  dst(0) += *m * src;
940 }
941 
942 
943 template <typename number>
944 inline void
946  const Vector<number> &src) const
947 {
948  Assert(m != nullptr, ExcNotInitialized());
949  Assert(src.size() == 1, ExcDimensionMismatch(src.size(), 1));
950 
951  dst.add(src(0), *m);
952 }
953 
954 
955 DEAL_II_NAMESPACE_CLOSE
956 
957 #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