Skip to content

Commit

Permalink
Merge pull request #12904 from kronbichler/simplify_mg_code
Browse files Browse the repository at this point in the history
  • Loading branch information
Rombur committed Nov 2, 2021
2 parents 4fed8fc + 7db1fbe commit a9d8426
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 57 deletions.
28 changes: 7 additions & 21 deletions include/deal.II/matrix_free/matrix_free.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,14 +835,12 @@ namespace internal
template <typename InIterator>
void
resolve_cell(const InIterator & cell,
std::vector<std::pair<unsigned int, unsigned int>> &cell_its,
const unsigned int subdomain_id)
std::vector<std::pair<unsigned int, unsigned int>> &cell_its)
{
if (cell->has_children())
for (unsigned int child = 0; child < cell->n_children(); ++child)
resolve_cell(cell->child(child), cell_its, subdomain_id);
else if (subdomain_id == numbers::invalid_subdomain_id ||
cell->subdomain_id() == subdomain_id)
resolve_cell(cell->child(child), cell_its);
else if (cell->is_locally_owned())
{
Assert(cell->is_active(), ExcInternalError());
cell_its.emplace_back(cell->level(), cell->index());
Expand All @@ -868,32 +866,20 @@ MatrixFree<dim, Number, VectorizedArrayType>::initialize_dof_handlers(
for (unsigned int no = 0; no < dof_handlers.size(); ++no)
dof_info[no].vectorization_length = VectorizedArrayType::size();

const unsigned int n_mpi_procs = task_info.n_procs;
const unsigned int my_pid = task_info.my_pid;

const Triangulation<dim> &tria = dof_handlers[0]->get_triangulation();
const unsigned int level = additional_data.mg_level;
if (level == numbers::invalid_unsigned_int)
{
if (n_mpi_procs == 1)
cell_level_index.reserve(tria.n_active_cells());
// For serial Triangulations always take all cells
const unsigned int subdomain_id =
(dynamic_cast<const parallel::TriangulationBase<dim> *>(
&dof_handlers[0]->get_triangulation()) != nullptr) ?
my_pid :
numbers::invalid_subdomain_id;
cell_level_index.reserve(tria.n_active_cells());

// Go through cells on zeroth level and then successively step down into
// children. This gives a z-ordering of the cells, which is beneficial
// when setting up neighboring relations between cells for thread
// parallelization
for (const auto &cell : tria.cell_iterators_on_level(0))
internal::MatrixFreeFunctions::resolve_cell(cell,
cell_level_index,
subdomain_id);
internal::MatrixFreeFunctions::resolve_cell(cell, cell_level_index);

Assert(n_mpi_procs > 1 ||
Assert(task_info.n_procs > 1 ||
cell_level_index.size() == tria.n_active_cells(),
ExcInternalError());
}
Expand All @@ -904,7 +890,7 @@ MatrixFree<dim, Number, VectorizedArrayType>::initialize_dof_handlers(
{
cell_level_index.reserve(tria.n_cells(level));
for (const auto &cell : tria.cell_iterators_on_level(level))
if (cell->level_subdomain_id() == my_pid)
if (cell->is_locally_owned_on_level())
cell_level_index.emplace_back(cell->level(), cell->index());
}
}
Expand Down
27 changes: 6 additions & 21 deletions source/multigrid/mg_tools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -606,13 +606,8 @@ namespace MGTools

const unsigned int dofs_per_cell = dof.get_fe().n_dofs_per_cell();
std::vector<types::global_dof_index> dofs_on_this_cell(dofs_per_cell);
typename DoFHandler<dim, spacedim>::cell_iterator cell = dof.begin(level),
endc = dof.end(level);
for (; cell != endc; ++cell)
if (dof.get_triangulation().locally_owned_subdomain() ==
numbers::invalid_subdomain_id ||
cell->level_subdomain_id() ==
dof.get_triangulation().locally_owned_subdomain())
for (const auto &cell : dof.cell_iterators_on_level(level))
if (cell->is_locally_owned_on_level())
{
cell->get_mg_dof_indices(dofs_on_this_cell);
constraints.add_entries_local_to_global(dofs_on_this_cell,
Expand Down Expand Up @@ -1348,9 +1343,7 @@ namespace MGTools
{
for (const auto &cell : dof.cell_iterators())
{
if (dof.get_triangulation().locally_owned_subdomain() !=
numbers::invalid_subdomain_id &&
cell->level_subdomain_id() == numbers::artificial_subdomain_id)
if (cell->is_artificial_on_level())
continue;
const FiniteElement<dim> &fe = cell->get_fe();
const unsigned int level = cell->level();
Expand Down Expand Up @@ -1380,9 +1373,7 @@ namespace MGTools
"It's probably worthwhile to select at least one component."));

for (const auto &cell : dof.cell_iterators())
if (dof.get_triangulation().locally_owned_subdomain() ==
numbers::invalid_subdomain_id ||
cell->level_subdomain_id() != numbers::artificial_subdomain_id)
if (!cell->is_artificial_on_level())
for (const unsigned int face_no : GeometryInfo<dim>::face_indices())
{
if (cell->at_boundary(face_no) == false)
Expand Down Expand Up @@ -1508,9 +1499,7 @@ namespace MGTools
{
// Do not look at artificial level cells (in a serial computation we
// need to ignore the level_subdomain_id() because it is never set).
if (mg_dof_handler.get_triangulation().locally_owned_subdomain() !=
numbers::invalid_subdomain_id &&
cell->level_subdomain_id() == numbers::artificial_subdomain_id)
if (cell->is_artificial_on_level())
continue;

bool has_coarser_neighbor = false;
Expand All @@ -1529,11 +1518,7 @@ namespace MGTools

// only process cell pairs if one or both of them are owned by
// me (ignore if running in serial)
if (mg_dof_handler.get_triangulation()
.locally_owned_subdomain() !=
numbers::invalid_subdomain_id &&
neighbor->level_subdomain_id() ==
numbers::artificial_subdomain_id)
if (neighbor->is_artificial_on_level())
continue;

// Do refinement face from the coarse side
Expand Down
20 changes: 5 additions & 15 deletions source/multigrid/mg_transfer_prebuilt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,11 @@ MGTransferPrebuilt<VectorType>::build(
DoFTools::extract_locally_relevant_level_dofs(dof_handler,
level + 1,
level_p1_relevant_dofs);
DynamicSparsityPattern dsp(this->sizes[level + 1],
DynamicSparsityPattern dsp(this->sizes[level + 1],
this->sizes[level],
level_p1_relevant_dofs);
typename DoFHandler<dim>::cell_iterator cell,
endc = dof_handler.end(level);
for (cell = dof_handler.begin(level); cell != endc; ++cell)
if (cell->has_children() &&
(dof_handler.get_triangulation().locally_owned_subdomain() ==
numbers::invalid_subdomain_id ||
cell->level_subdomain_id() ==
dof_handler.get_triangulation().locally_owned_subdomain()))
for (const auto &cell : dof_handler.cell_iterators_on_level(level))
if (cell->has_children() && cell->is_locally_owned_on_level())
{
cell->get_mg_dof_indices(dof_indices_parent);

Expand Down Expand Up @@ -301,12 +295,8 @@ MGTransferPrebuilt<VectorType>::build(
FullMatrix<typename VectorType::value_type> prolongation;

// now actually build the matrices
for (cell = dof_handler.begin(level); cell != endc; ++cell)
if (cell->has_children() &&
(dof_handler.get_triangulation().locally_owned_subdomain() ==
numbers::invalid_subdomain_id ||
cell->level_subdomain_id() ==
dof_handler.get_triangulation().locally_owned_subdomain()))
for (const auto &cell : dof_handler.cell_iterators_on_level(level))
if (cell->has_children() && cell->is_locally_owned_on_level())
{
cell->get_mg_dof_indices(dof_indices_parent);

Expand Down

0 comments on commit a9d8426

Please sign in to comment.