24 #ifdef LIBMESH_ENABLE_AMR 42 parallel_object_only();
44 bool flags_changed =
false;
48 std::vector<unsigned char> max_level_at_node (
_mesh.
n_nodes(), 0);
49 std::vector<unsigned char> max_p_level_at_node (
_mesh.
n_nodes(), 0);
54 const unsigned char elem_level =
55 cast_int<unsigned char>(elem->level() +
57 const unsigned char elem_p_level =
58 cast_int<unsigned char>(elem->p_level() +
62 for (
unsigned int n=0; n<elem->n_nodes(); n++)
66 libmesh_assert_less (node_number, max_level_at_node.size());
68 max_level_at_node[node_number] =
69 std::max (max_level_at_node[node_number], elem_level);
70 max_p_level_at_node[node_number] =
71 std::max (max_p_level_at_node[node_number], elem_p_level);
82 const unsigned int elem_level = elem->level();
83 const unsigned int elem_p_level = elem->p_level();
94 for (
unsigned int n=0; n<elem->n_nodes(); n++)
100 if ((elem_level + max_mismatch) < max_level_at_node[node_number]
104 flags_changed =
true;
106 if ((elem_p_level + max_mismatch) < max_p_level_at_node[node_number]
110 flags_changed =
true;
119 this->
comm().
max(flags_changed);
121 return flags_changed;
129 parallel_object_only();
131 bool flags_changed =
false;
135 std::map<std::pair<unsigned int, unsigned int>,
unsigned char>
137 std::map<std::pair<unsigned int, unsigned int>,
unsigned char>
143 const unsigned char elem_level =
144 cast_int<unsigned char>(elem->level() +
146 const unsigned char elem_p_level =
147 cast_int<unsigned char>(elem->p_level() +
151 for (
unsigned int n=0; n<elem->n_edges(); n++)
153 std::unique_ptr<const Elem> edge = elem->build_edge_ptr(n);
156 if (childnode1 < childnode0)
159 for (
const Elem * p = elem; p !=
nullptr; p = p->
parent())
161 std::unique_ptr<const Elem> pedge = p->build_edge_ptr(n);
174 if (node0 != childnode0 && node1 != childnode1)
180 std::pair<unsigned int, unsigned int> edge_key =
181 std::make_pair(node0, node1);
183 if (max_level_at_edge.find(edge_key) ==
184 max_level_at_edge.end())
186 max_level_at_edge[edge_key] = elem_level;
187 max_p_level_at_edge[edge_key] = elem_p_level;
191 max_level_at_edge[edge_key] =
192 std::max (max_level_at_edge[edge_key], elem_level);
193 max_p_level_at_edge[edge_key] =
194 std::max (max_p_level_at_edge[edge_key], elem_p_level);
205 const unsigned int elem_level = elem->level();
206 const unsigned int elem_p_level = elem->p_level();
215 for (
unsigned int n=0; n<elem->n_edges(); n++)
217 std::unique_ptr<Elem> edge = elem->build_edge_ptr(n);
223 std::pair<dof_id_type, dof_id_type> edge_key =
224 std::make_pair(node0, node1);
228 if ((elem_level + max_mismatch) < max_level_at_edge[edge_key]
232 flags_changed =
true;
235 if ((elem_p_level + max_mismatch) < max_p_level_at_edge[edge_key]
239 flags_changed =
true;
248 this->
comm().
max(flags_changed);
250 return flags_changed;
258 parallel_object_only();
260 bool flags_changed =
false;
267 if ((elem->dim() >= LIBMESH_DIM) ||
268 !elem->interior_parent())
271 const unsigned char elem_level =
272 cast_int<unsigned char>(elem->level() +
274 const unsigned char elem_p_level =
275 cast_int<unsigned char>(elem->p_level() +
279 std::set<const Elem *> neighbor_set;
280 elem->find_interior_neighbors(neighbor_set);
282 std::set<const Elem *>::iterator n_it = neighbor_set.begin();
283 for (; n_it != neighbor_set.end(); ++n_it)
287 Elem * neighbor =
const_cast<Elem *
>(*n_it);
289 if (max_mismatch >= 0)
291 if ((elem_level > neighbor->
level() + max_mismatch) &&
295 flags_changed =
true;
298 if ((elem_p_level > neighbor->
p_level() + max_mismatch) &&
302 flags_changed =
true;
309 this->
comm().
max(flags_changed);
311 return flags_changed;
319 parallel_object_only();
321 bool flags_changed =
false;
328 if ((elem->dim() >= LIBMESH_DIM) ||
329 !elem->interior_parent())
333 std::set<const Elem *> neighbor_set;
334 elem->find_interior_neighbors(neighbor_set);
336 std::set<const Elem *>::iterator n_it = neighbor_set.begin();
337 for (; n_it != neighbor_set.end(); ++n_it)
341 const Elem * neighbor = *n_it;
343 const unsigned char neighbor_level =
344 cast_int<unsigned char>(neighbor->
level() +
347 const unsigned char neighbor_p_level =
348 cast_int<unsigned char>(neighbor->
p_level() +
351 if (max_mismatch >= 0)
353 if ((neighbor_level >
354 elem->level() + max_mismatch) &&
358 flags_changed =
true;
361 if ((neighbor_p_level >
362 elem->p_level() + max_mismatch) &&
366 flags_changed =
true;
373 this->
comm().
max(flags_changed);
375 return flags_changed;
383 parallel_object_only();
385 bool flags_changed =
false;
396 bool h_flag_me =
false,
398 for (
auto neighbor : elem->neighbor_ptr_range())
401 if (neighbor !=
nullptr && neighbor !=
remote_elem)
421 libmesh_assert(elem->parent());
422 elem = elem->parent();
429 const unsigned int my_level = elem->level();
430 int my_p_adjustment = 0;
435 libmesh_assert_greater (elem->p_level(), 0);
436 my_p_adjustment = -1;
438 const unsigned int my_new_p_level = elem->p_level() +
442 for (
auto neighbor : elem->neighbor_ptr_range())
445 if (neighbor ==
nullptr || neighbor ==
remote_elem)
458 ((neighbor->level() < my_level) ||
462 ((neighbor->active()) &&
483 if (neighbor->active())
485 int p_adjustment = 0;
490 libmesh_assert_greater (neighbor->p_level(), 0);
493 if (my_new_p_level >= neighbor->p_level() + p_adjustment)
502 else if (neighbor->ancestor())
504 if (neighbor->min_new_p_level_by_neighbor(elem,
505 my_new_p_level + 2) <= my_new_p_level)
521 for (
auto & child : elem->child_ref_range())
523 libmesh_assert_equal_to (child.refinement_flag(),
531 flags_changed =
true;
539 flags_changed =
true;
544 this->
comm().
max(flags_changed);
546 return flags_changed;
553 unsigned max_mismatch)
556 bool flags_changed =
false;
566 std::set<const Elem *> neighbor_set;
573 libmesh_error_msg(
"Unrecognized NeighborType: " << nt);
576 for (
const auto & neighbor : neighbor_set)
578 if ((elem->
level() + 1 - max_mismatch) > neighbor->level())
581 flags_changed =
true;
583 if ((elem->
p_level() + 1 - max_mismatch) > neighbor->p_level())
586 flags_changed =
true;
591 return flags_changed;
bool limit_level_mismatch_at_edge(const unsigned int max_mismatch)
bool & enforce_mismatch_limit_prior_to_refinement()
RefinementState refinement_flag() const
const Elem * parent() const
bool limit_level_mismatch_at_node(const unsigned int max_mismatch)
bool limit_underrefined_boundary(const signed char max_mismatch)
RefinementState p_refinement_flag() const
The base class for all geometric element types.
void set_refinement_flag(const RefinementState rflag)
const Parallel::Communicator & comm() const
bool limit_overrefined_boundary(const signed char max_mismatch)
unsigned int p_level() const
void find_edge_neighbors(const Point &p1, const Point &p2, std::set< const Elem *> &neighbor_set) const
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
long double max(long double a, double b)
void find_point_neighbors(const Point &p, std::set< const Elem *> &neighbor_set) const
bool _enforce_mismatch_limit_prior_to_refinement
unsigned int level() const
void swap(Iterator &lhs, Iterator &rhs)
void set_p_refinement_flag(const RefinementState pflag)
bool eliminate_unrefined_patches()
virtual dof_id_type n_nodes() const =0
const RemoteElem * remote_elem