Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
DamselUtil.cpp
Go to the documentation of this file.
1 #include "DamselUtil.hpp"
2 #include "moab/Range.hpp"
3 
4 #include "damsel.h"
5 
6 namespace moab
7 {
8 
9 damsel_entity_type DamselUtil::mtod_entity_type[] = {
10  DAMSEL_ENTITY_TYPE_VERTEX, // MBVERTEX
11  DAMSEL_ENTITY_TYPE_EDGE, // MBEDGE
12  DAMSEL_ENTITY_TYPE_TRI, // MBTRI
13  DAMSEL_ENTITY_TYPE_QUAD, // MBQUAD
14  DAMSEL_ENTITY_TYPE_POLYGON, // MBPOLYGON
15  DAMSEL_ENTITY_TYPE_TET, // MBTET
16  DAMSEL_ENTITY_TYPE_PYRAMID, // MBPYRAMID
17  DAMSEL_ENTITY_TYPE_PRISM, // MBPRISM
18  DAMSEL_ENTITY_TYPE_UNDEFINED, // MBKNIFE
19  DAMSEL_ENTITY_TYPE_HEX, // MBHEX,
20  DAMSEL_ENTITY_TYPE_POLYHEDRON, // MBPOLYHEDRON
21  DAMSEL_ENTITY_TYPE_UNDEFINED // MBENTITYSET
22 };
23 
24 EntityType DamselUtil::dtom_entity_type[] = {
25  MBVERTEX, // MBVERTEX
26  MBEDGE, // MBEDGE
27  MBTRI, // MBTRI
28  MBQUAD, // MBQUAD
29  MBPOLYGON, // MBPOLYGON
30  MBTET, // MBTET
31  MBPRISM, // MBPRISM
32  MBPYRAMID, // MBPYRAMID
33  MBHEX, // MBHEX,
34  MBPOLYHEDRON, // MBPOLYHEDRON
35  MBMAXTYPE, // MBENTITYSET
36  MBMAXTYPE // MBMAXTYPE
37 };
38 
39 damsel_data_type DamselUtil::mtod_data_type[] = {
40  DAMSEL_DATA_TYPE_BYTES, // MB_TYPE_OPAQUE
41  DAMSEL_DATA_TYPE_INTEGER, // MB_TYPE_INTEGER
42  DAMSEL_DATA_TYPE_DOUBLE, // MB_TYPE_DOUBLE
43  DAMSEL_DATA_TYPE_INVALID, // MB_TYPE_BIT
44  DAMSEL_DATA_TYPE_HANDLE // MB_TYPE_HANDLE
45 };
46 
48  MB_TYPE_OPAQUE, // DAMSEL_DATA_TYPE_INVALID = 0,
49  MB_TYPE_OPAQUE, // DAMSEL_DATA_TYPE_BYTES = 1,
50  MB_TYPE_INTEGER, // DAMSEL_DATA_TYPE_INTEGER = 2,
51  MB_TYPE_OPAQUE, // DAMSEL_DATA_TYPE_INT64 = 3,
52  MB_TYPE_OPAQUE, // DAMSEL_DATA_TYPE_FLOAT = 4,
53  MB_TYPE_DOUBLE, // DAMSEL_DATA_TYPE_DOUBLE = 5,
54  MB_TYPE_HANDLE, // DAMSEL_DATA_TYPE_HANDLE = 6,
55  MB_TYPE_OPAQUE, // DAMSEL_DATA_TYPE_ID_T = 7,
56  MB_TYPE_OPAQUE, // DAMSEL_DATA_TYPE_SHORTINT = 8,
57  MB_TYPE_OPAQUE // DAMSEL_DATA_TYPE_PREDEFINED_WATERMARK = 9;
58 };
59 
61  : dmslLib( DAMSEL_LIBRARY_INVALID ), dmslModel( DAMSEL_MODEL_INVALID ), moabHandleType( DAMSEL_HANDLE_TYPE_INVALID )
62 {
63 }
64 
65 //! Convert handles in a container to a range; assumes EntityHandle and Damsel
66 //! entity handles are the same size
67 ErrorCode DamselUtil::container_to_range( damsel_model m, damsel_container& c, Range& r )
68 {
69  if( DMSLcontainer_get_type( c ) == DAMSEL_HANDLE_CONTAINER_TYPE_SEQUENCE )
70  {
71  damsel_handle start;
72  size_t count, stride;
73  damsel_err_t err = DMSLcontainer_sequence_get_contents( m, c, &start, &count, &stride );
74  CHK_DMSL_ERR_NM( err );
75  for( damsel_handle i = start + ( count - 1 ) * stride; i >= start; i -= stride )
76  r.insert( i );
77  }
78  else if( DMSLcontainer_get_type( c ) == DAMSEL_HANDLE_CONTAINER_TYPE_VECTOR )
79  {
80  damsel_handle* handle_ptr;
81  size_t count;
82  damsel_err_t err = DMSLcontainer_vector_get_contents( m, c, &handle_ptr, &count );
83  CHK_DMSL_ERR_NM( err );
84  for( int i = count - 1; i >= 0; i-- )
85  r.insert( handle_ptr[i] );
86  }
87  else if( DMSLcontainer_get_type( c ) == DAMSEL_HANDLE_CONTAINER_TYPE_TREE )
88  {
89  damsel_handle_ptr node_ptr = NULL;
90  damsel_container cont = NULL;
91  damsel_err_t err = DMSLcontainer_tree_get_contents( m, c, &node_ptr, &cont );
92  while( err.id == DMSL_OK.id && cont )
93  {
94  ErrorCode rval = container_to_range( m, c, r );
95  if( MB_SUCCESS != rval ) return rval;
96  err = DMSLcontainer_tree_get_contents( m, c, &node_ptr, &cont );
97  }
98  }
99 
100  return MB_SUCCESS;
101 }
102 
103 } // namespace moab