Skip to content

Commit

Permalink
Merge pull request #13636 from peterrum/MGTransferBlockMatrixFreeBase…
Browse files Browse the repository at this point in the history
…_copy_to_mg

Simplify MGTransferBlockMatrixFreeBase::copy_to_mg()
  • Loading branch information
kronbichler committed Apr 26, 2022
2 parents e99aafd + 1055238 commit 7e1892d
Showing 1 changed file with 6 additions and 57 deletions.
63 changes: 6 additions & 57 deletions include/deal.II/multigrid/mg_transfer_matrix_free.h
Original file line number Diff line number Diff line change
Expand Up @@ -662,70 +662,16 @@ MGTransferBlockMatrixFreeBase<dim, Number, TransferType>::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<dim, spacedim> *tria =
(dynamic_cast<const parallel::TriangulationBase<dim, spacedim> *>(
&(dof_handler[0]->get_triangulation())));
for (unsigned int i = 1; i < n_blocks; ++i)
AssertThrow(
(dynamic_cast<const parallel::TriangulationBase<dim, spacedim> *>(
&(dof_handler[0]->get_triangulation())) == tria),
ExcMessage("The DoFHandler use different Triangulations!"));

MGLevelObject<bool> 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<Number> &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<Number> &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<LinearAlgebra::distributed::Vector<Number>> dst_non_block(
min_level, max_level);

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,
Expand All @@ -734,6 +680,9 @@ MGTransferBlockMatrixFreeBase<dim, Number, TransferType>::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 <int dim, typename Number, typename TransferType>
Expand Down

0 comments on commit 7e1892d

Please sign in to comment.