Entity.cpp

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 #include <stddef.h>
00010 #include <stdexcept>
00011 #include <iostream>
00012 #include <sstream>
00013 #include <algorithm>
00014 
00015 #include <stk_mesh/base/Entity.hpp>
00016 #include <stk_mesh/base/BulkData.hpp>
00017 #include <stk_mesh/base/MetaData.hpp>
00018 
00019 namespace stk {
00020 namespace mesh {
00021 
00022 //----------------------------------------------------------------------
00023 
00024 std::ostream &
00025 print_entity_key( std::ostream & os , const MetaData & meta_data ,
00026                   unsigned type , EntityId id )
00027 {
00028   const std::string & name = meta_data.entity_type_name( type );
00029   return os << name << "[" << id << "]" ;
00030 }
00031 
00032 std::ostream &
00033 print_entity_key( std::ostream & os , const MetaData & meta_data ,
00034                   const EntityKey & key )
00035 {
00036   const unsigned type   = entity_type(key);
00037   const EntityId id = entity_id(key);
00038   return print_entity_key( os , meta_data , type , id );
00039 }
00040 
00041 //----------------------------------------------------------------------
00042 
00043 Entity::Entity( const EntityKey & arg_key )
00044   : m_key( arg_key ),
00045     m_relation(),
00046     m_comm(),
00047     m_bucket( NULL ),
00048     m_bucket_ord(0),
00049     m_owner_rank(0),
00050     m_sync_count(0)
00051 {}
00052 
00053 Entity::~Entity()
00054 {}
00055 
00056 //----------------------------------------------------------------------
00057 
00058 PairIterRelation Entity::relations( unsigned rank ) const
00059 {
00060   std::vector<Relation>::const_iterator i = m_relation.begin();
00061   std::vector<Relation>::const_iterator e = m_relation.end();
00062 
00063   if ( rank ) {
00064     const Relation::raw_attr_type lo_attr = Relation::attribute( rank , 0 );
00065     i = std::lower_bound( i , e , lo_attr , LessRelation() );
00066   }
00067 
00068   const Relation::raw_attr_type hi_attr = Relation::attribute( rank + 1 , 0 );
00069   e = std::lower_bound( i , e , hi_attr , LessRelation() );
00070 
00071   return PairIterRelation( i , e );
00072 }
00073 
00074 //----------------------------------------------------------------------
00075 
00076 PairIterEntityComm Entity::sharing() const
00077 {
00078   typedef std::vector< EntityCommInfo > EntityComm ;
00079 
00080   EntityComm::const_iterator i = m_comm.begin();
00081   EntityComm::const_iterator e = m_comm.end();
00082 
00083   e = std::lower_bound( i , e , EntityCommInfo(1,0) );
00084 
00085   return PairIterEntityComm( i , e );
00086 }
00087 
00088 PairIterEntityComm Entity::comm( const Ghosting & sub ) const
00089 {
00090   typedef std::vector< EntityCommInfo > EntityComm ;
00091 
00092   const EntityCommInfo s_begin( sub.ordinal() ,     0 );
00093   const EntityCommInfo s_end(   sub.ordinal() + 1 , 0 );
00094 
00095   EntityComm::const_iterator i = m_comm.begin();
00096   EntityComm::const_iterator e = m_comm.end();
00097 
00098   i = std::lower_bound( i , e , s_begin );
00099   e = std::lower_bound( i , e , s_end );
00100 
00101   return PairIterEntityComm( i , e );
00102 }
00103 
00104 bool Entity::insert( const EntityCommInfo & val )
00105 {
00106   std::vector< EntityCommInfo >::iterator i =
00107     std::lower_bound( m_comm.begin() , m_comm.end() , val );
00108 
00109   const bool result = i == m_comm.end() || val != *i ;
00110 
00111   if ( result ) { m_comm.insert( i , val ); }
00112 
00113   return result ;
00114 }
00115 
00116 //----------------------------------------------------------------------
00117 
00118 } // namespace mesh
00119 } // namespace stk
00120 

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