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());
477 template <
typename MatrixType2>
490 template <
typename MatrixType2,
class DATA>
505 template <
typename MatrixType2,
class DATA>
508 const DATA & additional_data,
509 const unsigned int block_row,
510 const unsigned int block_col);
522 template <
typename MatrixType2,
class DATA>
526 const unsigned int block_row,
527 const unsigned int block_col);
541 const VectorType & rhs)
const override;
561 const VectorType & rhs)
const override;
589template <
typename VectorType>
593 const VectorType &)
const
596template <
typename VectorType>
603template <
typename VectorType>
606 const bool symmetric,
616template <
typename VectorType>
624template <
typename VectorType>
632template <
typename VectorType>
640template <
typename VectorType>
648template <
typename VectorType>
659 template <
class RelaxationType,
typename VectorType>
661 const unsigned int steps,
663 const bool symmetric,
669 template <
class RelaxationType,
typename VectorType>
671 SmootherRelaxation<RelaxationType, VectorType>::clear()
677 template <
class RelaxationType,
typename VectorType>
678 template <
typename MatrixType2>
680 SmootherRelaxation<RelaxationType, VectorType>::initialize(
682 const typename RelaxationType::AdditionalData &data)
687 this->resize(min, max);
689 for (
unsigned int i = min; i <=
max; ++i)
690 (*
this)[i].initialize(m[i], data);
694 template <
class RelaxationType,
typename VectorType>
695 template <
typename MatrixType2,
class DATA>
697 SmootherRelaxation<RelaxationType, VectorType>::initialize(
704 this->resize(min, max);
706 for (
unsigned int i = min; i <=
max; ++i)
707 (*
this)[i].initialize(m[i], data[i]);
711 template <
class RelaxationType,
typename VectorType>
713 SmootherRelaxation<RelaxationType, VectorType>::smooth(
714 const unsigned int level,
716 const VectorType & rhs)
const
718 unsigned int maxlevel = this->max_level();
719 unsigned int steps2 = this->steps;
722 steps2 *= (1 << (maxlevel -
level));
725 if (this->symmetric && (steps2 % 2 == 0))
730 for (
unsigned int i = 0; i < steps2; ++i)
733 (*this)[
level].Tstep(u, rhs);
735 (*
this)[
level].step(u, rhs);
742 template <
class RelaxationType,
typename VectorType>
744 SmootherRelaxation<RelaxationType, VectorType>::apply(
745 const unsigned int level,
747 const VectorType & rhs)
const
749 unsigned int maxlevel = this->max_level();
750 unsigned int steps2 = this->steps;
753 steps2 *= (1 << (maxlevel -
level));
756 if (this->symmetric && (steps2 % 2 == 0))
762 (*this)[
level].Tvmult(u, rhs);
764 (*
this)[
level].vmult(u, rhs);
767 for (
unsigned int i = 1; i < steps2; ++i)
770 (*this)[
level].Tstep(u, rhs);
772 (*
this)[
level].step(u, rhs);
779 template <
class RelaxationType,
typename VectorType>
781 SmootherRelaxation<RelaxationType, VectorType>::memory_consumption()
const
792template <
typename MatrixType,
class RelaxationType,
typename VectorType>
796 const bool symmetric,
803template <
typename MatrixType,
class RelaxationType,
typename VectorType>
807 smoothers.clear_elements();
809 unsigned int i = matrices.min_level(), max_level = matrices.max_level();
810 for (; i <= max_level; ++i)
815template <
typename MatrixType,
class RelaxationType,
typename VectorType>
816template <
typename MatrixType2>
820 const typename RelaxationType::AdditionalData &data)
825 matrices.resize(min, max);
826 smoothers.resize(min, max);
828 for (
unsigned int i = min; i <=
max; ++i)
835 smoothers[i].initialize(m[i], data);
839template <
typename MatrixType,
class RelaxationType,
typename VectorType>
840template <
typename MatrixType2,
class DATA>
852 matrices.resize(min, max);
853 smoothers.resize(min, max);
855 for (
unsigned int i = min; i <=
max; ++i)
862 smoothers[i].initialize(m[i], data[i]);
866template <
typename MatrixType,
class RelaxationType,
typename VectorType>
867template <
typename MatrixType2,
class DATA>
872 const unsigned int row,
873 const unsigned int col)
878 matrices.resize(min, max);
879 smoothers.resize(min, max);
881 for (
unsigned int i = min; i <=
max; ++i)
887 m[i].block(row, col));
888 smoothers[i].initialize(m[i].block(row, col), data);
892template <
typename MatrixType,
class RelaxationType,
typename VectorType>
893template <
typename MatrixType2,
class DATA>
898 const unsigned int row,
899 const unsigned int col)
907 matrices.resize(min, max);
908 smoothers.resize(min, max);
910 for (
unsigned int i = min; i <=
max; ++i)
916 m[i].block(row, col));
917 smoothers[i].initialize(m[i].block(row, col), data[i]);
922template <
typename MatrixType,
class RelaxationType,
typename VectorType>
925 const unsigned int level,
927 const VectorType & rhs)
const
929 unsigned int maxlevel = smoothers.max_level();
930 unsigned int steps2 = this->steps;
933 steps2 *= (1 << (maxlevel -
level));
936 if (this->symmetric && (steps2 % 2 == 0))
941 for (
unsigned int i = 0; i < steps2; ++i)
944 smoothers[
level].Tstep(u, rhs);
946 smoothers[
level].step(u, rhs);
953template <
typename MatrixType,
class RelaxationType,
typename VectorType>
956 const unsigned int level,
958 const VectorType & rhs)
const
960 unsigned int maxlevel = smoothers.max_level();
961 unsigned int steps2 = this->steps;
964 steps2 *= (1 << (maxlevel -
level));
967 if (this->symmetric && (steps2 % 2 == 0))
973 smoothers[
level].Tvmult(u, rhs);
975 smoothers[
level].vmult(u, rhs);
978 for (
unsigned int i = 1; i < steps2; ++i)
981 smoothers[
level].Tstep(u, rhs);
983 smoothers[
level].step(u, rhs);
991template <
typename MatrixType,
class RelaxationType,
typename VectorType>
996 return sizeof(*this) + matrices.memory_consumption() +
997 smoothers.memory_consumption() +
998 this->vector_memory.memory_consumption();
1004template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1007 const bool variable,
1008 const bool symmetric,
1015template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1019 smoothers.clear_elements();
1021 unsigned int i = matrices.min_level(), max_level = matrices.max_level();
1022 for (; i <= max_level; ++i)
1028template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1029template <
typename MatrixType2>
1033 const typename PreconditionerType::AdditionalData &data)
1038 matrices.resize(min, max);
1039 smoothers.resize(min, max);
1041 for (
unsigned int i = min; i <=
max; ++i)
1055template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1056template <
typename MatrixType2>
1064 matrices.resize(min, max);
1065 smoothers.resize(min, max);
1067 for (
unsigned int i = min; i <=
max; ++i)
1080template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1081template <
typename MatrixType2,
class DATA>
1093 matrices.resize(min, max);
1094 smoothers.resize(min, max);
1096 for (
unsigned int i = min; i <=
max; ++i)
1110template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1111template <
typename MatrixType2,
class DATA>
1116 const unsigned int row,
1117 const unsigned int col)
1122 matrices.resize(min, max);
1123 smoothers.resize(min, max);
1125 for (
unsigned int i = min; i <=
max; ++i)
1127 matrices[i] = &(m[i].block(row, col));
1128 smoothers[i].initialize(m[i].block(row, col), data);
1134template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1135template <
typename MatrixType2,
class DATA>
1140 const unsigned int row,
1141 const unsigned int col)
1149 matrices.resize(min, max);
1150 smoothers.resize(min, max);
1152 for (
unsigned int i = min; i <=
max; ++i)
1154 matrices[i] = &(m[i].block(row, col));
1155 smoothers[i].initialize(m[i].block(row, col), data[i]);
1161template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1164 const unsigned int level,
1166 const VectorType & rhs)
const
1168 unsigned int maxlevel = matrices.max_level();
1169 unsigned int steps2 = this->steps;
1172 steps2 *= (1 << (maxlevel -
level));
1181 if (this->symmetric && (steps2 % 2 == 0))
1183 if (this->debug > 0)
1186 for (
unsigned int i = 0; i < steps2; ++i)
1190 if (this->debug > 0)
1192 matrices[
level].Tvmult(*r, u);
1193 r->sadd(-1., 1., rhs);
1194 if (this->debug > 2)
1195 deallog <<
' ' << r->l2_norm() <<
' ';
1196 smoothers[
level].Tvmult(*d, *r);
1197 if (this->debug > 1)
1198 deallog <<
' ' <<
d->l2_norm() <<
' ';
1202 if (this->debug > 0)
1204 matrices[
level].vmult(*r, u);
1206 if (this->debug > 2)
1207 deallog <<
' ' << r->l2_norm() <<
' ';
1208 smoothers[
level].vmult(*d, *r);
1209 if (this->debug > 1)
1210 deallog <<
' ' <<
d->l2_norm() <<
' ';
1213 if (this->symmetric)
1216 if (this->debug > 0)
1222template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1225 const unsigned int level,
1227 const VectorType & rhs)
const
1229 unsigned int maxlevel = matrices.max_level();
1230 unsigned int steps2 = this->steps;
1233 steps2 *= (1 << (maxlevel -
level));
1236 if (this->symmetric && (steps2 % 2 == 0))
1238 if (this->debug > 0)
1242 if (this->debug > 2)
1243 deallog <<
' ' << rhs.l2_norm() <<
' ';
1244 if (this->debug > 0)
1247 smoothers[
level].Tvmult(u, rhs);
1249 smoothers[
level].vmult(u, rhs);
1250 if (this->debug > 1)
1251 deallog <<
' ' << u.l2_norm() <<
' ';
1252 if (this->symmetric)
1264 for (
unsigned int i = 1; i < steps2; ++i)
1268 if (this->debug > 0)
1270 matrices[
level].Tvmult(*r, u);
1271 r->sadd(-1., 1., rhs);
1272 if (this->debug > 2)
1273 deallog <<
' ' << r->l2_norm() <<
' ';
1274 smoothers[
level].Tvmult(*d, *r);
1275 if (this->debug > 1)
1276 deallog <<
' ' <<
d->l2_norm() <<
' ';
1280 if (this->debug > 0)
1282 matrices[
level].vmult(*r, u);
1284 if (this->debug > 2)
1285 deallog <<
' ' << r->l2_norm() <<
' ';
1286 smoothers[
level].vmult(*d, *r);
1287 if (this->debug > 1)
1288 deallog <<
' ' <<
d->l2_norm() <<
' ';
1291 if (this->symmetric)
1294 if (this->debug > 0)
1300template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1305 return sizeof(*this) + matrices.memory_consumption() +
1306 smoothers.memory_consumption() +
1307 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 > &)