TopologyHelpers.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_TopologyHelpers_hpp
00010 #define stk_mesh_TopologyHelpers_hpp
00011 
00012 #include <sstream>
00013 #include <stdexcept>
00014 #include <Shards_CellTopologyTraits.hpp>
00015 #include <stk_mesh/base/Types.hpp>
00016 #include <stk_mesh/fem/EntityTypes.hpp>
00017 #include <stk_mesh/base/BulkData.hpp>
00018 
00019 namespace stk {
00020 namespace mesh {
00021 
00026 
00027 
00028 
00029 
00030 //----------------------------------------------------------------------
00034 void set_cell_topology( Part & , const CellTopologyData * singleton );
00035 
00039 template< class Traits >
00040 void set_cell_topology( Part & p )
00041 { return set_cell_topology( p , shards::getCellTopologyData<Traits>() ); }
00042 
00044 const CellTopologyData * get_cell_topology( const Part & );
00045 
00047 const CellTopologyData * get_cell_topology( const Bucket & );
00048 
00050 const CellTopologyData * get_cell_topology( const Entity & );
00051 
00052 //----------------------------------------------------------------------
00053 template< class Traits >
00054 void get_parts_with_topology(stk::mesh::BulkData& mesh,
00055                              stk::mesh::PartVector& parts)
00056 {
00057   parts.clear();
00058 
00059   const stk::mesh::PartVector& all_parts = mesh.mesh_meta_data().get_parts();
00060 
00061   stk::mesh::PartVector::const_iterator
00062     iter = all_parts.begin(),
00063     iter_end = all_parts.end();
00064  
00065   const CellTopologyData* topology = shards::getCellTopologyData<Traits>();
00066 
00067   for(; iter!=iter_end; ++iter) {
00068     stk::mesh::Part* part =  *iter;
00069     if (stk::mesh::get_cell_topology(*part) == topology) {
00070       parts.push_back(part);
00071     }
00072   }
00073 }
00074 
00075 //----------------------------------------------------------------------
00079 template< typename IdType >
00080 inline
00081 Entity & declare_element( BulkData & mesh ,
00082                           Part & part ,
00083                           const IdType elem_id ,
00084                           const IdType node_id[] )
00085 {
00086   const CellTopologyData * const top = get_cell_topology( part );
00087      
00088   if ( top == NULL ) {
00089     std::ostringstream msg ; 
00090     msg << "stk::mesh::declare_element( mesh , " ; 
00091     msg << part.name();
00092     msg << " , " ;
00093     msg << elem_id ;
00094     msg << " , node_id[] ) ERROR, Part does not have a local topology" ;
00095     throw std::runtime_error( msg.str() ); 
00096   }
00097  
00098   PartVector empty ;
00099   PartVector add( 1 ); add[0] = & part ;
00100  
00101   Entity & elem = mesh.declare_entity( Element, elem_id, add ); 
00102  
00103   for ( unsigned i = 0 ; i < top->node_count ; ++i ) {
00104     Entity & node = mesh.declare_entity( Node, node_id[i], empty );
00105     mesh.declare_relation( elem , node , i );
00106   }   
00107   return elem ; 
00108 }         
00109 
00113 template< typename IdType >
00114 Entity & declare_element( BulkData & mesh ,
00115                           Part & part ,
00116                           const IdType elem_id ,
00117                           Entity * node[] )
00118 {
00119   const CellTopologyData * const top = get_cell_topology( part );
00120      
00121   if ( top == NULL ) {
00122     std::ostringstream msg ; 
00123     msg << "stk::mesh::declare_element( mesh , " ; 
00124     msg << part.name();
00125     msg << " , " ;
00126     msg << elem_id ;
00127     msg << " , node[] ) ERROR, Part does not have a local topology" ;
00128     throw std::runtime_error( msg.str() ); 
00129   }
00130  
00131   PartVector add( 1 ); add[0] = & part ;
00132  
00133   Entity & elem = mesh.declare_entity( Element, elem_id, add ); 
00134  
00135   for ( unsigned i = 0 ; i < top->node_count ; ++i ) {
00136     mesh.declare_relation( elem , *node[i] , i );
00137   }   
00138   return elem ; 
00139 }         
00140 
00141 //----------------------------------------------------------------------
00146 Entity & declare_element_side( BulkData & mesh ,
00147                                const stk::mesh::EntityId global_side_id ,
00148                                Entity & elem ,
00149                                const unsigned local_side_id ,
00150                                Part * part = NULL );
00151 
00155 bool element_side_polarity( const Entity & elem ,
00156                             const Entity & side , int local_side_id = -1 );
00157 
00161 int element_local_side_id( const Entity & elem ,
00162                            const Entity & side );
00163 
00176 void get_adjacent_entities( const Entity & entity ,
00177                             unsigned subcell_rank ,
00178                             unsigned subcell_identifier ,
00179                             std::vector<std::pair<Entity*, unsigned > > & adjacent_entities );
00180 
00184 int element_local_side_id( const Entity & elem ,
00185                            const std::vector<Entity*>& entity_nodes );
00186 
00187 //----------------------------------------------------------------------
00188 
00191 }//namespace mesh
00192 }//namespace stk
00193 
00194 #endif
00195 

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