25#include <deal.II/dofs/dof_accessor.templates.h>
47 template <
int dim,
int spacedim>
51 if (dof_handler.get_fe_collection().
size() == 0)
55 Assert(dof_handler.has_hp_capabilities(),
59 dof_handler.get_triangulation().n_active_cells(),
true);
66 template <
int dim,
int spacedim>
69 const std::vector<bool> &
p_flags)
71 if (dof_handler.get_fe_collection().
size() == 0)
75 Assert(dof_handler.has_hp_capabilities(),
80 for (
const auto &cell : dof_handler.active_cell_iterators())
81 if (cell->is_locally_owned() &&
p_flags[cell->active_cell_index()])
83 if (cell->refine_flag_set())
86 dof_handler.get_fe_collection().next_in_hierarchy(
87 cell->active_fe_index());
93 else if (cell->coarsen_flag_set())
96 dof_handler.get_fe_collection().previous_in_hierarchy(
97 cell->active_fe_index());
108 template <
int dim,
typename Number,
int spacedim>
120 if (dof_handler.get_fe_collection().
size() == 0)
124 Assert(dof_handler.has_hp_capabilities(),
130 dof_handler.get_triangulation().n_active_cells(),
false);
132 for (
const auto &cell : dof_handler.active_cell_iterators())
133 if (cell->is_locally_owned() &&
134 ((cell->refine_flag_set() &&
137 (cell->coarsen_flag_set() &&
140 p_flags[cell->active_cell_index()] =
true;
147 template <
int dim,
typename Number,
int spacedim>
159 if (dof_handler.get_fe_collection().
size() == 0)
163 Assert(dof_handler.has_hp_capabilities(),
179 for (
const auto &cell : dof_handler.active_cell_iterators())
180 if (cell->is_locally_owned())
182 if (cell->refine_flag_set())
186 criteria(cell->active_cell_index()));
189 criteria(cell->active_cell_index()));
191 else if (cell->coarsen_flag_set())
195 criteria(cell->active_cell_index()));
198 criteria(cell->active_cell_index()));
204 &dof_handler.get_triangulation());
207 &dof_handler.get_triangulation()) ==
nullptr)
244 template <
int dim,
typename Number,
int spacedim>
256 if (dof_handler.get_fe_collection().
size() == 0)
260 Assert(dof_handler.has_hp_capabilities(),
274 [](
const Number &,
const Number &) {
return false; };
276 [](
const Number &,
const Number &) {
return true; };
283 dof_handler.get_triangulation().n_active_cells());
285 dof_handler.get_triangulation().n_active_cells());
286 for (
const auto &cell :
287 dof_handler.get_triangulation().active_cell_iterators())
288 if (!cell->is_artificial() && cell->is_locally_owned())
290 if (cell->refine_flag_set())
292 criteria(cell->active_cell_index());
293 else if (cell->coarsen_flag_set())
295 criteria(cell->active_cell_index());
323 &dof_handler.get_triangulation());
326 &dof_handler.get_triangulation()) ==
nullptr)
328#ifndef DEAL_II_WITH_P4EST
345 static_cast<unsigned int>(
348 static_cast<unsigned int>(
412 std::greater<Number>());
427 std::less<Number>());
445 template <
int dim,
typename Number,
int spacedim>
450 if (dof_handler.get_fe_collection().
size() == 0)
454 Assert(dof_handler.has_hp_capabilities(),
459 for (
const auto &cell : dof_handler.active_cell_iterators())
460 if (cell->is_locally_owned())
462 if (cell->refine_flag_set())
465 dof_handler.get_fe_collection().next_in_hierarchy(
466 cell->active_fe_index());
479 else if (cell->coarsen_flag_set())
482 dof_handler.get_fe_collection().previous_in_hierarchy(
483 cell->active_fe_index());
501 template <
int dim,
typename Number,
int spacedim>
512 if (dof_handler.get_fe_collection().
size() == 0)
516 Assert(dof_handler.has_hp_capabilities(),
524 dof_handler.get_triangulation().n_active_cells(),
false);
526 for (
const auto &cell : dof_handler.active_cell_iterators())
527 if (cell->is_locally_owned() &&
528 ((cell->refine_flag_set() &&
531 (cell->coarsen_flag_set() &&
534 p_flags[cell->active_cell_index()] =
true;
544 template <
int dim,
typename Number,
int spacedim>
553 if (dof_handler.get_fe_collection().
size() == 0)
571 std::map<typename DoFHandler<dim, spacedim>::cell_iterator,
unsigned int>
577 for (
const auto &cell : dof_handler.active_cell_iterators() |
581 if (!(cell->future_fe_index_set()) && !(cell->refine_flag_set()) &&
582 !(cell->coarsen_flag_set()))
590 if (cell->coarsen_flag_set())
593 ExcMessage(
"A coarse cell is flagged for coarsening. "
594 "Please read the note in the documentation "
595 "of predict_error()."));
599 const auto &parent = cell->parent();
604 for (
const auto &child : parent->child_iterators())
605 Assert(child->is_active() && child->coarsen_flag_set(),
607 dim>::ExcInconsistentCoarseningFlags());
611 internal::hp::DoFHandlerImplementation::
612 dominated_future_fe_on_children<dim, spacedim>(parent);
630 dof_handler.get_fe_collection()[cell->future_fe_index()].degree;
634 if (cell->future_fe_index_set())
642 if (cell->refine_flag_set())
650 else if (cell->coarsen_flag_set())
666 template <
int dim,
int spacedim>
670 if (dof_handler.get_fe_collection().
size() == 0)
674 Assert(dof_handler.has_hp_capabilities(),
677 for (
const auto &cell : dof_handler.active_cell_iterators())
678 if (cell->is_locally_owned() && cell->future_fe_index_set())
680 cell->clear_refine_flag();
681 cell->clear_coarsen_flag();
687 template <
int dim,
int spacedim>
691 if (dof_handler.get_fe_collection().
size() == 0)
695 Assert(dof_handler.has_hp_capabilities(),
702 &dof_handler.get_triangulation()) !=
nullptr)
706 for (
const auto &cell : dof_handler.active_cell_iterators())
707 if (cell->is_locally_owned() && cell->future_fe_index_set())
709 cell->clear_refine_flag();
715 if (cell->coarsen_flag_set())
717 if (cell->level() == 0)
722 cell->clear_coarsen_flag();
726 const auto & parent = cell->parent();
727 const unsigned int n_children = parent->n_children();
730 for (
const auto &child : parent->child_iterators())
732 if (child->is_active())
734 if (child->is_locally_owned())
736 if (child->coarsen_flag_set())
738 if (child->future_fe_index_set())
741 else if (child->is_ghost())
747 (
dynamic_cast<const parallel::shared::
748 Triangulation<dim, spacedim> *
>(
749 &dof_handler.get_triangulation()) !=
nullptr),
752 if (child->coarsen_flag_set())
759 if (internal::DoFCellAccessorImplementation::
761 future_fe_index_set<dim, spacedim, false>(
779 for (
const auto &child : parent->child_iterators())
784 if (child->is_locally_owned())
785 child->clear_future_fe_index();
792 for (
const auto &child : parent->child_iterators())
794 if (child->is_active() && child->is_locally_owned())
795 child->clear_coarsen_flag();
807 template <
int dim,
int spacedim>
813 if (dof_handler.get_fe_collection().
size() == 0)
817 Assert(dof_handler.has_hp_capabilities(),
822 "This function does not serve any purpose for max_difference = 0."));
824 dof_handler.get_fe_collection().
size());
839 dof_handler.get_fe_collection().get_hierarchy_sequence(
863 &(dof_handler.get_triangulation())))
866 parallel_tria->global_active_cell_index_partitioner().lock());
871 dof_handler.get_triangulation().n_active_cells());
874 for (
const auto &cell : dof_handler.active_cell_iterators() |
899 if (neighbor->is_locally_owned())
937 if (neighbor->coarsen_flag_set() && neighbor->is_locally_owned())
939 const auto parent = neighbor->parent();
943 for (
const auto &child : parent->child_iterators())
945 Assert(child->is_active() && child->coarsen_flag_set(),
947 ExcInconsistentCoarseningFlags()));
953 "The FiniteElement on one of the siblings of "
954 "a cell you are trying to coarsen is not part "
955 "of the registered p-adaptation hierarchy."));
965 for (
const auto &child : parent->child_iterators())
969 if (child->is_locally_owned() &&
991 for (
const auto &cell : dof_handler.active_cell_iterators())
992 if (!cell->is_artificial())
1006 for (
unsigned int f = 0; f < cell->n_faces(); ++f)
1007 if (cell->face(f)->at_boundary() ==
false)
1009 if (cell->face(f)->has_children())
1011 for (
unsigned int sf = 0;
1012 sf < cell->face(f)->n_children();
1015 const auto neighbor =
1016 cell->neighbor_child_on_subface(f, sf);
1027 const auto neighbor = cell->neighbor(f);
1040 dof_handler.get_communicator());
1046 for (
const auto &cell : dof_handler.active_cell_iterators() |
1054 const unsigned int fe_index =
1058 if (fe_index != cell->active_fe_index())
1059 cell->set_future_fe_index(fe_index);
1070#include "refinement.inst"
void reinit(value_type *starting_element, const std::size_t n_elements)
#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)
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)
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 > &)
::VectorizedArray< Number, width > pow(const ::VectorizedArray< Number, width > &, const Number p)
unsigned short int fe_index