Sierra Toolkit Version of the Day
Relation.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 
00010 #ifndef stk_mesh_Relation_hpp
00011 #define stk_mesh_Relation_hpp
00012 
00013 #include <iosfwd>
00014 #include <limits>
00015 
00016 #include <stk_mesh/base/EntityKey.hpp>
00017 
00018 namespace stk {
00019 namespace mesh {
00020 
00024 //----------------------------------------------------------------------
00047 class Relation {
00048 public:
00049   typedef uintptr_t raw_attr_type ;
00050 
00052   ~Relation() {}
00053 
00055   Relation() : m_attr(), m_entity(NULL) {}
00056 
00058   Relation( const Relation & r )
00059     : m_attr( r.m_attr ), m_entity(r.m_entity) {}
00060 
00062   Relation & operator = ( const Relation & r )
00063   {
00064     if( this != &r ) {
00065       m_attr   = r.m_attr ;
00066       m_entity = r.m_entity ;
00067     }
00068     return *this ;
00069   }
00070 
00074   Relation( raw_attr_type attr , Entity & entity );
00075 
00079   Relation( Entity & entity , unsigned identifier );
00080 
00082   static raw_attr_type attribute( unsigned rank , unsigned id );
00083 
00085   raw_attr_type attribute() const { return m_attr.value ; }
00086 
00088   unsigned entity_rank() const ;
00089 
00091   unsigned identifier() const ;
00092 
00094   Entity * entity() const { return m_entity ; }
00095 
00097   bool operator == ( const Relation & r ) const
00098     { return m_attr.value == r.m_attr.value && m_entity == r.m_entity ; }
00099 
00101   bool operator != ( const Relation & r ) const
00102     { return m_attr.value != r.m_attr.value || m_entity != r.m_entity ; }
00103 
00105   bool operator < ( const Relation & r ) const ;
00106 
00107 private:
00108 
00109   enum {
00110     attr_digits   = std::numeric_limits<raw_attr_type>::digits ,
00111     uint_digits   = std::numeric_limits<unsigned>::digits ,
00112     rank_digits   = EntityKey::rank_digits ,
00113     id_max_digits = attr_digits - rank_digits ,
00114     id_digits     = uint_digits - rank_digits ,
00115     id_mask       = ~(0u) >> ( uint_digits - id_digits ),
00116     rank_shift    = id_max_digits
00117   };
00118 
00119   union AttrType {
00120   public:
00121     raw_attr_type value ;
00122 
00123     struct {
00124       raw_attr_type identifier  : id_digits ;
00125       raw_attr_type entity_rank : rank_digits ;
00126     } normal_view ;
00127 
00128     struct {
00129       raw_attr_type entity_rank : rank_digits ;
00130       raw_attr_type identifier  : id_digits ;
00131     } reverse_view ;
00132 
00133     AttrType( raw_attr_type v ) : value(v) {}
00134     AttrType() : value(0) {}
00135     AttrType( const AttrType & rhs ) : value( rhs.value ) {}
00136     AttrType & operator = ( const AttrType & rhs )
00137       { value = rhs.value ; return *this ; }
00138   };
00139 
00140   AttrType m_attr ;
00141   Entity * m_entity ;
00142 };
00143 
00144 //----------------------------------------------------------------------
00145 
00146 inline
00147 unsigned Relation::entity_rank() const
00148 { return unsigned( m_attr.value >> rank_shift ); }
00149 
00150 inline
00151 unsigned Relation::identifier() const
00152 { return unsigned( m_attr.value & id_mask ); }
00153 
00154 struct LessRelation {
00155   bool operator() ( const Relation & lhs , const Relation & rhs ) const
00156     { return lhs < rhs ; }
00157 
00158   bool operator() ( const Relation & lhs , Relation::raw_attr_type rhs ) const
00159     { return lhs.attribute() < rhs ; }
00160 };
00161 
00162 //----------------------------------------------------------------------
00166 void get_entities_through_relations(
00167   const std::vector<Entity*> & entities ,
00168         std::vector<Entity*> & entities_related );
00169 
00170 void get_entities_through_relations(
00171   const std::vector<Entity*> & entities ,
00172         unsigned               entities_related_rank ,
00173         std::vector<Entity*> & entities_related );
00174 
00175 //----------------------------------------------------------------------
00179 bool membership_is_induced( const Part & part , unsigned entity_rank );
00180 
00184 void induced_part_membership( Part & part ,
00185                               unsigned entity_rank_from ,
00186                               unsigned entity_rank_to ,
00187                               unsigned relation_identifier ,
00188                               PartVector & induced_parts );
00189 
00193 void induced_part_membership( const Entity     & entity_from ,
00194                               const PartVector & omit ,
00195                                     unsigned     entity_rank_to ,
00196                                     unsigned     relation_identifier ,
00197                                     PartVector & entity_to_parts );
00198 
00202 void induced_part_membership( const Entity     & entity ,
00203                               const PartVector & omit ,
00204                                     PartVector & induced );
00205 
00206 
00207 //----------------------------------------------------------------------
00208 
00209 #if 0
00210 
00211 std::ostream &
00212 print_relation( std::ostream & , Relation::raw__attr_type );
00213 
00215 std::ostream &
00216 print_relation( std::ostream & , const MetaData & ,
00217                 Relation::raw__attr_type , EntityKey );
00218 #endif
00219 
00221 std::ostream & operator << ( std::ostream & , const Relation & );
00222 
00225 } // namespace mesh
00226 } // namespace stk
00227 
00228 //----------------------------------------------------------------------
00229 //----------------------------------------------------------------------
00230 
00231 #endif /* stk_mesh_Relation_hpp */
00232 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends