mesh_base.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_BASE_H 00021 #define LIBMESH_MESH_BASE_H 00022 00023 00024 00025 // Local Includes ----------------------------------- 00026 #include "libmesh/auto_ptr.h" 00027 #include "libmesh/boundary_info.h" 00028 #include "libmesh/dof_object.h" // for invalid_processor_id 00029 #include "libmesh/enum_elem_type.h" 00030 #include "libmesh/libmesh_common.h" 00031 #include "libmesh/multi_predicates.h" 00032 #include "libmesh/partitioner.h" // AutoPtr needs a real declaration 00033 #include "libmesh/point_locator_base.h" 00034 #include "libmesh/variant_filter_iterator.h" 00035 00036 // C++ Includes ----------------------------------- 00037 #include <cstddef> 00038 #include <string> 00039 00040 namespace libMesh 00041 { 00042 00043 // forward declarations 00044 class Elem; 00045 class Node; 00046 class Point; 00047 class MeshData; 00048 00049 00050 00066 // ------------------------------------------------------------ 00067 // MeshBase class definition 00068 class MeshBase 00069 { 00070 public: 00071 00077 MeshBase (unsigned int dim=1); 00078 00082 MeshBase (const MeshBase& other_mesh); 00083 00087 virtual AutoPtr<MeshBase> clone() const = 0; 00088 00092 virtual ~MeshBase (); 00093 00099 AutoPtr<BoundaryInfo> boundary_info; 00100 00104 virtual AutoPtr<Partitioner> &partitioner() { return _partitioner; } 00105 00109 virtual void clear (); 00110 00115 bool is_prepared () const 00116 { return _is_prepared; } 00117 00122 virtual bool is_serial () const 00123 { return true; } 00124 00129 virtual void allgather () {} 00130 00136 virtual void delete_remote_elements () {} 00137 00144 unsigned int mesh_dimension () const 00145 { return static_cast<unsigned int>(_dim); } 00146 00150 void set_mesh_dimension (unsigned int d) 00151 { _dim = d; } 00152 00157 unsigned int spatial_dimension () const 00158 { return static_cast<unsigned int>(LIBMESH_DIM); } 00159 00167 virtual dof_id_type n_nodes () const = 0; 00168 00176 virtual dof_id_type parallel_n_nodes () const = 0; 00177 00181 dof_id_type n_nodes_on_proc (const processor_id_type proc) const; 00182 00186 dof_id_type n_local_nodes () const 00187 { return this->n_nodes_on_proc (libMesh::processor_id()); } 00188 00192 dof_id_type n_unpartitioned_nodes () const 00193 { return this->n_nodes_on_proc (DofObject::invalid_processor_id); } 00194 00199 virtual dof_id_type max_node_id () const = 0; 00200 00208 virtual void reserve_nodes (const dof_id_type nn) = 0; 00209 00215 virtual dof_id_type n_elem () const = 0; 00216 00223 virtual dof_id_type parallel_n_elem () const = 0; 00224 00229 virtual dof_id_type max_elem_id () const = 0; 00230 00238 virtual void reserve_elem (const dof_id_type ne) = 0; 00239 00244 virtual void update_parallel_id_counts () = 0; 00245 00250 virtual dof_id_type n_active_elem () const = 0; 00251 00255 dof_id_type n_elem_on_proc (const processor_id_type proc) const; 00256 00260 dof_id_type n_local_elem () const 00261 { return this->n_elem_on_proc (libMesh::processor_id()); } 00262 00266 dof_id_type n_unpartitioned_elem () const 00267 { return this->n_elem_on_proc (DofObject::invalid_processor_id); } 00268 00272 dof_id_type n_active_elem_on_proc (const processor_id_type proc) const; 00273 00277 dof_id_type n_active_local_elem () const 00278 { return this->n_active_elem_on_proc (libMesh::processor_id()); } 00279 00287 dof_id_type n_sub_elem () const; 00288 00292 dof_id_type n_active_sub_elem () const; 00293 00299 virtual const Point& point (const dof_id_type i) const = 0; 00300 00306 virtual const Node& node (const dof_id_type i) const = 0; 00307 00312 virtual Node& node (const dof_id_type i) = 0; 00313 00318 virtual const Node* node_ptr (const dof_id_type i) const = 0; 00319 00325 virtual Node* node_ptr (const dof_id_type i) = 0; 00326 00331 virtual const Node* query_node_ptr (const dof_id_type i) const = 0; 00332 00337 virtual Node* query_node_ptr (const dof_id_type i) = 0; 00338 00343 virtual const Elem* elem (const dof_id_type i) const = 0; 00344 00350 virtual Elem* elem (const dof_id_type i) = 0; 00351 00356 virtual const Elem* query_elem (const dof_id_type i) const = 0; 00357 00362 virtual Elem* query_elem (const dof_id_type i) = 0; 00363 00374 virtual Node* add_point (const Point& p, 00375 const dof_id_type id = DofObject::invalid_id, 00376 const processor_id_type proc_id = 00377 DofObject::invalid_processor_id) = 0; 00378 00382 virtual Node* add_node (Node* n) = 0; 00383 00387 virtual void delete_node (Node* n) = 0; 00388 00394 virtual void renumber_node (dof_id_type old_id, dof_id_type new_id) = 0; 00395 00402 virtual Elem* add_elem (Elem* e) = 0; 00403 00408 virtual Elem* insert_elem (Elem* e) = 0; 00409 00416 virtual void delete_elem (Elem* e) = 0; 00417 00423 virtual void renumber_elem (dof_id_type old_id, dof_id_type new_id) = 0; 00424 00437 virtual void find_neighbors (const bool reset_remote_elements = false, 00438 const bool reset_current_list = true) = 0; 00439 00445 virtual void renumber_nodes_and_elements () = 0; 00446 00453 virtual void fix_broken_node_and_element_numbering () = 0; 00454 00455 00456 #ifdef LIBMESH_ENABLE_AMR 00457 00462 virtual bool contract () = 0; 00463 #endif 00464 00475 void prepare_for_use (const bool skip_renumber_nodes_and_elements=false); 00476 00480 virtual void partition (const unsigned int n_parts=libMesh::n_processors()); 00481 00487 virtual void redistribute () {} 00488 00493 virtual void update_post_partitioning () {} 00494 00501 void allow_renumbering(bool allow) { _skip_renumber_nodes_and_elements = !allow; } 00502 bool allow_renumbering() const { return !_skip_renumber_nodes_and_elements; } 00503 00516 void skip_partitioning(bool skip) { _skip_partitioning = skip; } 00517 bool skip_partitioning() const { return _skip_partitioning; } 00518 00526 void subdomain_ids (std::set<subdomain_id_type> &ids) const; 00527 00535 subdomain_id_type n_subdomains () const; 00536 00543 unsigned int n_partitions () const 00544 { return _n_parts; } 00545 00550 processor_id_type n_processors () const 00551 { return libmesh_cast_int<processor_id_type>(libMesh::n_processors()); } 00552 00556 processor_id_type processor_id () const 00557 { return libmesh_cast_int<processor_id_type>(libMesh::processor_id()); } 00558 00563 std::string get_info () const; 00564 00568 void print_info (std::ostream& os=libMesh::out) const; 00569 00575 friend std::ostream& operator << (std::ostream& os, const MeshBase& m); 00576 00581 virtual void read (const std::string& name, MeshData* mesh_data=NULL, 00582 bool skip_renumber_nodes_and_elements=false) = 0; 00583 virtual void write (const std::string& name, MeshData* mesh_data=NULL) = 0; 00584 00591 virtual void all_first_order () = 0; 00592 00604 virtual void all_second_order (const bool full_ordered=true) = 0; 00605 00610 typedef Predicates::multi_predicate Predicate; 00611 00618 struct element_iterator; 00619 struct const_element_iterator; 00620 00627 struct node_iterator; 00628 struct const_node_iterator; 00629 00639 unsigned int recalculate_n_partitions(); 00640 00647 const PointLocatorBase& point_locator () const; 00648 00656 AutoPtr<PointLocatorBase> sub_point_locator () const; 00657 00661 void clear_point_locator (); 00662 00670 virtual void libmesh_assert_valid_parallel_ids() const {} 00671 00676 std::string& subdomain_name(subdomain_id_type id); 00677 const std::string& subdomain_name(subdomain_id_type id) const; 00678 00683 subdomain_id_type get_id_by_name(const std::string& name) const; 00684 00685 public: 00686 00687 00688 00693 virtual element_iterator elements_begin () = 0; 00694 virtual element_iterator elements_end () = 0; 00695 virtual element_iterator active_elements_begin () = 0; 00696 virtual element_iterator active_elements_end () = 0; 00697 virtual element_iterator ancestor_elements_begin () = 0; 00698 virtual element_iterator ancestor_elements_end () = 0; 00699 virtual element_iterator subactive_elements_begin () = 0; 00700 virtual element_iterator subactive_elements_end () = 0; 00701 virtual element_iterator not_active_elements_begin () = 0; 00702 virtual element_iterator not_active_elements_end () = 0; 00703 virtual element_iterator not_ancestor_elements_begin () = 0; 00704 virtual element_iterator not_ancestor_elements_end () = 0; 00705 virtual element_iterator not_subactive_elements_begin () = 0; 00706 virtual element_iterator not_subactive_elements_end () = 0; 00707 virtual element_iterator local_elements_begin () = 0; 00708 virtual element_iterator local_elements_end () = 0; 00709 virtual element_iterator not_local_elements_begin () = 0; 00710 virtual element_iterator not_local_elements_end () = 0; 00711 virtual element_iterator active_local_elements_begin () = 0; 00712 virtual element_iterator active_local_elements_end () = 0; 00713 virtual element_iterator active_not_local_elements_begin () = 0; 00714 virtual element_iterator active_not_local_elements_end () = 0; 00715 virtual element_iterator level_elements_begin (const unsigned int level ) = 0; 00716 virtual element_iterator level_elements_end (const unsigned int level ) = 0; 00717 virtual element_iterator not_level_elements_begin (const unsigned int level ) = 0; 00718 virtual element_iterator not_level_elements_end (const unsigned int level ) = 0; 00719 virtual element_iterator local_level_elements_begin (const unsigned int level ) = 0; 00720 virtual element_iterator local_level_elements_end (const unsigned int level ) = 0; 00721 virtual element_iterator local_not_level_elements_begin (const unsigned int level ) = 0; 00722 virtual element_iterator local_not_level_elements_end (const unsigned int level ) = 0; 00723 virtual element_iterator pid_elements_begin (const processor_id_type proc_id) = 0; 00724 virtual element_iterator pid_elements_end (const processor_id_type proc_id) = 0; 00725 virtual element_iterator type_elements_begin (const ElemType type ) = 0; 00726 virtual element_iterator type_elements_end (const ElemType type ) = 0; 00727 virtual element_iterator active_type_elements_begin (const ElemType type ) = 0; 00728 virtual element_iterator active_type_elements_end (const ElemType type ) = 0; 00729 virtual element_iterator active_pid_elements_begin (const processor_id_type proc_id) = 0; 00730 virtual element_iterator active_pid_elements_end (const processor_id_type proc_id) = 0; 00731 virtual element_iterator unpartitioned_elements_begin () = 0; 00732 virtual element_iterator unpartitioned_elements_end () = 0; 00733 virtual element_iterator active_local_subdomain_elements_begin (const subdomain_id_type subdomain_id) = 0; 00734 virtual element_iterator active_local_subdomain_elements_end (const subdomain_id_type subdomain_id) = 0; 00735 virtual element_iterator active_subdomain_elements_begin (const subdomain_id_type subdomain_id) = 0; 00736 virtual element_iterator active_subdomain_elements_end (const subdomain_id_type subdomain_id) = 0; 00737 00738 00739 00740 00744 virtual const_element_iterator elements_begin () const = 0; 00745 virtual const_element_iterator elements_end () const = 0; 00746 virtual const_element_iterator active_elements_begin () const = 0; 00747 virtual const_element_iterator active_elements_end () const = 0; 00748 virtual const_element_iterator ancestor_elements_begin () const = 0; 00749 virtual const_element_iterator ancestor_elements_end () const = 0; 00750 virtual const_element_iterator subactive_elements_begin () const = 0; 00751 virtual const_element_iterator subactive_elements_end () const = 0; 00752 virtual const_element_iterator not_active_elements_begin () const = 0; 00753 virtual const_element_iterator not_active_elements_end () const = 0; 00754 virtual const_element_iterator not_ancestor_elements_begin () const = 0; 00755 virtual const_element_iterator not_ancestor_elements_end () const = 0; 00756 virtual const_element_iterator not_subactive_elements_begin () const = 0; 00757 virtual const_element_iterator not_subactive_elements_end () const = 0; 00758 virtual const_element_iterator local_elements_begin () const = 0; 00759 virtual const_element_iterator local_elements_end () const = 0; 00760 virtual const_element_iterator not_local_elements_begin () const = 0; 00761 virtual const_element_iterator not_local_elements_end () const = 0; 00762 virtual const_element_iterator active_local_elements_begin () const = 0; 00763 virtual const_element_iterator active_local_elements_end () const = 0; 00764 virtual const_element_iterator active_not_local_elements_begin () const = 0; 00765 virtual const_element_iterator active_not_local_elements_end () const = 0; 00766 virtual const_element_iterator level_elements_begin (const unsigned int level) const = 0; 00767 virtual const_element_iterator level_elements_end (const unsigned int level) const = 0; 00768 virtual const_element_iterator not_level_elements_begin (const unsigned int level) const = 0; 00769 virtual const_element_iterator not_level_elements_end (const unsigned int level) const = 0; 00770 virtual const_element_iterator local_level_elements_begin (const unsigned int level) const = 0; 00771 virtual const_element_iterator local_level_elements_end (const unsigned int level) const = 0; 00772 virtual const_element_iterator local_not_level_elements_begin (const unsigned int level) const = 0; 00773 virtual const_element_iterator local_not_level_elements_end (const unsigned int level) const = 0; 00774 virtual const_element_iterator pid_elements_begin (const processor_id_type proc_id) const = 0; 00775 virtual const_element_iterator pid_elements_end (const processor_id_type proc_id) const = 0; 00776 virtual const_element_iterator type_elements_begin (const ElemType type) const = 0; 00777 virtual const_element_iterator type_elements_end (const ElemType type) const = 0; 00778 virtual const_element_iterator active_type_elements_begin (const ElemType type) const = 0; 00779 virtual const_element_iterator active_type_elements_end (const ElemType type) const = 0; 00780 virtual const_element_iterator active_pid_elements_begin (const processor_id_type proc_id) const = 0; 00781 virtual const_element_iterator active_pid_elements_end (const processor_id_type proc_id) const = 0; 00782 virtual const_element_iterator unpartitioned_elements_begin () const = 0; 00783 virtual const_element_iterator unpartitioned_elements_end () const = 0; 00784 virtual const_element_iterator active_local_subdomain_elements_begin (const subdomain_id_type subdomain_id) const = 0; 00785 virtual const_element_iterator active_local_subdomain_elements_end (const subdomain_id_type subdomain_id) const = 0; 00786 virtual const_element_iterator active_subdomain_elements_begin (const subdomain_id_type subdomain_id) const = 0; 00787 virtual const_element_iterator active_subdomain_elements_end (const subdomain_id_type subdomain_id) const = 0; 00788 00789 00793 virtual node_iterator nodes_begin () = 0; 00794 virtual node_iterator nodes_end () = 0; 00795 virtual node_iterator active_nodes_begin () = 0; 00796 virtual node_iterator active_nodes_end () = 0; 00797 virtual node_iterator local_nodes_begin () = 0; 00798 virtual node_iterator local_nodes_end () = 0; 00799 virtual node_iterator pid_nodes_begin (const processor_id_type proc_id) = 0; 00800 virtual node_iterator pid_nodes_end (const processor_id_type proc_id) = 0; 00801 00802 00806 virtual const_node_iterator nodes_begin () const = 0; 00807 virtual const_node_iterator nodes_end () const = 0; 00808 virtual const_node_iterator active_nodes_begin () const = 0; 00809 virtual const_node_iterator active_nodes_end () const = 0; 00810 virtual const_node_iterator local_nodes_begin () const = 0; 00811 virtual const_node_iterator local_nodes_end () const = 0; 00812 virtual const_node_iterator pid_nodes_begin (const processor_id_type proc_id) const = 0; 00813 virtual const_node_iterator pid_nodes_end (const processor_id_type proc_id) const = 0; 00814 00815 00816 00817 protected: 00818 00819 00820 00821 00825 unsigned int& set_n_partitions () 00826 { return _n_parts; } 00827 00837 unsigned int _n_parts; 00838 00842 unsigned int _dim; 00843 00847 bool _is_prepared; 00848 00856 mutable AutoPtr<PointLocatorBase> _point_locator; 00857 00864 AutoPtr<Partitioner> _partitioner; 00865 00869 bool _skip_partitioning; 00870 00876 bool _skip_renumber_nodes_and_elements; 00877 00883 std::map<subdomain_id_type, std::string> _block_id_to_name; 00884 00889 friend class Partitioner; 00890 00895 friend class BoundaryInfo; 00896 00897 private: 00904 MeshBase& operator= (const MeshBase& other); 00905 }; 00906 00907 00908 00909 00910 00911 00912 00913 00914 00915 00916 00920 struct 00921 MeshBase::element_iterator : 00922 variant_filter_iterator<MeshBase::Predicate, 00923 Elem*> 00924 { 00925 // Templated forwarding ctor -- forwards to appropriate variant_filter_iterator ctor 00926 template <typename PredType, typename IterType> 00927 element_iterator (const IterType& d, 00928 const IterType& e, 00929 const PredType& p ) : 00930 variant_filter_iterator<MeshBase::Predicate, 00931 Elem*>(d,e,p) {} 00932 }; 00933 00934 00935 00936 00941 struct 00942 MeshBase::const_element_iterator : 00943 variant_filter_iterator<MeshBase::Predicate, 00944 Elem* const, 00945 Elem* const&, 00946 Elem* const*> 00947 { 00948 // Templated forwarding ctor -- forwards to appropriate variant_filter_iterator ctor 00949 template <typename PredType, typename IterType> 00950 const_element_iterator (const IterType& d, 00951 const IterType& e, 00952 const PredType& p ) : 00953 variant_filter_iterator<MeshBase::Predicate, 00954 Elem* const, 00955 Elem* const&, 00956 Elem* const*>(d,e,p) {} 00957 00958 00959 // The conversion-to-const ctor. Takes a regular iterator and calls the appropriate 00960 // variant_filter_iterator copy constructor. Note that this one is *not* templated! 00961 const_element_iterator (const MeshBase::element_iterator& rhs) : 00962 variant_filter_iterator<Predicate, 00963 Elem* const, 00964 Elem* const&, 00965 Elem* const*>(rhs) 00966 { 00967 // libMesh::out << "Called element_iterator conversion-to-const ctor." << std::endl; 00968 } 00969 }; 00970 00971 00972 00973 00974 00975 00976 00980 struct 00981 MeshBase::node_iterator : 00982 variant_filter_iterator<MeshBase::Predicate, 00983 Node*> 00984 { 00985 // Templated forwarding ctor -- forwards to appropriate variant_filter_iterator ctor 00986 template <typename PredType, typename IterType> 00987 node_iterator (const IterType& d, 00988 const IterType& e, 00989 const PredType& p ) : 00990 variant_filter_iterator<MeshBase::Predicate, 00991 Node*>(d,e,p) {} 00992 }; 00993 00994 00995 00996 01001 struct 01002 MeshBase::const_node_iterator : 01003 variant_filter_iterator<MeshBase::Predicate, 01004 Node* const, 01005 Node* const &, 01006 Node* const *> 01007 { 01008 // Templated forwarding ctor -- forwards to appropriate variant_filter_iterator ctor 01009 template <typename PredType, typename IterType> 01010 const_node_iterator (const IterType& d, 01011 const IterType& e, 01012 const PredType& p ) : 01013 variant_filter_iterator<MeshBase::Predicate, 01014 Node* const, 01015 Node* const &, 01016 Node* const *>(d,e,p) {} 01017 01018 01019 // The conversion-to-const ctor. Takes a regular iterator and calls the appropriate 01020 // variant_filter_iterator copy constructor. Note that this one is *not* templated! 01021 const_node_iterator (const MeshBase::node_iterator& rhs) : 01022 variant_filter_iterator<Predicate, 01023 Node* const, 01024 Node* const &, 01025 Node* const *>(rhs) 01026 { 01027 // libMesh::out << "Called node_iterator conversion-to-const ctor." << std::endl; 01028 } 01029 }; 01030 01031 01032 } // namespace libMesh 01033 01034 #endif // LIBMESH_MESH_BASE_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:47 UTC
Hosted By: