16#ifndef dealii_mg_smoother_h
17#define dealii_mg_smoother_h
49template <
typename VectorType>
139template <
typename VectorType>
149 smooth(
const unsigned int level, VectorType &u,
const VectorType &rhs)
const;
184 template <
class RelaxationType,
typename VectorType>
205 template <
typename MatrixType2>
208 const typename RelaxationType::AdditionalData &additional_data =
209 typename RelaxationType::AdditionalData());
218 template <
typename MatrixType2,
class DATA>
235 const VectorType & rhs)
const override;
256 const VectorType & rhs)
const override;
295template <
typename MatrixType,
class RelaxationType,
typename VectorType>
315 template <
typename MatrixType2>
318 const typename RelaxationType::AdditionalData &additional_data =
319 typename RelaxationType::AdditionalData());
329 template <
typename MatrixType2,
class DATA>
343 template <
typename MatrixType2,
class DATA>
346 const DATA & additional_data,
347 const unsigned int block_row,
348 const unsigned int block_col);
359 template <
typename MatrixType2,
class DATA>
363 const unsigned int block_row,
364 const unsigned int block_col);
376 smooth(
const unsigned int level, VectorType &u,
const VectorType &rhs)
const;
394 apply(
const unsigned int level, VectorType &u,
const VectorType &rhs)
const;
445template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
466 template <
typename MatrixType2>
469 const typename PreconditionerType::AdditionalData &
470 additional_data =
typename PreconditionerType::AdditionalData());
479 template <
typename MatrixType2>
492 template <
typename MatrixType2,
class DATA>
507 template <
typename MatrixType2,
class DATA>
510 const DATA & additional_data,
511 const unsigned int block_row,
512 const unsigned int block_col);
524 template <
typename MatrixType2,
class DATA>
528 const unsigned int block_row,
529 const unsigned int block_col);
543 const VectorType & rhs)
const override;
563 const VectorType & rhs)
const override;
591template <
typename VectorType>
595 const VectorType &)
const
598template <
typename VectorType>
605template <
typename VectorType>
608 const bool symmetric,
618template <
typename VectorType>
626template <
typename VectorType>
634template <
typename VectorType>
642template <
typename VectorType>
650template <
typename VectorType>
661 template <
class RelaxationType,
typename VectorType>
663 const unsigned int steps,
665 const bool symmetric,
671 template <
class RelaxationType,
typename VectorType>
673 SmootherRelaxation<RelaxationType, VectorType>::clear()
679 template <
class RelaxationType,
typename VectorType>
680 template <
typename MatrixType2>
682 SmootherRelaxation<RelaxationType, VectorType>::initialize(
684 const typename RelaxationType::AdditionalData &data)
689 this->resize(min, max);
691 for (
unsigned int i = min; i <=
max; ++i)
692 (*
this)[i].initialize(m[i], data);
696 template <
class RelaxationType,
typename VectorType>
697 template <
typename MatrixType2,
class DATA>
699 SmootherRelaxation<RelaxationType, VectorType>::initialize(
706 this->resize(min, max);
708 for (
unsigned int i = min; i <=
max; ++i)
709 (*
this)[i].initialize(m[i], data[i]);
713 template <
class RelaxationType,
typename VectorType>
715 SmootherRelaxation<RelaxationType, VectorType>::smooth(
716 const unsigned int level,
718 const VectorType & rhs)
const
720 unsigned int maxlevel = this->max_level();
721 unsigned int steps2 = this->steps;
724 steps2 *= (1 << (maxlevel -
level));
727 if (this->symmetric && (steps2 % 2 == 0))
732 for (
unsigned int i = 0; i < steps2; ++i)
735 (*this)[
level].Tstep(u, rhs);
737 (*
this)[
level].step(u, rhs);
744 template <
class RelaxationType,
typename VectorType>
746 SmootherRelaxation<RelaxationType, VectorType>::apply(
747 const unsigned int level,
749 const VectorType & rhs)
const
751 unsigned int maxlevel = this->max_level();
752 unsigned int steps2 = this->steps;
755 steps2 *= (1 << (maxlevel -
level));
758 if (this->symmetric && (steps2 % 2 == 0))
764 (*this)[
level].Tvmult(u, rhs);
766 (*
this)[
level].vmult(u, rhs);
769 for (
unsigned int i = 1; i < steps2; ++i)
772 (*this)[
level].Tstep(u, rhs);
774 (*
this)[
level].step(u, rhs);
781 template <
class RelaxationType,
typename VectorType>
783 SmootherRelaxation<RelaxationType, VectorType>::memory_consumption()
const
794template <
typename MatrixType,
class RelaxationType,
typename VectorType>
798 const bool symmetric,
805template <
typename MatrixType,
class RelaxationType,
typename VectorType>
809 smoothers.clear_elements();
811 unsigned int i = matrices.min_level(), max_level = matrices.max_level();
812 for (; i <= max_level; ++i)
817template <
typename MatrixType,
class RelaxationType,
typename VectorType>
818template <
typename MatrixType2>
822 const typename RelaxationType::AdditionalData &data)
827 matrices.resize(min, max);
828 smoothers.resize(min, max);
830 for (
unsigned int i = min; i <=
max; ++i)
837 smoothers[i].initialize(m[i], data);
841template <
typename MatrixType,
class RelaxationType,
typename VectorType>
842template <
typename MatrixType2,
class DATA>
854 matrices.resize(min, max);
855 smoothers.resize(min, max);
857 for (
unsigned int i = min; i <=
max; ++i)
864 smoothers[i].initialize(m[i], data[i]);
868template <
typename MatrixType,
class RelaxationType,
typename VectorType>
869template <
typename MatrixType2,
class DATA>
874 const unsigned int row,
875 const unsigned int col)
880 matrices.resize(min, max);
881 smoothers.resize(min, max);
883 for (
unsigned int i = min; i <=
max; ++i)
889 m[i].block(row, col));
890 smoothers[i].initialize(m[i].block(row, col), data);
894template <
typename MatrixType,
class RelaxationType,
typename VectorType>
895template <
typename MatrixType2,
class DATA>
900 const unsigned int row,
901 const unsigned int col)
909 matrices.resize(min, max);
910 smoothers.resize(min, max);
912 for (
unsigned int i = min; i <=
max; ++i)
918 m[i].block(row, col));
919 smoothers[i].initialize(m[i].block(row, col), data[i]);
924template <
typename MatrixType,
class RelaxationType,
typename VectorType>
927 const unsigned int level,
929 const VectorType & rhs)
const
931 unsigned int maxlevel = smoothers.max_level();
932 unsigned int steps2 = this->steps;
935 steps2 *= (1 << (maxlevel -
level));
938 if (this->symmetric && (steps2 % 2 == 0))
943 for (
unsigned int i = 0; i < steps2; ++i)
946 smoothers[
level].Tstep(u, rhs);
948 smoothers[
level].step(u, rhs);
955template <
typename MatrixType,
class RelaxationType,
typename VectorType>
958 const unsigned int level,
960 const VectorType & rhs)
const
962 unsigned int maxlevel = smoothers.max_level();
963 unsigned int steps2 = this->steps;
966 steps2 *= (1 << (maxlevel -
level));
969 if (this->symmetric && (steps2 % 2 == 0))
975 smoothers[
level].Tvmult(u, rhs);
977 smoothers[
level].vmult(u, rhs);
980 for (
unsigned int i = 1; i < steps2; ++i)
983 smoothers[
level].Tstep(u, rhs);
985 smoothers[
level].step(u, rhs);
993template <
typename MatrixType,
class RelaxationType,
typename VectorType>
998 return sizeof(*this) + matrices.memory_consumption() +
999 smoothers.memory_consumption() +
1000 this->vector_memory.memory_consumption();
1006template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1009 const bool variable,
1010 const bool symmetric,
1017template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1021 smoothers.clear_elements();
1023 unsigned int i = matrices.min_level(), max_level = matrices.max_level();
1024 for (; i <= max_level; ++i)
1030template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1031template <
typename MatrixType2>
1035 const typename PreconditionerType::AdditionalData &data)
1040 matrices.resize(min, max);
1041 smoothers.resize(min, max);
1043 for (
unsigned int i = min; i <=
max; ++i)
1057template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1058template <
typename MatrixType2>
1066 matrices.resize(min, max);
1067 smoothers.resize(min, max);
1069 for (
unsigned int i = min; i <=
max; ++i)
1082template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1083template <
typename MatrixType2,
class DATA>
1095 matrices.resize(min, max);
1096 smoothers.resize(min, max);
1098 for (
unsigned int i = min; i <=
max; ++i)
1112template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1113template <
typename MatrixType2,
class DATA>
1118 const unsigned int row,
1119 const unsigned int col)
1124 matrices.resize(min, max);
1125 smoothers.resize(min, max);
1127 for (
unsigned int i = min; i <=
max; ++i)
1129 matrices[i] = &(m[i].block(row, col));
1130 smoothers[i].initialize(m[i].block(row, col), data);
1136template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1137template <
typename MatrixType2,
class DATA>
1142 const unsigned int row,
1143 const unsigned int col)
1151 matrices.resize(min, max);
1152 smoothers.resize(min, max);
1154 for (
unsigned int i = min; i <=
max; ++i)
1156 matrices[i] = &(m[i].block(row, col));
1157 smoothers[i].initialize(m[i].block(row, col), data[i]);
1163template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1166 const unsigned int level,
1168 const VectorType & rhs)
const
1170 unsigned int maxlevel = matrices.max_level();
1171 unsigned int steps2 = this->steps;
1174 steps2 *= (1 << (maxlevel -
level));
1183 if (this->symmetric && (steps2 % 2 == 0))
1185 if (this->debug > 0)
1188 for (
unsigned int i = 0; i < steps2; ++i)
1192 if (this->debug > 0)
1194 matrices[
level].Tvmult(*r, u);
1195 r->sadd(-1., 1., rhs);
1196 if (this->debug > 2)
1197 deallog <<
' ' << r->l2_norm() <<
' ';
1198 smoothers[
level].Tvmult(*d, *r);
1199 if (this->debug > 1)
1200 deallog <<
' ' <<
d->l2_norm() <<
' ';
1204 if (this->debug > 0)
1206 matrices[
level].vmult(*r, u);
1208 if (this->debug > 2)
1209 deallog <<
' ' << r->l2_norm() <<
' ';
1210 smoothers[
level].vmult(*d, *r);
1211 if (this->debug > 1)
1212 deallog <<
' ' <<
d->l2_norm() <<
' ';
1215 if (this->symmetric)
1218 if (this->debug > 0)
1224template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1227 const unsigned int level,
1229 const VectorType & rhs)
const
1231 unsigned int maxlevel = matrices.max_level();
1232 unsigned int steps2 = this->steps;
1235 steps2 *= (1 << (maxlevel -
level));
1238 if (this->symmetric && (steps2 % 2 == 0))
1240 if (this->debug > 0)
1244 if (this->debug > 2)
1245 deallog <<
' ' << rhs.l2_norm() <<
' ';
1246 if (this->debug > 0)
1249 smoothers[
level].Tvmult(u, rhs);
1251 smoothers[
level].vmult(u, rhs);
1252 if (this->debug > 1)
1253 deallog <<
' ' << u.l2_norm() <<
' ';
1254 if (this->symmetric)
1266 for (
unsigned int i = 1; i < steps2; ++i)
1270 if (this->debug > 0)
1272 matrices[
level].Tvmult(*r, u);
1273 r->sadd(-1., 1., rhs);
1274 if (this->debug > 2)
1275 deallog <<
' ' << r->l2_norm() <<
' ';
1276 smoothers[
level].Tvmult(*d, *r);
1277 if (this->debug > 1)
1278 deallog <<
' ' <<
d->l2_norm() <<
' ';
1282 if (this->debug > 0)
1284 matrices[
level].vmult(*r, u);
1286 if (this->debug > 2)
1287 deallog <<
' ' << r->l2_norm() <<
' ';
1288 smoothers[
level].vmult(*d, *r);
1289 if (this->debug > 1)
1290 deallog <<
' ' <<
d->l2_norm() <<
' ';
1293 if (this->symmetric)
1296 if (this->debug > 0)
1302template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1307 return sizeof(*this) + matrices.memory_consumption() +
1308 smoothers.memory_consumption() +
1309 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
void initialize_matrices(const MGLevelObject< MatrixType2 > &matrices)
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)
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.
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 > &)