|
Sierra Toolkit
Version of the Day
|
00001 /*------------------------------------------------------------------------*/ 00002 /* Copyright 2010 Sandia Corporation. */ 00003 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */ 00004 /* license for use of this work by or on behalf of the U.S. Government. */ 00005 /* Export of this program may require a license from the */ 00006 /* United States Government. */ 00007 /*------------------------------------------------------------------------*/ 00008 00009 #ifndef stk_mesh_Part_hpp 00010 #define stk_mesh_Part_hpp 00011 00012 //---------------------------------------------------------------------- 00013 00014 #include <iosfwd> 00015 #include <string> 00016 #include <vector> 00017 #include <algorithm> 00018 00019 #include <stk_util/util/CSet.hpp> 00020 #include <stk_mesh/base/Types.hpp> 00021 #include <stk_mesh/base/PartRelation.hpp> 00022 #include <stk_mesh/baseImpl/PartImpl.hpp> 00023 00024 //---------------------------------------------------------------------- 00025 00026 namespace stk_classic { 00027 namespace mesh { 00028 00029 namespace impl { 00030 class PartRepository; 00031 } // namespace impl 00032 00037 //---------------------------------------------------------------------- 00049 class Part { 00050 public: 00051 00055 MetaData & mesh_meta_data() const { return m_partImpl.mesh_meta_data(); } 00056 00064 unsigned primary_entity_rank() const { return m_partImpl.primary_entity_rank(); } 00065 00067 const std::string & name() const { return m_partImpl.name(); } 00068 00072 unsigned mesh_meta_data_ordinal() const { return m_partImpl.mesh_meta_data_ordinal(); } 00073 00075 const PartVector & supersets() const { return m_partImpl.supersets(); } 00076 00078 const PartVector & subsets() const { return m_partImpl.subsets(); } 00079 00081 const PartVector & intersection_of() const { return m_partImpl.intersection_of(); } 00082 00084 const std::vector<PartRelation> & relations() const { return m_partImpl.relations(); } 00085 00087 bool operator == ( const Part & rhs ) const { return this == & rhs ; } 00088 00090 bool operator != ( const Part & rhs ) const { return this != & rhs ; } 00091 00093 template<class A> 00094 const A * attribute() const { return m_partImpl.attribute<A>(); } 00095 00096 private: 00097 00101 MetaData & meta_data() const { return m_partImpl.mesh_meta_data(); } 00102 00103 00104 impl::PartImpl m_partImpl; 00105 00106 /* \brief A part is owned by a PartRepository, as such only the owning 00107 * PartRepository can create, delete, or modify a part. 00108 * The owner-modifies rule is enforced by the implementation being 00109 * a private data object on the Part and the PartRepository is a 00110 * friend. 00111 */ 00112 friend class ::stk_classic::mesh::impl::PartRepository ; 00113 friend class ::stk_classic::mesh::MetaData ; 00114 00115 #ifndef DOXYGEN_COMPILE 00116 00120 Part( MetaData * arg_meta_data , const std::string & arg_name, EntityRank arg_rank, size_t arg_ordinal) 00121 : m_partImpl(arg_meta_data,arg_name,arg_rank,arg_ordinal) 00122 { } 00123 00124 ~Part() {} 00125 Part(); 00126 Part( const Part & ); 00127 Part & operator = ( const Part & ); 00128 00129 #endif /* DOXYGEN_COMPILE */ 00130 00131 }; 00132 00133 static const char INTERNAL_PART_PREFIX = '{'; 00134 static const char INTERNAL_PART_POSTFIX = '}'; 00135 00136 inline 00137 bool is_internal(const std::string& part_name) 00138 { 00139 return part_name.size() > 2 && *part_name.begin() == INTERNAL_PART_PREFIX && *part_name.rbegin() == INTERNAL_PART_POSTFIX; 00140 } 00141 00142 inline 00143 bool is_internal(const Part& part) 00144 { return is_internal(part.name()); } 00145 00146 std::string convert_to_internal_name(const std::string& part_name); 00147 00148 //---------------------------------------------------------------------- 00150 struct PartLess { 00151 00152 inline bool operator()( const Part & lhs , const Part & rhs ) const 00153 { return lhs.mesh_meta_data_ordinal() < rhs.mesh_meta_data_ordinal(); } 00154 00155 inline bool operator()( const Part & lhs , const Part * rhs ) const 00156 { return lhs.mesh_meta_data_ordinal() < rhs->mesh_meta_data_ordinal(); } 00157 00158 inline bool operator()( const Part * lhs , const Part & rhs ) const 00159 { return lhs->mesh_meta_data_ordinal() < rhs.mesh_meta_data_ordinal(); } 00160 00161 inline bool operator()( const Part * lhs , const Part * rhs ) const 00162 { return lhs->mesh_meta_data_ordinal() < rhs->mesh_meta_data_ordinal(); } 00163 }; 00164 00166 void order( PartVector & ); 00167 00168 inline 00169 void order( OrdinalVector & v ) 00170 { 00171 OrdinalVector::iterator ev = v.end(); 00172 OrdinalVector::iterator iv = v.begin(); 00173 std::sort( iv , ev ); 00174 iv = std::unique( iv , ev ); 00175 v.erase( iv , ev ); 00176 } 00177 00181 bool insert( PartVector & , Part & ); 00182 00183 inline 00184 bool insert_ordinal( OrdinalVector & v , unsigned part_ordinal ) 00185 { 00186 for(OrdinalVector::iterator i=v.begin(), e=v.end(); i!=e; ++i) { 00187 if (*i == part_ordinal) return false; 00188 if (*i > part_ordinal) { 00189 v.insert(i, part_ordinal); 00190 return true; 00191 } 00192 } 00193 00194 v.push_back(part_ordinal); 00195 return true ; 00196 } 00197 00199 void remove( PartVector & , Part & ); 00200 00202 Part * find( const PartVector & , const std::string & ); 00203 00205 bool contain( const PartVector & , const Part & ); 00206 00207 template<class Iterator> 00208 inline 00209 bool contains_ordinal( Iterator beg, Iterator end, unsigned part_ordinal ) 00210 { 00211 for(Iterator i=beg; i!=end; ++i) { 00212 if (*i == part_ordinal) return true; 00213 } 00214 00215 return false; 00216 } 00217 00219 bool contain( const PartVector & , const PartVector & ); 00220 00222 size_t intersect( const PartVector & , const PartVector & ); 00223 00225 size_t intersect( const PartVector & , const PartVector & , PartVector & ); 00226 00230 bool intersect( const Part & , const Part & ); 00231 00232 //---------------------------------------------------------------------- 00236 std::ostream & print( std::ostream & , const char * const , const Part & ); 00237 00238 00242 } // namespace mesh 00243 } // namespace stk_classic 00244 00245 //---------------------------------------------------------------------- 00246 //---------------------------------------------------------------------- 00247 00248 #endif 00249