moab
ExoIIUtil.cpp
Go to the documentation of this file.
00001 
00016 #include "ExoIIUtil.hpp"
00017 #include "Internals.hpp"
00018 #include "moab/Interface.hpp"
00019 #include "moab/CN.hpp"
00020 #include <string.h>
00021 
00022 namespace moab {
00023 
00024 //
00025 // definitions of ExoII-related static arrays
00026 //
00027 
00028 const EntityType ExoIIUtil::ExoIIElementMBEntity[] =
00029 {
00030   MBVERTEX, // SPHERE,
00031   MBEDGE, // SPRING,
00032   MBEDGE, // BAR = 0,
00033   MBEDGE, // BAR2,
00034   MBEDGE, // BAR3,
00035   MBEDGE, // BEAM,
00036   MBEDGE, // BEAM2,
00037   MBEDGE, // BEAM3,
00038   MBEDGE, // TRUSS,
00039   MBEDGE, // TRUSS2,
00040   MBEDGE, // TRUSS3,
00041   MBTRI, // TRI,
00042   MBTRI, // TRI3,
00043   MBTRI, // TRI6,
00044   MBTRI, // TRI7,
00045   MBQUAD, // QUAD,
00046   MBQUAD, // QUAD4,
00047   MBQUAD, // QUAD5,
00048   MBQUAD, // QUAD8,
00049   MBQUAD, // QUAD9,
00050   MBQUAD, // SHELL,
00051   MBQUAD, // SHELL4,
00052   MBQUAD, // SHELL5,
00053   MBQUAD, // SHELL8,
00054   MBQUAD, // SHELL9,
00055   MBTET, // TETRA,
00056   MBTET, // TETRA4,
00057   MBTET, // TET4
00058   MBTET, // TETRA8,
00059   MBTET, // TETRA10,
00060   MBTET, // TETRA14,
00061   MBPYRAMID, // PYRAMID,
00062   MBPYRAMID, // PYRAMID5,
00063   MBPYRAMID, // PYRAMID10,
00064   MBPYRAMID, // PYRAMID13,
00065   MBPYRAMID, // PYRAMID18,
00066   MBPRISM, // WEDGE,
00067   MBKNIFE, // KNIFE,
00068   MBHEX, // HEX,
00069   MBHEX, // HEX8,
00070   MBHEX, // HEX9,
00071   MBHEX, // HEX20,
00072   MBHEX, // HEX27,
00073   MBHEX, // HEXSHELL,
00074   MBMAXTYPE // UNKNOWN
00075 };
00076 
00077 
00078 const char* ExoIIUtil::ElementTypeNames[] =
00079 {
00080   "SPHERE",
00081   "SPRING",
00082   "BAR", 
00083   "BAR2", 
00084   "BAR3", 
00085   "BEAM", 
00086   "BEAM2", 
00087   "BEAM3",
00088   "TRUSS", 
00089   "TRUSS2", 
00090   "TRUSS3",
00091   "TRI", 
00092   "TRI3", 
00093   "TRI6", 
00094   "TRI7",
00095   "QUAD", 
00096   "QUAD4", 
00097   "QUAD5", 
00098   "QUAD8", 
00099   "QUAD9",
00100   "SHELL", 
00101   "SHELL4", 
00102   "SHELL5", 
00103   "SHELL8", 
00104   "SHELL9",
00105   "TETRA", 
00106   "TETRA4",
00107   "TET4",
00108   "TETRA8", 
00109   "TETRA10", 
00110   "TETRA14",
00111   "PYRAMID", 
00112   "PYRAMID5", 
00113   "PYRAMID10", 
00114   "PYRAMID13", 
00115   "PYRAMID18",
00116   "WEDGE",
00117   "KNIFE",
00118   "HEX", 
00119   "HEX8", 
00120   "HEX9", 
00121   "HEX20", 
00122   "HEX27",
00123   "HEXSHELL",
00124   "UNKNOWN"
00125 };
00126 
00127 const int ExoIIUtil::VerticesPerElement[] =
00128 {
00129   1,             // SPHERE 
00130   1,             // SPRING
00131   2, 
00132   2,  
00133   3,      // BAR
00134   2, 
00135   2,  
00136   3,      // BEAM
00137   2, 
00138   2,  
00139   3,      // TRUSS
00140   3, 
00141   3,  
00142   6,  
00143   7,  // TRI
00144   4, 
00145   4,  
00146   5,  
00147   8,  
00148   9,  // QUAD
00149   4, 
00150   4, 
00151   5, 
00152   8,  
00153   9,  // SHELL
00154   4, 
00155   4,  
00156   4,  // TET4
00157   8, 
00158   10, 
00159   14,  // TETRA
00160   5, 
00161   5,  
00162   10, 
00163   13, 
00164   18,  // PYRAMID
00165   6,  // WEDGE
00166   7,  // KNIFE
00167   8, 
00168   8,  
00169   9, 
00170   20, 
00171   27,  // HEX
00172   12,            // HEXSHELL
00173   0              // UNKNOWN
00174 };
00175 
00176 const int ExoIIUtil::HasMidNodes[][4] = 
00177 {
00178   {0, 0, 0, 0}, // SPHERE - no mid nodes
00179   {0, 0, 0, 0}, // SPRING - no mid nodes
00180   {0, 0, 0, 0}, // BAR - no mid nodes, same as BAR2
00181   {0, 0, 0, 0}, // BAR2 - no mid nodes
00182   {0, 1, 0, 0}, // BAR3 - mid nodes on edges
00183   {0, 0, 0, 0}, // BEAM - no mid nodes
00184   {0, 0, 0, 0}, // BEAM2 - no mid nodes
00185   {0, 1, 0, 0}, // BEAM3 - mid nodes on edges
00186   {0, 0, 0, 0}, // TRUSS - no mid nodes
00187   {0, 0, 0, 0}, // TRUSS2 - no mid nodes
00188   {0, 1, 0, 0}, // TRUSS3 - mid nodes on edges
00189   {0, 0, 0, 0}, // TRI - no mid nodes
00190   {0, 0, 0, 0}, // TRI3 - no mid nodes
00191   {0, 1, 0, 0}, // TRI6 - mid nodes on edges
00192   {0, 1, 1, 0}, // TRI7 - mid nodes on edges and faces
00193   {0, 0, 0, 0}, // QUAD - no mid nodes
00194   {0, 0, 0, 0}, // QUAD4 - no mid nodes
00195   {0, 0, 1, 0}, // QUAD5 - mid node on faces
00196   {0, 1, 0, 0}, // QUAD8 - mid nodes on edges
00197   {0, 1, 1, 0}, // QUAD9 - mid nodes on edges and faces
00198   {0, 0, 0, 0}, // SHELL - no mid nodes
00199   {0, 0, 0, 0}, // SHELL4 - no mid nodes
00200   {0, 0, 1, 0}, // SHELL5 - mid node on faces
00201   {0, 1, 0, 0}, // SHELL8 - mid nodes on edges
00202   {0, 1, 1, 0}, // SHELL9 - mid nodes on edges and faces
00203   {0, 0, 0, 0}, // TETRA - no mid nodes
00204   {0, 0, 0, 0}, // TETRA4 - no mid nodes
00205   {0, 0, 0, 0}, // TET4 - no mid nodes
00206   {0, 0, 1, 0}, // TETRA8 - mid nodes on faces
00207   {0, 1, 0, 0}, // TETRA10 - mid nodes on edges
00208   {0, 1, 1, 0}, // TETRA14 - mid nodes on edges and faces
00209   {0, 0, 0, 0}, // PYRAMID - no mid nodes
00210   {0, 0, 0, 0}, // PYRAMID5 - no mid nodes
00211   {0, 0, 1, 0}, // PYRAMID10 - *** TODO - not sure if this is right...
00212   {0, 1, 0, 0}, // PYRAMID13 - *** TODO - not sure if this is right...
00213   {0, 1, 1, 0}, // PYRAMID18 - *** TODO - not sure if this is right...
00214   {0, 0, 0, 0}, // WEDGE - no mid nodes
00215   {0, 0, 0, 0}, // KNIFE - no mid nodes
00216   {0, 0, 0, 0}, // HEX - no mid nodes
00217   {0, 0, 0, 0}, // HEX8 - no mid nodes
00218   {0, 0, 0, 1}, // HEX9 - mid node on element
00219   {0, 1, 0, 0}, // HEX20 - mid nodes on edges
00220   {0, 1, 1, 1}, // HEX27 - mid node on edges, faces and element
00221   {0, 0, 0, 0}, // HEXSHELL - *** TODO - not sure if this is right...
00222   {0, 0, 0, 0} // UNKNOWN - no mid nodes
00223 };
00224 
00225 const int ExoIIUtil::ElementGeometricDimension[] =  
00226 { 
00227   3,          // SPHERE  
00228   3,          // SPRING
00229   2, 
00230   2, 
00231   2,    // BAR
00232   3, 
00233   3, 
00234   3,    // BEAM
00235   3, 
00236   3, 
00237   3,    // TRUSS
00238   3, 
00239   3, 
00240   3, 
00241   3, // TRI
00242   2, 
00243   2, 
00244   2, 
00245   2, 
00246   2, // QUAD
00247   3, 
00248   3, 
00249   3, 
00250   3,
00251   3, // SHELL
00252   3, 
00253   3, 
00254   3, 
00255   3, 
00256   3, // TETRA
00257   3,
00258   3, 
00259   3, 
00260   3, 
00261   3, 
00262   3,// PYRAMID
00263   3, // WEDGE
00264   3, // KNIFE
00265   3, 
00266   3, 
00267   3, 
00268   3, 
00269   3, // HEX
00270   3,          // HEXSHELL
00271   0 // UNKNOWN
00272 };
00273 
00274 ExoIIElementType ExoIIUtil::static_element_name_to_type(const char *name) 
00275 {
00276   int i;
00277   for (i = 0; i < EXOII_MAX_ELEM_TYPE; i++)
00278     if (strcmp(ElementTypeNames[i], name) == 0)
00279       return (ExoIIElementType) i;
00280 
00281   return EXOII_MAX_ELEM_TYPE;
00282 }
00283 
00284 ExoIIElementType ExoIIUtil::static_get_element_type(Interface *mdbImpl, 
00285                                              const EntityHandle entity, 
00286                                              const Tag mid_nodes_tag, 
00287                                                     const Tag geom_dimension_tag,
00288                                              const EntityType indiv_entity_type) 
00289 {
00290     // branch based on what kind of entity we're looking at
00291   EntityType handle_type = mdbImpl->type_from_handle(entity);
00292   
00293   if (handle_type == MBENTITYSET) 
00294   {
00295 
00296       // it's a meshset - assume it's a block (check this?) and work off the midnodes tag
00297 
00298       //get the element type of the block; first, get the hasMidNodes tag, then convert to an exo element type
00299     int has_mid_nodes[4];
00300     int dimension = -1;
00301     if(mdbImpl->tag_get_data(mid_nodes_tag, &entity, 1, has_mid_nodes) != MB_SUCCESS) 
00302     {
00303         // no mid nodes tag - look for indiv entity type, and if it was input, output the default
00304         // number of vertices
00305       if (MBMAXTYPE != indiv_entity_type)
00306       {
00307         //get dimension
00308         if( indiv_entity_type == MBQUAD || 
00309             indiv_entity_type == MBTRI )
00310           dimension = 3; //want to ouput shells by default
00311         else if( indiv_entity_type == MBEDGE )
00312           dimension = 2;
00313         else
00314           dimension = CN::Dimension(indiv_entity_type);
00315           
00316         return get_element_type_from_num_verts(CN::VerticesPerEntity(indiv_entity_type), 
00317                                                indiv_entity_type, dimension);
00318       }
00319       else return EXOII_MAX_ELEM_TYPE;
00320     }
00321     else {
00322         // block meshset had midnodes tag - look for geometric dimension one too
00323       mdbImpl->tag_get_data(geom_dimension_tag, &entity, 1, &dimension);
00324     }
00325 
00326     for (int i = 0; i < EXOII_MAX_ELEM_TYPE; i++) {
00327       if ((indiv_entity_type == MBMAXTYPE || indiv_entity_type == ExoIIElementMBEntity[i]) &&
00328           has_mid_nodes[0] == HasMidNodes[i][0] &&
00329           has_mid_nodes[1] == HasMidNodes[i][1] &&
00330           has_mid_nodes[2] == HasMidNodes[i][2] &&
00331           has_mid_nodes[3] == HasMidNodes[i][3] &&
00332           (-1 == dimension || ElementGeometricDimension[i] == dimension))
00333         return (ExoIIElementType) i;
00334     }
00335   
00336     return EXOII_MAX_ELEM_TYPE;
00337   }
00338 
00339   else if (handle_type == MBVERTEX)
00340       // only have one type of entity for vertices...
00341     return EXOII_SPHERE;
00342 
00343   else {
00344     std::vector<EntityHandle> tmp(31);
00345 
00346     mdbImpl->get_connectivity(&entity, 1, tmp, true);
00347     return get_element_type_from_num_verts(tmp.size(), indiv_entity_type);
00348       // it's a regular entity - look for a connectivity tag
00349   }
00350 
00351     // if we've gotten here, we failed
00352   //return EXOII_MAX_ELEM_TYPE;
00353 }
00354 
00355 ExoIIElementType ExoIIUtil::get_element_type_from_num_verts(const int num_verts, 
00356                                                             const EntityType entity_type,
00357                                                             const int dimension) 
00358 {
00359   for (int i = 0; i < EXOII_MAX_ELEM_TYPE; i++) {
00360     if ((entity_type == MBMAXTYPE || entity_type == ExoIIElementMBEntity[i]) &&
00361         VerticesPerElement[i] == num_verts &&
00362         ElementGeometricDimension[i] >= dimension)
00363       return (ExoIIElementType) i;
00364   }
00365   
00366   return EXOII_MAX_ELEM_TYPE;
00367 }
00368 
00369 } // namespace moab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines