15#ifndef dealii_mg_smoother_h
16#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 <
typename RelaxationType,
typename VectorType>
205 template <
typename MatrixType2>
208 const typename RelaxationType::AdditionalData &additional_data =
209 typename RelaxationType::AdditionalData());
218 template <
typename MatrixType2,
typename DataType>
235 const VectorType &rhs)
const override;
256 const VectorType &rhs)
const override;
295template <
typename MatrixType,
typename RelaxationType,
typename VectorType>
315 template <
typename MatrixType2>
318 const typename RelaxationType::AdditionalData &additional_data =
319 typename RelaxationType::AdditionalData());
329 template <
typename MatrixType2,
typename DataType>
343 template <
typename MatrixType2,
typename DataType>
346 const DataType &additional_data,
347 const unsigned int block_row,
348 const unsigned int block_col);
359 template <
typename MatrixType2,
typename DataType>
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,
typename DataType>
507 template <
typename MatrixType2,
typename DataType>
510 const DataType &additional_data,
511 const unsigned int block_row,
512 const unsigned int block_col);
524 template <
typename MatrixType2,
typename DataType>
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 <
typename RelaxationType,
typename VectorType>
663 const unsigned int steps,
665 const bool symmetric,
671 template <
typename RelaxationType,
typename VectorType>
673 SmootherRelaxation<RelaxationType, VectorType>::clear()
679 template <
typename 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)
696 template <
typename RelaxationType,
typename VectorType>
697 template <
typename MatrixType2,
typename DataType>
699 SmootherRelaxation<RelaxationType, VectorType>::initialize(
706 this->resize(min, max);
708 for (
unsigned int i = min; i <=
max; ++i)
713 template <
typename 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))
730 deallog <<
'S' << level <<
' ';
732 for (
unsigned int i = 0; i < steps2; ++i)
735 (*this)[
level].Tstep(u, rhs);
737 (*
this)[
level].step(u, rhs);
744 template <
typename 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))
761 deallog <<
'S' << level <<
' ';
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 <
typename RelaxationType,
typename VectorType>
783 SmootherRelaxation<RelaxationType, VectorType>::memory_consumption()
const
794template <
typename MatrixType,
typename RelaxationType,
typename VectorType>
798 const bool symmetric,
805template <
typename MatrixType,
typename 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,
typename 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)
842template <
typename MatrixType,
typename RelaxationType,
typename VectorType>
843template <
typename MatrixType2,
typename DataType>
855 matrices.resize(min, max);
856 smoothers.resize(min, max);
858 for (
unsigned int i = min; i <=
max; ++i)
870template <
typename MatrixType,
typename RelaxationType,
typename VectorType>
871template <
typename MatrixType2,
typename DataType>
875 const DataType &
data,
876 const unsigned int row,
877 const unsigned int col)
882 matrices.resize(min, max);
883 smoothers.resize(min, max);
885 for (
unsigned int i = min; i <=
max; ++i)
891 m[i].block(row, col));
892 smoothers[i].initialize(m[i].block(row, col),
data);
896template <
typename MatrixType,
typename RelaxationType,
typename VectorType>
897template <
typename MatrixType2,
typename DataType>
902 const unsigned int row,
903 const unsigned int col)
911 matrices.resize(min, max);
912 smoothers.resize(min, max);
914 for (
unsigned int i = min; i <=
max; ++i)
920 m[i].block(row, col));
921 smoothers[i].initialize(m[i].block(row, col),
data[i]);
926template <
typename MatrixType,
typename RelaxationType,
typename VectorType>
929 const unsigned int level,
931 const VectorType &rhs)
const
933 unsigned int maxlevel = smoothers.max_level();
934 unsigned int steps2 = this->steps;
937 steps2 *= (1 << (maxlevel -
level));
940 if (this->symmetric && (steps2 % 2 == 0))
943 deallog <<
'S' << level <<
' ';
945 for (
unsigned int i = 0; i < steps2; ++i)
948 smoothers[
level].Tstep(u, rhs);
950 smoothers[
level].step(u, rhs);
957template <
typename MatrixType,
typename RelaxationType,
typename VectorType>
960 const unsigned int level,
962 const VectorType &rhs)
const
964 unsigned int maxlevel = smoothers.max_level();
965 unsigned int steps2 = this->steps;
968 steps2 *= (1 << (maxlevel -
level));
971 if (this->symmetric && (steps2 % 2 == 0))
974 deallog <<
'S' << level <<
' ';
977 smoothers[
level].Tvmult(u, rhs);
979 smoothers[
level].vmult(u, rhs);
982 for (
unsigned int i = 1; i < steps2; ++i)
985 smoothers[
level].Tstep(u, rhs);
987 smoothers[
level].step(u, rhs);
995template <
typename MatrixType,
typename RelaxationType,
typename VectorType>
1000 return sizeof(*this) + matrices.memory_consumption() +
1001 smoothers.memory_consumption() +
1002 this->vector_memory.memory_consumption();
1008template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1011 const bool variable,
1012 const bool symmetric,
1019template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1023 smoothers.clear_elements();
1025 unsigned int i = matrices.min_level(), max_level = matrices.max_level();
1026 for (; i <= max_level; ++i)
1032template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1033template <
typename MatrixType2>
1037 const typename PreconditionerType::AdditionalData &
data)
1042 matrices.resize(min, max);
1043 smoothers.resize(min, max);
1045 for (
unsigned int i = min; i <=
max; ++i)
1059template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1060template <
typename MatrixType2>
1068 matrices.resize(min, max);
1069 smoothers.resize(min, max);
1071 for (
unsigned int i = min; i <=
max; ++i)
1084template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1085template <
typename MatrixType2,
typename DataType>
1097 matrices.resize(min, max);
1098 smoothers.resize(min, max);
1100 for (
unsigned int i = min; i <=
max; ++i)
1114template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1115template <
typename MatrixType2,
typename DataType>
1119 const DataType &
data,
1120 const unsigned int row,
1121 const unsigned int col)
1126 matrices.resize(min, max);
1127 smoothers.resize(min, max);
1129 for (
unsigned int i = min; i <=
max; ++i)
1131 matrices[i] = &(m[i].block(row, col));
1132 smoothers[i].initialize(m[i].block(row, col),
data);
1138template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1139template <
typename MatrixType2,
typename DataType>
1144 const unsigned int row,
1145 const unsigned int col)
1153 matrices.resize(min, max);
1154 smoothers.resize(min, max);
1156 for (
unsigned int i = min; i <=
max; ++i)
1158 matrices[i] = &(m[i].block(row, col));
1159 smoothers[i].initialize(m[i].block(row, col),
data[i]);
1165template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1168 const unsigned int level,
1170 const VectorType &rhs)
const
1172 unsigned int maxlevel = matrices.max_level();
1173 unsigned int steps2 = this->steps;
1176 steps2 *= (1 << (maxlevel -
level));
1185 if (this->symmetric && (steps2 % 2 == 0))
1187 if (this->
debug > 0)
1188 deallog <<
'S' << level <<
' ';
1190 for (
unsigned int i = 0; i < steps2; ++i)
1194 if (this->
debug > 0)
1196 matrices[
level].Tvmult(*r, u);
1197 r->sadd(-1., 1., rhs);
1198 if (this->
debug > 2)
1199 deallog <<
' ' << r->l2_norm() <<
' ';
1200 smoothers[
level].Tvmult(*d, *r);
1201 if (this->
debug > 1)
1202 deallog <<
' ' <<
d->l2_norm() <<
' ';
1206 if (this->
debug > 0)
1208 matrices[
level].vmult(*r, u);
1210 if (this->
debug > 2)
1211 deallog <<
' ' << r->l2_norm() <<
' ';
1212 smoothers[
level].vmult(*d, *r);
1213 if (this->
debug > 1)
1214 deallog <<
' ' <<
d->l2_norm() <<
' ';
1217 if (this->symmetric)
1220 if (this->
debug > 0)
1226template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1229 const unsigned int level,
1231 const VectorType &rhs)
const
1233 unsigned int maxlevel = matrices.max_level();
1234 unsigned int steps2 = this->steps;
1237 steps2 *= (1 << (maxlevel -
level));
1240 if (this->symmetric && (steps2 % 2 == 0))
1242 if (this->
debug > 0)
1243 deallog <<
'S' << level <<
' ';
1246 if (this->
debug > 2)
1247 deallog <<
' ' << rhs.l2_norm() <<
' ';
1248 if (this->
debug > 0)
1251 smoothers[
level].Tvmult(u, rhs);
1253 smoothers[
level].vmult(u, rhs);
1254 if (this->
debug > 1)
1255 deallog <<
' ' << u.l2_norm() <<
' ';
1256 if (this->symmetric)
1268 for (
unsigned int i = 1; i < steps2; ++i)
1272 if (this->
debug > 0)
1274 matrices[
level].Tvmult(*r, u);
1275 r->sadd(-1., 1., rhs);
1276 if (this->
debug > 2)
1277 deallog <<
' ' << r->l2_norm() <<
' ';
1278 smoothers[
level].Tvmult(*d, *r);
1279 if (this->
debug > 1)
1280 deallog <<
' ' <<
d->l2_norm() <<
' ';
1284 if (this->
debug > 0)
1286 matrices[
level].vmult(*r, u);
1288 if (this->
debug > 2)
1289 deallog <<
' ' << r->l2_norm() <<
' ';
1290 smoothers[
level].vmult(*d, *r);
1291 if (this->
debug > 1)
1292 deallog <<
' ' <<
d->l2_norm() <<
' ';
1295 if (this->symmetric)
1298 if (this->
debug > 0)
1304template <
typename MatrixType,
typename PreconditionerType,
typename VectorType>
1310 smoothers.memory_consumption() +
1311 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 > &)