13#ifndef dealii_mg_smoother_h
14#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 <
typename RelaxationType,
typename VectorType>
203 template <
typename MatrixType2>
206 const typename RelaxationType::AdditionalData &additional_data =
207 typename RelaxationType::AdditionalData());
216 template <
typename MatrixType2,
typename DataType>
233 const VectorType &rhs)
const override;
254 const VectorType &rhs)
const override;
293template <
typename MatrixType,
typename RelaxationType,
typename VectorType>
313 template <
typename MatrixType2>
316 const typename RelaxationType::AdditionalData &additional_data =
317 typename RelaxationType::AdditionalData());
327 template <
typename MatrixType2,
typename DataType>
341 template <
typename MatrixType2,
typename DataType>
344 const DataType &additional_data,
345 const unsigned int block_row,
346 const unsigned int block_col);
357 template <
typename MatrixType2,
typename DataType>
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,
typename DataType>
505 template <
typename MatrixType2,
typename DataType>
508 const DataType &additional_data,
509 const unsigned int block_row,
510 const unsigned int block_col);
522 template <
typename MatrixType2,
typename DataType>
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 <
typename RelaxationType,
typename VectorType>
661 const unsigned int steps,
663 const bool symmetric,
669 template <
typename RelaxationType,
typename VectorType>
671 SmootherRelaxation<RelaxationType, VectorType>::clear()
677 template <
typename 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)
694 template <
typename RelaxationType,
typename VectorType>
695 template <
typename MatrixType2,
typename DataType>
697 SmootherRelaxation<RelaxationType, VectorType>::initialize(
704 this->resize(min, max);
706 for (
unsigned int i = min; i <=
max; ++i)
711 template <
typename 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 <
typename 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 <
typename RelaxationType,
typename VectorType>
781 SmootherRelaxation<RelaxationType, VectorType>::memory_consumption()
const
792template <
typename MatrixType,
typename RelaxationType,
typename VectorType>
796 const bool symmetric,
803template <
typename MatrixType,
typename 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,
typename 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)
840template <
typename MatrixType,
typename RelaxationType,
typename VectorType>
841template <
typename MatrixType2,
typename DataType>
853 matrices.resize(min, max);
854 smoothers.resize(min, max);
856 for (
unsigned int i = min; i <=
max; ++i)
868template <
typename MatrixType,
typename RelaxationType,
typename VectorType>
869template <
typename MatrixType2,
typename DataType>
873 const DataType &
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,
typename RelaxationType,
typename VectorType>
895template <
typename MatrixType2,
typename DataType>
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,
typename 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))
941 deallog <<
'S' << level <<
' ';
943 for (
unsigned int i = 0; i < steps2; ++i)
946 smoothers[
level].Tstep(u, rhs);
948 smoothers[
level].step(u, rhs);
955template <
typename MatrixType,
typename 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))
972 deallog <<
'S' << level <<
' ';
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,
typename 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,
typename DataType>
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,
typename DataType>
1117 const DataType &
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,
typename DataType>
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)
1186 deallog <<
'S' << level <<
' ';
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)
1241 deallog <<
'S' << level <<
' ';
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>
1308 smoothers.memory_consumption() +
1309 this->vector_memory.memory_consumption();
std::size_t memory_consumption() const
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(const MGLevelObject< MatrixType2 > &matrices, const MGLevelObject< DataType > &additional_data)
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 DataType &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< DataType > &additional_data, const unsigned int block_row, const unsigned int block_col)
virtual void smooth(const unsigned int level, VectorType &u, const VectorType &rhs) const
MGLevelObject< LinearOperator< VectorType > > matrices
void initialize(const MGLevelObject< MatrixType2 > &matrices, const DataType &additional_data, const unsigned int block_row, const unsigned int block_col)
void initialize(const MGLevelObject< MatrixType2 > &matrices, const MGLevelObject< DataType > &additional_data)
void initialize(const MGLevelObject< MatrixType2 > &matrices, const MGLevelObject< DataType > &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
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
void initialize(const MGLevelObject< MatrixType2 > &matrices, const MGLevelObject< DataType > &additional_data)
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 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)
std::vector< index_type > data
@ symmetric
Matrix is symmetric.
Tpetra::Vector< Number, LO, GO, NodeType< MemorySpace > > VectorType
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 > &)