Skip to content

Commit

Permalink
Move implementation of exchange_refinement_flags() to cc file.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcfehling committed Apr 11, 2024
1 parent cae1c7b commit c15ede0
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 53 deletions.
71 changes: 21 additions & 50 deletions include/deal.II/distributed/tria.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <deal.II/distributed/p4est_wrappers.h>
#include <deal.II/distributed/tria_base.h>

#include <deal.II/grid/grid_tools.h>
#include <deal.II/grid/tria.h>

#include <boost/range/iterator_range.hpp>
Expand Down Expand Up @@ -74,10 +73,30 @@ namespace parallel
{
namespace distributed
{
template <int, int>
class Triangulation;

template <int, int>
class TemporarilyMatchRefineFlags;
}
} // namespace distributed
} // 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 Expand Up @@ -1098,54 +1117,6 @@ namespace parallel



namespace internal
{
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,
dealii::parallel::distributed::Triangulation<dim, spacedim>>(tria,
pack,
unpack);
}
} // namespace TriangulationImplementation
} // namespace internal



namespace parallel
{
namespace distributed
Expand Down
57 changes: 55 additions & 2 deletions source/distributed/tria.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,59 @@ 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 @@ -2742,8 +2795,8 @@ 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::TriangulationImplementation::exchange_refinement_flags(
*this);
dealii::internal::parallel::distributed::TriangulationImplementation::
exchange_refinement_flags(*this);

// Now we can call the sequential version to apply mesh smoothing and
// other modifications:
Expand Down
2 changes: 1 addition & 1 deletion source/hp/refinement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ namespace hp
const_cast<dealii::Triangulation<dim, spacedim> *>(
&dof_handler.get_triangulation())))
{
dealii::internal::TriangulationImplementation::
dealii::internal::parallel::distributed::TriangulationImplementation::
exchange_refinement_flags(*tria);
}

Expand Down

0 comments on commit c15ede0

Please sign in to comment.