16#ifndef dealii_mg_smoother_h
17#define dealii_mg_smoother_h
47template <
typename VectorType>
137template <
typename VectorType>
147 smooth(
const unsigned int level, VectorType &u,
const VectorType &rhs)
const;
182 template <
class RelaxationType,
typename VectorType>
203 template <
typename MatrixType2>
206 const typename RelaxationType::AdditionalData &additional_data =
207 typename RelaxationType::AdditionalData());
216 template <
typename MatrixType2,
class DATA>
233 const VectorType & rhs)
const override;
254 const VectorType & rhs)
const override;
293template <
typename MatrixType,
class RelaxationType,
typename VectorType>
313 template <
typename MatrixType2>
316 const typename RelaxationType::AdditionalData &additional_data =
317 typename RelaxationType::AdditionalData());
327 template <
typename MatrixType2,
class DATA>
341 template <
typename MatrixType2,
class DATA>
344 const DATA & additional_data,
345 const unsigned int block_row,
346 const unsigned int block_col);
357 template <
typename MatrixType2,
class DATA>
361 const unsigned int block_row,
362 const unsigned int block_col);
374 smooth(
const unsigned int level, VectorType &u,
const VectorType &rhs)
const;
392 apply(
const unsigned int level, VectorType &u,
const VectorType &rhs)
const;
443template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
464 template <
typename MatrixType2>
467 const typename PreconditionerType::AdditionalData &
468 additional_data =
typename PreconditionerType::AdditionalData());
479 template <
typename MatrixType2,
class DATA>
494 template <
typename MatrixType2,
class DATA>
497 const DATA & additional_data,
498 const unsigned int block_row,
499 const unsigned int block_col);
511 template <
typename MatrixType2,
class DATA>
515 const unsigned int block_row,
516 const unsigned int block_col);
530 const VectorType & rhs)
const override;
550 const VectorType & rhs)
const override;
578template <
typename VectorType>
582 const VectorType &)
const
585template <
typename VectorType>
592template <
typename VectorType>
605template <
typename VectorType>
613template <
typename VectorType>
621template <
typename VectorType>
629template <
typename VectorType>
637template <
typename VectorType>
648 template <
class RelaxationType,
typename VectorType>
650 const unsigned int steps,
658 template <
class RelaxationType,
typename VectorType>
660 SmootherRelaxation<RelaxationType, VectorType>::clear()
666 template <
class RelaxationType,
typename VectorType>
667 template <
typename MatrixType2>
669 SmootherRelaxation<RelaxationType, VectorType>::initialize(
671 const typename RelaxationType::AdditionalData &data)
678 for (
unsigned int i =
min; i <=
max; ++i)
679 (*
this)[i].initialize(m[i], data);
683 template <
class RelaxationType,
typename VectorType>
684 template <
typename MatrixType2,
class DATA>
686 SmootherRelaxation<RelaxationType, VectorType>::initialize(
695 for (
unsigned int i =
min; i <=
max; ++i)
696 (*
this)[i].initialize(m[i], data[i]);
700 template <
class RelaxationType,
typename VectorType>
702 SmootherRelaxation<RelaxationType, VectorType>::smooth(
703 const unsigned int level,
705 const VectorType & rhs)
const
707 unsigned int maxlevel = this->max_level();
708 unsigned int steps2 = this->steps;
711 steps2 *= (1 << (maxlevel -
level));
714 if (this->
symmetric && (steps2 % 2 == 0))
719 for (
unsigned int i = 0; i < steps2; ++i)
722 (*this)[
level].Tstep(u, rhs);
724 (*
this)[
level].step(u, rhs);
731 template <
class RelaxationType,
typename VectorType>
733 SmootherRelaxation<RelaxationType, VectorType>::apply(
734 const unsigned int level,
736 const VectorType & rhs)
const
738 unsigned int maxlevel = this->max_level();
739 unsigned int steps2 = this->steps;
742 steps2 *= (1 << (maxlevel -
level));
745 if (this->
symmetric && (steps2 % 2 == 0))
751 (*this)[
level].Tvmult(u, rhs);
753 (*
this)[
level].vmult(u, rhs);
756 for (
unsigned int i = 1; i < steps2; ++i)
759 (*this)[
level].Tstep(u, rhs);
761 (*
this)[
level].step(u, rhs);
768 template <
class RelaxationType,
typename VectorType>
781template <
typename MatrixType,
class RelaxationType,
typename VectorType>
792template <
typename MatrixType,
class RelaxationType,
typename VectorType>
796 smoothers.clear_elements();
798 unsigned int i = matrices.min_level(), max_level = matrices.max_level();
799 for (; i <= max_level; ++i)
804template <
typename MatrixType,
class RelaxationType,
typename VectorType>
805template <
typename MatrixType2>
809 const typename RelaxationType::AdditionalData &data)
814 matrices.resize(
min,
max);
815 smoothers.resize(
min,
max);
817 for (
unsigned int i =
min; i <=
max; ++i)
824 smoothers[i].initialize(m[i], data);
828template <
typename MatrixType,
class RelaxationType,
typename VectorType>
829template <
typename MatrixType2,
class DATA>
841 matrices.resize(
min,
max);
842 smoothers.resize(
min,
max);
844 for (
unsigned int i =
min; i <=
max; ++i)
851 smoothers[i].initialize(m[i], data[i]);
855template <
typename MatrixType,
class RelaxationType,
typename VectorType>
856template <
typename MatrixType2,
class DATA>
861 const unsigned int row,
862 const unsigned int col)
867 matrices.resize(
min,
max);
868 smoothers.resize(
min,
max);
870 for (
unsigned int i =
min; i <=
max; ++i)
876 m[i].block(row, col));
877 smoothers[i].initialize(m[i].block(row, col), data);
881template <
typename MatrixType,
class RelaxationType,
typename VectorType>
882template <
typename MatrixType2,
class DATA>
887 const unsigned int row,
888 const unsigned int col)
896 matrices.resize(
min,
max);
897 smoothers.resize(
min,
max);
899 for (
unsigned int i =
min; i <=
max; ++i)
905 m[i].block(row, col));
906 smoothers[i].initialize(m[i].block(row, col), data[i]);
911template <
typename MatrixType,
class RelaxationType,
typename VectorType>
914 const unsigned int level,
916 const VectorType & rhs)
const
918 unsigned int maxlevel = smoothers.max_level();
919 unsigned int steps2 = this->steps;
922 steps2 *= (1 << (maxlevel -
level));
925 if (this->
symmetric && (steps2 % 2 == 0))
930 for (
unsigned int i = 0; i < steps2; ++i)
933 smoothers[
level].Tstep(u, rhs);
935 smoothers[
level].step(u, rhs);
942template <
typename MatrixType,
class RelaxationType,
typename VectorType>
945 const unsigned int level,
947 const VectorType & rhs)
const
949 unsigned int maxlevel = smoothers.max_level();
950 unsigned int steps2 = this->steps;
953 steps2 *= (1 << (maxlevel -
level));
956 if (this->
symmetric && (steps2 % 2 == 0))
962 smoothers[
level].Tvmult(u, rhs);
964 smoothers[
level].vmult(u, rhs);
967 for (
unsigned int i = 1; i < steps2; ++i)
970 smoothers[
level].Tstep(u, rhs);
972 smoothers[
level].step(u, rhs);
980template <
typename MatrixType,
class RelaxationType,
typename VectorType>
985 return sizeof(*this) + matrices.memory_consumption() +
986 smoothers.memory_consumption() +
987 this->vector_memory.memory_consumption();
993template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1004template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1008 smoothers.clear_elements();
1010 unsigned int i = matrices.min_level(), max_level = matrices.max_level();
1011 for (; i <= max_level; ++i)
1017template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1018template <
typename MatrixType2>
1022 const typename PreconditionerType::AdditionalData &data)
1027 matrices.resize(
min,
max);
1028 smoothers.resize(
min,
max);
1030 for (
unsigned int i =
min; i <=
max; ++i)
1037 smoothers[i].initialize(m[i], data);
1043template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1044template <
typename MatrixType2,
class DATA>
1056 matrices.resize(
min,
max);
1057 smoothers.resize(
min,
max);
1059 for (
unsigned int i =
min; i <=
max; ++i)
1073template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1074template <
typename MatrixType2,
class DATA>
1079 const unsigned int row,
1080 const unsigned int col)
1085 matrices.resize(
min,
max);
1086 smoothers.resize(
min,
max);
1088 for (
unsigned int i =
min; i <=
max; ++i)
1090 matrices[i] = &(m[i].block(row, col));
1091 smoothers[i].initialize(m[i].block(row, col), data);
1097template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1098template <
typename MatrixType2,
class DATA>
1103 const unsigned int row,
1104 const unsigned int col)
1112 matrices.resize(
min,
max);
1113 smoothers.resize(
min,
max);
1115 for (
unsigned int i =
min; i <=
max; ++i)
1117 matrices[i] = &(m[i].block(row, col));
1118 smoothers[i].initialize(m[i].block(row, col), data[i]);
1124template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1127 const unsigned int level,
1129 const VectorType & rhs)
const
1131 unsigned int maxlevel = matrices.max_level();
1132 unsigned int steps2 = this->steps;
1135 steps2 *= (1 << (maxlevel -
level));
1144 if (this->
symmetric && (steps2 % 2 == 0))
1146 if (this->debug > 0)
1149 for (
unsigned int i = 0; i < steps2; ++i)
1153 if (this->debug > 0)
1155 matrices[
level].Tvmult(*r, u);
1156 r->sadd(-1., 1., rhs);
1157 if (this->debug > 2)
1158 deallog <<
' ' << r->l2_norm() <<
' ';
1159 smoothers[
level].Tvmult(*
d, *r);
1160 if (this->debug > 1)
1161 deallog <<
' ' <<
d->l2_norm() <<
' ';
1165 if (this->debug > 0)
1167 matrices[
level].vmult(*r, u);
1169 if (this->debug > 2)
1170 deallog <<
' ' << r->l2_norm() <<
' ';
1171 smoothers[
level].vmult(*
d, *r);
1172 if (this->debug > 1)
1173 deallog <<
' ' <<
d->l2_norm() <<
' ';
1179 if (this->debug > 0)
1185template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1188 const unsigned int level,
1190 const VectorType & rhs)
const
1192 unsigned int maxlevel = matrices.max_level();
1193 unsigned int steps2 = this->steps;
1196 steps2 *= (1 << (maxlevel -
level));
1199 if (this->
symmetric && (steps2 % 2 == 0))
1201 if (this->debug > 0)
1205 if (this->debug > 2)
1206 deallog <<
' ' << rhs.l2_norm() <<
' ';
1207 if (this->debug > 0)
1210 smoothers[
level].Tvmult(u, rhs);
1212 smoothers[
level].vmult(u, rhs);
1213 if (this->debug > 1)
1214 deallog <<
' ' << u.l2_norm() <<
' ';
1227 for (
unsigned int i = 1; i < steps2; ++i)
1231 if (this->debug > 0)
1233 matrices[
level].Tvmult(*r, u);
1234 r->sadd(-1., 1., rhs);
1235 if (this->debug > 2)
1236 deallog <<
' ' << r->l2_norm() <<
' ';
1237 smoothers[
level].Tvmult(*
d, *r);
1238 if (this->debug > 1)
1239 deallog <<
' ' <<
d->l2_norm() <<
' ';
1243 if (this->debug > 0)
1245 matrices[
level].vmult(*r, u);
1247 if (this->debug > 2)
1248 deallog <<
' ' << r->l2_norm() <<
' ';
1249 smoothers[
level].vmult(*
d, *r);
1250 if (this->debug > 1)
1251 deallog <<
' ' <<
d->l2_norm() <<
' ';
1257 if (this->debug > 0)
1263template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1268 return sizeof(*this) + matrices.memory_consumption() +
1269 smoothers.memory_consumption() +
1270 this->vector_memory.memory_consumption();
std::size_t memory_consumption() const
unsigned int max_level() const
unsigned int min_level() const
virtual void smooth(const unsigned int level, VectorType &u, const VectorType &rhs) const
std::size_t memory_consumption() const
MGLevelObject< PreconditionerType > smoothers
virtual void smooth(const unsigned int level, VectorType &u, const VectorType &rhs) const override
void initialize(const MGLevelObject< MatrixType2 > &matrices, const typename PreconditionerType::AdditionalData &additional_data=typename PreconditionerType::AdditionalData())
virtual void apply(const unsigned int level, VectorType &u, const VectorType &rhs) const override
void initialize(const MGLevelObject< MatrixType2 > &matrices, const MGLevelObject< DATA > &additional_data, const unsigned int block_row, const unsigned int block_col)
void initialize(const MGLevelObject< MatrixType2 > &matrices, const DATA &additional_data, const unsigned int block_row, const unsigned int block_col)
MGLevelObject< LinearOperator< VectorType > > matrices
MGSmootherPrecondition(const unsigned int steps=1, const bool variable=false, const bool symmetric=false, const bool transpose=false)
void initialize(const MGLevelObject< MatrixType2 > &matrices, const MGLevelObject< DATA > &additional_data)
virtual void smooth(const unsigned int level, VectorType &u, const VectorType &rhs) const
MGLevelObject< LinearOperator< VectorType > > matrices
void initialize(const MGLevelObject< MatrixType2 > &matrices, const DATA &additional_data, const unsigned int block_row, const unsigned int block_col)
void initialize(const MGLevelObject< MatrixType2 > &matrices, const MGLevelObject< DATA > &additional_data, const unsigned int block_row, const unsigned int block_col)
std::size_t memory_consumption() const
virtual void apply(const unsigned int level, VectorType &u, const VectorType &rhs) const
MGLevelObject< RelaxationType > smoothers
void initialize(const MGLevelObject< MatrixType2 > &matrices, const MGLevelObject< DATA > &additional_data)
MGSmootherRelaxation(const unsigned int steps=1, const bool variable=false, const bool symmetric=false, const bool transpose=false)
void initialize(const MGLevelObject< MatrixType2 > &matrices, const typename RelaxationType::AdditionalData &additional_data=typename RelaxationType::AdditionalData())
GrowingVectorMemory< VectorType > vector_memory
MGSmoother(const unsigned int steps=1, const bool variable=false, const bool symmetric=false, const bool transpose=false)
void set_debug(const unsigned int level)
void set_steps(const unsigned int)
void set_symmetric(const bool)
void set_transpose(const bool)
void set_variable(const bool)
VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &x, const ::VectorizedArray< Number, width > &y)
VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &x, const ::VectorizedArray< Number, width > &y)
std::size_t memory_consumption() const
SmootherRelaxation(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 override
virtual void apply(const unsigned int level, VectorType &u, const VectorType &rhs) const override
void initialize(const MGLevelObject< MatrixType2 > &matrices, const MGLevelObject< DATA > &additional_data)
void initialize(const MGLevelObject< MatrixType2 > &matrices, const typename RelaxationType::AdditionalData &additional_data=typename RelaxationType::AdditionalData())
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
@ symmetric
Matrix is symmetric.
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
T & get_underlying_value(T &p)
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)