From: Peter Munch Date: Sun, 24 Apr 2022 09:43:24 +0000 (+0200) Subject: Simplify MGTransferBlockMatrixFreeBase::copy_to_mg() X-Git-Tag: v9.4.0-rc1~302^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=105523836bfff3f0bb51b638a19b4f0d6c5e3558;p=dealii.git Simplify MGTransferBlockMatrixFreeBase::copy_to_mg() --- diff --git a/include/deal.II/multigrid/mg_transfer_matrix_free.h b/include/deal.II/multigrid/mg_transfer_matrix_free.h index 84ea6ba8b0..3368326066 100644 --- a/include/deal.II/multigrid/mg_transfer_matrix_free.h +++ b/include/deal.II/multigrid/mg_transfer_matrix_free.h @@ -662,61 +662,9 @@ MGTransferBlockMatrixFreeBase::copy_to_mg( const unsigned int min_level = dst.min_level(); const unsigned int max_level = dst.max_level(); - // this function is normally called within the Multigrid class with - // dst == defect level block vector. At first run this vector is not - // initialized. Do this below: - { - const parallel::TriangulationBase *tria = - (dynamic_cast *>( - &(dof_handler[0]->get_triangulation()))); - for (unsigned int i = 1; i < n_blocks; ++i) - AssertThrow( - (dynamic_cast *>( - &(dof_handler[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) - { - 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); - if (v.size() != - dof_handler[b]->locally_owned_mg_dofs(level).size() || - v.locally_owned_size() != - dof_handler[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(dof_handler[b]->locally_owned_mg_dofs(level), - dof_handler[b]->get_communicator()); - } - dst[level].collect_sizes(); - } - else - dst[level] = 0; - } - } + for (unsigned int level = min_level; level <= max_level; ++level) + if (dst[level].n_blocks() != n_blocks) + dst[level].reinit(n_blocks); // FIXME: this a quite ugly as we need a temporary object: MGLevelObject> dst_non_block( @@ -724,8 +672,6 @@ MGTransferBlockMatrixFreeBase::copy_to_mg( for (unsigned int b = 0; b < n_blocks; ++b) { - for (unsigned int l = min_level; l <= max_level; ++l) - dst_non_block[l].reinit(dst[l].block(b)); const unsigned int data_block = same_for_all ? 0 : b; matrix_free_transfer_vector[data_block].copy_to_mg(*dof_handler[b], dst_non_block, @@ -734,6 +680,9 @@ MGTransferBlockMatrixFreeBase::copy_to_mg( for (unsigned int l = min_level; l <= max_level; ++l) dst[l].block(b) = dst_non_block[l]; } + + for (unsigned int level = min_level; level <= max_level; ++level) + dst[level].collect_sizes(); } template