17 #ifndef __deal2__mg_smoother_h
18 #define __deal2__mg_smoother_h
21 #include <deal.II/base/config.h>
22 #include <deal.II/base/smartpointer.h>
23 #include <deal.II/lac/pointer_matrix.h>
24 #include <deal.II/lac/vector_memory.h>
25 #include <deal.II/multigrid/mg_base.h>
26 #include <deal.II/base/mg_level_object.h>
46 template <
class VECTOR>
73 const unsigned int steps = 1,
109 void set_debug (
const unsigned int level);
176 template <
class VECTOR>
190 virtual void smooth (
const unsigned int level,
192 const VECTOR &rhs)
const;
193 virtual void clear ();
233 template<
class RELAX,
class VECTOR>
259 template <
class MATRIX2>
261 const typename RELAX::AdditionalData &additional_data =
typename RELAX::AdditionalData());
276 template <
class MATRIX2,
class DATA>
305 virtual void smooth (
const unsigned int level,
307 const VECTOR &rhs)
const;
357 template<
class MATRIX,
class RELAX,
class VECTOR>
377 const unsigned int steps = 1,
397 template <
class MATRIX2>
399 const typename RELAX::AdditionalData &additional_data =
typename RELAX::AdditionalData());
416 template <
class MATRIX2,
class DATA>
440 template <
class MATRIX2,
class DATA>
442 const DATA &additional_data,
443 const unsigned int block_row,
444 const unsigned int block_col);
466 template <
class MATRIX2,
class DATA>
469 const unsigned int block_row,
470 const unsigned int block_col);
480 virtual void smooth (
const unsigned int level,
482 const VECTOR &rhs)
const;
537 template<
class MATRIX,
class PRECONDITIONER,
class VECTOR>
557 const unsigned int steps = 1,
577 template <
class MATRIX2>
579 const typename PRECONDITIONER::AdditionalData &additional_data =
typename PRECONDITIONER::AdditionalData());
596 template <
class MATRIX2,
class DATA>
620 template <
class MATRIX2,
class DATA>
622 const DATA &additional_data,
623 const unsigned int block_row,
624 const unsigned int block_col);
646 template <
class MATRIX2,
class DATA>
649 const unsigned int block_row,
650 const unsigned int block_col);
660 virtual void smooth (
const unsigned int level,
662 const VECTOR &rhs)
const;
690 template <
class VECTOR>
693 const unsigned int, VECTOR &,
694 const VECTOR &)
const
697 template <
class VECTOR>
704 template <
class VECTOR>
707 const unsigned int steps,
709 const bool symmetric,
714 symmetric(symmetric),
715 transpose(transpose),
721 template <
class VECTOR>
725 const unsigned int steps,
727 const bool symmetric,
732 symmetric(symmetric),
733 transpose(transpose),
739 template <
class VECTOR>
747 template <
class VECTOR>
755 template <
class VECTOR>
763 template <
class VECTOR>
771 template <
class VECTOR>
782 template <
class RELAX,
class VECTOR>
785 const unsigned int steps,
787 const bool symmetric,
788 const bool transpose)
789 :
MGSmoother<VECTOR>(steps, variable, symmetric, transpose)
793 template <
class RELAX,
class VECTOR>
795 SmootherRelaxation<RELAX, VECTOR>::clear ()
801 template <
class RELAX,
class VECTOR>
802 template <
class MATRIX2>
804 SmootherRelaxation<RELAX, VECTOR>::initialize (
806 const typename RELAX::AdditionalData &data)
811 this->resize(min, max);
813 for (
unsigned int i=min; i<=
max; ++i)
814 (*
this)[i].initialize(m[i], data);
818 template <
class RELAX,
class VECTOR>
819 template <
class MATRIX2,
class DATA>
821 SmootherRelaxation<RELAX, VECTOR>::initialize (
828 this->resize(min, max);
830 for (
unsigned int i=min; i<=
max; ++i)
831 (*
this)[i].initialize(m[i], data[i]);
835 template <
class RELAX,
class VECTOR>
837 SmootherRelaxation<RELAX, VECTOR>::smooth(
838 const unsigned int level,
840 const VECTOR &rhs)
const
842 unsigned int maxlevel = this->max_level();
843 unsigned int steps2 = this->steps;
846 steps2 *= (1<<(maxlevel-level));
849 if (this->symmetric && (steps2 % 2 == 0))
852 deallog <<
'S' << level <<
' ';
854 for (
unsigned int i=0; i<steps2; ++i)
857 (*this)[level].Tstep(u, rhs);
859 (*
this)[level].step(u, rhs);
866 template <
class RELAX,
class VECTOR>
869 SmootherRelaxation<RELAX, VECTOR>::
870 memory_consumption ()
const
882 template <
class MATRIX,
class RELAX,
class VECTOR>
886 const unsigned int steps,
888 const bool symmetric,
891 MGSmoother<VECTOR>(mem, steps, variable, symmetric, transpose)
896 template <
class MATRIX,
class RELAX,
class VECTOR>
899 const unsigned int steps,
901 const bool symmetric,
904 MGSmoother<VECTOR>(steps, variable, symmetric, transpose)
909 template <
class MATRIX,
class RELAX,
class VECTOR>
915 unsigned int i=matrices.min_level(),
916 max_level=matrices.max_level();
917 for (; i<=max_level; ++i)
922 template <
class MATRIX,
class RELAX,
class VECTOR>
923 template <
class MATRIX2>
927 const typename RELAX::AdditionalData &data)
932 matrices.resize(min, max);
933 smoothers.resize(min, max);
935 for (
unsigned int i=min; i<=
max; ++i)
938 smoothers[i].initialize(m[i], data);
942 template <
class MATRIX,
class RELAX,
class VECTOR>
943 template <
class MATRIX2,
class DATA>
957 matrices.resize(min, max);
958 smoothers.resize(min, max);
960 for (
unsigned int i=min; i<=
max; ++i)
963 smoothers[i].initialize(m[i], data[i]);
967 template <
class MATRIX,
class RELAX,
class VECTOR>
968 template <
class MATRIX2,
class DATA>
973 const unsigned int row,
974 const unsigned int col)
979 matrices.resize(min, max);
980 smoothers.resize(min, max);
982 for (
unsigned int i=min; i<=
max; ++i)
984 matrices[i] = &(m[i].block(row, col));
985 smoothers[i].initialize(m[i].block(row, col), data);
989 template <
class MATRIX,
class RELAX,
class VECTOR>
990 template <
class MATRIX2,
class DATA>
995 const unsigned int row,
996 const unsigned int col)
1006 matrices.resize(min, max);
1007 smoothers.resize(min, max);
1009 for (
unsigned int i=min; i<=
max; ++i)
1011 matrices[i] = &(m[i].block(row, col));
1012 smoothers[i].initialize(m[i].block(row, col), data[i]);
1017 template <
class MATRIX,
class RELAX,
class VECTOR>
1020 const unsigned int level,
1022 const VECTOR &rhs)
const
1024 unsigned int maxlevel = smoothers.max_level();
1025 unsigned int steps2 = this->steps;
1028 steps2 *= (1<<(maxlevel-level));
1031 if (this->symmetric && (steps2 % 2 == 0))
1033 if (this->debug > 0)
1034 deallog <<
'S' << level <<
' ';
1036 for (
unsigned int i=0; i<steps2; ++i)
1039 smoothers[level].Tstep(u, rhs);
1041 smoothers[level].step(u, rhs);
1042 if (this->symmetric)
1049 template <
class MATRIX,
class RELAX,
class VECTOR>
1055 return sizeof(*this)
1056 + matrices.memory_consumption()
1057 + smoothers.memory_consumption()
1058 + this->mem->memory_consumption();
1064 template <
class MATRIX,
class PRECONDITIONER,
class VECTOR>
1068 const unsigned int steps,
1069 const bool variable,
1070 const bool symmetric,
1073 MGSmoother<VECTOR>(mem, steps, variable, symmetric, transpose)
1078 template <
class MATRIX,
class PRECONDITIONER,
class VECTOR>
1081 const unsigned int steps,
1082 const bool variable,
1083 const bool symmetric,
1086 MGSmoother<VECTOR>(steps, variable, symmetric, transpose)
1091 template <
class MATRIX,
class PRECONDITIONER,
class VECTOR>
1097 unsigned int i=matrices.min_level(),
1098 max_level=matrices.max_level();
1099 for (; i<=max_level; ++i)
1105 template <
class MATRIX,
class PRECONDITIONER,
class VECTOR>
1106 template <
class MATRIX2>
1110 const typename PRECONDITIONER::AdditionalData &data)
1115 matrices.resize(min, max);
1116 smoothers.resize(min, max);
1118 for (
unsigned int i=min; i<=
max; ++i)
1120 matrices[i] = &m[i];
1121 smoothers[i].initialize(m[i], data);
1127 template <
class MATRIX,
class PRECONDITIONER,
class VECTOR>
1128 template <
class MATRIX2,
class DATA>
1142 matrices.resize(min, max);
1143 smoothers.resize(min, max);
1145 for (
unsigned int i=min; i<=
max; ++i)
1147 matrices[i] = &m[i];
1148 smoothers[i].initialize(m[i], data[i]);
1154 template <
class MATRIX,
class PRECONDITIONER,
class VECTOR>
1155 template <
class MATRIX2,
class DATA>
1160 const unsigned int row,
1161 const unsigned int col)
1166 matrices.resize(min, max);
1167 smoothers.resize(min, max);
1169 for (
unsigned int i=min; i<=
max; ++i)
1171 matrices[i] = &(m[i].block(row, col));
1172 smoothers[i].initialize(m[i].block(row, col), data);
1178 template <
class MATRIX,
class PRECONDITIONER,
class VECTOR>
1179 template <
class MATRIX2,
class DATA>
1184 const unsigned int row,
1185 const unsigned int col)
1195 matrices.resize(min, max);
1196 smoothers.resize(min, max);
1198 for (
unsigned int i=min; i<=
max; ++i)
1200 matrices[i] = &(m[i].block(row, col));
1201 smoothers[i].initialize(m[i].block(row, col), data[i]);
1207 template <
class MATRIX,
class PRECONDITIONER,
class VECTOR>
1210 const unsigned int level,
1212 const VECTOR &rhs)
const
1214 unsigned int maxlevel = matrices.max_level();
1215 unsigned int steps2 = this->steps;
1218 steps2 *= (1<<(maxlevel-level));
1227 if (this->symmetric && (steps2 % 2 == 0))
1229 if (this->debug > 0)
1230 deallog <<
'S' << level <<
' ';
1232 for (
unsigned int i=0; i<steps2; ++i)
1236 if (this->debug > 0)
1238 if (i == 0 && u.all_zero())
1242 matrices[level].Tvmult(*r,u);
1243 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 if (i == 0 && u.all_zero())
1259 matrices[level].vmult(*r,u);
1262 if (this->debug > 2)
1263 deallog <<
' ' << r->l2_norm() <<
' ';
1264 smoothers[level].vmult(*d, *r);
1265 if (this->debug > 1)
1266 deallog <<
' ' << d->l2_norm() <<
' ';
1269 if (this->symmetric)
1272 if (this->debug > 0)
1273 deallog << std::endl;
1278 template <
class MATRIX,
class PRECONDITIONER,
class VECTOR>
1284 return sizeof(*this)
1285 + matrices.memory_consumption()
1286 + smoothers.memory_consumption()
1287 + this->mem->memory_consumption();
1293 DEAL_II_NAMESPACE_CLOSE
SmootherRelaxation(const unsigned int steps=1, const bool variable=false, const bool symmetric=false, const bool transpose=false)
MGSmootherRelaxation(const unsigned int steps=1, const bool variable=false, const bool symmetric=false, const bool transpose=false)
std::size_t memory_consumption() const
MGSmoother(const unsigned int steps=1, const bool variable=false, const bool symmetric=false, const bool transpose=false)
MGLevelObject< PointerMatrix< MATRIX, VECTOR > > matrices
MGSmootherPrecondition(const unsigned int steps=1, const bool variable=false, const bool symmetric=false, const bool transpose=false)
void set_transpose(const bool)
SmartPointer< VectorMemory< VECTOR >, MGSmoother< VECTOR > > mem
void initialize(const MGLevelObject< MATRIX2 > &matrices, const typename PRECONDITIONER::AdditionalData &additional_data=typename PRECONDITIONER::AdditionalData())
void initialize(const MGLevelObject< MATRIX2 > &matrices, const typename RELAX::AdditionalData &additional_data=typename RELAX::AdditionalData())
void set_debug(const unsigned int level)
MGLevelObject< RELAX > smoothers
virtual void smooth(const unsigned int level, VECTOR &u, const VECTOR &rhs) const
virtual void smooth(const unsigned int level, VECTOR &u, const VECTOR &rhs) const
virtual void smooth(const unsigned int level, VECTOR &u, const VECTOR &rhs) const
std::size_t memory_consumption() const
void set_steps(const unsigned int)
VectorizedArray< Number > min(const ::VectorizedArray< Number > &x, const ::VectorizedArray< Number > &y)
void set_variable(const bool)
#define Assert(cond, exc)
MGLevelObject< PRECONDITIONER > smoothers
BlockCompressedSparsityPattern CompressedBlockSparsityPattern DEAL_II_DEPRECATED
GrowingVectorMemory< VECTOR > my_memory
MGLevelObject< PointerMatrix< MATRIX, VECTOR > > matrices
unsigned int min_level() const
void set_symmetric(const bool)
std::size_t memory_consumption() const
std::size_t memory_consumption() const
::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
unsigned int max_level() const
VectorizedArray< Number > max(const ::VectorizedArray< Number > &x, const ::VectorizedArray< Number > &y)
void initialize(const MGLevelObject< MATRIX2 > &matrices, const typename RELAX::AdditionalData &additional_data=typename RELAX::AdditionalData())
virtual void smooth(const unsigned int level, VECTOR &u, const VECTOR &rhs) const