From: Peter Munch Date: Tue, 17 Aug 2021 06:28:17 +0000 (+0200) Subject: Add MGCoarseGridApplyOperator X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d169fedf01590f6d872ade7ae464e9488d241cf;p=dealii.git Add MGCoarseGridApplyOperator --- diff --git a/include/deal.II/multigrid/mg_coarse.h b/include/deal.II/multigrid/mg_coarse.h index b9d98289ba..0a847c41ba 100644 --- a/include/deal.II/multigrid/mg_coarse.h +++ b/include/deal.II/multigrid/mg_coarse.h @@ -80,6 +80,55 @@ private: +/** + * 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 MGCoarseGridApplyOperator : public MGCoarseGridBase +{ +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> + matrix; +}; + + + /** * Coarse grid multigrid operator for an iterative solver. * @@ -284,6 +333,54 @@ MGCoarseGridApplySmoother::operator()(const unsigned int level, coarse_smooth->apply(level, dst, src); } +/* ------------------ Functions for MGCoarseGridApplyOperator ----------*/ + +template +MGCoarseGridApplyOperator::MGCoarseGridApplyOperator() + : matrix(0, typeid(*this).name()) +{} + + + +template +MGCoarseGridApplyOperator:: + MGCoarseGridApplyOperator(const PreconditionerType &matrix) + : matrix(&matrix, typeid(*this).name()) +{} + + + +template +void +MGCoarseGridApplyOperator::initialize( + const PreconditionerType &matrix_) +{ + matrix = &matrix_; +} + + + +template +void +MGCoarseGridApplyOperator::clear() +{ + matrix = 0; +} + + +template +void +MGCoarseGridApplyOperator::operator()( + const unsigned int /*level*/, + VectorType &dst, + const VectorType &src) const +{ + Assert(matrix != nullptr, ExcNotInitialized()); + + matrix->vmult(dst, src); +} + /* ------------------ Functions for MGCoarseGridIterativeSolver ------------ */ template + 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; diff --git a/tests/multigrid/mg_coarse_01.with_p4est=true.with_trilinos=true.mpirun=1.output b/tests/multigrid/mg_coarse_01.with_p4est=true.with_trilinos=true.mpirun=1.output index 80c6792b39..cdd60bddca 100644 --- a/tests/multigrid/mg_coarse_01.with_p4est=true.with_trilinos=true.mpirun=1.output +++ b/tests/multigrid/mg_coarse_01.with_p4est=true.with_trilinos=true.mpirun=1.output @@ -21,6 +21,11 @@ DEAL::AMG: 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 @@ -44,6 +49,11 @@ DEAL::AMG: 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 @@ -64,6 +74,11 @@ DEAL::check residual: 0.00725329 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 diff --git a/tests/multigrid/mg_coarse_01.with_p4est=true.with_trilinos=true.mpirun=3.output b/tests/multigrid/mg_coarse_01.with_p4est=true.with_trilinos=true.mpirun=3.output index 2e0aadb5ff..4a5f245648 100644 --- a/tests/multigrid/mg_coarse_01.with_p4est=true.with_trilinos=true.mpirun=3.output +++ b/tests/multigrid/mg_coarse_01.with_p4est=true.with_trilinos=true.mpirun=3.output @@ -21,6 +21,11 @@ DEAL::AMG: 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 @@ -44,6 +49,11 @@ DEAL::AMG: 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 @@ -64,6 +74,11 @@ DEAL::check residual: 0.00725329 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