Skip to content

Commit

Permalink
Move implementation of exchange_refinement_flags() to DistributedTria…
Browse files Browse the repository at this point in the history
…ngulationBase.
  • Loading branch information
marcfehling committed Apr 12, 2024
1 parent b4f74bd commit e8c04c8
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 91 deletions.
17 changes: 0 additions & 17 deletions include/deal.II/distributed/tria.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,6 @@ namespace parallel
class TemporarilyMatchRefineFlags;
}
} // namespace parallel

namespace internal
{
namespace parallel
{
namespace distributed
{
namespace TriangulationImplementation
{
template <int dim, int spacedim>
void
exchange_refinement_flags(
dealii::parallel::distributed::Triangulation<dim, spacedim> &);
}
} // namespace distributed
} // namespace parallel
} // namespace internal
# endif

namespace parallel
Expand Down
28 changes: 28 additions & 0 deletions include/deal.II/distributed/tria_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,34 @@

DEAL_II_NAMESPACE_OPEN

// Forward declarations
#ifndef DOXYGEN

namespace parallel
{
template <int dim, int spacedim>
DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<dim, spacedim>))
class DistributedTriangulationBase;
}

namespace internal
{
namespace parallel
{
namespace TriangulationImplementation
{
template <int dim, int spacedim>
void
exchange_refinement_flags(
dealii::parallel::DistributedTriangulationBase<dim, spacedim> &);
}
} // namespace parallel
} // namespace internal

#endif



namespace parallel
{
/**
Expand Down
55 changes: 1 addition & 54 deletions source/distributed/tria.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1685,59 +1685,6 @@ namespace



namespace internal
{
namespace parallel
{
namespace distributed
{
namespace TriangulationImplementation
{
/**
* Communicate refinement flags on ghost cells from the owner of the
* cell.
*
* This is necessary to get consistent refinement, as mesh smoothing
* would undo some of the requested coarsening/refinement.
*/
template <int dim, int spacedim>
void
exchange_refinement_flags(
dealii::parallel::distributed::Triangulation<dim, spacedim> &tria)
{
auto pack =
[](const typename Triangulation<dim, spacedim>::active_cell_iterator
&cell) -> std::uint8_t {
if (cell->refine_flag_set())
return 1;
if (cell->coarsen_flag_set())
return 2;
return 0;
};

auto unpack =
[](const typename Triangulation<dim, spacedim>::active_cell_iterator
&cell,
const std::uint8_t &flag) -> void {
cell->clear_coarsen_flag();
cell->clear_refine_flag();
if (flag == 1)
cell->set_refine_flag();
else if (flag == 2)
cell->set_coarsen_flag();
};

GridTools::exchange_cell_data_to_ghosts<std::uint8_t>(tria,
pack,
unpack);
}
} // namespace TriangulationImplementation
} // namespace distributed
} // namespace parallel
} // namespace internal



namespace parallel
{
namespace distributed
Expand Down Expand Up @@ -2795,7 +2742,7 @@ namespace parallel
// First exchange coarsen/refinement flags on ghost cells. After this
// collective communication call all flags on ghost cells match the
// flags set by the user on the owning rank.
dealii::internal::parallel::distributed::TriangulationImplementation::
dealii::internal::parallel::TriangulationImplementation::
exchange_refinement_flags(*this);

// Now we can call the sequential version to apply mesh smoothing and
Expand Down
19 changes: 0 additions & 19 deletions source/distributed/tria.inst.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,4 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS)
#endif
\}
\}

namespace internal
\{
namespace parallel
\{
namespace distributed
\{
namespace TriangulationImplementation
\{
#if deal_II_dimension <= deal_II_space_dimension
template void
exchange_refinement_flags(
dealii::parallel::distributed::
Triangulation<deal_II_dimension, deal_II_space_dimension> &);
#endif
\}
\}
\}
\}
}
50 changes: 50 additions & 0 deletions source/distributed/tria_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,56 @@

DEAL_II_NAMESPACE_OPEN

namespace internal
{
namespace parallel
{
namespace TriangulationImplementation
{
/**
* Communicate refinement flags on ghost cells from the owner of the
* cell.
*
* This is necessary to get consistent refinement, as mesh smoothing
* would undo some of the requested coarsening/refinement.
*/
template <int dim, int spacedim>
void
exchange_refinement_flags(
dealii::parallel::DistributedTriangulationBase<dim, spacedim> &tria)
{
auto pack =
[](const typename Triangulation<dim, spacedim>::active_cell_iterator
&cell) -> std::uint8_t {
if (cell->refine_flag_set())
return 1;
if (cell->coarsen_flag_set())
return 2;
return 0;
};

auto unpack =
[](const typename Triangulation<dim, spacedim>::active_cell_iterator
&cell,
const std::uint8_t &flag) -> void {
cell->clear_coarsen_flag();
cell->clear_refine_flag();
if (flag == 1)
cell->set_refine_flag();
else if (flag == 2)
cell->set_coarsen_flag();
};

GridTools::exchange_cell_data_to_ghosts<std::uint8_t>(tria,
pack,
unpack);
}
} // namespace TriangulationImplementation
} // namespace parallel
} // namespace internal



namespace parallel
{
template <int dim, int spacedim>
Expand Down
20 changes: 20 additions & 0 deletions source/distributed/tria_base.inst.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,23 @@ for (deal_II_dimension : DIMENSIONS)
#endif
\}
}

for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS)
{
namespace internal
\{
namespace parallel
\{
namespace TriangulationImplementation
\{
#if deal_II_dimension <= deal_II_space_dimension
template void
exchange_refinement_flags(
dealii::parallel::DistributedTriangulationBase<
deal_II_dimension,
deal_II_space_dimension> &);
#endif
\}
\}
\}
}
2 changes: 1 addition & 1 deletion source/hp/refinement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ namespace hp
const_cast<dealii::Triangulation<dim, spacedim> *>(
&dof_handler.get_triangulation())))
{
dealii::internal::parallel::distributed::TriangulationImplementation::
dealii::internal::parallel::TriangulationImplementation::
exchange_refinement_flags(*tria);
}

Expand Down

0 comments on commit e8c04c8

Please sign in to comment.