26 const char*
CN::entityTypeNames[] = {
"Vertex",
"Edge",
"Tri",
"Quad",
"Polygon",
"Tet",
"Pyramid",
27 "Prism",
"Knife",
"Hex",
"Polyhedron",
"EntitySet",
"MaxType" };
39 short CN::increasingInts[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
40 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39 };
68 const int sub_dimension,
70 EntityType& subentity_topo,
71 int& num_sub_entity_nodes,
72 int sub_entity_conn[] )
75 if( sub_dimension == 0 )
77 assert( sub_index < num_nodes );
79 num_sub_entity_nodes = 1;
80 sub_entity_conn[0] = sub_index;
84 const int ho_bits =
HasMidNodes( this_topo, num_nodes );
85 subentity_topo =
SubEntityType( this_topo, sub_dimension, sub_index );
88 std::copy( corners, corners + num_sub_entity_nodes, sub_entity_conn );
91 int side, sense, offset;
92 for(
int dim = 1;
dim <= sub_dimension; ++
dim )
94 if( !( ho_bits & ( 1 <<
dim ) ) )
continue;
97 for(
int i = 0; i < num_mid; ++i )
103 for(
int j = 0; j < sub_sub_num_vert; ++j )
104 sub_sub_corners[j] = corners[sub_sub_corners[j]];
105 SideNumber( this_topo, sub_sub_corners, sub_sub_num_vert,
dim, side, sense, offset );
106 sub_entity_conn[num_sub_entity_nodes++] =
HONodeIndex( this_topo, num_nodes,
dim, side );
120 const EntityType parent_type,
121 const int sub_dimension,
123 void* sub_entity_conn,
124 int& num_sub_vertices )
131 void** parent_conn_ptr =
static_cast< void**
>(
const_cast< void*
>( parent_conn ) );
132 void** sub_conn_ptr =
static_cast< void**
>( sub_entity_conn );
133 for(
int i = 0; i < num_sub_vertices; i++ )
134 sub_conn_ptr[i] = parent_conn_ptr[sub_indices[i]];
139 const int* source_indices,
140 const int num_source_indices,
141 const int source_dim,
142 const int target_dim,
143 std::vector< int >& index_list,
144 const int operation_type )
147 std::vector< int > tmp_indices;
148 const int* it1 = source_indices;
150 assert( source_dim <= 3 && target_dim >= 0 && target_dim <= 3 &&
152 ( ( source_dim > 0 && *it1 <
mConnectivityMap[this_type][source_dim - 1].num_sub_elements ) ||
157 #define MUC CN::mUpConnMap[this_type][source_dim][target_dim]
161 if( num_source_indices == 1 && 0 == target_dim && source_dim != target_dim )
167 std::copy( cm.
conn[source_indices[0]],
169 std::back_inserter( index_list ) );
174 for( it1 = source_indices; it1 != source_indices + num_source_indices; it1++ )
180 if( operation_type ==
CN::UNION || ( it1 == source_indices && index_list.empty() ) )
182 std::copy(
MUC.targets_per_source_element[*it1],
183 MUC.targets_per_source_element[*it1] +
MUC.num_targets_per_source_element[*it1],
184 std::back_inserter( index_list ) );
190 for(
int i =
MUC.num_targets_per_source_element[*it1] - 1; i >= 0; i-- )
191 if( std::find( index_list.begin(), index_list.end(),
MUC.targets_per_source_element[*it1][i] ) !=
193 tmp_indices.push_back(
MUC.targets_per_source_element[*it1][i] );
199 index_list.swap( tmp_indices );
203 if( index_list.empty() )
return 0;
207 if( operation_type ==
CN::UNION && num_source_indices != 1 )
210 std::sort( index_list.begin(), index_list.end() );
211 index_list.erase( std::unique( index_list.begin(), index_list.end() ), index_list.end() );
217 template <
typename T >
219 const EntityType parent_type,
221 const int child_num_verts,
229 assert(
sizeof( side_indices ) /
sizeof( side_indices[0] ) >= (
size_t)child_num_verts );
231 for(
int i = 0; i < child_num_verts; i++ )
233 side_indices[i] = std::find( parent_conn, parent_conn + parent_num_verts, child_conn[i] ) - parent_conn;
234 if( side_indices[i] == parent_num_verts )
return -1;
237 return CN::SideNumber( parent_type, &side_indices[0], child_num_verts, child_dim, side_no, sense, offset );
241 const int* parent_conn,
242 const int* child_conn,
243 const int child_num_verts,
249 return side_number( parent_conn, parent_type, child_conn, child_num_verts, child_dim, side_no, sense, offset );
253 const unsigned int* parent_conn,
254 const unsigned int* child_conn,
255 const int child_num_verts,
261 return side_number( parent_conn, parent_type, child_conn, child_num_verts, child_dim, side_no, sense, offset );
264 const long* parent_conn,
265 const long* child_conn,
266 const int child_num_verts,
272 return side_number( parent_conn, parent_type, child_conn, child_num_verts, child_dim, side_no, sense, offset );
275 const unsigned long* parent_conn,
276 const unsigned long* child_conn,
277 const int child_num_verts,
283 return side_number( parent_conn, parent_type, child_conn, child_num_verts, child_dim, side_no, sense, offset );
287 const unsigned long long* parent_conn,
288 const unsigned long long* child_conn,
289 const int child_num_verts,
296 return side_number( parent_conn, parent_type, child_conn, child_num_verts, child_dim, side_no, sense, offset );
300 void*
const* parent_conn,
301 void*
const* child_conn,
302 const int child_num_verts,
308 return side_number( parent_conn, parent_type, child_conn, child_num_verts, child_dim, side_no, sense, offset );
312 const int* child_conn_indices,
313 const int child_num_verts,
319 int parent_dim =
Dimension( parent_type );
325 if( child_num_verts != 1 )
return -1;
326 side_no = *child_conn_indices;
333 if( child_dim > parent_dim || child_dim < 0 )
return -1;
336 if( parent_dim == child_dim && parent_num_verts != child_num_verts )
344 int sub_conn_indices[10];
345 for(
int i = 0; i <
NumSubEntities( parent_type, child_dim ); i++ )
348 if( sub_size != child_num_verts )
continue;
351 bool they_match =
ConnectivityMatch( child_conn_indices, sub_conn_indices, sub_size, sense, offset );
380 const int child_index,
385 switch( parent_type )
391 opposite_index = 1 - child_index;
400 opposite_index = ( child_index + 1 ) % 3;
404 opposite_index = ( child_index + 2 ) % 3;
416 opposite_dim = child_dim;
417 opposite_index = ( child_index + 2 ) % 4;
429 opposite_index = ( child_index + 1 ) % 3 + 2 * ( child_index / 3 );
433 opposite_index = child_index < 3 ? 3 + ( child_index + 2 ) % 3 : ( child_index + 1 ) % 3;
437 opposite_index = ( child_index + 2 ) % 3 + child_index / 3;
444 opposite_dim = child_dim;
448 opposite_index = child_index < 4 ? 4 + ( child_index + 2 ) % 4 : ( child_index - 2 ) % 4;
451 opposite_index = 4 * ( 2 - child_index / 4 ) + ( child_index + 2 ) % 4;
454 opposite_index = child_index < 4 ? ( child_index + 2 ) % 4 : 9 - child_index;
468 template <
typename T >
469 inline bool connectivity_match(
const T* conn1_i,
const T* conn2_i,
const int num_vertices,
int& direct,
int& offset )
476 if( num_vertices == 2 )
479 if( conn1_i[0] == conn2_i[0] && conn1_i[1] == conn2_i[1] )
485 else if( conn1_i[0] == conn2_i[1] && conn1_i[1] == conn2_i[0] )
496 iter = std::find( &conn2_i[0], &conn2_i[num_vertices], conn1_i[0] );
497 if( iter == &conn2_i[num_vertices] )
return false;
501 offset = iter - conn2_i;
505 for( i = 1; i < num_vertices; ++i )
507 if( conn1_i[i] != conn2_i[( offset + i ) % num_vertices] )
514 if( they_match ==
true )
523 for( i = 1; i < num_vertices; i++ )
525 if( conn1_i[i] != conn2_i[( offset + num_vertices - i ) % num_vertices] )
540 bool CN::ConnectivityMatch(
const int* conn1_i,
const int* conn2_i,
const int num_vertices,
int& direct,
int& offset )
542 return connectivity_match< int >( conn1_i, conn2_i, num_vertices, direct, offset );
546 const unsigned int* conn2_i,
547 const int num_vertices,
551 return connectivity_match< unsigned int >( conn1_i, conn2_i, num_vertices, direct, offset );
554 bool CN::ConnectivityMatch(
const long* conn1_i,
const long* conn2_i,
const int num_vertices,
int& direct,
int& offset )
556 return connectivity_match< long >( conn1_i, conn2_i, num_vertices, direct, offset );
560 const unsigned long* conn2_i,
561 const int num_vertices,
565 return connectivity_match< unsigned long >( conn1_i, conn2_i, num_vertices, direct, offset );
569 const unsigned long long* conn2_i,
570 const int num_vertices,
574 return connectivity_match< unsigned long long >( conn1_i, conn2_i, num_vertices, direct, offset );
578 void*
const* conn2_i,
579 const int num_vertices,
583 return connectivity_match< void* >( conn1_i, conn2_i, num_vertices, direct, offset );
590 const int subfacet_dim,
591 const int subfacet_index )
598 if( subfacet_index != -1 && !has_mids[subfacet_dim] )
return -1;
606 for( i = 1; i < subfacet_dim; i++ )
610 if( subfacet_index == -1 && has_mids[subfacet_dim] )
614 else if( subfacet_index != -1 && has_mids[subfacet_dim] )
625 void CN::HONodeParent( EntityType elem_type,
int num_verts,
int ho_index,
int& parent_dim,
int& parent_index )
628 parent_dim = parent_index = -1;
639 for(
int i = 1; i <
dim; i++ )
648 parent_index = ho_index - index - 1;
659 if( has_mids[
dim] && ho_index == index + 1 )
674 using moab::EntityType;
679 *rval = CN::GetBasis();
685 CN::SetBasis( in_basis );
691 const char* rval_tmp = CN::EntityTypeName( (EntityType)this_type );
692 int rval_len_tmp = strlen( rval_tmp );
693 rval_len_tmp = ( rval_len_tmp < rval_len ? rval_len_tmp : rval_len );
694 strncpy( rval, rval_tmp, rval_len_tmp );
700 *rval = CN::EntityTypeFromName( name );
706 *rval = CN::Dimension( (EntityType)t );
712 *rval = CN::VerticesPerEntity( (EntityType)t );
718 *rval = CN::NumSubEntities( (EntityType)t, d );
730 *rval = CN::SubEntityType( (EntityType)this_type, sub_dimension, index );
739 const int sub_dimension,
741 int sub_entity_conn[] )
743 CN::SubEntityVertexIndices( (EntityType)this_type, sub_dimension, sub_index, sub_entity_conn );
773 const int* source_indices,
774 const int num_source_indices,
775 const int source_dim,
776 const int target_dim,
779 const int operation_type,
782 std::vector< int > tmp_index_list;
783 *rval = CN::AdjacentSubEntities( (EntityType)this_type, source_indices, num_source_indices, source_dim, target_dim,
784 tmp_index_list, operation_type );
785 std::copy( tmp_index_list.begin(), tmp_index_list.end(), index_list );
786 *num_indices = tmp_index_list.size();
800 const int* child_conn_indices,
801 const int child_num_verts,
807 CN::SideNumber( (EntityType)parent_type, child_conn_indices, child_num_verts, child_dim, *side_no, *sense,
812 const EntityType parent_type,
813 const int* child_conn,
814 const int child_num_verts,
820 moab::side_number( parent_conn, parent_type, child_conn, child_num_verts, child_dim, *side_no, *sense, *offset );
824 const EntityType parent_type,
825 const unsigned int* child_conn,
826 const int child_num_verts,
832 moab::side_number( parent_conn, parent_type, child_conn, child_num_verts, child_dim, *side_no, *sense, *offset );
836 const EntityType parent_type,
837 const long* child_conn,
838 const int child_num_verts,
844 moab::side_number( parent_conn, parent_type, child_conn, child_num_verts, child_dim, *side_no, *sense, *offset );
848 const EntityType parent_type,
849 const unsigned long* child_conn,
850 const int child_num_verts,
856 moab::side_number( parent_conn, parent_type, child_conn, child_num_verts, child_dim, *side_no, *sense, *offset );
860 const EntityType parent_type,
861 void*
const* child_conn,
862 const int child_num_verts,
868 moab::side_number( parent_conn, parent_type, child_conn, child_num_verts, child_dim, *side_no, *sense, *offset );
885 const int child_index,
891 *rval = CN::OppositeSide( (EntityType)parent_type, child_index, child_dim, *opposite_index, *opposite_dim );
903 const int num_vertices,
908 *rval = CN::ConnectivityMatch( conn1, conn2, num_vertices, *direct, *offset );
912 const unsigned int* conn2,
913 const int num_vertices,
918 *rval = CN::ConnectivityMatch( conn1, conn2, num_vertices, *direct, *offset );
923 const int num_vertices,
928 *rval = CN::ConnectivityMatch( conn1, conn2, num_vertices, *direct, *offset );
932 const unsigned long* conn2,
933 const int num_vertices,
938 *rval = CN::ConnectivityMatch( conn1, conn2, num_vertices, *direct, *offset );
943 const int num_vertices,
948 *rval = CN::ConnectivityMatch( conn1, conn2, num_vertices, *direct, *offset );
958 *rval = CN::HasMidEdgeNodes( (EntityType)this_type, num_verts );
968 *rval = CN::HasMidFaceNodes( (EntityType)this_type, num_verts );
978 *rval = CN::HasMidRegionNodes( (EntityType)this_type, num_verts );
989 return CN::HasMidNodes( (EntityType)this_type, num_verts, mid_nodes );
1001 void MBCN_HONodeParent(
int elem_type,
int num_nodes,
int ho_node_index,
int* parent_dim,
int* parent_index )
1003 return CN::HONodeParent( (EntityType)elem_type, num_nodes, ho_node_index, *parent_dim, *parent_index );
1015 const int num_verts,
1016 const int subfacet_dim,
1017 const int subfacet_index,
1022 *rval = CN::HONodeIndex( (EntityType)this_type, num_verts, subfacet_dim, subfacet_index );
1028 template <
typename T >
1029 inline int permute_this( EntityType t,
const int dim, T* conn,
const int indices_per_ent,
const int num_entries )
1036 for(
int j = 0; j < num_entries; j++ )
1038 for(
int i = 0; i < indices_per_ent; i++ )
1039 tmp_conn[tvec[i]] = pvec[i];
1040 memcpy( pvec, tmp_conn, indices_per_ent *
sizeof( T ) );
1041 pvec += indices_per_ent;
1047 template <
typename T >
1048 inline int rev_permute_this( EntityType t,
const int dim, T* conn,
const int indices_per_ent,
const int num_entries )
1055 for(
int j = 0; j < num_entries; j++ )
1057 for(
int i = 0; i < indices_per_ent; i++ )
1058 tmp_conn[i] = pvec[tvec[i]];
1059 memcpy( pvec, tmp_conn, indices_per_ent *
sizeof( T ) );
1060 pvec += indices_per_ent;
1085 EntityType
CN::SubEntityType(
const EntityType this_type,
const int sub_dimension,
const int index )
1088 : (
Dimension( this_type ) == sub_dimension && 0 == index
1094 const int sub_dimension,
1096 EntityType& sub_type,
1099 if( sub_dimension == 0 )
1110 return map.
conn[index];
1115 inline int CN::permuteThis(
const EntityType t,
const int dim,
int* pvec,
const int num_indices,
const int num_entries )
1122 const int num_indices,
1123 const int num_entries )
1130 const int num_indices,
1131 const int num_entries )
1138 const int num_indices,
1139 const int num_entries )
1148 const int num_indices,
1149 const int num_entries )
1156 const int num_indices,
1157 const int num_entries )
1164 const int num_indices,
1165 const int num_entries )
1172 const int num_indices,
1173 const int num_entries )