libMesh
Loading...
Searching...
No Matches
mesh_refinement.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19
20#ifndef LIBMESH_MESH_REFINEMENT_H
21#define LIBMESH_MESH_REFINEMENT_H
22
23
24
25#include "libmesh/libmesh_config.h"
26
27#ifdef LIBMESH_ENABLE_AMR
28
29// Local Includes
30#include "libmesh/libmesh_common.h"
31#include "libmesh/libmesh.h" // libMesh::invalid_uint
32#include "libmesh/topology_map.h"
33#include "libmesh/parallel_object.h"
34
35// C++ Includes
36#include <vector>
37
38namespace libMesh
39{
40
41// Forward Declarations
42class MeshBase;
43class Point;
44class Node;
45class ErrorVector;
46class PeriodicBoundaries;
47class Elem;
48class PointLocatorBase;
49
62{
63public:
64
68 explicit
70
71private:
72 // Both the copy ctor and the assignment operator are
73 // declared private but not implemented. This is the
74 // standard practice to prevent them from being used.
77
78public:
79
89 {
90 public:
94 virtual ~ElementFlagging () = default;
95
99 virtual void flag_elements () = 0;
100 };
101
106
111
115 void clear ();
116
128 void flag_elements_by_error_fraction (const ErrorVector & error_per_cell,
129 const Real refine_fraction = 0.3,
130 const Real coarsen_fraction = 0.0,
131 const unsigned int max_level = libMesh::invalid_uint);
132
147 void flag_elements_by_error_tolerance (const ErrorVector & error_per_cell);
148
163 bool flag_elements_by_nelem_target (const ErrorVector & error_per_cell);
164
178 void flag_elements_by_elem_fraction (const ErrorVector & error_per_cell,
179 const Real refine_fraction = 0.3,
180 const Real coarsen_fraction = 0.0,
181 const unsigned int max_level = libMesh::invalid_uint);
182
196 void flag_elements_by_mean_stddev (const ErrorVector & error_per_cell,
197 const Real refine_fraction = 1.0,
198 const Real coarsen_fraction = 0.0,
199 const unsigned int max_level = libMesh::invalid_uint);
200
205 void flag_elements_by (ElementFlagging & element_flagging);
206
212
218
232
249 bool coarsen_elements ();
250
262 bool refine_elements ();
263
267 void uniformly_refine (unsigned int n=1);
268
272 void uniformly_coarsen (unsigned int n=1);
273
277 void uniformly_p_refine (unsigned int n=1);
278
282 void uniformly_p_coarsen (unsigned int n=1);
283
289
297 bool test_level_one (bool libmesh_assert_yes = false) const;
298
306 bool test_unflagged (bool libmesh_assert_yes = false) const;
307
317 Node * add_node (Elem & parent,
318 unsigned int child,
319 unsigned int node,
320 processor_id_type proc_id);
321
325 Elem * add_elem (Elem * elem);
326
334 Elem * add_elem (std::unique_ptr<Elem> elem);
335
340 const MeshBase & get_mesh () const { return _mesh; }
341
346 MeshBase & get_mesh () { return _mesh; }
347
355 bool & coarsen_by_parents();
356
365
374
381 unsigned int & max_h_level();
382
392
401
412
423 unsigned char & face_level_mismatch_limit();
424
434 unsigned char & edge_level_mismatch_limit();
435
445 unsigned char & node_level_mismatch_limit();
446
464 signed char & overrefined_boundary_limit();
465
481 signed char & underrefined_boundary_limit();
482
493
501
509
510private:
511
525 bool _coarsen_elements ();
526
535 bool _refine_elements ();
536
545 void _smooth_flags (bool refining, bool coarsening);
546
547 //------------------------------------------------------
548 // "Smoothing" algorithms for refined meshes
549
613 bool limit_level_mismatch_at_node (const unsigned int max_mismatch);
614
615 /*
616 * This algorithm restricts the maximum level mismatch
617 * at any edge in the mesh. See the ASCII art in the comment of
618 * limit_level_mismatch_at_node, and pretend they're hexes.
619 */
620 bool limit_level_mismatch_at_edge (const unsigned int max_mismatch);
621
622 /*
623 * This algorithm flags interior elements for refinement as needed
624 * to prevent corresponding boundary element refinement mismatch
625 * from exceeding the given limit.
626 */
627 bool limit_overrefined_boundary (const signed char max_mismatch);
628
629 /*
630 * This algorithm flags boundary elements for refinement as needed
631 * to prevent corresponding interior element refinement mismatch
632 * from exceeding the given limit.
633 */
634 bool limit_underrefined_boundary (const signed char max_mismatch);
635
690
691
692 //---------------------------------------------
693 // Utility algorithms
694
700 void create_parent_error_vector (const ErrorVector & error_per_cell,
701 ErrorVector & error_per_parent,
702 Real & parent_error_min,
703 Real & parent_error_max);
704
708 void update_nodes_map ();
709
718
727
733 const PointLocatorBase * point_locator,
734 const unsigned int side) const;
735
740 bool has_topological_neighbor (const Elem * elem,
741 const PointLocatorBase * point_locator,
742 const Elem * neighbor) const;
743
748
753
760
766
768
770
771 unsigned int _max_h_level;
772
774
776
778
782
785
787
857
869 NeighborType nt,
870 unsigned max_mismatch);
871
872#ifdef LIBMESH_ENABLE_PERIODIC
874#endif
875};
876
877
878
879// ------------------------------------------------------------
880// MeshRefinement class inline members
881
883{
885 return _coarsen_by_parents;
886}
887
893
899
900inline unsigned int & MeshRefinement::max_h_level()
901{
903 return _max_h_level;
904}
905
911
917
923
925{
927}
928
930{
932}
933
935{
937}
938
943
948
953
958
959inline bool
964
965inline void
970
971
972
973} // namespace libMesh
974
975#endif // end #ifdef LIBMESH_ENABLE_AMR
976#endif // LIBMESH_MESH_REFINEMENT_H
This is the base class from which all geometric element types are derived.
Definition elem.h:96
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
This is the MeshBase class.
Definition mesh_base.h:81
Abstract base class to be used for user-specified element flagging.
virtual ~ElementFlagging()=default
Destructor.
virtual void flag_elements()=0
Callback function to be used for marking elements for refinement.
Implements (adaptive) mesh refinement algorithms for a MeshBase.
Elem * add_elem(Elem *elem)
Adds the element elem to the mesh.
void uniformly_coarsen(unsigned int n=1)
Attempts to uniformly coarsen the mesh n times.
bool make_flags_parallel_consistent()
Copy refinement flags on ghost elements from their local processors.
Elem * topological_neighbor(Elem *elem, const PointLocatorBase *point_locator, const unsigned int side) const
Local dispatch function for getting the correct topological neighbor from the Elem class.
void uniformly_p_coarsen(unsigned int n=1)
Attempts to uniformly p coarsen the mesh n times.
bool make_coarsening_compatible()
Take user-specified coarsening flags and augment them so that level-one dependency is satisfied.
signed char _underrefined_boundary_limit
bool limit_underrefined_boundary(const signed char max_mismatch)
bool eliminate_unrefined_patches()
This algorithm selects an element for refinement if all of its neighbors are (or will be) refined.
void update_nodes_map()
Updates the _new_nodes_map.
void flag_elements_by_error_tolerance(const ErrorVector &error_per_cell)
Flags elements for coarsening and refinement based on the computed error passed in error_per_cell.
bool has_topological_neighbor(const Elem *elem, const PointLocatorBase *point_locator, const Elem *neighbor) const
Local dispatch function for checking the correct has_neighbor function from the Elem class.
bool _enforce_mismatch_limit_prior_to_refinement
This option enforces the mismatch level prior to refinement by checking if refining any element marke...
NeighborType
This helper function enforces the desired mismatch limits prior to refinement.
Real & absolute_global_tolerance()
If absolute_global_tolerance is set to a nonzero value, methods like flag_elements_by_global_toleranc...
bool limit_overrefined_boundary(const signed char max_mismatch)
void uniformly_refine(unsigned int n=1)
Uniformly refines the mesh n times.
bool coarsen_elements()
Only coarsens the user-requested elements.
bool _coarsen_elements()
Coarsens user-requested elements.
PeriodicBoundaries * _periodic_boundaries
signed char _overrefined_boundary_limit
bool & enforce_mismatch_limit_prior_to_refinement()
Get/set the _enforce_mismatch_limit_prior_to_refinement flag.
void switch_h_to_p_refinement()
Takes a mesh whose elements are flagged for h refinement and coarsening, and switches those flags to ...
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)
Flags elements for coarsening and refinement based on the computed error passed in error_per_cell.
unsigned char _face_level_mismatch_limit
bool & coarsen_by_parents()
If coarsen_by_parents is true, complete groups of sibling elements (elements with the same parent) wi...
TopologyMap _new_nodes_map
Data structure that holds the new nodes information.
bool limit_level_mismatch_at_edge(const unsigned int max_mismatch)
void clean_refinement_flags()
Sets the refinement flag to Elem::DO_NOTHING for each element in the mesh.
MeshBase & _mesh
Reference to the mesh.
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)
Flags elements for coarsening and refinement based on the computed error passed in error_per_cell.
const MeshBase & get_mesh() const
bool flag_elements_by_nelem_target(const ErrorVector &error_per_cell)
Flags elements for coarsening and refinement based on the computed error passed in error_per_cell.
bool & allow_unrefined_patches()
This flag defaults to false in order to maintain the original behavior of the code,...
unsigned char & node_level_mismatch_limit()
If node_level_mismatch_limit is set to a nonzero value, then refinement and coarsening will produce m...
Real & coarsen_threshold()
The coarsen_threshold provides hysteresis in AMR/C strategies.
unsigned char & face_level_mismatch_limit()
If face_level_mismatch_limit is set to a nonzero value, then refinement and coarsening will produce m...
void _smooth_flags(bool refining, bool coarsening)
Smooths refinement flags according to current settings.
dof_id_type & nelem_target()
If nelem_target is set to a nonzero value, methods like flag_elements_by_nelem_target() will attempt ...
void set_periodic_boundaries_ptr(PeriodicBoundaries *pb_ptr)
Sets the PeriodicBoundaries pointer.
MeshRefinement(const MeshRefinement &)
Node * add_node(Elem &parent, unsigned int child, unsigned int node, processor_id_type proc_id)
Add a node to the mesh.
unsigned int & max_h_level()
The max_h_level is the greatest refinement level an element should reach.
void flag_elements_by(ElementFlagging &element_flagging)
Flag elements based on a function object.
signed char & underrefined_boundary_limit()
If underrefined_boundary_limit is set to a nonnegative value, then refinement and coarsening will pro...
void add_p_to_h_refinement()
Takes a mesh whose elements are flagged for h refinement and coarsening, and adds flags to request p ...
bool refine_and_coarsen_elements()
Refines and coarsens user-requested elements.
bool test_level_one(bool libmesh_assert_yes=false) const
bool _coarsen_by_parents
Refinement parameter values.
void create_parent_error_vector(const ErrorVector &error_per_cell, ErrorVector &error_per_parent, Real &parent_error_min, Real &parent_error_max)
Calculates the error on all coarsenable parents.
~MeshRefinement()
Destructor.
void clear()
Deletes all the data that are currently stored.
Real & refine_fraction()
The refine_fraction sets either a desired target or a desired maximum number of elements to flag for ...
void uniformly_p_refine(unsigned int n=1)
Uniformly p refines the mesh n times.
bool limit_level_mismatch_at_node(const unsigned int max_mismatch)
This algorithm restricts the maximum level mismatch at any node in the mesh.
bool _use_member_parameters
For backwards compatibility, we initialize this as false and then set it to true if the user uses any...
bool _refine_elements()
Refines user-requested elements.
unsigned char & edge_level_mismatch_limit()
If edge_level_mismatch_limit is set to a nonzero value, then refinement and coarsening will produce m...
bool test_unflagged(bool libmesh_assert_yes=false) const
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)
Flags elements for coarsening and refinement based on the computed error passed in error_per_cell.
unsigned char _edge_level_mismatch_limit
unsigned char _node_level_mismatch_limit
bool refine_elements()
Only refines the user-requested elements.
MeshRefinement & operator=(const MeshRefinement &)
bool make_refinement_compatible()
Take user-specified refinement flags and augment them so that level-one dependency is satisfied.
signed char & overrefined_boundary_limit()
If overrefined_boundary_limit is set to a nonnegative value, then refinement and coarsening will prod...
Real & coarsen_fraction()
The coarsen_fraction sets either a desired target or a desired maximum number of elements to flag for...
A Node is like a Point, but with more information.
Definition node.h:55
An object whose state is distributed along a set of processors.
We're using a class instead of a typedef to allow forward declarations and future flexibility.
This is the base class for point locators.
Data structures that enable topology-based lookups of nodes created by mesh refinement.
MeshBase & mesh
The libMesh namespace provides an interface to certain functionality in the library.
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
Definition libmesh.h:303
uint8_t dof_id_type
Definition id_types.h:67
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type
Definition id_types.h:104