Reference documentation for deal.II version 9.0.0
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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_pointer_matrix_h
17 #define dealii_pointer_matrix_h
18 
19 #include <deal.II/base/subscriptor.h>
20 #include <deal.II/base/smartpointer.h>
21 #include <deal.II/lac/vector.h>
22 #include <deal.II/lac/vector_memory.h>
23 
24 DEAL_II_NAMESPACE_OPEN
25 
26 template <typename VectorType> class VectorMemory;
27 
28 class IdentityMatrix;
29 template <typename number> class FullMatrix;
30 template <typename number> class LAPACKFullMatrix;
31 template <typename number> class SparseMatrix;
32 template <typename number> class BlockSparseMatrix;
33 template <typename number> class SparseMatrixEZ;
34 template <typename number> class BlockSparseMatrixEZ;
35 template <typename number> class TridiagonalMatrix;
36 template <typename number, typename BlockVectorType> class BlockMatrixArray;
37 
52 template <typename VectorType>
53 class DEAL_II_DEPRECATED PointerMatrixBase : public Subscriptor
54 {
55 public:
64  typedef typename VectorType::value_type value_type;
65 
71  virtual ~PointerMatrixBase () = default;
72 
76  virtual void clear () = 0;
77 
81  virtual void vmult (VectorType &dst,
82  const VectorType &src) const = 0;
83 
87  virtual void Tvmult (VectorType &dst,
88  const VectorType &src) const = 0;
89 
93  virtual void vmult_add (VectorType &dst,
94  const VectorType &src) const = 0;
95 
99  virtual void Tvmult_add (VectorType &dst,
100  const VectorType &src) const = 0;
101 };
102 
103 
116 template <typename MatrixType, typename VectorType>
117 class DEAL_II_DEPRECATED PointerMatrix : public PointerMatrixBase<VectorType>
118 {
119 public:
127  PointerMatrix (const MatrixType *M=nullptr);
128 
139  PointerMatrix(const char *name);
140 
152  PointerMatrix(const MatrixType *M,
153  const char *name);
154 
155  // Use doc from base class
156  virtual void clear();
157 
161  bool empty () const;
162 
168  const PointerMatrix &operator= (const MatrixType *M);
169 
173  virtual void vmult (VectorType &dst,
174  const VectorType &src) const;
175 
179  virtual void Tvmult (VectorType &dst,
180  const VectorType &src) const;
181 
185  virtual void vmult_add (VectorType &dst,
186  const VectorType &src) const;
187 
191  virtual void Tvmult_add (VectorType &dst,
192  const VectorType &src) const;
193 
194 private:
199 };
200 
201 
218 template <typename MatrixType, typename VectorType>
219 class DEAL_II_DEPRECATED PointerMatrixAux : public PointerMatrixBase<VectorType>
220 {
221 public:
232  const MatrixType *M = 0);
233 
245  const char *name);
246 
259  const MatrixType *M,
260  const char *name);
261 
262  // Use doc from base class
263  virtual void clear();
264 
268  bool empty () const;
269 
273  void set_memory(VectorMemory<VectorType> *mem);
274 
280  const PointerMatrixAux &operator= (const MatrixType *M);
281 
285  virtual void vmult (VectorType &dst,
286  const VectorType &src) const;
287 
291  virtual void Tvmult (VectorType &dst,
292  const VectorType &src) const;
293 
297  virtual void vmult_add (VectorType &dst,
298  const VectorType &src) const;
299 
303  virtual void Tvmult_add (VectorType &dst,
304  const VectorType &src) const;
305 
306 private:
311 
316 
321 };
322 
323 
324 
337 template <typename number>
338 class DEAL_II_DEPRECATED PointerMatrixVector : public PointerMatrixBase<Vector<number> >
339 {
340 public:
348  PointerMatrixVector (const Vector<number> *M=0);
349 
360  PointerMatrixVector (const char *name);
361 
374  const char *name);
375 
376  // Use doc from base class
377  virtual void clear();
378 
382  bool empty () const;
383 
390 
398  virtual void vmult (Vector<number> &dst,
399  const Vector<number> &src) const;
400 
408  virtual void Tvmult (Vector<number> &dst,
409  const Vector<number> &src) const;
410 
417  virtual void vmult_add (Vector<number> &dst,
418  const Vector<number> &src) const;
419 
426  virtual void Tvmult_add (Vector<number> &dst,
427  const Vector<number> &src) const;
428 
429 private:
434 };
435 
436 
437 
455 template <typename VectorType, typename MatrixType>
456 inline
458 new_pointer_matrix_base(MatrixType &matrix, const VectorType &, const char *name = "PointerMatrixAux")
459 {
460  return new PointerMatrixAux<MatrixType, VectorType>(nullptr, &matrix, name);
461 }
462 
468 template <typename numberv>
470 new_pointer_matrix_base(const IdentityMatrix &matrix, const Vector<numberv> &, const char *name = "PointerMatrix")
471 {
472  return new PointerMatrix<IdentityMatrix, Vector<numberv> >(&matrix, name);
473 }
474 
475 
481 template <typename numberv, typename numberm>
483 new_pointer_matrix_base(const FullMatrix<numberm> &matrix, const Vector<numberv> &, const char *name = "PointerMatrix")
484 {
485  return new PointerMatrix<FullMatrix<numberm>, Vector<numberv> >(&matrix, name);
486 }
487 
488 
494 template <typename numberv, typename numberm>
496 new_pointer_matrix_base(const LAPACKFullMatrix<numberm> &matrix, const Vector<numberv> &, const char *name = "PointerMatrix")
497 {
498  return new PointerMatrix<LAPACKFullMatrix<numberm>, Vector<numberv> >(&matrix, name);
499 }
500 
501 
507 template <typename numberv, typename numberm>
509 new_pointer_matrix_base(const SparseMatrix<numberm> &matrix, const Vector<numberv> &, const char *name = "PointerMatrix")
510 {
511  return new PointerMatrix<SparseMatrix<numberm>, Vector<numberv> >(&matrix, name);
512 }
513 
514 
520 template <typename VectorType, typename numberm>
522 new_pointer_matrix_base(const BlockSparseMatrix<numberm> &matrix, const VectorType &, const char *name = "PointerMatrix")
523 {
524  return new PointerMatrix<BlockSparseMatrix<numberm>, VectorType>(&matrix, name);
525 }
526 
527 
533 template <typename numberv, typename numberm>
535 new_pointer_matrix_base(const SparseMatrixEZ<numberm> &matrix, const Vector<numberv> &, const char *name = "PointerMatrix")
536 {
537  return new PointerMatrix<SparseMatrixEZ<numberm>, Vector<numberv> >(&matrix, name);
538 }
539 
540 
546 template <typename VectorType, typename numberm>
548 new_pointer_matrix_base(const BlockSparseMatrixEZ<numberm> &matrix, const VectorType &, const char *name = "PointerMatrix")
549 {
550  return new PointerMatrix<BlockSparseMatrixEZ<numberm>, VectorType>(&matrix, name);
551 }
552 
553 
559 template <typename numberv, typename numberm, typename BLOCK_VectorType>
561 new_pointer_matrix_base(const BlockMatrixArray<numberm,BLOCK_VectorType> &matrix, const BLOCK_VectorType &, const char *name = "PointerMatrix")
562 {
564 }
565 
566 
572 template <typename numberv, typename numberm>
574 new_pointer_matrix_base(const TridiagonalMatrix<numberm> &matrix, const Vector<numberv> &, const char *name = "PointerMatrix")
575 {
576  return new PointerMatrix<TridiagonalMatrix<numberm>, Vector<numberv> >(&matrix, name);
577 }
578 
579 
580 
582 //---------------------------------------------------------------------------
583 
584 
585 template <typename MatrixType, typename VectorType>
587  : m(M, typeid(*this).name())
588 {}
589 
590 
591 template <typename MatrixType, typename VectorType>
593  : m(nullptr, name)
594 {}
595 
596 
597 template <typename MatrixType, typename VectorType>
599  const char *name)
600  : m(M, name)
601 {}
602 
603 
604 template <typename MatrixType, typename VectorType>
605 inline void
607 {
608  m = nullptr;
609 }
610 
611 
612 template <typename MatrixType, typename VectorType>
615 {
616  m = M;
617  return *this;
618 }
619 
620 
621 template <typename MatrixType, typename VectorType>
622 inline bool
624 {
625  if (m == nullptr)
626  return true;
627  return m->empty();
628 }
629 
630 template <typename MatrixType, typename VectorType>
631 inline void
633  const VectorType &src) const
634 {
635  Assert (m != nullptr, ExcNotInitialized());
636  m->vmult (dst, src);
637 }
638 
639 
640 template <typename MatrixType, typename VectorType>
641 inline void
643  const VectorType &src) const
644 {
645  Assert (m != nullptr, ExcNotInitialized());
646  m->Tvmult (dst, src);
647 }
648 
649 
650 template <typename MatrixType, typename VectorType>
651 inline void
653  const VectorType &src) const
654 {
655  Assert (m != nullptr, ExcNotInitialized());
656  m->vmult_add (dst, src);
657 }
658 
659 
660 template <typename MatrixType, typename VectorType>
661 inline void
663  const VectorType &src) const
664 {
665  Assert (m != nullptr, ExcNotInitialized());
666  m->Tvmult_add (dst, src);
667 }
668 
669 
670 
671 //----------------------------------------------------------------------//
672 
673 
674 template <typename MatrixType, typename VectorType>
676  const MatrixType *M)
677  : mem(mem, typeid(*this).name()),
678  m(M, typeid(*this).name())
679 {
680  if (mem == 0) mem = &my_memory;
681 }
682 
683 
684 template <typename MatrixType, typename VectorType>
686  const char *name)
687  : mem(mem, name),
688  m(0, name)
689 {
690  if (mem == 0) mem = &my_memory;
691 }
692 
693 
694 template <typename MatrixType, typename VectorType>
696  const MatrixType *M,
697  const char *name)
698  : mem(mem, name),
699  m(M, name)
700 {
701  if (mem == nullptr) mem = &my_memory;
702 }
703 
704 
705 template <typename MatrixType, typename VectorType>
706 inline void
708 {
709  m = nullptr;
710 }
711 
712 
713 template <typename MatrixType, typename VectorType>
716 {
717  m = M;
718  return *this;
719 }
720 
721 
722 template <typename MatrixType, typename VectorType>
723 inline void
725 {
726  mem = M;
727  if (mem == 0)
728  mem = &my_memory;
729 }
730 
731 
732 template <typename MatrixType, typename VectorType>
733 inline bool
735 {
736  if (m == 0)
737  return true;
738  return m->empty();
739 }
740 
741 template <typename MatrixType, typename VectorType>
742 inline void
744  const VectorType &src) const
745 {
746  if (mem == nullptr)
747  mem = &my_memory;
748  Assert (mem != nullptr, ExcNotInitialized());
749  Assert (m != nullptr, ExcNotInitialized());
750  m->vmult (dst, src);
751 }
752 
753 
754 template <typename MatrixType, typename VectorType>
755 inline void
757  const VectorType &src) const
758 {
759  if (mem == nullptr)
760  mem = &my_memory;
761  Assert (mem != nullptr, ExcNotInitialized());
762  Assert (m != nullptr, ExcNotInitialized());
763  m->Tvmult (dst, src);
764 }
765 
766 
767 template <typename MatrixType, typename VectorType>
768 inline void
770  const VectorType &src) const
771 {
772  if (mem == nullptr)
773  mem = &my_memory;
774  Assert (mem != nullptr, ExcNotInitialized());
775  Assert (m != nullptr, ExcNotInitialized());
776  VectorType *v = mem->alloc();
777  v->reinit(dst);
778  m->vmult (*v, src);
779  dst += *v;
780  mem->free(v);
781 }
782 
783 
784 template <typename MatrixType, typename VectorType>
785 inline void
787  const VectorType &src) const
788 {
789  if (mem == nullptr)
790  mem = &my_memory;
791  Assert (mem != nullptr, ExcNotInitialized());
792  Assert (m != nullptr, ExcNotInitialized());
793  VectorType *v = mem->alloc();
794  v->reinit(dst);
795  m->Tvmult (*v, src);
796  dst += *v;
797  mem->free(v);
798 }
799 
800 
801 //----------------------------------------------------------------------//
802 
803 
804 template <typename number>
806  : m(M, typeid(*this).name())
807 {}
808 
809 
810 template <typename number>
812  : m(0, name)
813 {}
814 
815 
816 template <typename number>
818  const char *name)
819  : m(M, name)
820 {}
821 
822 
823 template <typename number>
824 inline void
826 {
827  m = nullptr;
828 }
829 
830 
831 template <typename number>
832 inline const PointerMatrixVector<number> &
834 {
835  m = M;
836  return *this;
837 }
838 
839 
840 template <typename number>
841 inline bool
843 {
844  if (m == 0)
845  return true;
846  return m->empty();
847 }
848 
849 template <typename number>
850 inline void
852  const Vector<number> &src) const
853 {
854  Assert (m != nullptr, ExcNotInitialized());
855  Assert (dst.size() == 1, ExcDimensionMismatch(dst.size(), 1));
856 
857  dst(0) = *m * src;
858 }
859 
860 
861 template <typename number>
862 inline void
864  const Vector<number> &src) const
865 {
866  Assert (m != nullptr, ExcNotInitialized());
867  Assert(src.size() == 1, ExcDimensionMismatch(src.size(), 1));
868 
869  dst.equ (src(0), *m);
870 }
871 
872 
873 template <typename number>
874 inline void
876  const Vector<number> &src) const
877 {
878  Assert (m != nullptr, ExcNotInitialized());
879  Assert (dst.size() == 1, ExcDimensionMismatch(dst.size(), 1));
880 
881  dst(0) += *m * src;
882 }
883 
884 
885 template <typename number>
886 inline void
888  const Vector<number> &src) const
889 {
890  Assert (m != nullptr, ExcNotInitialized());
891  Assert(src.size() == 1, ExcDimensionMismatch(src.size(), 1));
892 
893  dst.add (src(0), *m);
894 }
895 
896 
897 DEAL_II_NAMESPACE_CLOSE
898 
899 #endif
SmartPointer< const Vector< number >, PointerMatrixVector< number > > m
bool empty() const
virtual void clear()
SmartPointer< const MatrixType, PointerMatrix< MatrixType, VectorType > > m
Subscriptor & operator=(const Subscriptor &)
Definition: subscriptor.cc:129
virtual void Tvmult_add(VectorType &dst, const VectorType &src) const
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 vmult_add(VectorType &dst, const VectorType &src) const
static ::ExceptionBase & ExcNotInitialized()
virtual void Tvmult(VectorType &dst, const VectorType &src) const
PointerMatrixVector(const Vector< number > *M=0)
virtual void Tvmult(VectorType &dst, const VectorType &src) const
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 Tvmult(Vector< number > &dst, const Vector< number > &src) const
#define Assert(cond, exc)
Definition: exceptions.h:1142
virtual void vmult(VectorType &dst, const VectorType &src) const =0
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
virtual void clear()
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)
SmartPointer< const MatrixType, PointerMatrixAux< MatrixType, VectorType > > m
virtual void vmult(VectorType &dst, const VectorType &src) const
virtual void vmult(VectorType &dst, const VectorType &src) const
SmartPointer< VectorMemory< VectorType >, PointerMatrixAux< MatrixType, VectorType > > mem
VectorType::value_type value_type
const PointerMatrixVector & operator=(const Vector< number > *M)
size_type size() const
void set_memory(VectorMemory< VectorType > *mem)
virtual void vmult_add(VectorType &dst, const VectorType &src) const
virtual void Tvmult(VectorType &dst, const VectorType &src) const =0
virtual void Tvmult_add(VectorType &dst, const VectorType &src) const