|
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_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/FEMTypes.hpp> 00017 #include <stk_mesh/fem/EntityRanks.hpp> 00018 #include <stk_mesh/base/BulkData.hpp> 00019 #include <stk_mesh/fem/TopologicalMetaData.hpp> 00020 00021 #ifndef SKIP_DEPRECATED_STK_MESH_TOPOLOGY_HELPERS 00022 #include <stk_mesh/fem/TopologyHelpersDeprecated.hpp> 00023 #endif // SKIP_DEPRECATED_STK_MESH_TOPOLOGY_HELPERS 00024 00025 namespace stk { 00026 namespace mesh { 00027 00032 00033 00034 00035 00036 //---------------------------------------------------------------------- 00037 template< class Traits > 00038 void get_parts_with_topology(stk::mesh::BulkData& mesh, 00039 stk::mesh::PartVector& parts) 00040 { 00041 parts.clear(); 00042 00043 const stk::mesh::PartVector& all_parts = mesh.mesh_meta_data().get_parts(); 00044 00045 stk::mesh::PartVector::const_iterator 00046 iter = all_parts.begin(), 00047 iter_end = all_parts.end(); 00048 00049 const CellTopologyData* topology = shards::getCellTopologyData<Traits>(); 00050 00051 for(; iter!=iter_end; ++iter) { 00052 stk::mesh::Part* part = *iter; 00053 #ifndef SKIP_DEPRECATED_STK_MESH_TOPOLOGY_HELPERS 00054 if (get_cell_topology(*part) == topology) { 00055 parts.push_back(part); 00056 } 00057 #else // SKIP_DEPRECATED_STK_MESH_TOPOLOGY_HELPERS 00058 if (TopologicalMetaData::get_cell_topology(*part) == topology) { 00059 parts.push_back(part); 00060 } 00061 #endif // SKIP_DEPRECATED_STK_MESH_TOPOLOGY_HELPERS 00062 } 00063 } 00064 00065 //---------------------------------------------------------------------- 00069 template< typename IdType > 00070 inline 00071 Entity & declare_element( BulkData & mesh , 00072 Part & part , 00073 const IdType elem_id , 00074 const IdType node_id[] ) 00075 { 00076 #ifndef SKIP_DEPRECATED_STK_MESH_TOPOLOGY_HELPERS 00077 const CellTopologyData * const top = get_cell_topology( part ); 00078 #else // SKIP_DEPRECATED_STK_MESH_TOPOLOGY_HELPERS 00079 const CellTopologyData * const top = TopologicalMetaData::get_cell_topology( part ); 00080 #endif // SKIP_DEPRECATED_STK_MESH_TOPOLOGY_HELPERS 00081 00082 if ( top == NULL ) { 00083 std::ostringstream msg ; 00084 msg << "stk::mesh::declare_element( mesh , " ; 00085 msg << part.name(); 00086 msg << " , " ; 00087 msg << elem_id ; 00088 msg << " , node_id[] ) ERROR, Part does not have a local topology" ; 00089 throw std::runtime_error( msg.str() ); 00090 } 00091 00092 PartVector empty ; 00093 PartVector add( 1 ); add[0] = & part ; 00094 00095 #ifndef SKIP_DEPRECATED_STK_MESH_TOPOLOGY_HELPERS 00096 const EntityRank entity_rank = element_rank_deprecated(part.mesh_meta_data()); 00097 #else // SKIP_DEPRECATED_STK_MESH_TOPOLOGY_HELPERS 00098 const EntityRank entity_rank = top->dimension; 00099 #endif // SKIP_DEPRECATED_STK_MESH_TOPOLOGY_HELPERS 00100 00101 Entity & elem = mesh.declare_entity( entity_rank, elem_id, add ); 00102 00103 for ( unsigned i = 0 ; i < top->node_count ; ++i ) { 00104 //declare node if it doesn't already exist 00105 Entity * node = mesh.get_entity( NodeRank , node_id[i]); 00106 if ( NULL == node) { 00107 node = & mesh.declare_entity( NodeRank , node_id[i], empty ); 00108 } 00109 00110 mesh.declare_relation( elem , *node , i ); 00111 } 00112 return elem ; 00113 } 00114 00118 template< typename IdType > 00119 Entity & declare_element( BulkData & mesh , 00120 Part & part , 00121 const IdType elem_id , 00122 Entity * node[] ) 00123 { 00124 #ifndef SKIP_DEPRECATED_STK_MESH_TOPOLOGY_HELPERS 00125 const CellTopologyData * const top = get_cell_topology( part ); 00126 #else // SKIP_DEPRECATED_STK_MESH_TOPOLOGY_HELPERS 00127 const CellTopologyData * const top = TopologicalMetaData::get_cell_topology( part ); 00128 #endif // SKIP_DEPRECATED_STK_MESH_TOPOLOGY_HELPERS 00129 00130 if ( top == NULL ) { 00131 std::ostringstream msg ; 00132 msg << "stk::mesh::declare_element( mesh , " ; 00133 msg << part.name(); 00134 msg << " , " ; 00135 msg << elem_id ; 00136 msg << " , node[] ) ERROR, Part does not have a local topology" ; 00137 throw std::runtime_error( msg.str() ); 00138 } 00139 00140 PartVector add( 1 ); add[0] = & part ; 00141 00142 #ifndef SKIP_DEPRECATED_STK_MESH_TOPOLOGY_HELPERS 00143 const EntityRank entity_rank = element_rank_deprecated(part.mesh_meta_data()); 00144 #else // SKIP_DEPRECATED_STK_MESH_TOPOLOGY_HELPERS 00145 const EntityRank entity_rank = top->dimension; 00146 #endif // SKIP_DEPRECATED_STK_MESH_TOPOLOGY_HELPERS 00147 00148 Entity & elem = mesh.declare_entity( entity_rank, elem_id, add ); 00149 00150 for ( unsigned i = 0 ; i < top->node_count ; ++i ) { 00151 mesh.declare_relation( elem , *node[i] , i ); 00152 } 00153 return elem ; 00154 } 00155 00156 //---------------------------------------------------------------------- 00161 Entity & declare_element_side( BulkData & mesh , 00162 const stk::mesh::EntityId global_side_id , 00163 Entity & elem , 00164 const unsigned local_side_id , 00165 Part * part = NULL ); 00166 00167 Entity & declare_element_side( Entity & elem , 00168 Entity & side , 00169 const unsigned local_side_id , 00170 Part * part = NULL ); 00171 00175 bool element_side_polarity( const Entity & elem , 00176 const Entity & side , int local_side_id = -1 ); 00177 00178 00183 int element_local_side_id( const Entity & elem , 00184 const CellTopologyData * side_topology, 00185 const std::vector<Entity*>& side_nodes ); 00186 00187 //---------------------------------------------------------------------- 00188 00191 }//namespace mesh 00192 }//namespace stk 00193 00194 #endif 00195