mesh_refinement.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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"
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 
310  Node * add_node (Elem & parent,
311  unsigned int child,
312  unsigned int node,
313  processor_id_type proc_id);
314 
318  Elem * add_elem (Elem * elem);
319 
324  const MeshBase & get_mesh () const { return _mesh; }
325 
330  MeshBase & get_mesh () { return _mesh; }
331 
339  bool & coarsen_by_parents();
340 
348  Real & refine_fraction();
349 
358 
365  unsigned int & max_h_level();
366 
376 
385 
396 
407  unsigned char & face_level_mismatch_limit();
408 
418  unsigned char & edge_level_mismatch_limit();
419 
429  unsigned char & node_level_mismatch_limit();
430 
448  signed char & overrefined_boundary_limit();
449 
465  signed char & underrefined_boundary_limit();
466 
467 
475 
482 #ifdef LIBMESH_ENABLE_DEPRECATED
484 #endif
485 
492 #ifdef LIBMESH_ENABLE_DEPRECATED
494 #endif
495 
501 
502 private:
503 
517  bool _coarsen_elements ();
518 
527  bool _refine_elements ();
528 
537  void _smooth_flags (bool refining, bool coarsening);
538 
539  //------------------------------------------------------
540  // "Smoothing" algorithms for refined meshes
541 
605  bool limit_level_mismatch_at_node (const unsigned int max_mismatch);
606 
607  /*
608  * This algorithm restricts the maximum level mismatch
609  * at any edge in the mesh. See the ASCII art in the comment of
610  * limit_level_mismatch_at_node, and pretend they're hexes.
611  */
612  bool limit_level_mismatch_at_edge (const unsigned int max_mismatch);
613 
614  /*
615  * This algorithm flags interior elements for refinement as needed
616  * to prevent corresponding boundary element refinement mismatch
617  * from exceeding the given limit.
618  */
619  bool limit_overrefined_boundary (const signed char max_mismatch);
620 
621  /*
622  * This algorithm flags boundary elements for refinement as needed
623  * to prevent corresponding interior element refinement mismatch
624  * from exceeding the given limit.
625  */
626  bool limit_underrefined_boundary (const signed char max_mismatch);
627 
680 
681 
682  //---------------------------------------------
683  // Utility algorithms
684 
690  void create_parent_error_vector (const ErrorVector & error_per_cell,
691  ErrorVector & error_per_parent,
692  Real & parent_error_min,
693  Real & parent_error_max);
694 
698  void update_nodes_map ();
699 
708 
717 
722  Elem * topological_neighbor (Elem * elem,
723  const PointLocatorBase * point_locator,
724  const unsigned int side);
725 
730  bool has_topological_neighbor (const Elem * elem,
731  const PointLocatorBase * point_locator,
732  const Elem * neighbor);
733 
738 
743 
750 
756 
758 
760 
761  unsigned int _max_h_level;
762 
764 
766 
768 
772 
775 
845 
857  NeighborType nt,
858  unsigned max_mismatch);
859 
860 #ifdef LIBMESH_ENABLE_PERIODIC
862 #endif
863 };
864 
865 
866 
867 // ------------------------------------------------------------
868 // MeshRefinement class inline members
869 
871 {
872  _use_member_parameters = true;
873  return _coarsen_by_parents;
874 }
875 
877 {
878  _use_member_parameters = true;
879  return _refine_fraction;
880 }
881 
883 {
884  _use_member_parameters = true;
885  return _coarsen_fraction;
886 }
887 
888 inline unsigned int & MeshRefinement::max_h_level()
889 {
890  _use_member_parameters = true;
891  return _max_h_level;
892 }
893 
895 {
896  _use_member_parameters = true;
897  return _coarsen_threshold;
898 }
899 
901 {
902  _use_member_parameters = true;
903  return _nelem_target;
904 }
905 
907 {
908  _use_member_parameters = true;
910 }
911 
913 {
915 }
916 
918 {
920 }
921 
923 {
925 }
926 
928 {
930 }
931 
933 {
935 }
936 
937 #ifdef LIBMESH_ENABLE_DEPRECATED
939 {
940  libmesh_deprecated();
942 }
943 
945 {
946  libmesh_deprecated();
948 }
949 #endif
950 
952 {
954 }
955 
956 
957 
958 } // namespace libMesh
959 
960 #endif // end #ifdef LIBMESH_ENABLE_AMR
961 #endif // LIBMESH_MESH_REFINEMENT_H
bool limit_level_mismatch_at_edge(const unsigned int max_mismatch)
bool & enforce_mismatch_limit_prior_to_refinement()
void uniformly_p_refine(unsigned int n=1)
Enables topology-based lookups of nodes.
Definition: topology_map.h:69
A geometric point in (x,y,z) space associated with a DOF.
Definition: node.h:52
const unsigned int invalid_uint
Definition: libmesh.h:245
bool limit_level_mismatch_at_node(const unsigned int max_mismatch)
void flag_elements_by_error_tolerance(const ErrorVector &error_per_cell)
bool limit_underrefined_boundary(const signed char max_mismatch)
Maps between boundary ids and PeriodicBoundaryBase objects.
unsigned short int side
Definition: xdr_io.C:50
bool flag_elements_by_nelem_target(const ErrorVector &error_per_cell)
The base class for all geometric element types.
Definition: elem.h:100
MeshBase & mesh
uint8_t processor_id_type
Definition: id_types.h:99
void uniformly_p_coarsen(unsigned int n=1)
unsigned char & edge_level_mismatch_limit()
bool limit_overrefined_boundary(const signed char max_mismatch)
MeshRefinement & operator=(const MeshRefinement &)
void create_parent_error_vector(const ErrorVector &error_per_cell, ErrorVector &error_per_parent, Real &parent_error_min, Real &parent_error_max)
PeriodicBoundaries * _periodic_boundaries
unsigned int & max_h_level()
unsigned int max_level(const MeshBase &mesh)
signed char _underrefined_boundary_limit
Base class for Mesh.
Definition: mesh_base.h:77
dof_id_type & nelem_target()
signed char & underrefined_boundary_limit()
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)
unsigned char & node_level_mismatch_limit()
bool test_level_one(bool libmesh_assert_yes=false)
Responsible for mesh refinement algorithms and data.
unsigned char _face_level_mismatch_limit
void uniformly_coarsen(unsigned int n=1)
void set_enforce_mismatch_limit_prior_to_refinement(bool enforce)
signed char _overrefined_boundary_limit
void flag_elements_by(ElementFlagging &element_flagging)
bool _enforce_mismatch_limit_prior_to_refinement
unsigned char & face_level_mismatch_limit()
An object whose state is distributed along a set of processors.
const MeshBase & get_mesh() const
bool has_topological_neighbor(const Elem *elem, const PointLocatorBase *point_locator, const Elem *neighbor)
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)
MeshRefinement(MeshBase &mesh)
Node * add_node(Elem &parent, unsigned int child, unsigned int node, processor_id_type proc_id)
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)
signed char & overrefined_boundary_limit()
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 _smooth_flags(bool refining, bool coarsening)
bool get_enforce_mismatch_limit_prior_to_refinement()
unsigned char _edge_level_mismatch_limit
void set_periodic_boundaries_ptr(PeriodicBoundaries *pb_ptr)
Elem * topological_neighbor(Elem *elem, const PointLocatorBase *point_locator, const unsigned int side)
uint8_t dof_id_type
Definition: id_types.h:64
void uniformly_refine(unsigned int n=1)