libMesh
mesh_refinement.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 
38 namespace libMesh
39 {
40 
41 // Forward Declarations
42 class MeshBase;
43 class Point;
44 class Node;
45 class ErrorVector;
46 class PeriodicBoundaries;
47 class Elem;
48 class PointLocatorBase;
49 
59 {
60 public:
61 
65  explicit
67 
68 private:
69  // Both the copy ctor and the assignment operator are
70  // declared private but not implemented. This is the
71  // standard practice to prevent them from being used.
74 
75 public:
76 
86  {
87  public:
91  virtual ~ElementFlagging () {}
92 
96  virtual void flag_elements () = 0;
97  };
98 
103 
107  ~MeshRefinement ();
108 
112  void clear ();
113 
125  void flag_elements_by_error_fraction (const ErrorVector & error_per_cell,
126  const Real refine_fraction = 0.3,
127  const Real coarsen_fraction = 0.0,
128  const unsigned int max_level = libMesh::invalid_uint);
129 
144  void flag_elements_by_error_tolerance (const ErrorVector & error_per_cell);
145 
160  bool flag_elements_by_nelem_target (const ErrorVector & error_per_cell);
161 
175  void flag_elements_by_elem_fraction (const ErrorVector & error_per_cell,
176  const Real refine_fraction = 0.3,
177  const Real coarsen_fraction = 0.0,
178  const unsigned int max_level = libMesh::invalid_uint);
179 
193  void flag_elements_by_mean_stddev (const ErrorVector & error_per_cell,
194  const Real refine_fraction = 1.0,
195  const Real coarsen_fraction = 0.0,
196  const unsigned int max_level = libMesh::invalid_uint);
197 
202  void flag_elements_by (ElementFlagging & element_flagging);
203 
209 
214  void add_p_to_h_refinement();
215 
229 
242  bool coarsen_elements ();
243 
255  bool refine_elements ();
256 
260  void uniformly_refine (unsigned int n=1);
261 
265  void uniformly_coarsen (unsigned int n=1);
266 
270  void uniformly_p_refine (unsigned int n=1);
271 
275  void uniformly_p_coarsen (unsigned int n=1);
276 
281  void clean_refinement_flags ();
282 
290  bool test_level_one (bool libmesh_assert_yes = false);
291 
299  bool test_unflagged (bool libmesh_assert_yes = false);
300 
308  Node * add_node (Elem & parent,
309  unsigned int child,
310  unsigned int node,
311  processor_id_type proc_id);
312 
316  Elem * add_elem (Elem * elem);
317 
322  const MeshBase & get_mesh () const { return _mesh; }
323 
328  MeshBase & get_mesh () { return _mesh; }
329 
337  bool & coarsen_by_parents();
338 
346  Real & refine_fraction();
347 
356 
363  unsigned int & max_h_level();
364 
374 
383 
394 
405  unsigned char & face_level_mismatch_limit();
406 
416  unsigned char & edge_level_mismatch_limit();
417 
427  unsigned char & node_level_mismatch_limit();
428 
446  signed char & overrefined_boundary_limit();
447 
463  signed char & underrefined_boundary_limit();
464 
465 
473 
480 #ifdef LIBMESH_ENABLE_DEPRECATED
482 #endif
483 
490 #ifdef LIBMESH_ENABLE_DEPRECATED
492 #endif
493 
499 
500 private:
501 
515  bool _coarsen_elements ();
516 
525  bool _refine_elements ();
526 
535  void _smooth_flags (bool refining, bool coarsening);
536 
537  //------------------------------------------------------
538  // "Smoothing" algorithms for refined meshes
539 
603  bool limit_level_mismatch_at_node (const unsigned int max_mismatch);
604 
605  /*
606  * This algorithm restricts the maximum level mismatch
607  * at any edge in the mesh. See the ASCII art in the comment of
608  * limit_level_mismatch_at_node, and pretend they're hexes.
609  */
610  bool limit_level_mismatch_at_edge (const unsigned int max_mismatch);
611 
612  /*
613  * This algorithm flags interior elements for refinement as needed
614  * to prevent corresponding boundary element refinement mismatch
615  * from exceeding the given limit.
616  */
617  bool limit_overrefined_boundary (const signed char max_mismatch);
618 
619  /*
620  * This algorithm flags boundary elements for refinement as needed
621  * to prevent corresponding interior element refinement mismatch
622  * from exceeding the given limit.
623  */
624  bool limit_underrefined_boundary (const signed char max_mismatch);
625 
678 
679 
680  //---------------------------------------------
681  // Utility algorithms
682 
688  void create_parent_error_vector (const ErrorVector & error_per_cell,
689  ErrorVector & error_per_parent,
690  Real & parent_error_min,
691  Real & parent_error_max);
692 
696  void update_nodes_map ();
697 
706 
715 
720  Elem * topological_neighbor (Elem * elem,
721  const PointLocatorBase * point_locator,
722  const unsigned int side);
723 
728  bool has_topological_neighbor (const Elem * elem,
729  const PointLocatorBase * point_locator,
730  const Elem * neighbor);
731 
736 
741 
748 
754 
756 
758 
759  unsigned int _max_h_level;
760 
762 
764 
766 
770 
773 
843 
855  NeighborType nt,
856  unsigned max_mismatch);
857 
858 #ifdef LIBMESH_ENABLE_PERIODIC
860 #endif
861 };
862 
863 
864 
865 // ------------------------------------------------------------
866 // MeshRefinement class inline members
867 
869 {
870  _use_member_parameters = true;
871  return _coarsen_by_parents;
872 }
873 
875 {
876  _use_member_parameters = true;
877  return _refine_fraction;
878 }
879 
881 {
882  _use_member_parameters = true;
883  return _coarsen_fraction;
884 }
885 
886 inline unsigned int & MeshRefinement::max_h_level()
887 {
888  _use_member_parameters = true;
889  return _max_h_level;
890 }
891 
893 {
894  _use_member_parameters = true;
895  return _coarsen_threshold;
896 }
897 
899 {
900  _use_member_parameters = true;
901  return _nelem_target;
902 }
903 
905 {
906  _use_member_parameters = true;
908 }
909 
911 {
913 }
914 
916 {
918 }
919 
921 {
923 }
924 
926 {
928 }
929 
931 {
933 }
934 
935 #ifdef LIBMESH_ENABLE_DEPRECATED
937 {
938  libmesh_deprecated();
940 }
941 
943 {
944  libmesh_deprecated();
946 }
947 #endif
948 
950 {
952 }
953 
954 
955 
956 } // namespace libMesh
957 
958 #endif // end #ifdef LIBMESH_ENABLE_AMR
959 #endif // LIBMESH_MESH_REFINEMENT_H
bool limit_level_mismatch_at_edge(const unsigned int max_mismatch)
bool & enforce_mismatch_limit_prior_to_refinement()
Get/set the _enforce_mismatch_limit_prior_to_refinement flag.
~MeshRefinement()
Destructor.
void uniformly_p_refine(unsigned int n=1)
Uniformly p refines the mesh n times.
Data structures that enable topology-based lookups of nodes created by mesh refinement.
Definition: topology_map.h:69
bool _refine_elements()
Refines user-requested elements.
A Node is like a Point, but with more information.
Definition: node.h:52
NeighborType
This helper function enforces the desired mismatch limits prior to refinement.
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:184
bool limit_level_mismatch_at_node(const unsigned int max_mismatch)
This algorithm restricts the maximum level mismatch at any node in the mesh.
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...
void update_nodes_map()
Updates the _new_nodes_map.
TopologyMap _new_nodes_map
Data structure that holds the new nodes information.
bool limit_underrefined_boundary(const signed char max_mismatch)
MeshBase & _mesh
Reference to the mesh.
Real & absolute_global_tolerance()
If absolute_global_tolerance is set to a nonzero value, methods like flag_elements_by_global_toleranc...
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
Definition: error_vector.h:50
We&#39;re using a class instead of a typedef to allow forward declarations and future flexibility...
bool refine_elements()
Only refines the user-requested elements.
unsigned short int side
Definition: xdr_io.C:49
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...
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
Real & coarsen_fraction()
The coarsen_fraction sets either a desired target or a desired maximum number of elements to flag for...
MeshBase & mesh
uint8_t processor_id_type
Definition: id_types.h:99
void uniformly_p_coarsen(unsigned int n=1)
Attempts to uniformly p coarsen the mesh n times.
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 limit_overrefined_boundary(const signed char max_mismatch)
Real & refine_fraction()
The refine_fraction sets either a desired target or a desired maximum number of elements to flag for ...
MeshRefinement & operator=(const MeshRefinement &)
void clean_refinement_flags()
Sets the refinement flag to Elem::DO_NOTHING for each element in the mesh.
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.
The libMesh namespace provides an interface to certain functionality in the library.
PeriodicBoundaries * _periodic_boundaries
unsigned int & max_h_level()
The max_h_level is the greatest refinement level an element should reach.
bool & coarsen_by_parents()
If coarsen_by_parents is true, complete groups of sibling elements (elements with the same parent) wi...
unsigned int max_level(const MeshBase &mesh)
Find the maximum h-refinement level in a mesh.
signed char _underrefined_boundary_limit
This is the MeshBase class.
Definition: mesh_base.h:68
bool make_refinement_compatible()
Take user-specified refinement flags and augment them so that level-one dependency is satisfied...
dof_id_type & nelem_target()
If nelem_target is set to a nonzero value, methods like flag_elements_by_nelem_target() will attempt ...
bool coarsen_elements()
Only coarsens the user-requested elements.
signed char & underrefined_boundary_limit()
If underrefined_boundary_limit is set to a nonnegative value, then refinement and coarsening will pro...
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_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 & node_level_mismatch_limit()
If node_level_mismatch_limit is set to a nonzero value, then refinement and coarsening will produce m...
bool test_level_one(bool libmesh_assert_yes=false)
This is the MeshRefinement class.
unsigned char _face_level_mismatch_limit
Abstract base class to be used for user-specified element flagging.
bool _use_member_parameters
For backwards compatibility, we initialize this as false and then set it to true if the user uses any...
void uniformly_coarsen(unsigned int n=1)
Attempts to uniformly coarsen the mesh n times.
Real & coarsen_threshold()
The coarsen_threshold provides hysteresis in AMR/C strategies.
void set_enforce_mismatch_limit_prior_to_refinement(bool enforce)
Set _enforce_mismatch_limit_prior_to_refinement option.
bool make_flags_parallel_consistent()
Copy refinement flags on ghost elements from their local processors.
This is the base class for point locators.
signed char _overrefined_boundary_limit
bool make_coarsening_compatible()
Take user-specified coarsening flags and augment them so that level-one dependency is satisfied...
void flag_elements_by(ElementFlagging &element_flagging)
Flag elements based on a function object.
bool _enforce_mismatch_limit_prior_to_refinement
This option enforces the mismatch level prior to refinement by checking if refining any element marke...
unsigned char & face_level_mismatch_limit()
If face_level_mismatch_limit is set to a nonzero value, then refinement and coarsening will produce m...
This class forms the base class for all other classes that are expected to be implemented in parallel...
bool has_topological_neighbor(const Elem *elem, const PointLocatorBase *point_locator, const Elem *neighbor)
Local dispatch function for checking the correct has_neighbor function from the Elem class...
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...
MeshRefinement(MeshBase &mesh)
Constructor.
Node * add_node(Elem &parent, unsigned int child, unsigned int node, processor_id_type proc_id)
Add a node to the mesh.
unsigned char _node_level_mismatch_limit
bool test_unflagged(bool libmesh_assert_yes=false)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Elem * add_elem(Elem *elem)
Adds the element elem to the mesh.
signed char & overrefined_boundary_limit()
If overrefined_boundary_limit is set to a nonnegative value, then refinement and coarsening will prod...
bool refine_and_coarsen_elements()
Refines and coarsens user-requested elements.
void clear()
Deletes all the data that are currently stored.
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...
void _smooth_flags(bool refining, bool coarsening)
Smooths refinement flags according to current settings.
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 get_enforce_mismatch_limit_prior_to_refinement()
unsigned char _edge_level_mismatch_limit
bool _coarsen_elements()
Coarsens user-requested elements.
bool eliminate_unrefined_patches()
This algorithm selects an element for refinement if all of its neighbors are (or will be) refined...
const MeshBase & get_mesh() const
void set_periodic_boundaries_ptr(PeriodicBoundaries *pb_ptr)
Sets the PeriodicBoundaries pointer.
Elem * topological_neighbor(Elem *elem, const PointLocatorBase *point_locator, const unsigned int side)
Local dispatch function for getting the correct topological neighbor from the Elem class...
bool _coarsen_by_parents
Refinement parameter values.
uint8_t dof_id_type
Definition: id_types.h:64
void uniformly_refine(unsigned int n=1)
Uniformly refines the mesh n times.
virtual void flag_elements()=0
Callback function to be used for marking elements for refinement.