mesh_refinement.h
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_MESH_REFINEMENT_H 00021 #define LIBMESH_MESH_REFINEMENT_H 00022 00023 00024 00025 #include "libmesh/libmesh_config.h" 00026 00027 #ifdef LIBMESH_ENABLE_AMR 00028 00029 // Local Includes ----------------------------------- 00030 #include "libmesh/libmesh_common.h" 00031 #include "libmesh/libmesh.h" // libMesh::invalid_uint 00032 #include "libmesh/location_maps.h" 00033 #include "libmesh/elem.h" 00034 #include "libmesh/point_locator_base.h" 00035 00036 // C++ Includes ----------------------------------- 00037 #include <vector> 00038 00039 namespace libMesh 00040 { 00041 00042 // Forward Declarations ----------------------------- 00043 class MeshBase; 00044 class Point; 00045 class Node; 00046 class ErrorVector; 00047 class PeriodicBoundaries; 00048 00049 00050 00059 // ------------------------------------------------------------ 00060 // MeshRefinement class definition 00061 class MeshRefinement 00062 { 00063 public: 00064 00068 explicit 00069 MeshRefinement (MeshBase& mesh); 00070 00071 private: 00072 // Both the copy ctor and the assignment operator are 00073 // declared private but not implemented. This is the 00074 // standard practice to prevent them from being used. 00075 MeshRefinement (const MeshRefinement&); 00076 MeshRefinement& operator=(const MeshRefinement&); 00077 00078 public: 00079 00080 void set_periodic_boundaries_ptr(PeriodicBoundaries * pb_ptr); 00081 00085 ~MeshRefinement (); 00086 00090 void clear (); 00091 00103 void flag_elements_by_error_fraction (const ErrorVector& error_per_cell, 00104 const Real refine_fraction = 0.3, 00105 const Real coarsen_fraction = 0.0, 00106 const unsigned int max_level = libMesh::invalid_uint); 00107 00122 void flag_elements_by_error_tolerance (const ErrorVector& error_per_cell); 00123 00137 bool flag_elements_by_nelem_target (const ErrorVector& error_per_cell); 00138 00152 void flag_elements_by_elem_fraction (const ErrorVector& error_per_cell, 00153 const Real refine_fraction = 0.3, 00154 const Real coarsen_fraction = 0.0, 00155 const unsigned int max_level = libMesh::invalid_uint); 00156 00170 void flag_elements_by_mean_stddev (const ErrorVector& error_per_cell, 00171 const Real refine_fraction = 1.0, 00172 const Real coarsen_fraction = 0.0, 00173 const unsigned int max_level = libMesh::invalid_uint); 00174 00179 void switch_h_to_p_refinement(); 00180 00185 void add_p_to_h_refinement(); 00186 00198 bool refine_and_coarsen_elements (const bool maintain_level_one=true); 00199 00211 bool coarsen_elements (const bool maintain_level_one=true); 00212 00223 bool refine_elements (const bool maintain_level_one=true); 00224 00228 void uniformly_refine (unsigned int n=1); 00229 00233 void uniformly_coarsen (unsigned int n=1); 00234 00238 void uniformly_p_refine (unsigned int n=1); 00239 00243 void uniformly_p_coarsen (unsigned int n=1); 00244 00249 void clean_refinement_flags (); 00250 00257 bool test_level_one (bool libmesh_assert_yes = false); 00258 00266 bool test_unflagged (bool libmesh_assert_yes = false); 00267 00275 Node* add_point (const Point& p, 00276 const processor_id_type processor_id, 00277 const Real tol); 00278 00282 Elem* add_elem (Elem* elem); 00283 00288 const MeshBase& get_mesh () const { return _mesh; } 00289 00294 MeshBase& get_mesh () { return _mesh; } 00295 00303 bool& coarsen_by_parents(); 00304 00312 Real& refine_fraction(); 00313 00321 Real& coarsen_fraction(); 00322 00329 unsigned int& max_h_level(); 00330 00339 Real& coarsen_threshold(); 00340 00348 dof_id_type& nelem_target(); 00349 00359 Real& absolute_global_tolerance(); 00360 00371 unsigned char& face_level_mismatch_limit(); 00372 00382 unsigned char& edge_level_mismatch_limit(); 00383 00393 unsigned char& node_level_mismatch_limit(); 00394 00395 private: 00396 00411 bool _coarsen_elements (); 00412 00421 bool _refine_elements (); 00422 00423 00424 00425 //------------------------------------------------------ 00426 // "Smoothing" algorthms for refined meshes 00427 00492 bool limit_level_mismatch_at_node (const unsigned int max_mismatch); 00493 00494 /* 00495 * This algorithm restricts the maximum level mismatch 00496 * at any edge in the mesh. See the ASCII art in the comment of 00497 * limit_level_mismatch_at_node, and pretend they're hexes. 00498 */ 00499 bool limit_level_mismatch_at_edge (const unsigned int max_mismatch); 00500 00553 bool eliminate_unrefined_patches (); 00554 00555 00556 //--------------------------------------------- 00557 // Utility algorithms 00558 00564 void create_parent_error_vector (const ErrorVector& error_per_cell, 00565 ErrorVector& error_per_parent, 00566 Real &parent_error_min, 00567 Real &parent_error_max); 00568 00572 void update_nodes_map (); 00573 00578 bool make_coarsening_compatible (const bool); 00579 00584 bool make_refinement_compatible (const bool); 00585 00590 bool make_flags_parallel_consistent (); 00591 00596 Elem* topological_neighbor (Elem* elem, 00597 const PointLocatorBase* point_locator, 00598 const unsigned int side); 00599 00604 bool has_topological_neighbor (Elem* elem, 00605 const PointLocatorBase* point_locator, 00606 Elem* neighbor); 00607 00611 LocationMap<Node> _new_nodes_map; 00612 00616 MeshBase& _mesh; 00617 00623 bool _use_member_parameters; 00624 00629 bool _coarsen_by_parents; 00630 00631 Real _refine_fraction; 00632 00633 Real _coarsen_fraction; 00634 00635 unsigned int _max_h_level; 00636 00637 Real _coarsen_threshold; 00638 00639 dof_id_type _nelem_target; 00640 00641 Real _absolute_global_tolerance; 00642 00643 unsigned char _face_level_mismatch_limit, _edge_level_mismatch_limit, 00644 _node_level_mismatch_limit; 00645 00646 #ifdef LIBMESH_ENABLE_PERIODIC 00647 PeriodicBoundaries * _periodic_boundaries; 00648 #endif 00649 }; 00650 00651 00652 00653 // ------------------------------------------------------------ 00654 // MeshRefinement class inline members 00655 00656 inline bool& MeshRefinement::coarsen_by_parents() 00657 { 00658 _use_member_parameters = true; 00659 return _coarsen_by_parents; 00660 } 00661 00662 inline Real& MeshRefinement::refine_fraction() 00663 { 00664 _use_member_parameters = true; 00665 return _refine_fraction; 00666 } 00667 00668 inline Real& MeshRefinement::coarsen_fraction() 00669 { 00670 _use_member_parameters = true; 00671 return _coarsen_fraction; 00672 } 00673 00674 inline unsigned int& MeshRefinement::max_h_level() 00675 { 00676 _use_member_parameters = true; 00677 return _max_h_level; 00678 } 00679 00680 inline Real& MeshRefinement::coarsen_threshold() 00681 { 00682 _use_member_parameters = true; 00683 return _coarsen_threshold; 00684 } 00685 00686 inline dof_id_type& MeshRefinement::nelem_target() 00687 { 00688 _use_member_parameters = true; 00689 return _nelem_target; 00690 } 00691 00692 inline Real& MeshRefinement::absolute_global_tolerance() 00693 { 00694 _use_member_parameters = true; 00695 return _absolute_global_tolerance; 00696 } 00697 00698 inline unsigned char& MeshRefinement::face_level_mismatch_limit() 00699 { 00700 return _face_level_mismatch_limit; 00701 } 00702 00703 inline unsigned char& MeshRefinement::edge_level_mismatch_limit() 00704 { 00705 return _edge_level_mismatch_limit; 00706 } 00707 00708 inline unsigned char& MeshRefinement::node_level_mismatch_limit() 00709 { 00710 return _node_level_mismatch_limit; 00711 } 00712 00713 00714 } // namespace libMesh 00715 00716 #endif // end #ifdef LIBMESH_ENABLE_AMR 00717 #endif // LIBMESH_MESH_REFINEMENT_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:47 UTC
Hosted By: