24#include <deal.II/dofs/dof_accessor.templates.h>
46 template <
int dim,
int spacedim>
50 if (dof_handler.get_fe_collection().size() == 0)
54 Assert(dof_handler.has_hp_capabilities(),
58 dof_handler.get_triangulation().n_active_cells(),
true);
65 template <
int dim,
int spacedim>
68 const std::vector<bool> &
p_flags)
70 if (dof_handler.get_fe_collection().size() == 0)
74 Assert(dof_handler.has_hp_capabilities(),
79 for (
const auto &cell : dof_handler.active_cell_iterators())
80 if (cell->is_locally_owned() &&
p_flags[cell->active_cell_index()])
82 if (cell->refine_flag_set())
85 dof_handler.get_fe_collection().next_in_hierarchy(
86 cell->active_fe_index());
92 else if (cell->coarsen_flag_set())
95 dof_handler.get_fe_collection().previous_in_hierarchy(
96 cell->active_fe_index());
107 template <
int dim,
typename Number,
int spacedim>
119 if (dof_handler.get_fe_collection().size() == 0)
123 Assert(dof_handler.has_hp_capabilities(),
129 dof_handler.get_triangulation().n_active_cells(),
false);
131 for (
const auto &cell : dof_handler.active_cell_iterators())
132 if (cell->is_locally_owned() &&
133 ((cell->refine_flag_set() &&
136 (cell->coarsen_flag_set() &&
139 p_flags[cell->active_cell_index()] =
true;
146 template <
int dim,
typename Number,
int spacedim>
158 if (dof_handler.get_fe_collection().size() == 0)
162 Assert(dof_handler.has_hp_capabilities(),
178 for (
const auto &cell : dof_handler.active_cell_iterators())
179 if (cell->is_locally_owned())
181 if (cell->refine_flag_set())
185 criteria(cell->active_cell_index()));
188 criteria(cell->active_cell_index()));
190 else if (cell->coarsen_flag_set())
194 criteria(cell->active_cell_index()));
197 criteria(cell->active_cell_index()));
203 &dof_handler.get_triangulation());
206 &dof_handler.get_triangulation()) ==
nullptr)
243 template <
int dim,
typename Number,
int spacedim>
255 if (dof_handler.get_fe_collection().size() == 0)
259 Assert(dof_handler.has_hp_capabilities(),
273 [](
const Number &,
const Number &) {
return false; };
275 [](
const Number &,
const Number &) {
return true; };
282 dof_handler.get_triangulation().n_active_cells());
284 dof_handler.get_triangulation().n_active_cells());
285 for (
const auto &cell :
286 dof_handler.get_triangulation().active_cell_iterators())
287 if (!cell->is_artificial() && cell->is_locally_owned())
289 if (cell->refine_flag_set())
291 criteria(cell->active_cell_index());
292 else if (cell->coarsen_flag_set())
294 criteria(cell->active_cell_index());
322 &dof_handler.get_triangulation());
325 &dof_handler.get_triangulation()) ==
nullptr)
327#ifndef DEAL_II_WITH_P4EST
344 static_cast<unsigned int>(
347 static_cast<unsigned int>(
411 std::greater<Number>());
426 std::less<Number>());
444 template <
int dim,
typename Number,
int spacedim>
449 if (dof_handler.get_fe_collection().size() == 0)
453 Assert(dof_handler.has_hp_capabilities(),
458 for (
const auto &cell : dof_handler.active_cell_iterators())
459 if (cell->is_locally_owned())
461 if (cell->refine_flag_set())
464 dof_handler.get_fe_collection().next_in_hierarchy(
465 cell->active_fe_index());
478 else if (cell->coarsen_flag_set())
481 dof_handler.get_fe_collection().previous_in_hierarchy(
482 cell->active_fe_index());
500 template <
int dim,
typename Number,
int spacedim>
511 if (dof_handler.get_fe_collection().size() == 0)
515 Assert(dof_handler.has_hp_capabilities(),
523 dof_handler.get_triangulation().n_active_cells(),
false);
525 for (
const auto &cell : dof_handler.active_cell_iterators())
526 if (cell->is_locally_owned() &&
527 ((cell->refine_flag_set() &&
530 (cell->coarsen_flag_set() &&
533 p_flags[cell->active_cell_index()] =
true;
543 template <
int dim,
typename Number,
int spacedim>
552 if (dof_handler.get_fe_collection().size() == 0)
570 std::map<typename DoFHandler<dim, spacedim>::cell_iterator,
unsigned int>
576 for (
const auto &cell : dof_handler.active_cell_iterators() |
580 if (!(cell->future_fe_index_set()) && !(cell->refine_flag_set()) &&
581 !(cell->coarsen_flag_set()))
589 if (cell->coarsen_flag_set())
592 ExcMessage(
"A coarse cell is flagged for coarsening. "
593 "Please read the note in the documentation "
594 "of predict_error()."));
598 const auto &parent = cell->parent();
603 for (
const auto &child : parent->child_iterators())
604 Assert(child->is_active() && child->coarsen_flag_set(),
606 dim>::ExcInconsistentCoarseningFlags());
610 internal::hp::DoFHandlerImplementation::
611 dominated_future_fe_on_children<dim, spacedim>(parent);
629 dof_handler.get_fe_collection()[cell->future_fe_index()].degree;
633 if (cell->future_fe_index_set())
651 if (cell->refine_flag_set())
659 else if (cell->coarsen_flag_set())
675 template <
int dim,
int spacedim>
679 if (dof_handler.get_fe_collection().size() == 0)
683 Assert(dof_handler.has_hp_capabilities(),
686 for (
const auto &cell : dof_handler.active_cell_iterators())
687 if (cell->is_locally_owned() && cell->future_fe_index_set())
689 cell->clear_refine_flag();
690 cell->clear_coarsen_flag();
696 template <
int dim,
int spacedim>
700 if (dof_handler.get_fe_collection().size() == 0)
704 Assert(dof_handler.has_hp_capabilities(),
711 &dof_handler.get_triangulation()) !=
nullptr)
715 for (
const auto &cell : dof_handler.active_cell_iterators())
716 if (cell->is_locally_owned() && cell->future_fe_index_set())
718 cell->clear_refine_flag();
724 if (cell->coarsen_flag_set())
726 if (cell->level() == 0)
731 cell->clear_coarsen_flag();
735 const auto &parent = cell->parent();
736 const unsigned int n_children = parent->n_children();
739 for (
const auto &child : parent->child_iterators())
741 if (child->is_active())
743 if (child->is_locally_owned())
745 if (child->coarsen_flag_set())
747 if (child->future_fe_index_set())
750 else if (child->is_ghost())
756 (
dynamic_cast<const parallel::shared::
757 Triangulation<dim, spacedim> *
>(
758 &dof_handler.get_triangulation()) !=
nullptr),
761 if (child->coarsen_flag_set())
768 if (internal::DoFCellAccessorImplementation::
770 future_fe_index_set<dim, spacedim, false>(
788 for (
const auto &child : parent->child_iterators())
793 if (child->is_locally_owned())
794 child->clear_future_fe_index();
801 for (
const auto &child : parent->child_iterators())
803 if (child->is_active() && child->is_locally_owned())
804 child->clear_coarsen_flag();
816 template <
int dim,
int spacedim>
822 if (dof_handler.get_fe_collection().size() == 0)
826 Assert(dof_handler.has_hp_capabilities(),
831 "This function does not serve any purpose for max_difference = 0."));
833 dof_handler.get_fe_collection().size());
848 dof_handler.get_fe_collection().get_hierarchy_sequence(
872 &(dof_handler.get_triangulation())))
875 parallel_tria->global_active_cell_index_partitioner().lock());
880 dof_handler.get_triangulation().n_active_cells());
883 for (
const auto &cell : dof_handler.active_cell_iterators() |
908 if (neighbor->is_locally_owned())
946 if (neighbor->coarsen_flag_set() && neighbor->is_locally_owned())
948 const auto parent = neighbor->parent();
952 for (
const auto &child : parent->child_iterators())
954 Assert(child->is_active() && child->coarsen_flag_set(),
956 ExcInconsistentCoarseningFlags()));
962 "The FiniteElement on one of the siblings of "
963 "a cell you are trying to coarsen is not part "
964 "of the registered p-adaptation hierarchy."));
974 for (
const auto &child : parent->child_iterators())
978 if (child->is_locally_owned() &&
1000 for (
const auto &cell : dof_handler.active_cell_iterators())
1001 if (!cell->is_artificial())
1015 for (
unsigned int f = 0; f < cell->n_faces(); ++f)
1016 if (cell->face(f)->at_boundary() ==
false)
1018 if (cell->face(f)->has_children())
1020 for (
unsigned int sf = 0;
1021 sf < cell->face(f)->n_children();
1024 const auto neighbor =
1025 cell->neighbor_child_on_subface(f, sf);
1036 const auto neighbor = cell->neighbor(f);
1049 dof_handler.get_communicator());
1055 for (
const auto &cell : dof_handler.active_cell_iterators() |
1063 const unsigned int fe_index =
1066 if (fe_index != cell->active_fe_index())
1067 cell->set_future_fe_index(fe_index);
1069 cell->clear_future_fe_index();
1080#include "refinement.inst"
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcInvalidParameterValue()
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define DEAL_II_ASSERT_UNREACHABLE()
T sum(const T &t, const MPI_Comm mpi_communicator)
T logical_or(const T &t, const MPI_Comm mpi_communicator)
T max(const T &t, const MPI_Comm mpi_communicator)
T min(const T &t, const MPI_Comm mpi_communicator)
constexpr T pow(const T base, const int iexp)
void force_p_over_h(const DoFHandler< dim, spacedim > &dof_handler)
void p_adaptivity_from_reference(const DoFHandler< dim, spacedim > &dof_handler, const Vector< Number > &criteria, const Vector< Number > &references, const ComparisonFunction< std_cxx20::type_identity_t< Number > > &compare_refine, const ComparisonFunction< std_cxx20::type_identity_t< Number > > &compare_coarsen)
void full_p_adaptivity(const DoFHandler< dim, spacedim > &dof_handler)
void p_adaptivity_from_regularity(const DoFHandler< dim, spacedim > &dof_handler, const Vector< Number > &sobolev_indices)
bool limit_p_level_difference(const DoFHandler< dim, spacedim > &dof_handler, const unsigned int max_difference=1, const unsigned int contains_fe_index=0)
void predict_error(const DoFHandler< dim, spacedim > &dof_handler, const Vector< Number > &error_indicators, Vector< Number > &predicted_errors, const double gamma_p=std::sqrt(0.4), const double gamma_h=2., const double gamma_n=1.)
void p_adaptivity_from_absolute_threshold(const DoFHandler< dim, spacedim > &dof_handler, const Vector< Number > &criteria, const Number p_refine_threshold, const Number p_coarsen_threshold, const ComparisonFunction< std_cxx20::type_identity_t< Number > > &compare_refine=std::greater_equal< Number >(), const ComparisonFunction< std_cxx20::type_identity_t< Number > > &compare_coarsen=std::less_equal< Number >())
void choose_p_over_h(const DoFHandler< dim, spacedim > &dof_handler)
void p_adaptivity_fixed_number(const DoFHandler< dim, spacedim > &dof_handler, const Vector< Number > &criteria, const double p_refine_fraction=0.5, const double p_coarsen_fraction=0.5, const ComparisonFunction< std_cxx20::type_identity_t< Number > > &compare_refine=std::greater_equal< Number >(), const ComparisonFunction< std_cxx20::type_identity_t< Number > > &compare_coarsen=std::less_equal< Number >())
std::function< bool(const Number &, const Number &)> ComparisonFunction
void p_adaptivity_from_relative_threshold(const DoFHandler< dim, spacedim > &dof_handler, const Vector< Number > &criteria, const double p_refine_fraction=0.5, const double p_coarsen_fraction=0.5, const ComparisonFunction< std_cxx20::type_identity_t< Number > > &compare_refine=std::greater_equal< Number >(), const ComparisonFunction< std_cxx20::type_identity_t< Number > > &compare_coarsen=std::less_equal< Number >())
void p_adaptivity_from_flags(const DoFHandler< dim, spacedim > &dof_handler, const std::vector< bool > &p_flags)
void communicate_future_fe_indices(DoFHandler< dim, spacedim > &dof_handler)
number compute_threshold(const ::Vector< number > &criteria, const std::pair< double, double > &global_min_and_max, const types::global_cell_index n_target_cells, const MPI_Comm mpi_communicator)
std::pair< number, number > compute_global_min_and_max_at_root(const ::Vector< number > &criteria, const MPI_Comm mpi_communicator)
static const unsigned int invalid_unsigned_int
typename type_identity< T >::type type_identity_t
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
unsigned short int fe_index