$extrastylesheet
00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2014 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" // UniquePtr needs a real declaration 00033 #include "libmesh/point_locator_base.h" 00034 #include "libmesh/variant_filter_iterator.h" 00035 #include "libmesh/parallel_object.h" 00036 00037 // C++ Includes ----------------------------------- 00038 #include <cstddef> 00039 #include <string> 00040 00041 namespace libMesh 00042 { 00043 00044 // forward declarations 00045 class Elem; 00046 class Node; 00047 class Point; 00048 class MeshData; 00049 00050 template <class MT> 00051 class MeshInput; 00052 00053 00069 // ------------------------------------------------------------ 00070 // MeshBase class definition 00071 class MeshBase : public ParallelObject 00072 { 00073 public: 00074 00080 MeshBase (const Parallel::Communicator &comm_in, 00081 unsigned char dim=1); 00082 00083 #ifndef LIBMESH_DISABLE_COMMWORLD 00084 00089 MeshBase (unsigned char dim=1); 00090 #endif 00091 00095 MeshBase (const MeshBase& other_mesh); 00096 00100 virtual UniquePtr<MeshBase> clone() const = 0; 00101 00105 virtual ~MeshBase (); 00106 00110 virtual UniquePtr<Partitioner> &partitioner() { return _partitioner; } 00111 00115 const BoundaryInfo& get_boundary_info() const { return *boundary_info; } 00116 00120 BoundaryInfo& get_boundary_info() { return *boundary_info; } 00121 00125 virtual void clear (); 00126 00131 bool is_prepared () const 00132 { return _is_prepared; } 00133 00138 virtual bool is_serial () const 00139 { return true; } 00140 00145 virtual void allgather () {} 00146 00152 virtual void delete_remote_elements () {} 00153 00160 unsigned int mesh_dimension () const; 00161 00169 void set_mesh_dimension (unsigned char d) 00170 { _elem_dims.clear(); _elem_dims.insert(d); } 00171 00175 const std::set<unsigned char>& elem_dimensions() const 00176 { return _elem_dims; } 00177 00182 unsigned int spatial_dimension () const 00183 { return cast_int<unsigned int>(LIBMESH_DIM); } 00184 00192 virtual dof_id_type n_nodes () const = 0; 00193 00201 virtual dof_id_type parallel_n_nodes () const = 0; 00202 00206 dof_id_type n_nodes_on_proc (const processor_id_type proc) const; 00207 00211 dof_id_type n_local_nodes () const 00212 { return this->n_nodes_on_proc (this->processor_id()); } 00213 00217 dof_id_type n_unpartitioned_nodes () const 00218 { return this->n_nodes_on_proc (DofObject::invalid_processor_id); } 00219 00224 virtual dof_id_type max_node_id () const = 0; 00225 00226 #ifdef LIBMESH_ENABLE_UNIQUE_ID 00227 00230 unique_id_type next_unique_id() { return _next_unique_id; } 00231 00235 void set_next_unique_id(unique_id_type id) { _next_unique_id = id; } 00236 #endif 00237 00245 virtual void reserve_nodes (const dof_id_type nn) = 0; 00246 00252 virtual dof_id_type n_elem () const = 0; 00253 00260 virtual dof_id_type parallel_n_elem () const = 0; 00261 00266 virtual dof_id_type max_elem_id () const = 0; 00267 00275 virtual void reserve_elem (const dof_id_type ne) = 0; 00276 00281 virtual void update_parallel_id_counts () = 0; 00282 00287 virtual dof_id_type n_active_elem () const = 0; 00288 00292 dof_id_type n_elem_on_proc (const processor_id_type proc) const; 00293 00297 dof_id_type n_local_elem () const 00298 { return this->n_elem_on_proc (this->processor_id()); } 00299 00303 dof_id_type n_unpartitioned_elem () const 00304 { return this->n_elem_on_proc (DofObject::invalid_processor_id); } 00305 00309 dof_id_type n_active_elem_on_proc (const processor_id_type proc) const; 00310 00314 dof_id_type n_active_local_elem () const 00315 { return this->n_active_elem_on_proc (this->processor_id()); } 00316 00324 dof_id_type n_sub_elem () const; 00325 00329 dof_id_type n_active_sub_elem () const; 00330 00336 virtual const Point& point (const dof_id_type i) const = 0; 00337 00343 virtual const Node& node (const dof_id_type i) const = 0; 00344 00349 virtual Node& node (const dof_id_type i) = 0; 00350 00355 virtual const Node* node_ptr (const dof_id_type i) const = 0; 00356 00362 virtual Node* node_ptr (const dof_id_type i) = 0; 00363 00368 virtual const Node* query_node_ptr (const dof_id_type i) const = 0; 00369 00374 virtual Node* query_node_ptr (const dof_id_type i) = 0; 00375 00380 virtual const Elem* elem (const dof_id_type i) const = 0; 00381 00387 virtual Elem* elem (const dof_id_type i) = 0; 00388 00393 virtual const Elem* query_elem (const dof_id_type i) const = 0; 00394 00399 virtual Elem* query_elem (const dof_id_type i) = 0; 00400 00411 virtual Node* add_point (const Point& p, 00412 const dof_id_type id = DofObject::invalid_id, 00413 const processor_id_type proc_id = 00414 DofObject::invalid_processor_id) = 0; 00415 00419 virtual Node* add_node (Node* n) = 0; 00420 00428 virtual Node* insert_node(Node* n) = 0; 00429 00433 virtual void delete_node (Node* n) = 0; 00434 00440 virtual void renumber_node (dof_id_type old_id, dof_id_type new_id) = 0; 00441 00448 virtual Elem* add_elem (Elem* e) = 0; 00449 00454 virtual Elem* insert_elem (Elem* e) = 0; 00455 00462 virtual void delete_elem (Elem* e) = 0; 00463 00469 virtual void renumber_elem (dof_id_type old_id, dof_id_type new_id) = 0; 00470 00483 virtual void find_neighbors (const bool reset_remote_elements = false, 00484 const bool reset_current_list = true) = 0; 00485 00491 virtual void renumber_nodes_and_elements () = 0; 00492 00499 virtual void fix_broken_node_and_element_numbering () = 0; 00500 00501 00502 #ifdef LIBMESH_ENABLE_AMR 00503 00508 virtual bool contract () = 0; 00509 #endif 00510 00522 void prepare_for_use (const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false); 00523 00527 virtual void partition (const unsigned int n_parts); 00528 00529 void partition () 00530 { this->partition(this->n_processors()); } 00531 00537 virtual void redistribute () {} 00538 00543 virtual void update_post_partitioning () {} 00544 00551 void allow_renumbering(bool allow) { _skip_renumber_nodes_and_elements = !allow; } 00552 bool allow_renumbering() const { return !_skip_renumber_nodes_and_elements; } 00553 00566 void skip_partitioning(bool skip) { _skip_partitioning = skip; } 00567 bool skip_partitioning() const { return _skip_partitioning; } 00568 00576 void subdomain_ids (std::set<subdomain_id_type> &ids) const; 00577 00585 subdomain_id_type n_subdomains () const; 00586 00593 unsigned int n_partitions () const 00594 { return _n_parts; } 00595 00600 std::string get_info () const; 00601 00605 void print_info (std::ostream& os=libMesh::out) const; 00606 00612 friend std::ostream& operator << (std::ostream& os, const MeshBase& m); 00613 00618 virtual void read (const std::string& name, MeshData* mesh_data=NULL, 00619 bool skip_renumber_nodes_and_elements=false) = 0; 00620 virtual void write (const std::string& name, MeshData* mesh_data=NULL) = 0; 00621 00628 virtual void all_first_order () = 0; 00629 00641 virtual void all_second_order (const bool full_ordered=true) = 0; 00642 00647 typedef Predicates::multi_predicate Predicate; 00648 00655 struct element_iterator; 00656 struct const_element_iterator; 00657 00664 struct node_iterator; 00665 struct const_node_iterator; 00666 00676 unsigned int recalculate_n_partitions(); 00677 00684 const PointLocatorBase& point_locator () const; 00685 00693 UniquePtr<PointLocatorBase> sub_point_locator () const; 00694 00698 void clear_point_locator (); 00699 00707 virtual void libmesh_assert_valid_parallel_ids() const {} 00708 00713 std::string& subdomain_name(subdomain_id_type id); 00714 const std::string& subdomain_name(subdomain_id_type id) const; 00715 00720 subdomain_id_type get_id_by_name(const std::string& name) const; 00721 00726 virtual element_iterator elements_begin () = 0; 00727 virtual element_iterator elements_end () = 0; 00728 virtual element_iterator active_elements_begin () = 0; 00729 virtual element_iterator active_elements_end () = 0; 00730 virtual element_iterator ancestor_elements_begin () = 0; 00731 virtual element_iterator ancestor_elements_end () = 0; 00732 virtual element_iterator subactive_elements_begin () = 0; 00733 virtual element_iterator subactive_elements_end () = 0; 00734 virtual element_iterator not_active_elements_begin () = 0; 00735 virtual element_iterator not_active_elements_end () = 0; 00736 virtual element_iterator not_ancestor_elements_begin () = 0; 00737 virtual element_iterator not_ancestor_elements_end () = 0; 00738 virtual element_iterator not_subactive_elements_begin () = 0; 00739 virtual element_iterator not_subactive_elements_end () = 0; 00740 virtual element_iterator local_elements_begin () = 0; 00741 virtual element_iterator local_elements_end () = 0; 00742 virtual element_iterator semilocal_elements_begin () = 0; 00743 virtual element_iterator semilocal_elements_end () = 0; 00744 virtual element_iterator facelocal_elements_begin () = 0; 00745 virtual element_iterator facelocal_elements_end () = 0; 00746 virtual element_iterator not_local_elements_begin () = 0; 00747 virtual element_iterator not_local_elements_end () = 0; 00748 virtual element_iterator active_local_elements_begin () = 0; 00749 virtual element_iterator active_local_elements_end () = 0; 00750 virtual element_iterator active_not_local_elements_begin () = 0; 00751 virtual element_iterator active_not_local_elements_end () = 0; 00752 virtual element_iterator level_elements_begin (const unsigned int level ) = 0; 00753 virtual element_iterator level_elements_end (const unsigned int level ) = 0; 00754 virtual element_iterator not_level_elements_begin (const unsigned int level ) = 0; 00755 virtual element_iterator not_level_elements_end (const unsigned int level ) = 0; 00756 virtual element_iterator local_level_elements_begin (const unsigned int level ) = 0; 00757 virtual element_iterator local_level_elements_end (const unsigned int level ) = 0; 00758 virtual element_iterator local_not_level_elements_begin (const unsigned int level ) = 0; 00759 virtual element_iterator local_not_level_elements_end (const unsigned int level ) = 0; 00760 virtual element_iterator pid_elements_begin (const processor_id_type proc_id) = 0; 00761 virtual element_iterator pid_elements_end (const processor_id_type proc_id) = 0; 00762 virtual element_iterator type_elements_begin (const ElemType type ) = 0; 00763 virtual element_iterator type_elements_end (const ElemType type ) = 0; 00764 virtual element_iterator active_type_elements_begin (const ElemType type ) = 0; 00765 virtual element_iterator active_type_elements_end (const ElemType type ) = 0; 00766 virtual element_iterator active_pid_elements_begin (const processor_id_type proc_id) = 0; 00767 virtual element_iterator active_pid_elements_end (const processor_id_type proc_id) = 0; 00768 virtual element_iterator unpartitioned_elements_begin () = 0; 00769 virtual element_iterator unpartitioned_elements_end () = 0; 00770 virtual element_iterator active_local_subdomain_elements_begin (const subdomain_id_type subdomain_id) = 0; 00771 virtual element_iterator active_local_subdomain_elements_end (const subdomain_id_type subdomain_id) = 0; 00772 virtual element_iterator active_subdomain_elements_begin (const subdomain_id_type subdomain_id) = 0; 00773 virtual element_iterator active_subdomain_elements_end (const subdomain_id_type subdomain_id) = 0; 00774 00775 00776 00777 00781 virtual const_element_iterator elements_begin () const = 0; 00782 virtual const_element_iterator elements_end () const = 0; 00783 virtual const_element_iterator active_elements_begin () const = 0; 00784 virtual const_element_iterator active_elements_end () const = 0; 00785 virtual const_element_iterator ancestor_elements_begin () const = 0; 00786 virtual const_element_iterator ancestor_elements_end () const = 0; 00787 virtual const_element_iterator subactive_elements_begin () const = 0; 00788 virtual const_element_iterator subactive_elements_end () const = 0; 00789 virtual const_element_iterator not_active_elements_begin () const = 0; 00790 virtual const_element_iterator not_active_elements_end () const = 0; 00791 virtual const_element_iterator not_ancestor_elements_begin () const = 0; 00792 virtual const_element_iterator not_ancestor_elements_end () const = 0; 00793 virtual const_element_iterator not_subactive_elements_begin () const = 0; 00794 virtual const_element_iterator not_subactive_elements_end () const = 0; 00795 virtual const_element_iterator local_elements_begin () const = 0; 00796 virtual const_element_iterator local_elements_end () const = 0; 00797 virtual const_element_iterator semilocal_elements_begin () const = 0; 00798 virtual const_element_iterator semilocal_elements_end () const = 0; 00799 virtual const_element_iterator facelocal_elements_begin () const = 0; 00800 virtual const_element_iterator facelocal_elements_end () const = 0; 00801 virtual const_element_iterator not_local_elements_begin () const = 0; 00802 virtual const_element_iterator not_local_elements_end () const = 0; 00803 virtual const_element_iterator active_local_elements_begin () const = 0; 00804 virtual const_element_iterator active_local_elements_end () const = 0; 00805 virtual const_element_iterator active_not_local_elements_begin () const = 0; 00806 virtual const_element_iterator active_not_local_elements_end () const = 0; 00807 virtual const_element_iterator level_elements_begin (const unsigned int level) const = 0; 00808 virtual const_element_iterator level_elements_end (const unsigned int level) const = 0; 00809 virtual const_element_iterator not_level_elements_begin (const unsigned int level) const = 0; 00810 virtual const_element_iterator not_level_elements_end (const unsigned int level) const = 0; 00811 virtual const_element_iterator local_level_elements_begin (const unsigned int level) const = 0; 00812 virtual const_element_iterator local_level_elements_end (const unsigned int level) const = 0; 00813 virtual const_element_iterator local_not_level_elements_begin (const unsigned int level) const = 0; 00814 virtual const_element_iterator local_not_level_elements_end (const unsigned int level) const = 0; 00815 virtual const_element_iterator pid_elements_begin (const processor_id_type proc_id) const = 0; 00816 virtual const_element_iterator pid_elements_end (const processor_id_type proc_id) const = 0; 00817 virtual const_element_iterator type_elements_begin (const ElemType type) const = 0; 00818 virtual const_element_iterator type_elements_end (const ElemType type) const = 0; 00819 virtual const_element_iterator active_type_elements_begin (const ElemType type) const = 0; 00820 virtual const_element_iterator active_type_elements_end (const ElemType type) const = 0; 00821 virtual const_element_iterator active_pid_elements_begin (const processor_id_type proc_id) const = 0; 00822 virtual const_element_iterator active_pid_elements_end (const processor_id_type proc_id) const = 0; 00823 virtual const_element_iterator unpartitioned_elements_begin () const = 0; 00824 virtual const_element_iterator unpartitioned_elements_end () const = 0; 00825 virtual const_element_iterator active_local_subdomain_elements_begin (const subdomain_id_type subdomain_id) const = 0; 00826 virtual const_element_iterator active_local_subdomain_elements_end (const subdomain_id_type subdomain_id) const = 0; 00827 virtual const_element_iterator active_subdomain_elements_begin (const subdomain_id_type subdomain_id) const = 0; 00828 virtual const_element_iterator active_subdomain_elements_end (const subdomain_id_type subdomain_id) const = 0; 00829 00830 00834 virtual node_iterator nodes_begin () = 0; 00835 virtual node_iterator nodes_end () = 0; 00836 virtual node_iterator active_nodes_begin () = 0; 00837 virtual node_iterator active_nodes_end () = 0; 00838 virtual node_iterator local_nodes_begin () = 0; 00839 virtual node_iterator local_nodes_end () = 0; 00840 virtual node_iterator pid_nodes_begin (const processor_id_type proc_id) = 0; 00841 virtual node_iterator pid_nodes_end (const processor_id_type proc_id) = 0; 00842 00843 00847 virtual const_node_iterator nodes_begin () const = 0; 00848 virtual const_node_iterator nodes_end () const = 0; 00849 virtual const_node_iterator active_nodes_begin () const = 0; 00850 virtual const_node_iterator active_nodes_end () const = 0; 00851 virtual const_node_iterator local_nodes_begin () const = 0; 00852 virtual const_node_iterator local_nodes_end () const = 0; 00853 virtual const_node_iterator pid_nodes_begin (const processor_id_type proc_id) const = 0; 00854 virtual const_node_iterator pid_nodes_end (const processor_id_type proc_id) const = 0; 00855 00856 00860 std::map<subdomain_id_type, std::string>& set_subdomain_name_map () 00861 { return _block_id_to_name; } 00862 const std::map<subdomain_id_type, std::string>& get_subdomain_name_map () const 00863 { return _block_id_to_name; } 00864 00865 00871 void cache_elem_dims(); 00872 00873 00882 UniquePtr<BoundaryInfo> boundary_info; 00883 00884 00885 protected: 00886 00891 #ifdef LIBMESH_ENABLE_UNIQUE_ID 00892 virtual void assign_unique_ids() = 0; 00893 #endif 00894 00898 unsigned int& set_n_partitions () 00899 { return _n_parts; } 00900 00910 unsigned int _n_parts; 00911 00915 bool _is_prepared; 00916 00924 mutable UniquePtr<PointLocatorBase> _point_locator; 00925 00932 UniquePtr<Partitioner> _partitioner; 00933 00934 #ifdef LIBMESH_ENABLE_UNIQUE_ID 00935 00938 unique_id_type _next_unique_id; 00939 #endif 00940 00944 bool _skip_partitioning; 00945 00951 bool _skip_renumber_nodes_and_elements; 00952 00958 std::map<subdomain_id_type, std::string> _block_id_to_name; 00959 00965 std::set<unsigned char> _elem_dims; 00966 00971 friend class Partitioner; 00972 00977 friend class MeshInput<MeshBase>; 00978 00983 friend class BoundaryInfo; 00984 00985 private: 00992 MeshBase& operator= (const MeshBase& other); 00993 }; 00994 00995 00996 00997 00998 00999 01000 01001 01002 01003 01004 01008 struct 01009 MeshBase::element_iterator : 01010 variant_filter_iterator<MeshBase::Predicate, 01011 Elem*> 01012 { 01013 // Templated forwarding ctor -- forwards to appropriate variant_filter_iterator ctor 01014 template <typename PredType, typename IterType> 01015 element_iterator (const IterType& d, 01016 const IterType& e, 01017 const PredType& p ) : 01018 variant_filter_iterator<MeshBase::Predicate, 01019 Elem*>(d,e,p) {} 01020 }; 01021 01022 01023 01024 01029 struct 01030 MeshBase::const_element_iterator : 01031 variant_filter_iterator<MeshBase::Predicate, 01032 Elem* const, 01033 Elem* const&, 01034 Elem* const*> 01035 { 01036 // Templated forwarding ctor -- forwards to appropriate variant_filter_iterator ctor 01037 template <typename PredType, typename IterType> 01038 const_element_iterator (const IterType& d, 01039 const IterType& e, 01040 const PredType& p ) : 01041 variant_filter_iterator<MeshBase::Predicate, 01042 Elem* const, 01043 Elem* const&, 01044 Elem* const*>(d,e,p) {} 01045 01046 01047 // The conversion-to-const ctor. Takes a regular iterator and calls the appropriate 01048 // variant_filter_iterator copy constructor. Note that this one is *not* templated! 01049 const_element_iterator (const MeshBase::element_iterator& rhs) : 01050 variant_filter_iterator<Predicate, 01051 Elem* const, 01052 Elem* const&, 01053 Elem* const*>(rhs) 01054 { 01055 // libMesh::out << "Called element_iterator conversion-to-const ctor." << std::endl; 01056 } 01057 }; 01058 01059 01060 01061 01062 01063 01064 01068 struct 01069 MeshBase::node_iterator : 01070 variant_filter_iterator<MeshBase::Predicate, 01071 Node*> 01072 { 01073 // Templated forwarding ctor -- forwards to appropriate variant_filter_iterator ctor 01074 template <typename PredType, typename IterType> 01075 node_iterator (const IterType& d, 01076 const IterType& e, 01077 const PredType& p ) : 01078 variant_filter_iterator<MeshBase::Predicate, 01079 Node*>(d,e,p) {} 01080 }; 01081 01082 01083 01084 01089 struct 01090 MeshBase::const_node_iterator : 01091 variant_filter_iterator<MeshBase::Predicate, 01092 Node* const, 01093 Node* const &, 01094 Node* const *> 01095 { 01096 // Templated forwarding ctor -- forwards to appropriate variant_filter_iterator ctor 01097 template <typename PredType, typename IterType> 01098 const_node_iterator (const IterType& d, 01099 const IterType& e, 01100 const PredType& p ) : 01101 variant_filter_iterator<MeshBase::Predicate, 01102 Node* const, 01103 Node* const &, 01104 Node* const *>(d,e,p) {} 01105 01106 01107 // The conversion-to-const ctor. Takes a regular iterator and calls the appropriate 01108 // variant_filter_iterator copy constructor. Note that this one is *not* templated! 01109 const_node_iterator (const MeshBase::node_iterator& rhs) : 01110 variant_filter_iterator<Predicate, 01111 Node* const, 01112 Node* const &, 01113 Node* const *>(rhs) 01114 { 01115 // libMesh::out << "Called node_iterator conversion-to-const ctor." << std::endl; 01116 } 01117 }; 01118 01119 01120 } // namespace libMesh 01121 01122 #endif // LIBMESH_MESH_BASE_H