16 #ifndef dealii_mg_smoother_h 17 #define dealii_mg_smoother_h 47 template <
typename VectorType>
137 template <
typename VectorType>
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>
252 apply(
const unsigned int level,
293 template <
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);
443 template <
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);
548 apply(
const unsigned int level,
578 template <
typename VectorType>
585 template <
typename VectorType>
592 template <
typename VectorType>
605 template <
typename VectorType>
613 template <
typename VectorType>
621 template <
typename VectorType>
629 template <
typename VectorType>
637 template <
typename VectorType>
648 template <
class RelaxationType,
typename VectorType>
649 inline SmootherRelaxation<RelaxationType, VectorType>::SmootherRelaxation(
650 const unsigned int steps,
652 const bool symmetric,
653 const bool transpose)
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)
676 this->resize(min, max);
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(
693 this->resize(min, max);
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,
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))
717 deallog <<
'S' << level <<
' ';
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>
734 const unsigned int level,
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))
748 deallog <<
'S' << level <<
' ';
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>
781 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
785 const bool symmetric,
786 const bool transpose)
792 template <
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)
804 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
805 template <
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);
828 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
829 template <
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]);
855 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
856 template <
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);
881 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
882 template <
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]);
911 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
914 const unsigned int level,
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))
928 deallog <<
'S' << level <<
' ';
930 for (
unsigned int i = 0; i < steps2; ++i)
933 smoothers[
level].Tstep(u, rhs);
935 smoothers[
level].step(u, rhs);
942 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
945 const unsigned int level,
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))
959 deallog <<
'S' << level <<
' ';
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);
980 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
985 return sizeof(*this) + matrices.memory_consumption() +
986 smoothers.memory_consumption() +
993 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
997 const bool symmetric,
998 const bool transpose)
1004 template <
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)
1017 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1018 template <
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);
1043 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1044 template <
typename MatrixType2,
class DATA>
1056 matrices.resize(min, max);
1057 smoothers.resize(min, max);
1059 for (
unsigned int i = min; i <=
max; ++i)
1073 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1074 template <
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);
1097 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1098 template <
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]);
1124 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1127 const unsigned int level,
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)
1147 deallog <<
'S' << level <<
' ';
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() <<
' ';
1176 if (this->symmetric)
1179 if (this->
debug > 0)
1185 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1188 const unsigned int level,
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)
1202 deallog <<
'S' << level <<
' ';
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() <<
' ';
1215 if (this->symmetric)
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() <<
' ';
1254 if (this->symmetric)
1257 if (this->
debug > 0)
1263 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1268 return sizeof(*this) + matrices.memory_consumption() +
1269 smoothers.memory_consumption() +
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)
void set_symmetric(const bool)
T & get_underlying_value(T &p)
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
MGLevelObject< RelaxationType > smoothers
unsigned int min_level() const
void set_debug(const unsigned int level)
MGLevelObject< PreconditionerType > smoothers
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
auto apply(F &&fn, Tuple &&t) -> decltype(apply_impl(std::forward< F >(fn), std::forward< Tuple >(t), std::make_index_sequence< std::tuple_size< typename std::remove_reference< Tuple >::type >::value >()))
#define DEAL_II_NAMESPACE_CLOSE
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())
std::size_t memory_consumption() const
virtual void smooth(const unsigned int level, VectorType &u, const VectorType &rhs) const =0
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
virtual void apply(const unsigned int level, VectorType &u, const VectorType &rhs) const
#define DEAL_II_NAMESPACE_OPEN
T min(const T &t, const MPI_Comm &mpi_communicator)
virtual void apply(const unsigned int level, VectorType &u, const VectorType &rhs) const override
virtual void smooth(const unsigned int level, VectorType &u, const VectorType &rhs) const override
T max(const T &t, const MPI_Comm &mpi_communicator)
void initialize(const MGLevelObject< MatrixType2 > &matrices, const typename PreconditionerType::AdditionalData &additional_data=typename PreconditionerType::AdditionalData())
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
virtual void smooth(const unsigned int level, VectorType &u, const VectorType &rhs) const