+/**
+ * Coarse grid solver using an operator, e.g., preconditioner, only.
+ * This is a little wrapper, transforming an operator into a coarse grid solver.
+ */
+template <class VectorType, class MatrixType>
+class MGCoarseGridApplyOperator : public MGCoarseGridBase<VectorType>
+{
+public:
+ /**
+ * Default constructor.
+ */
+ MGCoarseGridApplyOperator();
+
+ /**
+ * Constructor. Store a pointer to the operator for later use.
+ */
+ MGCoarseGridApplyOperator(const MatrixType &matrix);
+
+ /**
+ * Clear the pointer.
+ */
+ void
+ clear();
+
+ /**
+ * Initialize new data.
+ */
+ void
+ initialize(const MatrixType &matrix);
+
+ /**
+ * Implementation of the abstract function.
+ */
+ virtual void
+ operator()(const unsigned int level,
+ VectorType &dst,
+ const VectorType &src) const override;
+
+private:
+ /**
+ * Reference to the operator.
+ */
+ ObserverPointer<const MatrixType,
+ MGCoarseGridApplyOperator<VectorType, MatrixType>>
+ matrix;
+};
+
+
+
/**
* Coarse grid multigrid operator for an iterative solver.
*
coarse_smooth->apply(level, dst, src);
}
+/* ------------------ Functions for MGCoarseGridApplyOperator ----------*/
+
+template <class VectorType, class PreconditionerType>
+MGCoarseGridApplyOperator<VectorType,
+ PreconditionerType>::MGCoarseGridApplyOperator()
+ : matrix(0, typeid(*this).name())
+{}
+
+
+
+template <class VectorType, class PreconditionerType>
+MGCoarseGridApplyOperator<VectorType, PreconditionerType>::
+ MGCoarseGridApplyOperator(const PreconditionerType &matrix)
+ : matrix(&matrix, typeid(*this).name())
+{}
+
+
+
+template <class VectorType, class PreconditionerType>
+void
+MGCoarseGridApplyOperator<VectorType, PreconditionerType>::initialize(
+ const PreconditionerType &matrix_)
+{
+ matrix = &matrix_;
+}
+
+
+
+template <class VectorType, class PreconditionerType>
+void
+MGCoarseGridApplyOperator<VectorType, PreconditionerType>::clear()
+{
+ matrix = 0;
+}
+
+
+template <class VectorType, class PreconditionerType>
+void
+MGCoarseGridApplyOperator<VectorType, PreconditionerType>::operator()(
+ const unsigned int /*level*/,
+ VectorType &dst,
+ const VectorType &src) const
+{
+ Assert(matrix != nullptr, ExcNotInitialized());
+
+ matrix->vmult(dst, src);
+}
+
/* ------------------ Functions for MGCoarseGridIterativeSolver ------------ */
template <typename VectorType,
<< std::endl;
}
+ {
+ deallog << "AMG:" << std::endl;
+
+ LA::MPI::PreconditionAMG prec;
+ prec.initialize(coarse_matrix);
+
+ MGCoarseGridApplyOperator<vector_t, LA::MPI::PreconditionAMG>
+ coarse_grid_solver(prec);
+
+ vcycle(coarse_grid_solver);
+ deallog << "coarse iterations: " << coarse_solver_control.last_step()
+ << std::endl;
+ }
+
{
deallog << "AMG:" << std::endl;
LA::MPI::PreconditionAMG::AdditionalData Amg_data;
DEAL::check residual: 0.0231622
DEAL::check residual: 0.0192417
DEAL::check residual: 0.0172953
+DEAL::coarse iterations: 1
+DEAL::AMG:
+DEAL::check residual: 0.0231622
+DEAL::check residual: 0.0192417
+DEAL::check residual: 0.0172953
DEAL::applications: 3
DEAL::Cycle 1:
DEAL:: Number of active cells: 484
DEAL::check residual: 0.0126770
DEAL::check residual: 0.0105349
DEAL::check residual: 0.00947063
+DEAL::coarse iterations: 1
+DEAL::AMG:
+DEAL::check residual: 0.0126770
+DEAL::check residual: 0.0105349
+DEAL::check residual: 0.00947063
DEAL::applications: 3
DEAL::Cycle 2:
DEAL:: Number of active cells: 1024
DEAL::check residual: 0.00652099
DEAL::coarse iterations: 22
DEAL::AMG:
+DEAL::check residual: 0.0125665
+DEAL::check residual: 0.0140128
+DEAL::check residual: 0.0147028
+DEAL::coarse iterations: 22
+DEAL::AMG:
DEAL::check residual: 0.0114120
DEAL::check residual: 0.0128120
DEAL::check residual: 0.0135811
DEAL::check residual: 0.0231622
DEAL::check residual: 0.0192417
DEAL::check residual: 0.0172953
+DEAL::coarse iterations: 1
+DEAL::AMG:
+DEAL::check residual: 0.0231622
+DEAL::check residual: 0.0192417
+DEAL::check residual: 0.0172953
DEAL::applications: 3
DEAL::Cycle 1:
DEAL:: Number of active cells: 484
DEAL::check residual: 0.0126770
DEAL::check residual: 0.0105349
DEAL::check residual: 0.00947063
+DEAL::coarse iterations: 1
+DEAL::AMG:
+DEAL::check residual: 0.0126770
+DEAL::check residual: 0.0105349
+DEAL::check residual: 0.00947063
DEAL::applications: 3
DEAL::Cycle 2:
DEAL:: Number of active cells: 1024
DEAL::check residual: 0.00652099
DEAL::coarse iterations: 20
DEAL::AMG:
+DEAL::check residual: 0.0121261
+DEAL::check residual: 0.0132637
+DEAL::check residual: 0.0138558
+DEAL::coarse iterations: 20
+DEAL::AMG:
DEAL::check residual: 0.0115344
DEAL::check residual: 0.0130870
DEAL::check residual: 0.0139614