24 #ifdef LIBMESH_ENABLE_AMR 45 const Real refine_frac,
46 const Real coarsen_frac,
47 const unsigned int max_l)
49 parallel_object_only();
57 if (refine_frac != 0.3 ||
58 coarsen_frac != 0.0 ||
80 Real error_min = 1.e30;
84 Real parent_error_min = 1.e30;
85 Real parent_error_max = 0.;
101 libmesh_assert_less (
id, error_per_cell.size());
103 error_max =
std::max (error_max, error_per_cell[
id]);
104 error_min =
std::min (error_min, error_per_cell[
id]);
110 const Real error_delta = (error_max - error_min);
111 const Real parent_error_delta = parent_error_max - parent_error_min;
134 libmesh_assert_less (
id, error_per_cell.size());
144 if (error_per_parent[parentid] >= 0. &&
145 error_per_parent[parentid] <= parent_cutoff)
151 else if (elem_error <= coarsen_cutoff)
158 if (elem_error >= refine_cutoff)
168 parallel_object_only();
180 const Real local_refinement_tolerance =
182 const Real local_coarsening_tolerance =
189 Real parent_error_min, parent_error_max;
203 if (elem_error > local_refinement_tolerance &&
208 local_coarsening_tolerance)
214 if (parent_error >= 0.)
216 const Real parent_coarsening_tolerance =
218 local_coarsening_tolerance *
219 local_coarsening_tolerance);
220 if (parent_error < parent_coarsening_tolerance)
231 parallel_object_only();
262 const std::ptrdiff_t n_elem_new =
263 std::ptrdiff_t(
_nelem_target) - std::ptrdiff_t(n_active_elem);
268 std::vector<std::pair<ErrorVectorReal, dof_id_type>> sorted_error;
270 sorted_error.reserve (n_active_elem);
275 std::vector<bool> is_active(max_elem_id,
false);
280 is_active[eid] =
true;
281 libmesh_assert_less (eid, error_per_cell.size());
282 sorted_error.push_back
283 (std::make_pair(error_per_cell[eid], eid));
292 std::sort (sorted_error.begin(), sorted_error.end());
293 std::reverse (sorted_error.begin(), sorted_error.end());
298 std::vector<std::pair<ErrorVectorReal, dof_id_type>> sorted_parent_error;
299 Real parent_error_min, parent_error_max;
308 for (std::size_t i=0; i != error_per_parent.size(); ++i)
309 if (error_per_parent[i] != -1)
310 sorted_parent_error.push_back(std::make_pair(error_per_parent[i], i));
312 std::sort (sorted_parent_error.begin(), sorted_parent_error.end());
319 unsigned int twotodim = 1;
320 for (
unsigned int i=0; i!=dim; ++i)
329 std::min(cast_int<dof_id_type>(n_elem_new / (twotodim-1)),
337 std::min(cast_int<dof_id_type>(-n_elem_new / (twotodim-1)),
342 while (coarsen_count < max_elem_coarsen &&
343 refine_count < max_elem_refine &&
344 coarsen_count < sorted_parent_error.size() &&
345 refine_count < sorted_error.size() &&
346 sorted_error[refine_count].first >
357 std::vector<bool> is_refinable(max_elem_id,
false);
359 for (std::size_t i=0; i != sorted_error.size(); ++i)
364 is_refinable[eid] =
true;
366 this->
comm().
max(is_refinable);
368 if (refine_count > max_elem_refine)
369 refine_count = max_elem_refine;
370 for (std::size_t i=0; i != sorted_error.size(); ++i)
372 if (successful_refine_count >= refine_count)
377 if (is_refinable[eid])
381 successful_refine_count++;
388 if (coarsen_count < (refine_count - successful_refine_count))
391 coarsen_count -= (refine_count - successful_refine_count);
393 if (coarsen_count > max_elem_coarsen)
394 coarsen_count = max_elem_coarsen;
399 for (std::size_t i=0; i != sorted_parent_error.size(); ++i)
401 if (successful_coarsen_count >= coarsen_count * twotodim)
404 dof_id_type parent_id = sorted_parent_error[i].second;
416 libmesh_assert(elem.active());
418 successful_coarsen_count++;
425 if (!successful_coarsen_count &&
426 !successful_refine_count)
435 const Real refine_frac,
436 const Real coarsen_frac,
437 const unsigned int max_l)
439 parallel_object_only();
447 if (refine_frac != 0.3 ||
448 coarsen_frac != 0.0 ||
450 libmesh_deprecated();
485 std::vector<ErrorVectorReal> sorted_error;
487 sorted_error.reserve (n_active_elem);
492 sorted_error.push_back (error_per_cell[elem->id()]);
497 std::sort (sorted_error.begin(), sorted_error.end());
505 Real parent_error_min, parent_error_max;
512 sorted_parent_error = error_per_parent;
513 std::sort (sorted_parent_error.begin(), sorted_parent_error.end());
516 sorted_parent_error.erase (std::remove(sorted_parent_error.begin(),
517 sorted_parent_error.end(), 0.),
518 sorted_parent_error.end());
529 unsigned int twotodim = 1;
530 for (
unsigned int i=0; i!=dim; ++i)
533 dof_id_type n_parent_coarsen = n_elem_coarsen / (twotodim - 1);
535 if (n_parent_coarsen)
536 bottom_error = sorted_parent_error[n_parent_coarsen - 1];
538 else if (n_elem_coarsen)
540 bottom_error = sorted_error[n_elem_coarsen - 1];
544 top_error = sorted_error[sorted_error.size() - n_elem_refine];
552 error_per_parent[parent->
id()] <= bottom_error)
556 error_per_cell[elem->id()] <= bottom_error)
561 error_per_cell[elem->id()] >= top_error)
569 const Real refine_frac,
570 const Real coarsen_frac,
571 const unsigned int max_l)
579 if (refine_frac != 0.3 ||
580 coarsen_frac != 0.0 ||
582 libmesh_deprecated();
590 const Real mean = error_per_cell.
mean();
594 const Real stddev = std::sqrt (error_per_cell.
variance());
612 libmesh_assert_less (
id, error_per_cell.size());
617 if (elem_error <= coarsen_cutoff)
621 if ((elem_error >= refine_cutoff) && (elem->level() <
_max_h_level))
641 elem->set_p_refinement_flag(elem->refinement_flag());
646 elem->set_p_refinement_flag(elem->refinement_flag());
657 elem->set_p_refinement_flag(elem->refinement_flag());
const Elem * parent() const
virtual dof_id_type n_active_elem() const =0
unsigned int _max_h_level
const unsigned int invalid_uint
void flag_elements_by_error_tolerance(const ErrorVector &error_per_cell)
void allgather(const T &send, std::vector< T, A > &recv) const
bool flag_elements_by_nelem_target(const ErrorVector &error_per_cell)
The base class for all geometric element types.
void set_refinement_flag(const RefinementState rflag)
const Parallel::Communicator & comm() const
virtual Real variance() const override
virtual unsigned int n_children() const =0
void clean_refinement_flags()
void create_parent_error_vector(const ErrorVector &error_per_cell, ErrorVector &error_per_parent, Real &parent_error_min, Real &parent_error_max)
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
long double max(long double a, double b)
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
SimpleRange< ChildRefIter > child_ref_range()
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
void switch_h_to_p_refinement()
void flag_elements_by_mean_stddev(const ErrorVector &error_per_cell, const Real refine_fraction=1.0, const Real coarsen_fraction=0.0, const unsigned int max_level=libMesh::invalid_uint)
virtual SimpleRange< element_iterator > element_ptr_range()=0
bool _use_member_parameters
virtual dof_id_type max_elem_id() const =0
void flag_elements_by(ElementFlagging &element_flagging)
void flag_elements_by_elem_fraction(const ErrorVector &error_per_cell, const Real refine_fraction=0.3, const Real coarsen_fraction=0.0, const unsigned int max_level=libMesh::invalid_uint)
unsigned int level() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
unsigned int mesh_dimension() const
void flag_elements_by_error_fraction(const ErrorVector &error_per_cell, const Real refine_fraction=0.3, const Real coarsen_fraction=0.0, const unsigned int max_level=libMesh::invalid_uint)
void add_p_to_h_refinement()
dof_id_type _nelem_target
long double min(long double a, double b)
bool has_children() const
virtual Real mean() const override
Real _absolute_global_tolerance
const RemoteElem * remote_elem
virtual void flag_elements()=0