16 #ifndef dealii_mg_smoother_h 17 #define dealii_mg_smoother_h 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> 28 DEAL_II_NAMESPACE_OPEN
45 template <
typename VectorType>
82 void set_debug (
const unsigned int level);
132 template <
typename VectorType>
141 virtual void smooth (
const unsigned int level,
143 const VectorType &rhs)
const;
145 virtual void clear ();
180 template <
class RelaxationType,
typename VectorType>
200 template <
typename MatrixType2>
202 const typename RelaxationType::AdditionalData &additional_data
203 =
typename RelaxationType::AdditionalData());
212 template <
typename MatrixType2,
class DATA>
224 virtual void smooth (
const unsigned int level,
226 const VectorType &rhs)
const;
243 virtual void apply (
const unsigned int level,
245 const VectorType &rhs)
const;
285 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
305 template <
typename MatrixType2>
307 const typename RelaxationType::AdditionalData &additional_data
308 =
typename RelaxationType::AdditionalData());
318 template <
typename MatrixType2,
class DATA>
331 template <
typename MatrixType2,
class DATA>
333 const DATA &additional_data,
334 const unsigned int block_row,
335 const unsigned int block_col);
346 template <
typename MatrixType2,
class DATA>
349 const unsigned int block_row,
350 const unsigned int block_col);
360 virtual void smooth (
const unsigned int level,
362 const VectorType &rhs)
const;
379 virtual void apply (
const unsigned int level,
381 const VectorType &rhs)
const;
434 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
455 template <
typename MatrixType2>
457 const typename PreconditionerType::AdditionalData &additional_data =
typename PreconditionerType::AdditionalData());
468 template <
typename MatrixType2,
class DATA>
482 template <
typename MatrixType2,
class DATA>
484 const DATA &additional_data,
485 const unsigned int block_row,
486 const unsigned int block_col);
498 template <
typename MatrixType2,
class DATA>
501 const unsigned int block_row,
502 const unsigned int block_col);
512 virtual void smooth (
const unsigned int level,
514 const VectorType &rhs)
const;
531 virtual void apply (
const unsigned int level,
533 const VectorType &rhs)
const;
560 template <
typename VectorType>
564 const VectorType &)
const 567 template <
typename VectorType>
574 template <
typename VectorType>
578 const bool symmetric,
589 template <
typename VectorType>
597 template <
typename VectorType>
605 template <
typename VectorType>
613 template <
typename VectorType>
621 template <
typename VectorType>
632 template <
class RelaxationType,
typename VectorType>
635 (
const unsigned int steps,
637 const bool symmetric,
643 template <
class RelaxationType,
typename VectorType>
645 SmootherRelaxation<RelaxationType, VectorType>::clear ()
651 template <
class RelaxationType,
typename VectorType>
652 template <
typename MatrixType2>
654 SmootherRelaxation<RelaxationType, VectorType>::initialize
656 const typename RelaxationType::AdditionalData &data)
663 for (
unsigned int i=
min; i<=
max; ++i)
664 (*
this)[i].initialize(m[i], data);
668 template <
class RelaxationType,
typename VectorType>
669 template <
typename MatrixType2,
class DATA>
671 SmootherRelaxation<RelaxationType, VectorType>::initialize
680 for (
unsigned int i=
min; i<=
max; ++i)
681 (*
this)[i].initialize(m[i], data[i]);
685 template <
class RelaxationType,
typename VectorType>
687 SmootherRelaxation<RelaxationType, VectorType>::smooth (
const unsigned int level,
689 const VectorType &rhs)
const 691 unsigned int maxlevel = this->max_level();
692 unsigned int steps2 = this->steps;
695 steps2 *= (1<<(maxlevel-level));
698 if (this->symmetric && (steps2 % 2 == 0))
701 deallog <<
'S' << level <<
' ';
703 for (
unsigned int i=0; i<steps2; ++i)
706 (*this)[level].Tstep(u, rhs);
708 (*
this)[level].step(u, rhs);
715 template <
class RelaxationType,
typename VectorType>
717 SmootherRelaxation<RelaxationType, VectorType>::apply (
const unsigned int level,
719 const VectorType &rhs)
const 721 unsigned int maxlevel = this->max_level();
722 unsigned int steps2 = this->steps;
725 steps2 *= (1<<(maxlevel-level));
728 if (this->symmetric && (steps2 % 2 == 0))
731 deallog <<
'S' << level <<
' ';
734 (*this)[level].Tvmult(u, rhs);
736 (*
this)[level].vmult(u, rhs);
739 for (
unsigned int i=1; i<steps2; ++i)
742 (*this)[level].Tstep(u, rhs);
744 (*
this)[level].step(u, rhs);
751 template <
class RelaxationType,
typename VectorType>
754 SmootherRelaxation<RelaxationType, VectorType>::
755 memory_consumption ()
const 767 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
770 (
const unsigned int steps,
772 const bool symmetric,
780 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
784 smoothers.clear_elements();
786 unsigned int i=matrices.min_level(),
787 max_level=matrices.max_level();
788 for (; i<=max_level; ++i)
793 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
794 template <
typename MatrixType2>
798 const typename RelaxationType::AdditionalData &data)
803 matrices.resize(
min,
max);
804 smoothers.resize(
min,
max);
806 for (
unsigned int i=
min; i<=
max; ++i)
813 smoothers[i].initialize(m[i], data);
817 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
818 template <
typename MatrixType2,
class DATA>
832 matrices.resize(
min,
max);
833 smoothers.resize(
min,
max);
835 for (
unsigned int i=
min; i<=
max; ++i)
842 smoothers[i].initialize(m[i], data[i]);
846 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
847 template <
typename MatrixType2,
class DATA>
852 const unsigned int row,
853 const unsigned int col)
858 matrices.resize(
min,
max);
859 smoothers.resize(
min,
max);
861 for (
unsigned int i=
min; i<=
max; ++i)
867 m[i].block(row, col));
868 smoothers[i].initialize(m[i].block(row, col), data);
872 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
873 template <
typename MatrixType2,
class DATA>
878 const unsigned int row,
879 const unsigned int col)
889 matrices.resize(
min,
max);
890 smoothers.resize(
min,
max);
892 for (
unsigned int i=
min; i<=
max; ++i)
898 m[i].block(row, col));
899 smoothers[i].initialize(m[i].block(row, col), data[i]);
904 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
908 const VectorType &rhs)
const 910 unsigned int maxlevel = smoothers.max_level();
911 unsigned int steps2 = this->steps;
914 steps2 *= (1<<(maxlevel-level));
917 if (this->symmetric && (steps2 % 2 == 0))
920 deallog <<
'S' << level <<
' ';
922 for (
unsigned int i=0; i<steps2; ++i)
925 smoothers[level].Tstep(u, rhs);
927 smoothers[level].step(u, rhs);
934 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
938 const VectorType &rhs)
const 940 unsigned int maxlevel = smoothers.max_level();
941 unsigned int steps2 = this->steps;
944 steps2 *= (1<<(maxlevel-level));
947 if (this->symmetric && (steps2 % 2 == 0))
950 deallog <<
'S' << level <<
' ';
953 smoothers[level].Tvmult(u, rhs);
955 smoothers[level].vmult(u, rhs);
958 for (
unsigned int i=1; i<steps2; ++i)
961 smoothers[level].Tstep(u, rhs);
963 smoothers[level].step(u, rhs);
971 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
978 + matrices.memory_consumption()
979 + smoothers.memory_consumption()
980 + this->vector_memory.memory_consumption();
986 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
989 (
const unsigned int steps,
991 const bool symmetric,
999 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1003 smoothers.clear_elements();
1005 unsigned int i=matrices.min_level(),
1006 max_level=matrices.max_level();
1007 for (; i<=max_level; ++i)
1013 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1014 template <
typename MatrixType2>
1018 const typename PreconditionerType::AdditionalData &data)
1023 matrices.resize(
min,
max);
1024 smoothers.resize(
min,
max);
1026 for (
unsigned int i=
min; i<=
max; ++i)
1033 smoothers[i].initialize(m[i], data);
1039 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1040 template <
typename MatrixType2,
class DATA>
1054 matrices.resize(
min,
max);
1055 smoothers.resize(
min,
max);
1057 for (
unsigned int i=
min; i<=
max; ++i)
1064 smoothers[i].initialize(m[i], data[i]);
1070 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1071 template <
typename MatrixType2,
class DATA>
1076 const unsigned int row,
1077 const unsigned int col)
1082 matrices.resize(
min,
max);
1083 smoothers.resize(
min,
max);
1085 for (
unsigned int i=
min; i<=
max; ++i)
1087 matrices[i] = &(m[i].block(row, col));
1088 smoothers[i].initialize(m[i].block(row, col), data);
1094 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1095 template <
typename MatrixType2,
class DATA>
1100 const unsigned int row,
1101 const unsigned int col)
1111 matrices.resize(
min,
max);
1112 smoothers.resize(
min,
max);
1114 for (
unsigned int i=
min; i<=
max; ++i)
1116 matrices[i] = &(m[i].block(row, col));
1117 smoothers[i].initialize(m[i].block(row, col), data[i]);
1123 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1126 (
const unsigned int level,
1128 const VectorType &rhs)
const 1130 unsigned int maxlevel = matrices.max_level();
1131 unsigned int steps2 = this->steps;
1134 steps2 *= (1<<(maxlevel-level));
1143 if (this->symmetric && (steps2 % 2 == 0))
1145 if (this->debug > 0)
1146 deallog <<
'S' << level <<
' ';
1148 for (
unsigned int i=0; i<steps2; ++i)
1152 if (this->debug > 0)
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() <<
' ';
1164 if (this->debug > 0)
1166 matrices[level].vmult(*r,u);
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() <<
' ';
1175 if (this->symmetric)
1178 if (this->debug > 0)
1179 deallog << std::endl;
1184 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1187 (
const unsigned int level,
1189 const VectorType &rhs)
const 1191 unsigned int maxlevel = matrices.max_level();
1192 unsigned int steps2 = this->steps;
1195 steps2 *= (1<<(maxlevel-level));
1198 if (this->symmetric && (steps2 % 2 == 0))
1200 if (this->debug > 0)
1201 deallog <<
'S' << level <<
' ';
1204 if (this->debug > 2)
1205 deallog <<
' ' << rhs.l2_norm() <<
' ';
1206 if (this->debug > 0)
1207 deallog << (T ?
'T' :
'N');
1209 smoothers[level].Tvmult(u, rhs);
1211 smoothers[level].vmult(u, rhs);
1212 if (this->debug > 1)
1213 deallog <<
' ' << u.l2_norm() <<
' ';
1214 if (this->symmetric)
1226 for (
unsigned int i=1; i<steps2; ++i)
1230 if (this->debug > 0)
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() <<
' ';
1242 if (this->debug > 0)
1244 matrices[level].vmult(*r,u);
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() <<
' ';
1253 if (this->symmetric)
1256 if (this->debug > 0)
1257 deallog << std::endl;
1262 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1268 return sizeof(*this)
1269 + matrices.memory_consumption()
1270 + smoothers.memory_consumption()
1271 + this->vector_memory.memory_consumption();
1277 DEAL_II_NAMESPACE_CLOSE
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)
MGLevelObject< LinearOperator< VectorType > > matrices
void set_transpose(const bool)
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)
SmootherRelaxation(const unsigned int steps=1, const bool variable=false, const bool symmetric=false, const bool transpose=false)
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
unsigned int min_level() const
void set_debug(const unsigned int level)
MGLevelObject< PreconditionerType > smoothers
VectorizedArray< Number > min(const ::VectorizedArray< Number > &x, const ::VectorizedArray< Number > &y)
std::size_t memory_consumption() const
#define Assert(cond, exc)
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
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
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())
virtual void apply(const unsigned int level, VectorType &u, const VectorType &rhs) const
VectorizedArray< Number > max(const ::VectorizedArray< Number > &x, const ::VectorizedArray< Number > &y)
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