From: Peter Munch Date: Thu, 1 Jul 2021 13:09:28 +0000 (+0200) Subject: Add new signals to Multigrid X-Git-Tag: v9.4.0-rc1~1167^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F12531%2Fhead;p=dealii.git Add new signals to Multigrid --- diff --git a/include/deal.II/multigrid/multigrid.h b/include/deal.II/multigrid/multigrid.h index d2775abd2a..2d7cdba9a3 100644 --- a/include/deal.II/multigrid/multigrid.h +++ b/include/deal.II/multigrid/multigrid.h @@ -118,11 +118,25 @@ namespace mg /** * This signal is triggered before (@p before is true) and after (@p before * is false) the call to a post-smoothing step via MGPostSmoother::apply() - * on - * @p level. + * on @p level. */ boost::signals2::signal post_smoother_step; + + /** + * This signal is triggered before (@p before is true) and after (@p before + * is false) the computation of the residual vector on @p level, including + * the result of edge_out and edge_down. + */ + boost::signals2::signal + residual_step; + + /** + * This signal is triggered before (@p before is true) and after (@p before + * is false) the execution of edge_in and edge_up. + */ + boost::signals2::signal + edge_prolongation; }; } // namespace mg @@ -288,10 +302,17 @@ public: void set_cycle(Cycle); /** - * Connect a function to mg::Signals::coarse_solve. + * Connect a function to mg::Signals::pre_smoother_step. */ boost::signals2::connection - connect_coarse_solve( + connect_pre_smoother_step( + const std::function &slot); + + /** + * Connect a function to mg::Signals::residual_step. + */ + boost::signals2::connection + connect_residual_step( const std::function &slot); /** @@ -301,6 +322,13 @@ public: connect_restriction( const std::function &slot); + /** + * Connect a function to mg::Signals::coarse_solve. + */ + boost::signals2::connection + connect_coarse_solve( + const std::function &slot); + /** * Connect a function to mg::Signals::prolongation. */ @@ -309,10 +337,10 @@ public: const std::function &slot); /** - * Connect a function to mg::Signals::pre_smoother_step. + * Connect a function to mg::Signals::edge_prolongation. */ boost::signals2::connection - connect_pre_smoother_step( + connect_edge_prolongation( const std::function &slot); /** diff --git a/include/deal.II/multigrid/multigrid.templates.h b/include/deal.II/multigrid/multigrid.templates.h index d8f40db0f2..3e4333d926 100644 --- a/include/deal.II/multigrid/multigrid.templates.h +++ b/include/deal.II/multigrid/multigrid.templates.h @@ -115,6 +115,7 @@ Multigrid::level_v_step(const unsigned int level) this->signals.pre_smoother_step(false, level); // compute residual on level, which includes the (CG) edge matrix + this->signals.residual_step(true, level); matrix->vmult(level, t[level], solution[level]); if (edge_out != nullptr) { @@ -129,6 +130,7 @@ Multigrid::level_v_step(const unsigned int level) edge_down->vmult(level, t[level - 1], solution[level]); defect[level - 1] -= t[level - 1]; } + this->signals.residual_step(false, level); this->signals.restriction(true, level); transfer->restrict_and_add(level, defect[level - 1], t[level]); @@ -142,6 +144,7 @@ Multigrid::level_v_step(const unsigned int level) transfer->prolongate_and_add(level, solution[level], solution[level - 1]); this->signals.prolongation(false, level); + this->signals.edge_prolongation(true, level); // get in contribution from edge matrices to the defect if (edge_in != nullptr) { @@ -153,6 +156,7 @@ Multigrid::level_v_step(const unsigned int level) edge_up->Tvmult(level, t[level], solution[level - 1]); defect[level] -= t[level]; } + this->signals.edge_prolongation(false, level); // post-smoothing this->signals.post_smoother_step(true, level); @@ -185,6 +189,7 @@ Multigrid::level_step(const unsigned int level, Cycle cycle) this->signals.pre_smoother_step(false, level); // compute residual on level, which includes the (CG) edge matrix + this->signals.residual_step(true, level); matrix->vmult(level, t[level], solution[level]); if (edge_out != nullptr) edge_out->vmult_add(level, t[level], solution[level]); @@ -196,6 +201,7 @@ Multigrid::level_step(const unsigned int level, Cycle cycle) edge_down->vmult(level, defect2[level - 1], solution[level]); else defect2[level - 1] = typename VectorType::value_type(0.); + this->signals.residual_step(false, level); this->signals.restriction(true, level); transfer->restrict_and_add(level, defect2[level - 1], t[level]); @@ -221,6 +227,8 @@ Multigrid::level_step(const unsigned int level, Cycle cycle) this->signals.prolongation(true, level); transfer->prolongate(level, t[level], solution[level - 1]); this->signals.prolongation(false, level); + + this->signals.edge_prolongation(true, level); solution[level] += t[level]; // get in contribution from edge matrices to the defect @@ -235,6 +243,7 @@ Multigrid::level_step(const unsigned int level, Cycle cycle) edge_up->Tvmult(level, t[level], solution[level - 1]); defect2[level] -= t[level]; } + this->signals.edge_prolongation(false, level); // post-smoothing this->signals.post_smoother_step(true, level); @@ -350,6 +359,26 @@ Multigrid::connect_post_smoother_step( } + +template +boost::signals2::connection +Multigrid::connect_residual_step( + const std::function &slot) +{ + return this->signals.post_smoother_step.connect(slot); +} + + + +template +boost::signals2::connection +Multigrid::connect_edge_prolongation( + const std::function &slot) +{ + return this->signals.edge_prolongation.connect(slot); +} + + DEAL_II_NAMESPACE_CLOSE #endif diff --git a/tests/multigrid/cycles.cc b/tests/multigrid/cycles.cc index 43ff46f3d3..17fe68adea 100644 --- a/tests/multigrid/cycles.cc +++ b/tests/multigrid/cycles.cc @@ -132,6 +132,21 @@ test_cycles(unsigned int minlevel, unsigned int maxlevel) } }; + auto print_residual_step = [](const bool start, const unsigned int level) { + if (start) + { + deallog << "Residual step level " << level << std::endl; + } + }; + + auto print_edge_prolongation = [](const bool start, + const unsigned int level) { + if (start) + { + deallog << "Edge prol. level " << level << std::endl; + } + }; + const auto coarse_connection = mg1.connect_coarse_solve(print_coarse_solve); const auto restriction_connection = mg1.connect_restriction(print_restriction); @@ -141,6 +156,10 @@ test_cycles(unsigned int minlevel, unsigned int maxlevel) mg1.connect_pre_smoother_step(print_pre_smoother_step); const auto post_smoother_connection = mg1.connect_post_smoother_step(print_post_smoother_step); + const auto residual_step_connection = + mg1.connect_residual_step(print_residual_step); + const auto edge_prolongation_connection = + mg1.connect_residual_step(print_edge_prolongation); mg1.cycle(); deallog << std::endl; @@ -150,6 +169,8 @@ test_cycles(unsigned int minlevel, unsigned int maxlevel) prolongation_connection.disconnect(); pre_smoother_connection.disconnect(); post_smoother_connection.disconnect(); + residual_step_connection.disconnect(); + edge_prolongation_connection.disconnect(); } { @@ -198,6 +219,22 @@ test_cycles(unsigned int minlevel, unsigned int maxlevel) } }; + auto print_residual_step_w = [](const bool start, + const unsigned int level) { + if (start) + { + deallog << "W-cycle Res. step level " << level << std::endl; + } + }; + + auto print_edge_prolongation_w = [](const bool start, + const unsigned int level) { + if (start) + { + deallog << "W-cycle Edge pro. level " << level << std::endl; + } + }; + const auto coarse_connection = mg1.connect_coarse_solve(print_coarse_solve_w); const auto restriction_connection = @@ -208,6 +245,10 @@ test_cycles(unsigned int minlevel, unsigned int maxlevel) mg1.connect_pre_smoother_step(print_pre_smoother_step_w); const auto post_smoother_connection = mg1.connect_post_smoother_step(print_post_smoother_step_w); + const auto residual_step_connection = + mg1.connect_residual_step(print_residual_step_w); + const auto edge_prolongation_connection = + mg1.connect_residual_step(print_edge_prolongation_w); mg1.set_cycle(Multigrid::w_cycle); mg1.cycle(); @@ -218,6 +259,8 @@ test_cycles(unsigned int minlevel, unsigned int maxlevel) prolongation_connection.disconnect(); pre_smoother_connection.disconnect(); post_smoother_connection.disconnect(); + residual_step_connection.disconnect(); + edge_prolongation_connection.disconnect(); } { @@ -266,11 +309,29 @@ test_cycles(unsigned int minlevel, unsigned int maxlevel) } }; + auto print_residual_step_f = [](const bool start, + const unsigned int level) { + if (start) + { + deallog << "F-cycle Res. step level " << level << std::endl; + } + }; + + auto print_edge_prolongation_f = [](const bool start, + const unsigned int level) { + if (start) + { + deallog << "F-cycle Edge pro. level " << level << std::endl; + } + }; + mg1.connect_coarse_solve(print_coarse_solve_f); mg1.connect_restriction(print_restriction_f); mg1.connect_prolongation(print_prolongation_f); mg1.connect_pre_smoother_step(print_pre_smoother_step_f); mg1.connect_post_smoother_step(print_post_smoother_step_f); + mg1.connect_residual_step(print_residual_step_f); + mg1.connect_residual_step(print_edge_prolongation_f); mg1.set_cycle(Multigrid::f_cycle); mg1.cycle(); diff --git a/tests/multigrid/cycles.output b/tests/multigrid/cycles.output index 12b14e07bc..f728ae9e8a 100644 --- a/tests/multigrid/cycles.output +++ b/tests/multigrid/cycles.output @@ -31,21 +31,29 @@ DEAL::V-cycle Defect norm 0 DEAL::Smoothing on level 1 DEAL::Solution norm 0 DEAL::V-cycle leaving level 1 +DEAL::Residual step level 1 +DEAL::Edge prol. level 1 DEAL::Prolongate norm 0 DEAL::V-cycle Defect norm 0 DEAL::Smoothing on level 2 DEAL::Solution norm 0 DEAL::V-cycle leaving level 2 +DEAL::Residual step level 2 +DEAL::Edge prol. level 2 DEAL::Prolongate norm 0 DEAL::V-cycle Defect norm 0 DEAL::Smoothing on level 3 DEAL::Solution norm 0 DEAL::V-cycle leaving level 3 +DEAL::Residual step level 3 +DEAL::Edge prol. level 3 DEAL::Prolongate norm 0 DEAL::V-cycle Defect norm 0 DEAL::Smoothing on level 4 DEAL::Solution norm 0 DEAL::V-cycle leaving level 4 +DEAL::Residual step level 4 +DEAL::Edge prol. level 4 DEAL:: DEAL::W-cycle entering level 4 DEAL::W-cycle defect norm 0 @@ -78,6 +86,8 @@ DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 1 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 1 +DEAL::W-cycle Res. step level 1 +DEAL::W-cycle Edge pro. level 1 DEAL::W-cycle entering level 1 DEAL::W-cycle defect norm 0 DEAL::W-cycle smoothing level 1 @@ -91,10 +101,14 @@ DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 1 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 1 +DEAL::W-cycle Res. step level 1 +DEAL::W-cycle Edge pro. level 1 DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 2 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 2 +DEAL::W-cycle Res. step level 2 +DEAL::W-cycle Edge pro. level 2 DEAL::W-cycle entering level 2 DEAL::W-cycle defect norm 0 DEAL::W-cycle smoothing level 2 @@ -114,6 +128,8 @@ DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 1 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 1 +DEAL::W-cycle Res. step level 1 +DEAL::W-cycle Edge pro. level 1 DEAL::W-cycle entering level 1 DEAL::W-cycle defect norm 0 DEAL::W-cycle smoothing level 1 @@ -127,14 +143,20 @@ DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 1 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 1 +DEAL::W-cycle Res. step level 1 +DEAL::W-cycle Edge pro. level 1 DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 2 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 2 +DEAL::W-cycle Res. step level 2 +DEAL::W-cycle Edge pro. level 2 DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 3 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 3 +DEAL::W-cycle Res. step level 3 +DEAL::W-cycle Edge pro. level 3 DEAL::W-cycle entering level 3 DEAL::W-cycle defect norm 0 DEAL::W-cycle smoothing level 3 @@ -160,6 +182,8 @@ DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 1 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 1 +DEAL::W-cycle Res. step level 1 +DEAL::W-cycle Edge pro. level 1 DEAL::W-cycle entering level 1 DEAL::W-cycle defect norm 0 DEAL::W-cycle smoothing level 1 @@ -173,10 +197,14 @@ DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 1 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 1 +DEAL::W-cycle Res. step level 1 +DEAL::W-cycle Edge pro. level 1 DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 2 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 2 +DEAL::W-cycle Res. step level 2 +DEAL::W-cycle Edge pro. level 2 DEAL::W-cycle entering level 2 DEAL::W-cycle defect norm 0 DEAL::W-cycle smoothing level 2 @@ -196,6 +224,8 @@ DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 1 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 1 +DEAL::W-cycle Res. step level 1 +DEAL::W-cycle Edge pro. level 1 DEAL::W-cycle entering level 1 DEAL::W-cycle defect norm 0 DEAL::W-cycle smoothing level 1 @@ -209,18 +239,26 @@ DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 1 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 1 +DEAL::W-cycle Res. step level 1 +DEAL::W-cycle Edge pro. level 1 DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 2 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 2 +DEAL::W-cycle Res. step level 2 +DEAL::W-cycle Edge pro. level 2 DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 3 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 3 +DEAL::W-cycle Res. step level 3 +DEAL::W-cycle Edge pro. level 3 DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 4 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 4 +DEAL::W-cycle Res. step level 4 +DEAL::W-cycle Edge pro. level 4 DEAL:: DEAL::F-cycle entering level 4 DEAL::F-cycle defect norm 0 @@ -253,6 +291,8 @@ DEAL::F-cycle Defect norm 0 DEAL::F-cycle smoothing level 1 DEAL::F-cycle solution norm 0 DEAL::F-cycle leaving level 1 +DEAL::F-cycle Res. step level 1 +DEAL::F-cycle Edge pro. level 1 DEAL::F-cycle entering level 1 DEAL::F-cycle defect norm 0 DEAL::F-cycle smoothing level 1 @@ -266,10 +306,14 @@ DEAL::F-cycle Defect norm 0 DEAL::F-cycle smoothing level 1 DEAL::F-cycle solution norm 0 DEAL::F-cycle leaving level 1 +DEAL::F-cycle Res. step level 1 +DEAL::F-cycle Edge pro. level 1 DEAL::F-cycle Defect norm 0 DEAL::F-cycle smoothing level 2 DEAL::F-cycle solution norm 0 DEAL::F-cycle leaving level 2 +DEAL::F-cycle Res. step level 2 +DEAL::F-cycle Edge pro. level 2 DEAL::F-cycle entering level 2 DEAL::F-cycle defect norm 0 DEAL::F-cycle smoothing level 2 @@ -289,14 +333,20 @@ DEAL::F-cycle Defect norm 0 DEAL::F-cycle smoothing level 1 DEAL::F-cycle solution norm 0 DEAL::F-cycle leaving level 1 +DEAL::F-cycle Res. step level 1 +DEAL::F-cycle Edge pro. level 1 DEAL::F-cycle Defect norm 0 DEAL::F-cycle smoothing level 2 DEAL::F-cycle solution norm 0 DEAL::F-cycle leaving level 2 +DEAL::F-cycle Res. step level 2 +DEAL::F-cycle Edge pro. level 2 DEAL::F-cycle Defect norm 0 DEAL::F-cycle smoothing level 3 DEAL::F-cycle solution norm 0 DEAL::F-cycle leaving level 3 +DEAL::F-cycle Res. step level 3 +DEAL::F-cycle Edge pro. level 3 DEAL::F-cycle entering level 3 DEAL::F-cycle defect norm 0 DEAL::F-cycle smoothing level 3 @@ -322,18 +372,26 @@ DEAL::F-cycle Defect norm 0 DEAL::F-cycle smoothing level 1 DEAL::F-cycle solution norm 0 DEAL::F-cycle leaving level 1 +DEAL::F-cycle Res. step level 1 +DEAL::F-cycle Edge pro. level 1 DEAL::F-cycle Defect norm 0 DEAL::F-cycle smoothing level 2 DEAL::F-cycle solution norm 0 DEAL::F-cycle leaving level 2 +DEAL::F-cycle Res. step level 2 +DEAL::F-cycle Edge pro. level 2 DEAL::F-cycle Defect norm 0 DEAL::F-cycle smoothing level 3 DEAL::F-cycle solution norm 0 DEAL::F-cycle leaving level 3 +DEAL::F-cycle Res. step level 3 +DEAL::F-cycle Edge pro. level 3 DEAL::F-cycle Defect norm 0 DEAL::F-cycle smoothing level 4 DEAL::F-cycle solution norm 0 DEAL::F-cycle leaving level 4 +DEAL::F-cycle Res. step level 4 +DEAL::F-cycle Edge pro. level 4 DEAL::V-cycle entering level 5 DEAL::V-cycle Defect norm 0 DEAL::Smoothing on level 5 @@ -360,16 +418,22 @@ DEAL::V-cycle Defect norm 0 DEAL::Smoothing on level 3 DEAL::Solution norm 0 DEAL::V-cycle leaving level 3 +DEAL::Residual step level 3 +DEAL::Edge prol. level 3 DEAL::Prolongate norm 0 DEAL::V-cycle Defect norm 0 DEAL::Smoothing on level 4 DEAL::Solution norm 0 DEAL::V-cycle leaving level 4 +DEAL::Residual step level 4 +DEAL::Edge prol. level 4 DEAL::Prolongate norm 0 DEAL::V-cycle Defect norm 0 DEAL::Smoothing on level 5 DEAL::Solution norm 0 DEAL::V-cycle leaving level 5 +DEAL::Residual step level 5 +DEAL::Edge prol. level 5 DEAL:: DEAL::W-cycle entering level 5 DEAL::W-cycle defect norm 0 @@ -396,6 +460,8 @@ DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 3 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 3 +DEAL::W-cycle Res. step level 3 +DEAL::W-cycle Edge pro. level 3 DEAL::W-cycle entering level 3 DEAL::W-cycle defect norm 0 DEAL::W-cycle smoothing level 3 @@ -409,10 +475,14 @@ DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 3 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 3 +DEAL::W-cycle Res. step level 3 +DEAL::W-cycle Edge pro. level 3 DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 4 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 4 +DEAL::W-cycle Res. step level 4 +DEAL::W-cycle Edge pro. level 4 DEAL::W-cycle entering level 4 DEAL::W-cycle defect norm 0 DEAL::W-cycle smoothing level 4 @@ -432,6 +502,8 @@ DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 3 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 3 +DEAL::W-cycle Res. step level 3 +DEAL::W-cycle Edge pro. level 3 DEAL::W-cycle entering level 3 DEAL::W-cycle defect norm 0 DEAL::W-cycle smoothing level 3 @@ -445,14 +517,20 @@ DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 3 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 3 +DEAL::W-cycle Res. step level 3 +DEAL::W-cycle Edge pro. level 3 DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 4 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 4 +DEAL::W-cycle Res. step level 4 +DEAL::W-cycle Edge pro. level 4 DEAL::W-cycle Defect norm 0 DEAL::W-cycle smoothing level 5 DEAL::W-cycle solution norm 0 DEAL::W-cycle leaving level 5 +DEAL::W-cycle Res. step level 5 +DEAL::W-cycle Edge pro. level 5 DEAL:: DEAL::F-cycle entering level 5 DEAL::F-cycle defect norm 0 @@ -479,6 +557,8 @@ DEAL::F-cycle Defect norm 0 DEAL::F-cycle smoothing level 3 DEAL::F-cycle solution norm 0 DEAL::F-cycle leaving level 3 +DEAL::F-cycle Res. step level 3 +DEAL::F-cycle Edge pro. level 3 DEAL::F-cycle entering level 3 DEAL::F-cycle defect norm 0 DEAL::F-cycle smoothing level 3 @@ -492,10 +572,14 @@ DEAL::F-cycle Defect norm 0 DEAL::F-cycle smoothing level 3 DEAL::F-cycle solution norm 0 DEAL::F-cycle leaving level 3 +DEAL::F-cycle Res. step level 3 +DEAL::F-cycle Edge pro. level 3 DEAL::F-cycle Defect norm 0 DEAL::F-cycle smoothing level 4 DEAL::F-cycle solution norm 0 DEAL::F-cycle leaving level 4 +DEAL::F-cycle Res. step level 4 +DEAL::F-cycle Edge pro. level 4 DEAL::F-cycle entering level 4 DEAL::F-cycle defect norm 0 DEAL::F-cycle smoothing level 4 @@ -515,11 +599,17 @@ DEAL::F-cycle Defect norm 0 DEAL::F-cycle smoothing level 3 DEAL::F-cycle solution norm 0 DEAL::F-cycle leaving level 3 +DEAL::F-cycle Res. step level 3 +DEAL::F-cycle Edge pro. level 3 DEAL::F-cycle Defect norm 0 DEAL::F-cycle smoothing level 4 DEAL::F-cycle solution norm 0 DEAL::F-cycle leaving level 4 +DEAL::F-cycle Res. step level 4 +DEAL::F-cycle Edge pro. level 4 DEAL::F-cycle Defect norm 0 DEAL::F-cycle smoothing level 5 DEAL::F-cycle solution norm 0 DEAL::F-cycle leaving level 5 +DEAL::F-cycle Res. step level 5 +DEAL::F-cycle Edge pro. level 5