Reference documentation for deal.II version Git 399dbefe9a 2020-01-19 15:10:10 -0500
\(\newcommand{\vcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\vcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
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/config.h>
20 
21 #include <deal.II/base/smartpointer.h>
22 #include <deal.II/base/subscriptor.h>
23 
24 #include <deal.II/lac/vector.h>
25 #include <deal.II/lac/vector_memory.h>
26 
27 DEAL_II_NAMESPACE_OPEN
28 
29 // Forward declarations
30 #ifndef DOXYGEN
31 template <typename VectorType>
32 class VectorMemory;
33 
34 class IdentityMatrix;
35 template <typename number>
36 class FullMatrix;
37 template <typename number>
38 class LAPACKFullMatrix;
39 template <typename number>
40 class SparseMatrix;
41 template <typename number>
42 class BlockSparseMatrix;
43 template <typename number>
44 class SparseMatrixEZ;
45 template <typename number>
47 template <typename number>
48 class TridiagonalMatrix;
49 template <typename number, typename BlockVectorType>
50 class BlockMatrixArray;
51 #endif
52 
67 template <typename VectorType>
68 class DEAL_II_DEPRECATED PointerMatrixBase : public Subscriptor
69 {
70 public:
79  using value_type = typename VectorType::value_type;
80 
86  virtual ~PointerMatrixBase() override = default;
87 
91  virtual void
92  clear() = 0;
93 
97  virtual void
98  vmult(VectorType &dst, const VectorType &src) const = 0;
99 
103  virtual void
104  Tvmult(VectorType &dst, const VectorType &src) const = 0;
105 
109  virtual void
110  vmult_add(VectorType &dst, const VectorType &src) const = 0;
111 
115  virtual void
116  Tvmult_add(VectorType &dst, const VectorType &src) const = 0;
117 };
118 
119 
132 template <typename MatrixType, typename VectorType>
133 class DEAL_II_DEPRECATED PointerMatrix : public PointerMatrixBase<VectorType>
134 {
135 public:
143  PointerMatrix(const MatrixType *M = nullptr);
144 
155  PointerMatrix(const char *name);
156 
168  PointerMatrix(const MatrixType *M, const char *name);
169 
170  // Use doc from base class
171  virtual void
172  clear() override;
173 
177  bool
178  empty() const;
179 
185  const PointerMatrix &
186  operator=(const MatrixType *M);
187 
191  virtual void
192  vmult(VectorType &dst, const VectorType &src) const override;
193 
197  virtual void
198  Tvmult(VectorType &dst, const VectorType &src) const override;
199 
203  virtual void
204  vmult_add(VectorType &dst, const VectorType &src) const override;
205 
209  virtual void
210  Tvmult_add(VectorType &dst, const VectorType &src) const override;
211 
212 private:
217 };
218 
219 
236 template <typename MatrixType, typename VectorType>
237 class DEAL_II_DEPRECATED PointerMatrixAux : public PointerMatrixBase<VectorType>
238 {
239 public:
249  PointerMatrixAux(VectorMemory<VectorType> *mem = 0, const MatrixType *M = 0);
250 
261  PointerMatrixAux(VectorMemory<VectorType> *mem, const char *name);
262 
275  const MatrixType * M,
276  const char * name);
277 
278  // Use doc from base class
279  virtual void
280  clear() override;
281 
285  bool
286  empty() const;
287 
291  void
292  set_memory(VectorMemory<VectorType> *mem);
293 
299  const PointerMatrixAux &
300  operator=(const MatrixType *M);
301 
305  virtual void
306  vmult(VectorType &dst, const VectorType &src) const override;
307 
311  virtual void
312  Tvmult(VectorType &dst, const VectorType &src) const override;
313 
317  virtual void
318  vmult_add(VectorType &dst, const VectorType &src) const override;
319 
323  virtual void
324  Tvmult_add(VectorType &dst, const VectorType &src) const override;
325 
326 private:
331 
338 
343 };
344 
345 
346 
359 template <typename number>
360 class DEAL_II_DEPRECATED PointerMatrixVector
361  : public PointerMatrixBase<Vector<number>>
362 {
363 public:
371  PointerMatrixVector(const Vector<number> *M = 0);
372 
383  PointerMatrixVector(const char *name);
384 
396  PointerMatrixVector(const Vector<number> *M, const char *name);
397 
398  // Use doc from base class
399  virtual void
400  clear();
401 
405  bool
406  empty() const;
407 
413  const PointerMatrixVector &
414  operator=(const Vector<number> *M);
415 
423  virtual void
424  vmult(Vector<number> &dst, const Vector<number> &src) const;
425 
433  virtual void
434  Tvmult(Vector<number> &dst, const Vector<number> &src) const;
435 
442  virtual void
443  vmult_add(Vector<number> &dst, const Vector<number> &src) const;
444 
451  virtual void
452  Tvmult_add(Vector<number> &dst, const Vector<number> &src) const;
453 
454 private:
459 };
460 
461 
462 
480 template <typename VectorType, typename MatrixType>
482 new_pointer_matrix_base(MatrixType &matrix,
483  const VectorType &,
484  const char *name = "PointerMatrixAux")
485 {
486  return new PointerMatrixAux<MatrixType, VectorType>(nullptr, &matrix, name);
487 }
488 
494 template <typename numberv>
497  const Vector<numberv> &,
498  const char *name = "PointerMatrix")
499 {
500  return new PointerMatrix<IdentityMatrix, Vector<numberv>>(&matrix, name);
501 }
502 
503 
509 template <typename numberv, typename numberm>
512  const Vector<numberv> &,
513  const char *name = "PointerMatrix")
514 {
515  return new PointerMatrix<FullMatrix<numberm>, Vector<numberv>>(&matrix, name);
516 }
517 
518 
524 template <typename numberv, typename numberm>
527  const Vector<numberv> &,
528  const char *name = "PointerMatrix")
529 {
530  return new PointerMatrix<LAPACKFullMatrix<numberm>, Vector<numberv>>(&matrix,
531  name);
532 }
533 
534 
540 template <typename numberv, typename numberm>
543  const Vector<numberv> &,
544  const char *name = "PointerMatrix")
545 {
546  return new PointerMatrix<SparseMatrix<numberm>, Vector<numberv>>(&matrix,
547  name);
548 }
549 
550 
556 template <typename VectorType, typename numberm>
559  const VectorType &,
560  const char *name = "PointerMatrix")
561 {
562  return new PointerMatrix<BlockSparseMatrix<numberm>, VectorType>(&matrix,
563  name);
564 }
565 
566 
572 template <typename numberv, typename numberm>
575  const Vector<numberv> &,
576  const char *name = "PointerMatrix")
577 {
578  return new PointerMatrix<SparseMatrixEZ<numberm>, Vector<numberv>>(&matrix,
579  name);
580 }
581 
582 
588 template <typename VectorType, typename numberm>
591  const VectorType &,
592  const char *name = "PointerMatrix")
593 {
594  return new PointerMatrix<BlockSparseMatrixEZ<numberm>, VectorType>(&matrix,
595  name);
596 }
597 
598 
604 template <typename numberv, typename numberm, typename BLOCK_VectorType>
608  const BLOCK_VectorType &,
609  const char *name = "PointerMatrix")
610 {
612  BlockVector<numberv>>(&matrix, name);
613 }
614 
615 
621 template <typename numberv, typename numberm>
624  const Vector<numberv> &,
625  const char *name = "PointerMatrix")
626 {
627  return new PointerMatrix<TridiagonalMatrix<numberm>, Vector<numberv>>(&matrix,
628  name);
629 }
630 
631 
632 
634 //---------------------------------------------------------------------------
635 
636 
637 template <typename MatrixType, typename VectorType>
639  : m(M, typeid(*this).name())
640 {}
641 
642 
643 template <typename MatrixType, typename VectorType>
645  : m(nullptr, name)
646 {}
647 
648 
649 template <typename MatrixType, typename VectorType>
651  const char * name)
652  : m(M, name)
653 {}
654 
655 
656 template <typename MatrixType, typename VectorType>
657 inline void
659 {
660  m = nullptr;
661 }
662 
663 
664 template <typename MatrixType, typename VectorType>
667 {
668  m = M;
669  return *this;
670 }
671 
672 
673 template <typename MatrixType, typename VectorType>
674 inline bool
676 {
677  if (m == nullptr)
678  return true;
679  return m->empty();
680 }
681 
682 template <typename MatrixType, typename VectorType>
683 inline void
685  const VectorType &src) const
686 {
687  Assert(m != nullptr, ExcNotInitialized());
688  m->vmult(dst, src);
689 }
690 
691 
692 template <typename MatrixType, typename VectorType>
693 inline void
695  const VectorType &src) const
696 {
697  Assert(m != nullptr, ExcNotInitialized());
698  m->Tvmult(dst, src);
699 }
700 
701 
702 template <typename MatrixType, typename VectorType>
703 inline void
705  const VectorType &src) const
706 {
707  Assert(m != nullptr, ExcNotInitialized());
708  m->vmult_add(dst, src);
709 }
710 
711 
712 template <typename MatrixType, typename VectorType>
713 inline void
715  const VectorType &src) const
716 {
717  Assert(m != nullptr, ExcNotInitialized());
718  m->Tvmult_add(dst, src);
719 }
720 
721 
722 
723 //----------------------------------------------------------------------//
724 
725 
726 template <typename MatrixType, typename VectorType>
729  const MatrixType * M)
730  : mem(mem, typeid(*this).name())
731  , m(M, typeid(*this).name())
732 {
733  if (mem == 0)
734  mem = &my_memory;
735 }
736 
737 
738 template <typename MatrixType, typename VectorType>
741  const char * name)
742  : mem(mem, name)
743  , m(0, name)
744 {
745  if (mem == 0)
746  mem = &my_memory;
747 }
748 
749 
750 template <typename MatrixType, typename VectorType>
753  const MatrixType * M,
754  const char * name)
755  : mem(mem, name)
756  , m(M, name)
757 {
758  if (mem == nullptr)
759  mem = &my_memory;
760 }
761 
762 
763 template <typename MatrixType, typename VectorType>
764 inline void
766 {
767  m = nullptr;
768 }
769 
770 
771 template <typename MatrixType, typename VectorType>
774 {
775  m = M;
776  return *this;
777 }
778 
779 
780 template <typename MatrixType, typename VectorType>
781 inline void
784 {
785  mem = M;
786  if (mem == 0)
787  mem = &my_memory;
788 }
789 
790 
791 template <typename MatrixType, typename VectorType>
792 inline bool
794 {
795  if (m == 0)
796  return true;
797  return m->empty();
798 }
799 
800 template <typename MatrixType, typename VectorType>
801 inline void
803  const VectorType &src) const
804 {
805  if (mem == nullptr)
806  mem = &my_memory;
807  Assert(mem != nullptr, ExcNotInitialized());
808  Assert(m != nullptr, ExcNotInitialized());
809  m->vmult(dst, src);
810 }
811 
812 
813 template <typename MatrixType, typename VectorType>
814 inline void
816  const VectorType &src) const
817 {
818  if (mem == nullptr)
819  mem = &my_memory;
820  Assert(mem != nullptr, ExcNotInitialized());
821  Assert(m != nullptr, ExcNotInitialized());
822  m->Tvmult(dst, src);
823 }
824 
825 
826 template <typename MatrixType, typename VectorType>
827 inline void
829  const VectorType &src) const
830 {
831  if (mem == nullptr)
832  mem = &my_memory;
833  Assert(mem != nullptr, ExcNotInitialized());
834  Assert(m != nullptr, ExcNotInitialized());
835  VectorType *v = mem->alloc();
836  v->reinit(dst);
837  m->vmult(*v, src);
838  dst += *v;
839  mem->free(v);
840 }
841 
842 
843 template <typename MatrixType, typename VectorType>
844 inline void
846  VectorType & dst,
847  const VectorType &src) const
848 {
849  if (mem == nullptr)
850  mem = &my_memory;
851  Assert(mem != nullptr, ExcNotInitialized());
852  Assert(m != nullptr, ExcNotInitialized());
853  VectorType *v = mem->alloc();
854  v->reinit(dst);
855  m->Tvmult(*v, src);
856  dst += *v;
857  mem->free(v);
858 }
859 
860 
861 //----------------------------------------------------------------------//
862 
863 
864 template <typename number>
866  : m(M, typeid(*this).name())
867 {}
868 
869 
870 template <typename number>
872  : m(0, name)
873 {}
874 
875 
876 template <typename number>
878  const char * name)
879  : m(M, name)
880 {}
881 
882 
883 template <typename number>
884 inline void
886 {
887  m = nullptr;
888 }
889 
890 
891 template <typename number>
892 inline const PointerMatrixVector<number> &
894 {
895  m = M;
896  return *this;
897 }
898 
899 
900 template <typename number>
901 inline bool
903 {
904  if (m == 0)
905  return true;
906  return m->empty();
907 }
908 
909 template <typename number>
910 inline void
912  const Vector<number> &src) const
913 {
914  Assert(m != nullptr, ExcNotInitialized());
915  Assert(dst.size() == 1, ExcDimensionMismatch(dst.size(), 1));
916 
917  dst(0) = *m * src;
918 }
919 
920 
921 template <typename number>
922 inline void
924  const Vector<number> &src) const
925 {
926  Assert(m != nullptr, ExcNotInitialized());
927  Assert(src.size() == 1, ExcDimensionMismatch(src.size(), 1));
928 
929  dst.equ(src(0), *m);
930 }
931 
932 
933 template <typename number>
934 inline void
936  const Vector<number> &src) const
937 {
938  Assert(m != nullptr, ExcNotInitialized());
939  Assert(dst.size() == 1, ExcDimensionMismatch(dst.size(), 1));
940 
941  dst(0) += *m * src;
942 }
943 
944 
945 template <typename number>
946 inline void
948  const Vector<number> &src) const
949 {
950  Assert(m != nullptr, ExcNotInitialized());
951  Assert(src.size() == 1, ExcDimensionMismatch(src.size(), 1));
952 
953  dst.add(src(0), *m);
954 }
955 
956 
957 DEAL_II_NAMESPACE_CLOSE
958 
959 #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:1411
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