1"""Header file for MOAB"""
2from libcpp cimport bool
3from libcpp.vector cimport vector
4from libcpp.string cimport string as std_string
5
6from eh cimport EntityHandle, EntityID
7cimport numpy as np
8
9cdef extern from 'moab/Types.hpp' namespace "moab":
10
11    ctypedef enum EntitySetProperty:
12        MESHSET_TRACK_OWNER = 0x01
13        MESHSET_SET = 0x02
14        MESHSET_ORDERED = 0x03
15
16    cdef enum DataType:
17        MB_TYPE_OPAQUE   = 0
18        MB_TYPE_INTEGER  = 1
19        MB_TYPE_DOUBLE   = 2
20        MB_TYPE_BIT      = 3
21        MB_TYPE_HANDLE   = 4
22        MB_MAX_DATA_TYPE = 4
23
24    cdef enum TagType:
25        MB_TAG_BIT
26        MB_TAG_SPARSE
27        MB_TAG_DENSE
28        MB_TAG_MESH
29        MB_TAG_BYTES
30        MB_TAG_VARLEN
31        MB_TAG_CREAT
32        MB_TAG_EXCL
33        MB_TAG_STORE
34        MB_TAG_ANY
35        MB_TAG_NOOPQ
36        MB_TAG_DFTOK
37
38
39cdef extern from "TagInfo.hpp" namespace "moab":
40
41    cdef cppclass TagInfo:
42        TagInfo()
43        DataType get_data_type()
44        int get_size()
45        int size_from_data_type(DataType t)
46        std_string& get_name()
47        const void* get_default_value()
48
49cdef extern from "moab/Types.hpp" namespace "moab":
50
51    cdef enum ErrorCode:
52        MB_SUCCESS
53        MB_INDEX_OUT_OF_RANGE
54        MB_TYPE_OUT_OF_RANGE
55        MB_MEMORY_ALLOCATION_FAILED
56        MB_ENTITY_NOT_FOUND
57        MB_MULTIPLE_ENTITIES_FOUND
58        MB_TAG_NOT_FOUND
59        MB_FILE_DOES_NOT_EXIST
60        MB_FILE_WRITE_ERROR
61        MB_NOT_IMPLEMENTED
62        MB_ALREADY_ALLOCATED
63        MB_VARIABLE_DATA_LENGTH
64        MB_INVALID_SIZE
65        MB_UNSUPPORTED_OPERATION
66        MB_UNHANDLED_OPTION
67        MB_STRUCTURED_MESH
68        MB_FAILURE
69
70    ctypedef TagInfo* Tag
71
72cdef extern from "moab/EntityType.hpp" namespace "moab":
73
74    ctypedef enum EntityType:
75        MBVERTEX = 0
76        MBEDGE
77        MBTRI
78        MBQUAD
79        MBPOLYGON
80        MBTET
81        MBPYRAMID
82        MBPRISM
83        MBKNIFE
84        MBHEX
85        MBPOLYHEDRON
86        MBENTITYSET
87        MBMAXTYPE
88
89cdef extern from "moab/Range.hpp" namespace "moab":
90
91    Range intersect(Range&, Range&)
92    Range subtract(Range&, Range&)
93    Range unite(Range&, Range&)
94
95    cdef cppclass Range:
96        Range()
97        Range(EntityHandle val1, EntityHandle val2)
98
99        size_t size()
100        size_t psize()
101        bint empty()
102        void clear()
103        bool all_of_type(EntityType t)
104        bool all_of_dimension(int dimension)
105        unsigned num_of_type( EntityType type )
106        unsigned num_of_dimension( int dim )
107        void print_ "print"()
108        std_string str_rep()
109        void insert(EntityHandle val)
110        void erase(EntityHandle val)
111        void merge(Range& range)
112        bool contains(const Range& range)
113        EntityHandle pop_front()
114        EntityHandle pop_back()
115
116        Range subset_by_type(EntityType t)
117        Range subset_by_dimension(int dim)
118
119
120        EntityHandle operator[](EntityID index)
121
122
123cdef extern from "moab/Interface.hpp" namespace "moab":
124
125    cdef cppclass Interface:
126        Interface()
127
128
129cdef extern from "moab/MeshTopoUtil.hpp" namespace "moab":
130
131    cdef cppclass MeshTopoUtil:
132        MeshTopoUtil(Interface *impl)
133
134        ErrorCode construct_aentities(const Range &vertices)
135        ErrorCode get_bridge_adjacencies(Range &from_entities,
136                                         int bridge_dim,
137                                         int to_dim,
138                                         Range &to_ents,
139                                         int num_layers)
140        ErrorCode get_bridge_adjacencies(const EntityHandle from_entity,
141                                         const int bridge_dim,
142                                         const int to_dim,
143                                         Range &to_adjs)
144        ErrorCode get_average_position(Range& entities,
145                                       double *avg_position)
146        ErrorCode get_average_position(const EntityHandle *entities,
147                                       const int num_entities,
148                                       double * avg_position)
149
150
151cdef extern from "moab/Core.hpp" namespace "moab":
152
153    cdef cppclass Core:
154        # Constructors
155        Core()
156
157        # member functions
158        float impl_version()
159        float impl_version(std_string *version_string)
160
161        ErrorCode write_file(const char *file_name)
162        ErrorCode write_file(const char *file_name, const char *file_type)
163        ErrorCode write_file(const char *file_name, const char *file_type,
164                             const char *options)
165        ErrorCode write_file(const char *file_name, const char *file_type,
166                             const char *options, const EntityHandle *output_sets)
167        ErrorCode write_file(const char *file_name, const char *file_type,
168                             const char *options, const EntityHandle *output_sets,
169                             int num_output_sets)
170        ErrorCode write_file(const char *file_name, const char *file_type,
171                             const char *options, Range output_sets,
172                             const Tag *tag_list, int num_tags)
173        ErrorCode load_file(const char *file_name)
174        ErrorCode load_file(const char *file_name, const EntityHandle* file_set)
175        ErrorCode load_file(const char *file_name, const EntityHandle* file_set,
176                            const char *options)
177        ErrorCode load_file(const char *file_name, const EntityHandle* file_set,
178                            const char *options, const char *set_tag_names)
179        ErrorCode load_file(const char *file_name, const EntityHandle* file_set,
180                            const char *options, const char *set_tag_names,
181                            const char *set_tag_values)
182        ErrorCode load_file(const char *file_name, const EntityHandle* file_set,
183                            const char *options, const char *set_tag_names,
184                            const char *set_tag_values, int num_set_tag_values)
185
186        ErrorCode create_meshset(const unsigned int options, EntityHandle &ms_handle)
187        ErrorCode create_meshset(const unsigned int options, EntityHandle &ms_handle, int start_id)
188
189        ErrorCode add_entities(EntityHandle meshset, const EntityHandle *entities, int num_entities)
190        ErrorCode add_entities(EntityHandle meshset, const Range &entities)
191
192        ErrorCode create_vertices(const double *coordinates, const int nverts,
193                                  Range &entity_handles)
194
195        ErrorCode create_element(const EntityType type, const EntityHandle *connectivity,
196                                 const int num_nodes, EntityHandle &element_handle)
197
198        ErrorCode get_connectivity(const EntityHandle *entity_handles,
199                                   const int num_handles,
200                                   vector[EntityHandle] & connectivity)
201        ErrorCode get_connectivity(const EntityHandle *entity_handles,
202                                   const int num_handles,
203                                   vector[EntityHandle] & connectivity,
204                                   bool corners_only)
205        ErrorCode get_connectivity(const EntityHandle *entity_handles,
206                                   const int num_handles,
207                                   vector[EntityHandle] & connectivity,
208                                   bool corners_only,
209                                   vector[int] * offsets)
210        ErrorCode tag_get_handle(const char* name,
211                                 int size,
212                                 DataType type,
213                                 Tag & tag_handle,
214                                 unsigned flags,
215                                 const void * default_value,
216                                 bool * created)
217
218        ErrorCode tag_get_handle(const char* name,
219                                 Tag & tag_handle)
220
221        ErrorCode tag_set_data(Tag& tag,
222                               const EntityHandle* entity_handles,
223                               int num_entities,
224                               const void * data)
225        ErrorCode tag_set_data(Tag& tag,
226                               Range& entity_handles,
227                               const void * data)
228        ErrorCode tag_get_data(const Tag tag_handle,
229                               const Range& entity_handles,
230                               void* tag_data)
231        ErrorCode tag_get_data(const Tag tag_handle,
232                               const EntityHandle * entity_handles,
233                               const int num_entities,
234                               void* tag_data)
235
236        ErrorCode tag_delete_data(Tag tag_handle,
237                                  const EntityHandle *entity_handles,
238                                  int num_handles)
239        ErrorCode tag_delete_data(Tag tag_handle,
240                                  const Range &entity_range)
241
242        ErrorCode tag_delete(Tag tag_handle);
243
244        ErrorCode tag_get_data_type(const Tag tag_handle,
245	                            DataType& type)
246        ErrorCode tag_get_length(const Tag tag_handle,
247                                 int & length)
248
249        ErrorCode tag_get_default_value(const Tag tag,
250                                        void* def_val)
251
252        ErrorCode tag_get_name(const Tag tag_handle,
253                               std_string & tag_name)
254
255        ErrorCode tag_get_tags_on_entity( EntityHandle entity,
256                                          vector[Tag]& tag_handles)
257
258        ErrorCode get_adjacencies(const EntityHandle *from_entities,
259                                  const int num_entities,
260                                  const int to_dimension,
261                                  const bool create_if_missing,
262                                  Range &adj_entities,
263                                  const int operation_type)
264
265        ErrorCode get_adjacencies(const Range &from_entities,
266                                  const int to_dimension,
267                                  const bool create_if_missing,
268                                  Range &adj_entities,
269                                  const int operation_type)
270
271        EntityType type_from_handle(const EntityHandle handle)
272        ErrorCode get_child_meshsets(EntityHandle meshset,
273                                     Range &children,
274                                     const int num_hops)
275        ErrorCode get_parent_meshsets(EntityHandle meshset,
276                                     Range &parents,
277                                     const int num_hops)
278        ErrorCode add_parent_meshset(EntityHandle child_meshset,
279                                    const EntityHandle parent_meshset)
280        ErrorCode add_child_meshset(EntityHandle parent_meshset,
281                                    const EntityHandle child_meshset)
282        ErrorCode add_parent_child(EntityHandle parent,
283                                   EntityHandle child)
284        ErrorCode get_coords(const EntityHandle* entity_handles,
285                             const int num_entities,
286                             double* coords)
287        ErrorCode get_coords(const Range& entity_handles,
288                             double* coords)
289        ErrorCode set_coords(const EntityHandle* entity_handles,
290                             const int num_entities,
291                             const double* coords)
292        ErrorCode set_coords(const Range& entity_handles,
293                             const double* coords)
294        ErrorCode get_entities_by_type(const EntityHandle meshset,
295                                       const EntityType typ,
296                                       vector[EntityHandle]& entities,
297                                       const bool recursive)
298        ErrorCode get_entities_by_type(const EntityHandle meshset,
299                                       const EntityType typ,
300                                       Range& entities,
301                                       const bool recursive)
302        ErrorCode get_entities_by_type_and_tag(const EntityHandle meshset,
303                                               const EntityType typ,
304                                               const Tag* tags,
305                                               const void* const * values,
306                                               const int num_tags,
307                                               Range& entities,
308                                               const int condition,
309                                               const bool recursive)
310        ErrorCode get_entities_by_handle(const EntityHandle meshset,
311                                         Range& entities,
312                                         const bool recursive)
313        ErrorCode get_entities_by_handle(const EntityHandle meshset,
314                                         vector[EntityHandle]& entities,
315                                         const bool recursive)
316        ErrorCode get_entities_by_dimension(const EntityHandle meshset,
317                                            const int dimension,
318                                            Range& entities,
319                                            const bool recursive)
320        ErrorCode get_entities_by_dimension(const EntityHandle meshset,
321                                            const int dimension,
322                                            vector[EntityHandle] entities,
323                                            const bool recursive)
324        ErrorCode remove_entities(EntityHandle meshset,
325                                  const EntityHandle* entities,
326                                  const int num_entities)
327        ErrorCode remove_entities(EntityHandle meshset,
328                                  Range& entities)
329        ErrorCode delete_entities(Range& entities)
330        ErrorCode delete_entities(const EntityHandle* entities,
331                                  const int num_entities)
332        ErrorCode delete_mesh()
333
334
335cdef extern from "moab/HomXform.hpp" namespace "moab":
336
337     cdef cppclass HomCoord:
338         #Constructors
339         HomCoord()
340         HomCoord(const HomCoord&)
341         HomCoord(const int*, const int)
342         HomCoord(const int, const int, const int, const int)
343         HomCoord(const int, const int, const int)
344
345         #Member functions
346         const int* hom_coord()
347         int& operator[](int)
348         int i()
349         int j()
350         int k()
351         int h()
352         void set(const int coords[])
353         void set(const int i, const int j, const int k, const int h)
354
355         int length_squared()
356         int length()
357         void normalize()
358
359         #operators
360         HomCoord operator+(const HomCoord&) const
361         HomCoord operator-(const HomCoord&) const
362         bool operator==(const HomCoord&) const
363
364
365cdef extern from "moab/ScdInterface.hpp" namespace "moab":
366
367    cdef cppclass ScdParData:
368        #Constructor
369        ScdParData()
370
371    cdef cppclass ScdInterface:
372        #Constructor
373        ScdInterface(Interface*, bint)
374
375        #structured mesh creation
376        ErrorCode construct_box(HomCoord low,
377                                HomCoord high,
378                                const double * const coords,
379                                unsigned int num_coords,
380                                ScdBox *& new_box,
381                                int * const lperiodic,
382                                ScdParData * const par_data,
383                                bool assign_global_ids,
384                                int resolve_shared_ents)
385        #Member functions
386        ErrorCode find_boxes(Range &boxes)
387        ErrorCode get_boxes(vector[ScdBox*] boxes)
388        ScdBox* get_scd_box(EntityHandle eh)
389        Tag box_set_tag(bool create_if_missing)
390
391    cdef cppclass ScdBox:
392
393        HomCoord box_min()
394        HomCoord box_max()
395        HomCoord box_size()
396        int num_vertices()
397        int num_elements()
398        EntityHandle box_set()
399        EntityHandle start_vertex()
400        EntityHandle start_element()
401        EntityHandle get_vertex(int i, int j, int k)
402        EntityHandle get_vertex(HomCoord& ijk)
403        EntityHandle get_element(int i, int j, int k)
404        EntityHandle get_element(HomCoord& ijk)
405        ErrorCode get_params(EntityHandle ent, int &i, int &j, int &k)
406        bool contains(int i, int j, int k)
407
408
409cdef extern from "moab/Skinner.hpp" namespace "moab":
410
411    cdef cppclass Skinner:
412        #Constructor
413        Skinner(Interface*)
414
415        # Compute the geometric skin
416        ErrorCode find_geometric_skin (const EntityHandle meshset, Range &forward_target_entities)
417
418        # 	get skin entities of prescribed dimension
419        #   will accept entities all of one dimension and return entities of n-1 dimension;
420        #   NOTE: get_vertices argument controls whether vertices or entities of n-1 dimension are returned,
421        #   and only one of these is allowed (i.e. this function returns only vertices or
422        #   (n-1)-dimensional entities, but not both)
423        # Defaults: *output_reverse_handles=0, create_vert_elem_adjs=false, create_skin_elements=true, look_for_scd=false
424        ErrorCode 	find_skin (const EntityHandle meshset, const Range &entities, bool get_vertices,
425                                Range &output_handles, Range *output_reverse_handles, bool create_vert_elem_adjs,
426                                bool create_skin_elements, bool look_for_scd)
427