Reference documentation for deal.II version 9.0.0
mg_smoother.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2017 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_mg_smoother_h
17 #define dealii_mg_smoother_h
18 
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/mg_level_object.h>
22 #include <deal.II/base/smartpointer.h>
23 #include <deal.II/lac/linear_operator.h>
24 #include <deal.II/lac/vector_memory.h>
25 #include <deal.II/multigrid/mg_base.h>
26 #include <vector>
27 
28 DEAL_II_NAMESPACE_OPEN
29 
30 /*
31  * MGSmootherBase is defined in mg_base.h
32  */
33 
36 
45 template <typename VectorType>
46 class MGSmoother : public MGSmootherBase<VectorType>
47 {
48 public:
52  MGSmoother(const unsigned int steps = 1,
53  const bool variable = false,
54  const bool symmetric = false,
55  const bool transpose = false);
56 
60  void set_steps (const unsigned int);
61 
65  void set_variable (const bool);
66 
70  void set_symmetric (const bool);
71 
76  void set_transpose (const bool);
77 
82  void set_debug (const unsigned int level);
83 
84 protected:
92 
97  unsigned int steps;
98 
103  bool variable;
104 
109  bool symmetric;
110 
115  bool transpose;
116 
120  unsigned int debug;
121 };
122 
123 
132 template <typename VectorType>
133 class MGSmootherIdentity : public MGSmootherBase<VectorType>
134 {
135 public:
141  virtual void smooth (const unsigned int level,
142  VectorType &u,
143  const VectorType &rhs) const;
144 
145  virtual void clear ();
146 };
147 
148 
149 namespace mg
150 {
180  template <class RelaxationType, typename VectorType>
181  class SmootherRelaxation : public MGLevelObject<RelaxationType>, public MGSmoother<VectorType>
182  {
183  public:
187  SmootherRelaxation(const unsigned int steps = 1,
188  const bool variable = false,
189  const bool symmetric = false,
190  const bool transpose = false);
191 
200  template <typename MatrixType2>
201  void initialize (const MGLevelObject<MatrixType2> &matrices,
202  const typename RelaxationType::AdditionalData &additional_data
203  = typename RelaxationType::AdditionalData());
204 
212  template <typename MatrixType2, class DATA>
213  void initialize (const MGLevelObject<MatrixType2> &matrices,
214  const MGLevelObject<DATA> &additional_data);
215 
219  void clear ();
220 
224  virtual void smooth (const unsigned int level,
225  VectorType &u,
226  const VectorType &rhs) const;
227 
243  virtual void apply (const unsigned int level,
244  VectorType &u,
245  const VectorType &rhs) const;
246 
250  std::size_t memory_consumption () const;
251  };
252 }
253 
285 template <typename MatrixType, class RelaxationType, typename VectorType>
286 class MGSmootherRelaxation : public MGSmoother<VectorType>
287 {
288 public:
292  MGSmootherRelaxation(const unsigned int steps = 1,
293  const bool variable = false,
294  const bool symmetric = false,
295  const bool transpose = false);
296 
305  template <typename MatrixType2>
307  const typename RelaxationType::AdditionalData &additional_data
308  = typename RelaxationType::AdditionalData());
309 
318  template <typename MatrixType2, class DATA>
320  const MGLevelObject<DATA> &additional_data);
321 
331  template <typename MatrixType2, class DATA>
333  const DATA &additional_data,
334  const unsigned int block_row,
335  const unsigned int block_col);
336 
346  template <typename MatrixType2, class DATA>
348  const MGLevelObject<DATA> &additional_data,
349  const unsigned int block_row,
350  const unsigned int block_col);
351 
355  void clear ();
356 
360  virtual void smooth (const unsigned int level,
361  VectorType &u,
362  const VectorType &rhs) const;
363 
379  virtual void apply (const unsigned int level,
380  VectorType &u,
381  const VectorType &rhs) const;
382 
387 
391  std::size_t memory_consumption () const;
392 
393 
394 private:
399 
400 };
401 
402 
403 
434 template <typename MatrixType, typename PreconditionerType, typename VectorType>
435 class MGSmootherPrecondition : public MGSmoother<VectorType>
436 {
437 public:
441  MGSmootherPrecondition(const unsigned int steps = 1,
442  const bool variable = false,
443  const bool symmetric = false,
444  const bool transpose = false);
445 
455  template <typename MatrixType2>
457  const typename PreconditionerType::AdditionalData &additional_data = typename PreconditionerType::AdditionalData());
458 
468  template <typename MatrixType2, class DATA>
470  const MGLevelObject<DATA> &additional_data);
471 
482  template <typename MatrixType2, class DATA>
484  const DATA &additional_data,
485  const unsigned int block_row,
486  const unsigned int block_col);
487 
498  template <typename MatrixType2, class DATA>
500  const MGLevelObject<DATA> &additional_data,
501  const unsigned int block_row,
502  const unsigned int block_col);
503 
507  void clear ();
508 
512  virtual void smooth (const unsigned int level,
513  VectorType &u,
514  const VectorType &rhs) const;
515 
531  virtual void apply (const unsigned int level,
532  VectorType &u,
533  const VectorType &rhs) const;
534 
539 
543  std::size_t memory_consumption () const;
544 
545 
546 private:
551 
552 };
553 
556 /* ------------------------------- Inline functions -------------------------- */
557 
558 #ifndef DOXYGEN
559 
560 template <typename VectorType>
561 inline void
562 MGSmootherIdentity<VectorType>::smooth (const unsigned int,
563  VectorType &,
564  const VectorType &) const
565 {}
566 
567 template <typename VectorType>
568 inline void
570 {}
571 
572 //---------------------------------------------------------------------------
573 
574 template <typename VectorType>
575 inline
576 MGSmoother<VectorType>::MGSmoother (const unsigned int steps,
577  const bool variable,
578  const bool symmetric,
579  const bool transpose)
580  :
581  steps(steps),
582  variable(variable),
585  debug(0)
586 {}
587 
588 
589 template <typename VectorType>
590 inline void
591 MGSmoother<VectorType>::set_steps (const unsigned int s)
592 {
593  steps = s;
594 }
595 
596 
597 template <typename VectorType>
598 inline void
599 MGSmoother<VectorType>::set_debug (const unsigned int s)
600 {
601  debug = s;
602 }
603 
604 
605 template <typename VectorType>
606 inline void
607 MGSmoother<VectorType>::set_variable (const bool flag)
608 {
609  variable = flag;
610 }
611 
612 
613 template <typename VectorType>
614 inline void
616 {
617  symmetric = flag;
618 }
619 
620 
621 template <typename VectorType>
622 inline void
624 {
625  transpose = flag;
626 }
627 
628 //----------------------------------------------------------------------//
629 
630 namespace mg
631 {
632  template <class RelaxationType, typename VectorType>
633  inline
635  (const unsigned int steps,
636  const bool variable,
637  const bool symmetric,
638  const bool transpose)
639  : MGSmoother<VectorType>(steps, variable, symmetric, transpose)
640  {}
641 
642 
643  template <class RelaxationType, typename VectorType>
644  inline void
645  SmootherRelaxation<RelaxationType, VectorType>::clear ()
646  {
648  }
649 
650 
651  template <class RelaxationType, typename VectorType>
652  template <typename MatrixType2>
653  inline void
654  SmootherRelaxation<RelaxationType, VectorType>::initialize
655  (const MGLevelObject<MatrixType2> &m,
656  const typename RelaxationType::AdditionalData &data)
657  {
658  const unsigned int min = m.min_level();
659  const unsigned int max = m.max_level();
660 
661  this->resize(min, max);
662 
663  for (unsigned int i=min; i<=max; ++i)
664  (*this)[i].initialize(m[i], data);
665  }
666 
667 
668  template <class RelaxationType, typename VectorType>
669  template <typename MatrixType2, class DATA>
670  inline void
671  SmootherRelaxation<RelaxationType, VectorType>::initialize
672  (const MGLevelObject<MatrixType2> &m,
673  const MGLevelObject<DATA> &data)
674  {
675  const unsigned int min = std::max(m.min_level(), data.min_level());
676  const unsigned int max = std::min(m.max_level(), data.max_level());
677 
678  this->resize(min, max);
679 
680  for (unsigned int i=min; i<=max; ++i)
681  (*this)[i].initialize(m[i], data[i]);
682  }
683 
684 
685  template <class RelaxationType, typename VectorType>
686  inline void
687  SmootherRelaxation<RelaxationType, VectorType>::smooth (const unsigned int level,
688  VectorType &u,
689  const VectorType &rhs) const
690  {
691  unsigned int maxlevel = this->max_level();
692  unsigned int steps2 = this->steps;
693 
694  if (this->variable)
695  steps2 *= (1<<(maxlevel-level));
696 
697  bool T = this->transpose;
698  if (this->symmetric && (steps2 % 2 == 0))
699  T = false;
700  if (this->debug > 0)
701  deallog << 'S' << level << ' ';
702 
703  for (unsigned int i=0; i<steps2; ++i)
704  {
705  if (T)
706  (*this)[level].Tstep(u, rhs);
707  else
708  (*this)[level].step(u, rhs);
709  if (this->symmetric)
710  T = !T;
711  }
712  }
713 
714 
715  template <class RelaxationType, typename VectorType>
716  inline void
717  SmootherRelaxation<RelaxationType, VectorType>::apply (const unsigned int level,
718  VectorType &u,
719  const VectorType &rhs) const
720  {
721  unsigned int maxlevel = this->max_level();
722  unsigned int steps2 = this->steps;
723 
724  if (this->variable)
725  steps2 *= (1<<(maxlevel-level));
726 
727  bool T = this->transpose;
728  if (this->symmetric && (steps2 % 2 == 0))
729  T = false;
730  if (this->debug > 0)
731  deallog << 'S' << level << ' ';
732 
733  if (T)
734  (*this)[level].Tvmult(u, rhs);
735  else
736  (*this)[level].vmult(u, rhs);
737  if (this->symmetric)
738  T = !T;
739  for (unsigned int i=1; i<steps2; ++i)
740  {
741  if (T)
742  (*this)[level].Tstep(u, rhs);
743  else
744  (*this)[level].step(u, rhs);
745  if (this->symmetric)
746  T = !T;
747  }
748  }
749 
750 
751  template <class RelaxationType, typename VectorType>
752  inline
753  std::size_t
754  SmootherRelaxation<RelaxationType, VectorType>::
755  memory_consumption () const
756  {
757  return sizeof(*this)
760  + this->vector_memory.memory_consumption();
761  }
762 }
763 
764 
765 //----------------------------------------------------------------------//
766 
767 template <typename MatrixType, class RelaxationType, typename VectorType>
768 inline
770 (const unsigned int steps,
771  const bool variable,
772  const bool symmetric,
773  const bool transpose)
774  :
775  MGSmoother<VectorType>(steps, variable, symmetric, transpose)
776 {}
777 
778 
779 
780 template <typename MatrixType, class RelaxationType, typename VectorType>
781 inline void
783 {
784  smoothers.clear_elements();
785 
786  unsigned int i=matrices.min_level(),
787  max_level=matrices.max_level();
788  for (; i<=max_level; ++i)
789  matrices[i] = LinearOperator<VectorType>();
790 }
791 
792 
793 template <typename MatrixType, class RelaxationType, typename VectorType>
794 template <typename MatrixType2>
795 inline void
798  const typename RelaxationType::AdditionalData &data)
799 {
800  const unsigned int min = m.min_level();
801  const unsigned int max = m.max_level();
802 
803  matrices.resize(min, max);
804  smoothers.resize(min, max);
805 
806  for (unsigned int i=min; i<=max; ++i)
807  {
808  // Workaround: Unfortunately, not every "m[i]" object has a rich
809  // enough interface to populate reinit_(domain|range)_vector. Thus,
810  // apply an empty LinearOperator exemplar.
811  matrices[i] =
812  linear_operator<VectorType>(LinearOperator<VectorType>(), m[i]);
813  smoothers[i].initialize(m[i], data);
814  }
815 }
816 
817 template <typename MatrixType, class RelaxationType, typename VectorType>
818 template <typename MatrixType2, class DATA>
819 inline void
822  const MGLevelObject<DATA> &data)
823 {
824  const unsigned int min = m.min_level();
825  const unsigned int max = m.max_level();
826 
827  Assert (data.min_level() == min,
829  Assert (data.max_level() == max,
831 
832  matrices.resize(min, max);
833  smoothers.resize(min, max);
834 
835  for (unsigned int i=min; i<=max; ++i)
836  {
837  // Workaround: Unfortunately, not every "m[i]" object has a rich
838  // enough interface to populate reinit_(domain|range)_vector. Thus,
839  // apply an empty LinearOperator exemplar.
840  matrices[i] =
841  linear_operator<VectorType>(LinearOperator<VectorType>(), m[i]);
842  smoothers[i].initialize(m[i], data[i]);
843  }
844 }
845 
846 template <typename MatrixType, class RelaxationType, typename VectorType>
847 template <typename MatrixType2, class DATA>
848 inline void
851  const DATA &data,
852  const unsigned int row,
853  const unsigned int col)
854 {
855  const unsigned int min = m.min_level();
856  const unsigned int max = m.max_level();
857 
858  matrices.resize(min, max);
859  smoothers.resize(min, max);
860 
861  for (unsigned int i=min; i<=max; ++i)
862  {
863  // Workaround: Unfortunately, not every "m[i]" object has a rich
864  // enough interface to populate reinit_(domain|range)_vector. Thus,
865  // apply an empty LinearOperator exemplar.
866  matrices[i] = linear_operator<VectorType>(LinearOperator<VectorType>(),
867  m[i].block(row, col));
868  smoothers[i].initialize(m[i].block(row, col), data);
869  }
870 }
871 
872 template <typename MatrixType, class RelaxationType, typename VectorType>
873 template <typename MatrixType2, class DATA>
874 inline void
877  const MGLevelObject<DATA> &data,
878  const unsigned int row,
879  const unsigned int col)
880 {
881  const unsigned int min = m.min_level();
882  const unsigned int max = m.max_level();
883 
884  Assert (data.min_level() == min,
886  Assert (data.max_level() == max,
888 
889  matrices.resize(min, max);
890  smoothers.resize(min, max);
891 
892  for (unsigned int i=min; i<=max; ++i)
893  {
894  // Workaround: Unfortunately, not every "m[i]" object has a rich
895  // enough interface to populate reinit_(domain|range)_vector. Thus,
896  // apply an empty LinearOperator exemplar.
897  matrices[i] = linear_operator<VectorType>(LinearOperator<VectorType>(),
898  m[i].block(row, col));
899  smoothers[i].initialize(m[i].block(row, col), data[i]);
900  }
901 }
902 
903 
904 template <typename MatrixType, class RelaxationType, typename VectorType>
905 inline void
907  VectorType &u,
908  const VectorType &rhs) const
909 {
910  unsigned int maxlevel = smoothers.max_level();
911  unsigned int steps2 = this->steps;
912 
913  if (this->variable)
914  steps2 *= (1<<(maxlevel-level));
915 
916  bool T = this->transpose;
917  if (this->symmetric && (steps2 % 2 == 0))
918  T = false;
919  if (this->debug > 0)
920  deallog << 'S' << level << ' ';
921 
922  for (unsigned int i=0; i<steps2; ++i)
923  {
924  if (T)
925  smoothers[level].Tstep(u, rhs);
926  else
927  smoothers[level].step(u, rhs);
928  if (this->symmetric)
929  T = !T;
930  }
931 }
932 
933 
934 template <typename MatrixType, class RelaxationType, typename VectorType>
935 inline void
937  VectorType &u,
938  const VectorType &rhs) const
939 {
940  unsigned int maxlevel = smoothers.max_level();
941  unsigned int steps2 = this->steps;
942 
943  if (this->variable)
944  steps2 *= (1<<(maxlevel-level));
945 
946  bool T = this->transpose;
947  if (this->symmetric && (steps2 % 2 == 0))
948  T = false;
949  if (this->debug > 0)
950  deallog << 'S' << level << ' ';
951 
952  if (T)
953  smoothers[level].Tvmult(u, rhs);
954  else
955  smoothers[level].vmult(u, rhs);
956  if (this->symmetric)
957  T = !T;
958  for (unsigned int i=1; i<steps2; ++i)
959  {
960  if (T)
961  smoothers[level].Tstep(u, rhs);
962  else
963  smoothers[level].step(u, rhs);
964  if (this->symmetric)
965  T = !T;
966  }
967 }
968 
969 
970 
971 template <typename MatrixType, class RelaxationType, typename VectorType>
972 inline
973 std::size_t
975 memory_consumption () const
976 {
977  return sizeof(*this)
978  + matrices.memory_consumption()
979  + smoothers.memory_consumption()
980  + this->vector_memory.memory_consumption();
981 }
982 
983 
984 //----------------------------------------------------------------------//
985 
986 template <typename MatrixType, typename PreconditionerType, typename VectorType>
987 inline
989 (const unsigned int steps,
990  const bool variable,
991  const bool symmetric,
992  const bool transpose)
993  :
994  MGSmoother<VectorType>(steps, variable, symmetric, transpose)
995 {}
996 
997 
998 
999 template <typename MatrixType, typename PreconditionerType, typename VectorType>
1000 inline void
1002 {
1003  smoothers.clear_elements();
1004 
1005  unsigned int i=matrices.min_level(),
1006  max_level=matrices.max_level();
1007  for (; i<=max_level; ++i)
1008  matrices[i]=LinearOperator<VectorType>();
1009 }
1010 
1011 
1012 
1013 template <typename MatrixType, typename PreconditionerType, typename VectorType>
1014 template <typename MatrixType2>
1015 inline void
1017 (const MGLevelObject<MatrixType2> &m,
1018  const typename PreconditionerType::AdditionalData &data)
1019 {
1020  const unsigned int min = m.min_level();
1021  const unsigned int max = m.max_level();
1022 
1023  matrices.resize(min, max);
1024  smoothers.resize(min, max);
1025 
1026  for (unsigned int i=min; i<=max; ++i)
1027  {
1028  // Workaround: Unfortunately, not every "m[i]" object has a rich
1029  // enough interface to populate reinit_(domain|range)_vector. Thus,
1030  // apply an empty LinearOperator exemplar.
1031  matrices[i] =
1032  linear_operator<VectorType>(LinearOperator<VectorType>(), m[i]);
1033  smoothers[i].initialize(m[i], data);
1034  }
1035 }
1036 
1037 
1038 
1039 template <typename MatrixType, typename PreconditionerType, typename VectorType>
1040 template <typename MatrixType2, class DATA>
1041 inline void
1043 (const MGLevelObject<MatrixType2> &m,
1044  const MGLevelObject<DATA> &data)
1045 {
1046  const unsigned int min = m.min_level();
1047  const unsigned int max = m.max_level();
1048 
1049  Assert (data.min_level() == min,
1051  Assert (data.max_level() == max,
1053 
1054  matrices.resize(min, max);
1055  smoothers.resize(min, max);
1056 
1057  for (unsigned int i=min; i<=max; ++i)
1058  {
1059  // Workaround: Unfortunately, not every "m[i]" object has a rich
1060  // enough interface to populate reinit_(domain|range)_vector. Thus,
1061  // apply an empty LinearOperator exemplar.
1062  matrices[i] =
1063  linear_operator<VectorType>(LinearOperator<VectorType>(), m[i]);
1064  smoothers[i].initialize(m[i], data[i]);
1065  }
1066 }
1067 
1068 
1069 
1070 template <typename MatrixType, typename PreconditionerType, typename VectorType>
1071 template <typename MatrixType2, class DATA>
1072 inline void
1074 (const MGLevelObject<MatrixType2> &m,
1075  const DATA &data,
1076  const unsigned int row,
1077  const unsigned int col)
1078 {
1079  const unsigned int min = m.min_level();
1080  const unsigned int max = m.max_level();
1081 
1082  matrices.resize(min, max);
1083  smoothers.resize(min, max);
1084 
1085  for (unsigned int i=min; i<=max; ++i)
1086  {
1087  matrices[i] = &(m[i].block(row, col));
1088  smoothers[i].initialize(m[i].block(row, col), data);
1089  }
1090 }
1091 
1092 
1093 
1094 template <typename MatrixType, typename PreconditionerType, typename VectorType>
1095 template <typename MatrixType2, class DATA>
1096 inline void
1098 (const MGLevelObject<MatrixType2> &m,
1099  const MGLevelObject<DATA> &data,
1100  const unsigned int row,
1101  const unsigned int col)
1102 {
1103  const unsigned int min = m.min_level();
1104  const unsigned int max = m.max_level();
1105 
1106  Assert (data.min_level() == min,
1108  Assert (data.max_level() == max,
1110 
1111  matrices.resize(min, max);
1112  smoothers.resize(min, max);
1113 
1114  for (unsigned int i=min; i<=max; ++i)
1115  {
1116  matrices[i] = &(m[i].block(row, col));
1117  smoothers[i].initialize(m[i].block(row, col), data[i]);
1118  }
1119 }
1120 
1121 
1122 
1123 template <typename MatrixType, typename PreconditionerType, typename VectorType>
1124 inline void
1126 (const unsigned int level,
1127  VectorType &u,
1128  const VectorType &rhs) const
1129 {
1130  unsigned int maxlevel = matrices.max_level();
1131  unsigned int steps2 = this->steps;
1132 
1133  if (this->variable)
1134  steps2 *= (1<<(maxlevel-level));
1135 
1136  typename VectorMemory<VectorType>::Pointer r(this->vector_memory);
1137  typename VectorMemory<VectorType>::Pointer d(this->vector_memory);
1138 
1139  r->reinit(u,true);
1140  d->reinit(u,true);
1141 
1142  bool T = this->transpose;
1143  if (this->symmetric && (steps2 % 2 == 0))
1144  T = false;
1145  if (this->debug > 0)
1146  deallog << 'S' << level << ' ';
1147 
1148  for (unsigned int i=0; i<steps2; ++i)
1149  {
1150  if (T)
1151  {
1152  if (this->debug > 0)
1153  deallog << 'T';
1154  matrices[level].Tvmult(*r,u);
1155  r->sadd(-1.,1.,rhs);
1156  if (this->debug > 2)
1157  deallog << ' ' << r->l2_norm() << ' ';
1158  smoothers[level].Tvmult(*d, *r);
1159  if (this->debug > 1)
1160  deallog << ' ' << d->l2_norm() << ' ';
1161  }
1162  else
1163  {
1164  if (this->debug > 0)
1165  deallog << 'N';
1166  matrices[level].vmult(*r,u);
1167  r->sadd(-1.,rhs);
1168  if (this->debug > 2)
1169  deallog << ' ' << r->l2_norm() << ' ';
1170  smoothers[level].vmult(*d, *r);
1171  if (this->debug > 1)
1172  deallog << ' ' << d->l2_norm() << ' ';
1173  }
1174  u += *d;
1175  if (this->symmetric)
1176  T = !T;
1177  }
1178  if (this->debug > 0)
1179  deallog << std::endl;
1180 }
1181 
1182 
1183 
1184 template <typename MatrixType, typename PreconditionerType, typename VectorType>
1185 inline void
1187 (const unsigned int level,
1188  VectorType &u,
1189  const VectorType &rhs) const
1190 {
1191  unsigned int maxlevel = matrices.max_level();
1192  unsigned int steps2 = this->steps;
1193 
1194  if (this->variable)
1195  steps2 *= (1<<(maxlevel-level));
1196 
1197  bool T = this->transpose;
1198  if (this->symmetric && (steps2 % 2 == 0))
1199  T = false;
1200  if (this->debug > 0)
1201  deallog << 'S' << level << ' ';
1202 
1203  // first step where we overwrite the result
1204  if (this->debug > 2)
1205  deallog << ' ' << rhs.l2_norm() << ' ';
1206  if (this->debug > 0)
1207  deallog << (T ? 'T' : 'N');
1208  if (T)
1209  smoothers[level].Tvmult(u, rhs);
1210  else
1211  smoothers[level].vmult(u, rhs);
1212  if (this->debug > 1)
1213  deallog << ' ' << u.l2_norm() << ' ';
1214  if (this->symmetric)
1215  T = !T;
1216 
1217  typename VectorMemory<VectorType>::Pointer r(this->vector_memory);
1218  typename VectorMemory<VectorType>::Pointer d(this->vector_memory);
1219 
1220  if (steps2 > 1)
1221  {
1222  r->reinit(u,true);
1223  d->reinit(u,true);
1224  }
1225 
1226  for (unsigned int i=1; i<steps2; ++i)
1227  {
1228  if (T)
1229  {
1230  if (this->debug > 0)
1231  deallog << 'T';
1232  matrices[level].Tvmult(*r,u);
1233  r->sadd(-1.,1.,rhs);
1234  if (this->debug > 2)
1235  deallog << ' ' << r->l2_norm() << ' ';
1236  smoothers[level].Tvmult(*d, *r);
1237  if (this->debug > 1)
1238  deallog << ' ' << d->l2_norm() << ' ';
1239  }
1240  else
1241  {
1242  if (this->debug > 0)
1243  deallog << 'N';
1244  matrices[level].vmult(*r,u);
1245  r->sadd(-1.,rhs);
1246  if (this->debug > 2)
1247  deallog << ' ' << r->l2_norm() << ' ';
1248  smoothers[level].vmult(*d, *r);
1249  if (this->debug > 1)
1250  deallog << ' ' << d->l2_norm() << ' ';
1251  }
1252  u += *d;
1253  if (this->symmetric)
1254  T = !T;
1255  }
1256  if (this->debug > 0)
1257  deallog << std::endl;
1258 }
1259 
1260 
1261 
1262 template <typename MatrixType, typename PreconditionerType, typename VectorType>
1263 inline
1264 std::size_t
1266 memory_consumption () const
1267 {
1268  return sizeof(*this)
1269  + matrices.memory_consumption()
1270  + smoothers.memory_consumption()
1271  + this->vector_memory.memory_consumption();
1272 }
1273 
1274 
1275 #endif // DOXYGEN
1276 
1277 DEAL_II_NAMESPACE_CLOSE
1278 
1279 #endif
std::size_t memory_consumption() const
unsigned int max_level() const
MGSmootherPrecondition(const unsigned int steps=1, const bool variable=false, const bool symmetric=false, const bool transpose=false)
Matrix is symmetric.
MGLevelObject< LinearOperator< VectorType > > matrices
Definition: mg_smoother.h:550
void set_transpose(const bool)
bool symmetric
Definition: mg_smoother.h:109
virtual void smooth(const unsigned int level, VectorType &u, const VectorType &rhs) const
virtual void apply(const unsigned int level, VectorType &u, const VectorType &rhs) const
void set_symmetric(const bool)
Definition: mg.h:81
SmootherRelaxation(const unsigned int steps=1, const bool variable=false, const bool symmetric=false, const bool transpose=false)
virtual void clear()
void set_variable(const bool)
MGSmootherRelaxation(const unsigned int steps=1, const bool variable=false, const bool symmetric=false, const bool transpose=false)
virtual void smooth(const unsigned int level, VectorType &u, const VectorType &rhs) const
std::size_t memory_consumption() const
MGLevelObject< RelaxationType > smoothers
Definition: mg_smoother.h:386
unsigned int min_level() const
void set_debug(const unsigned int level)
MGLevelObject< PreconditionerType > smoothers
Definition: mg_smoother.h:538
VectorizedArray< Number > min(const ::VectorizedArray< Number > &x, const ::VectorizedArray< Number > &y)
std::size_t memory_consumption() const
#define Assert(cond, exc)
Definition: exceptions.h:1142
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
MGSmoother(const unsigned int steps=1, const bool variable=false, const bool symmetric=false, const bool transpose=false)
GrowingVectorMemory< VectorType > vector_memory
Definition: mg_smoother.h:91
void initialize(const MGLevelObject< MatrixType2 > &matrices, const typename RelaxationType::AdditionalData &additional_data=typename RelaxationType::AdditionalData())
virtual void smooth(const unsigned int level, VectorType &u, const VectorType &rhs) const
SymmetricTensor< rank_, dim, Number > transpose(const SymmetricTensor< rank_, dim, Number > &t)
std::size_t memory_consumption() const
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
void set_steps(const unsigned int)
MGLevelObject< LinearOperator< VectorType > > matrices
Definition: mg_smoother.h:398
virtual void apply(const unsigned int level, VectorType &u, const VectorType &rhs) const
void initialize(const MGLevelObject< MatrixType2 > &matrices, const typename RelaxationType::AdditionalData &additional_data=typename RelaxationType::AdditionalData())
unsigned int debug
Definition: mg_smoother.h:120
bool transpose
Definition: mg_smoother.h:115
bool variable
Definition: mg_smoother.h:103
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)
virtual void apply(const unsigned int level, VectorType &u, const VectorType &rhs) const
VectorizedArray< Number > max(const ::VectorizedArray< Number > &x, const ::VectorizedArray< Number > &y)
unsigned int steps
Definition: mg_smoother.h:97
void initialize(const MGLevelObject< MatrixType2 > &matrices, const typename PreconditionerType::AdditionalData &additional_data=typename PreconditionerType::AdditionalData())
virtual void smooth(const unsigned int level, VectorType &u, const VectorType &rhs) const