From 80e45e16aa5e53ca62b5312eacc254f40abf0ece Mon Sep 17 00:00:00 2001 From: jodlbauer Date: Wed, 19 Dec 2018 11:14:44 +0100 Subject: [PATCH] block-transfer: only reinit blockvector if required --- .../multigrid/mg_transfer_matrix_free.h | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/include/deal.II/multigrid/mg_transfer_matrix_free.h b/include/deal.II/multigrid/mg_transfer_matrix_free.h index a12554fcbc..d45ac926c5 100644 --- a/include/deal.II/multigrid/mg_transfer_matrix_free.h +++ b/include/deal.II/multigrid/mg_transfer_matrix_free.h @@ -615,10 +615,16 @@ MGTransferBlockMatrixFree::copy_to_mg( &(mg_dof[0]->get_triangulation())) == tria), ExcMessage("The DoFHandler use different Triangulations!")); + MGLevelObject do_reinit; + do_reinit.resize(min_level, max_level); for (unsigned int level = min_level; level <= max_level; ++level) { - dst[level].reinit(n_blocks); - bool collect_size = false; + do_reinit[level] = false; + if (dst[level].n_blocks() != n_blocks) + { + do_reinit[level] = true; + continue; // level + } for (unsigned int b = 0; b < n_blocks; ++b) { LinearAlgebra::distributed::Vector &v = dst[level].block(b); @@ -626,16 +632,27 @@ MGTransferBlockMatrixFree::copy_to_mg( v.local_size() != mg_dof[b]->locally_owned_mg_dofs(level).n_elements()) { + do_reinit[level] = true; + break; // b + } + } + } + + for (unsigned int level = min_level; level <= max_level; ++level) + { + if (do_reinit[level]) + { + dst[level].reinit(n_blocks); + for (unsigned int b = 0; b < n_blocks; ++b) + { + LinearAlgebra::distributed::Vector &v = + dst[level].block(b); v.reinit(mg_dof[b]->locally_owned_mg_dofs(level), tria != nullptr ? tria->get_communicator() : MPI_COMM_SELF); - collect_size = true; } - else - v = 0.; + dst[level].collect_sizes(); } - if (collect_size) - dst[level].collect_sizes(); } } -- 2.39.5