Part.hpp

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 
00018 #include <stk_util/util/CSet.hpp>
00019 #include <stk_mesh/base/Types.hpp>
00020 
00021 //----------------------------------------------------------------------
00022 
00023 namespace stk {
00024 namespace mesh {
00025 
00030 //----------------------------------------------------------------------
00048 struct PartRelation {
00050   Part * m_root ;
00051 
00053   Part * m_target ;
00054 
00056   relation_stencil_ptr m_function ;
00057 
00058 #ifndef DOXYGEN_COMPILE
00059 
00060   ~PartRelation() {}
00061 
00062   PartRelation() : m_root( NULL ), m_target( NULL ), m_function( NULL ) {}
00063 
00064   PartRelation( const PartRelation & rhs )
00065     : m_root( rhs.m_root ),
00066       m_target( rhs.m_target ),
00067       m_function( rhs.m_function ) {}
00068 
00069   PartRelation & operator = ( const PartRelation & rhs )
00070   {
00071     m_root = rhs.m_root ;
00072     m_target = rhs.m_target ;
00073     m_function = rhs.m_function ;
00074     return *this ;
00075   }
00076 
00077 #endif /* DOXYGEN_COMPILE */
00078 
00079 };
00080 
00081 //----------------------------------------------------------------------
00093 class Part {
00094 public:
00095 
00099   MetaData & mesh_meta_data() const { return *m_mesh_meta_data ; }
00100 
00108   unsigned primary_entity_type() const { return m_entity_rank ; }
00109 
00111   const std::string & name() const { return m_name ; }
00112 
00116   unsigned mesh_meta_data_ordinal() const { return m_universe_ordinal ; }
00117 
00119   const PartVector & supersets() const { return m_supersets ; }
00120 
00122   const PartVector & subsets() const { return m_subsets ; }
00123 
00125   const PartVector & intersection_of() const { return m_intersect ; }
00126 
00128   const std::vector<PartRelation> & relations() const { return m_relations ; }
00129 
00131   bool operator == ( const Part & rhs ) const { return this == & rhs ; }
00132 
00134   bool operator != ( const Part & rhs ) const { return this != & rhs ; }
00135 
00137   template<class A>
00138   const A * attribute() const { return m_attribute.template get<A>(); }
00139 
00140 private:
00141 
00142   /* \brief  A part is owned by a MetaData, as such only the owning
00143    *         MetaData can create, delete, or modify a part.
00144    *         The owner-modifies rule is enforced by all non-const
00145    *         methods being private and the MetaData be a friend.
00146    */
00147   friend class ::stk::mesh::MetaData ;
00148 
00150   friend class ::stk::mesh::UnitTestMetaData ;
00151 
00153   explicit Part( MetaData * );
00154 
00156   Part & declare_part( const std::string & arg_name , EntityType arg_rank );
00157 
00159   Part & declare_part( const PartVector & part_intersect );
00160 
00162   void declare_subset( Part & subset );
00163 
00164 #ifndef DOXYGEN_COMPILE
00165 
00169   Part( MetaData * , const std::string & , EntityType , size_t );
00170 
00171   ~Part();
00172   Part();
00173   Part( const Part & );
00174   Part & operator = ( const Part & );
00175 
00176   const std::string         m_name ;
00177   CSet                      m_attribute ;
00178   PartVector                m_subsets ;
00179   PartVector                m_supersets ;
00180   PartVector                m_intersect ;
00181   std::vector<PartRelation> m_relations ;
00182   MetaData          * const m_mesh_meta_data ;
00183   const unsigned            m_universe_ordinal ;
00184   const unsigned            m_entity_rank ;
00185 
00186 #endif /* DOXYGEN_COMPILE */
00187 
00188 };
00189 
00190 //----------------------------------------------------------------------
00192 struct PartLess {
00193  
00194   inline bool operator()( const Part & lhs , const Part & rhs ) const
00195     { return lhs.mesh_meta_data_ordinal() < rhs.mesh_meta_data_ordinal(); }
00196 
00197   inline bool operator()( const Part & lhs , const Part * rhs ) const
00198     { return lhs.mesh_meta_data_ordinal() < rhs->mesh_meta_data_ordinal(); }
00199 
00200   inline bool operator()( const Part * lhs , const Part & rhs ) const
00201     { return lhs->mesh_meta_data_ordinal() < rhs.mesh_meta_data_ordinal(); }
00202  
00203   inline bool operator()( const Part * lhs , const Part * rhs ) const
00204     { return lhs->mesh_meta_data_ordinal() < rhs->mesh_meta_data_ordinal(); }
00205 };
00206 
00208 void order( PartVector & );
00209 
00213 bool insert( PartVector & , Part & );
00214 
00216 void remove( PartVector & , Part & );
00217 
00219 Part * find( const PartVector & , const std::string & );
00220 
00222 bool contain( const PartVector & , const Part & );
00223 
00225 bool contain( const PartVector & , const PartVector & );
00226 
00228 size_t intersect( const PartVector & , const PartVector & );
00229 
00231 size_t intersect( const PartVector & , const PartVector & , PartVector & );
00232 
00236 bool intersect( const Part & , const Part & );
00237 
00238 //----------------------------------------------------------------------
00242 std::ostream & print( std::ostream & , const char * const , const Part & );
00243 
00247 } // namespace mesh
00248 } // namespace stk
00249 
00250 //----------------------------------------------------------------------
00251 //----------------------------------------------------------------------
00252 
00253 #endif
00254 

Generated on Tue Jul 13 09:27:32 2010 for Sierra Toolkit by  doxygen 1.4.7