16 #ifndef dealii_mg_smoother_h 17 #define dealii_mg_smoother_h 20 #include <deal.II/base/config.h> 22 #include <deal.II/base/mg_level_object.h> 23 #include <deal.II/base/smartpointer.h> 25 #include <deal.II/lac/linear_operator.h> 26 #include <deal.II/lac/vector_memory.h> 28 #include <deal.II/multigrid/mg_base.h> 32 DEAL_II_NAMESPACE_OPEN
49 template <
typename VectorType>
141 template <
typename VectorType>
151 smooth(
const unsigned int level, VectorType &u,
const VectorType &rhs)
const;
189 template <
class RelaxationType,
typename VectorType>
210 template <
typename MatrixType2>
213 const typename RelaxationType::AdditionalData &additional_data =
214 typename RelaxationType::AdditionalData());
223 template <
typename MatrixType2,
class DATA>
238 smooth(
const unsigned int level,
240 const VectorType & rhs)
const override;
259 apply(
const unsigned int level,
261 const VectorType & rhs)
const override;
302 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
322 template <
typename MatrixType2>
325 const typename RelaxationType::AdditionalData &additional_data =
326 typename RelaxationType::AdditionalData());
336 template <
typename MatrixType2,
class DATA>
350 template <
typename MatrixType2,
class DATA>
353 const DATA & additional_data,
354 const unsigned int block_row,
355 const unsigned int block_col);
366 template <
typename MatrixType2,
class DATA>
370 const unsigned int block_row,
371 const unsigned int block_col);
383 smooth(
const unsigned int level, VectorType &u,
const VectorType &rhs)
const;
401 apply(
const unsigned int level, VectorType &u,
const VectorType &rhs)
const;
454 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
475 template <
typename MatrixType2>
478 const typename PreconditionerType::AdditionalData &
479 additional_data =
typename PreconditionerType::AdditionalData());
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);
539 smooth(
const unsigned int level,
541 const VectorType & rhs)
const override;
559 apply(
const unsigned int level,
561 const VectorType & rhs)
const override;
589 template <
typename VectorType>
593 const VectorType &)
const 596 template <
typename VectorType>
603 template <
typename VectorType>
606 const bool symmetric,
616 template <
typename VectorType>
624 template <
typename VectorType>
632 template <
typename VectorType>
640 template <
typename VectorType>
648 template <
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)
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(
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))
728 deallog <<
'S' << level <<
' ';
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))
759 deallog <<
'S' << level <<
' ';
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 792 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
796 const bool symmetric,
803 template <
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)
815 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
816 template <
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);
839 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
840 template <
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]);
866 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
867 template <
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);
892 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
893 template <
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]);
922 template <
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))
939 deallog <<
'S' << level <<
' ';
941 for (
unsigned int i = 0; i < steps2; ++i)
944 smoothers[level].Tstep(u, rhs);
946 smoothers[level].step(u, rhs);
953 template <
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))
970 deallog <<
'S' << level <<
' ';
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);
991 template <
typename MatrixType,
class RelaxationType,
typename VectorType>
996 return sizeof(*this) + matrices.memory_consumption() +
997 smoothers.memory_consumption() +
998 this->vector_memory.memory_consumption();
1004 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1007 const bool variable,
1008 const bool symmetric,
1015 template <
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)
1028 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1029 template <
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)
1048 smoothers[i].initialize(m[i], data);
1054 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1055 template <
typename MatrixType2,
class DATA>
1067 matrices.resize(
min,
max);
1068 smoothers.resize(
min,
max);
1070 for (
unsigned int i =
min; i <=
max; ++i)
1077 smoothers[i].initialize(m[i], data[i]);
1083 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1084 template <
typename MatrixType2,
class DATA>
1089 const unsigned int row,
1090 const unsigned int col)
1095 matrices.resize(
min,
max);
1096 smoothers.resize(
min,
max);
1098 for (
unsigned int i =
min; i <=
max; ++i)
1100 matrices[i] = &(m[i].block(row, col));
1101 smoothers[i].initialize(m[i].block(row, col), data);
1107 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1108 template <
typename MatrixType2,
class DATA>
1113 const unsigned int row,
1114 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[i]);
1134 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1137 const unsigned int level,
1139 const VectorType & rhs)
const 1141 unsigned int maxlevel = matrices.max_level();
1142 unsigned int steps2 = this->steps;
1145 steps2 *= (1 << (maxlevel - level));
1154 if (this->symmetric && (steps2 % 2 == 0))
1156 if (this->debug > 0)
1157 deallog <<
'S' << level <<
' ';
1159 for (
unsigned int i = 0; i < steps2; ++i)
1163 if (this->debug > 0)
1165 matrices[level].Tvmult(*r, u);
1166 r->sadd(-1., 1., rhs);
1167 if (this->debug > 2)
1168 deallog <<
' ' << r->l2_norm() <<
' ';
1169 smoothers[level].Tvmult(*d, *r);
1170 if (this->debug > 1)
1171 deallog <<
' ' <<
d->l2_norm() <<
' ';
1175 if (this->debug > 0)
1177 matrices[level].vmult(*r, u);
1179 if (this->debug > 2)
1180 deallog <<
' ' << r->l2_norm() <<
' ';
1181 smoothers[level].vmult(*d, *r);
1182 if (this->debug > 1)
1183 deallog <<
' ' <<
d->l2_norm() <<
' ';
1186 if (this->symmetric)
1189 if (this->debug > 0)
1190 deallog << std::endl;
1195 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1198 const unsigned int level,
1200 const VectorType & rhs)
const 1202 unsigned int maxlevel = matrices.max_level();
1203 unsigned int steps2 = this->steps;
1206 steps2 *= (1 << (maxlevel - level));
1209 if (this->symmetric && (steps2 % 2 == 0))
1211 if (this->debug > 0)
1212 deallog <<
'S' << level <<
' ';
1215 if (this->debug > 2)
1216 deallog <<
' ' << rhs.l2_norm() <<
' ';
1217 if (this->debug > 0)
1218 deallog << (T ?
'T' :
'N');
1220 smoothers[level].Tvmult(u, rhs);
1222 smoothers[level].vmult(u, rhs);
1223 if (this->debug > 1)
1224 deallog <<
' ' << u.l2_norm() <<
' ';
1225 if (this->symmetric)
1237 for (
unsigned int i = 1; i < steps2; ++i)
1241 if (this->debug > 0)
1243 matrices[level].Tvmult(*r, u);
1244 r->sadd(-1., 1., rhs);
1245 if (this->debug > 2)
1246 deallog <<
' ' << r->l2_norm() <<
' ';
1247 smoothers[level].Tvmult(*d, *r);
1248 if (this->debug > 1)
1249 deallog <<
' ' <<
d->l2_norm() <<
' ';
1253 if (this->debug > 0)
1255 matrices[level].vmult(*r, u);
1257 if (this->debug > 2)
1258 deallog <<
' ' << r->l2_norm() <<
' ';
1259 smoothers[level].vmult(*d, *r);
1260 if (this->debug > 1)
1261 deallog <<
' ' <<
d->l2_norm() <<
' ';
1264 if (this->symmetric)
1267 if (this->debug > 0)
1268 deallog << std::endl;
1273 template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1278 return sizeof(*this) + matrices.memory_consumption() +
1279 smoothers.memory_consumption() +
1280 this->vector_memory.memory_consumption();
1286 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)
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
virtual void apply(const unsigned int level, VectorType &u, const VectorType &rhs) const override
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())
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 override
virtual void smooth(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
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