1 /*
2  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3  * storing and accessing finite element mesh data.
4  *
5  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
6  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7  * retains certain rights in this software.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  */
15 
16 /**\file MeshSetSequence.hpp
17  *\author Jason Kraftcheck (kraftche@cae.wisc.edu)
18  *\date 2007-04-30
19  */
20 
21 #ifndef MESH_SET_SEQUENCE_HPP
22 #define MESH_SET_SEQUENCE_HPP
23 
24 #include "EntitySequence.hpp"
25 #include "MeshSet.hpp"
26 #include "SequenceData.hpp"
27 
28 namespace moab {
29 
30 class SequenceManager;
31 
32 class MeshSetSequence : public EntitySequence
33 {
34 public:
35 
36   MeshSetSequence( EntityHandle start,
37                    EntityID count,
38                    const unsigned* flags,
39                    SequenceData* data );
40 
41   MeshSetSequence( EntityHandle start,
42                    EntityID count,
43                    unsigned flags,
44                    SequenceData* data );
45 
46   MeshSetSequence( EntityHandle start,
47                    EntityID count,
48                    const unsigned* flags,
49                    EntityID sequence_size );
50 
51   MeshSetSequence( EntityHandle start,
52                    EntityID count,
53                    unsigned flags,
54                    EntityID sequence_size );
55 
56   virtual ~MeshSetSequence();
57 
58   EntitySequence* split( EntityHandle here );
59 
create_data_subset(EntityHandle,EntityHandle) const60   SequenceData* create_data_subset( EntityHandle, EntityHandle ) const
61     { return 0; }
62 
63   ErrorCode pop_back( EntityID count );
64   ErrorCode pop_front( EntityID count );
65   ErrorCode push_back( EntityID count, const unsigned* flags );
66   ErrorCode push_front( EntityID count, const unsigned* flags );
67 
68   void get_const_memory_use( unsigned long& bytes_per_entity,
69                              unsigned long& size_of_sequence ) const;
70   unsigned long get_per_entity_memory_use( EntityHandle first,
71                                            EntityHandle last ) const;
72 
73 
74   inline MeshSet* get_set( EntityHandle h );
75   inline const MeshSet* get_set( EntityHandle h ) const;
76 
77   ErrorCode get_entities( EntityHandle set, std::vector<EntityHandle>& entities ) const;
78   ErrorCode get_entities(  SequenceManager const* seqman, EntityHandle set,                    Range& entities, bool recursive ) const;
79   ErrorCode get_dimension( SequenceManager const* seqman, EntityHandle set, int dim,           std::vector<EntityHandle>& entities, bool recursive ) const;
80   ErrorCode get_dimension( SequenceManager const* seqman, EntityHandle set, int dim,           Range& entities, bool recursive ) const;
81   ErrorCode get_type(      SequenceManager const* seqman, EntityHandle set, EntityType type, std::vector<EntityHandle>& entities, bool recursive ) const;
82   ErrorCode get_type(      SequenceManager const* seqman, EntityHandle set, EntityType type, Range& entities, bool recursive ) const;
83 
84   ErrorCode num_entities(  SequenceManager const* seqman, EntityHandle set,                    int& count, bool recursive ) const;
85   ErrorCode num_dimension( SequenceManager const* seqman, EntityHandle set, int dim,           int& count, bool recursive ) const;
86   ErrorCode num_type(      SequenceManager const* seqman, EntityHandle set, EntityType type, int& count, bool recursive ) const;
87 
88   ErrorCode get_parents       ( SequenceManager const* seqman, EntityHandle of, std::vector<EntityHandle>& parents,  int num_hops ) const;
89   ErrorCode get_children      ( SequenceManager const* seqman, EntityHandle of, std::vector<EntityHandle>& children, int num_hops ) const;
90   ErrorCode get_contained_sets( SequenceManager const* seqman, EntityHandle of, std::vector<EntityHandle>& contents, int num_hops ) const;
91   ErrorCode num_parents       ( SequenceManager const* seqman, EntityHandle of, int& number, int num_hops ) const;
92   ErrorCode num_children      ( SequenceManager const* seqman, EntityHandle of, int& number, int num_hops ) const;
93   ErrorCode num_contained_sets( SequenceManager const* seqman, EntityHandle of, int& number, int num_hops ) const;
94 
95 private:
96 
97   enum SearchType { PARENTS, CHILDREN, CONTAINED };
98 
MeshSetSequence(MeshSetSequence & split_from,EntityHandle split_at)99   MeshSetSequence( MeshSetSequence& split_from, EntityHandle split_at )
100     : EntitySequence( split_from, split_at )
101     {}
102 
103   void initialize( const unsigned* set_flags );
104 
105   ErrorCode get_parent_child_meshsets( EntityHandle meshset,
106                                     SequenceManager const* set_sequences,
107                                     std::vector<EntityHandle>& results,
108                                     int num_hops, SearchType link_type ) const;
109 
110   static ErrorCode recursive_get_sets( EntityHandle start_set,
111                             SequenceManager const* set_sequences,
112                             std::vector<const MeshSet*>* sets_out = 0,
113                             Range* set_handles_out = 0,
114                             std::vector<EntityHandle>* set_handle_vect_out = 0 );
115   static ErrorCode recursive_get_sets( EntityHandle start_set,
116                             SequenceManager* set_sequences,
117                             std::vector<MeshSet*>& sets_out );
118 
119   enum { SET_SIZE = sizeof(MeshSet) };
120 
array() const121   inline const unsigned char* array() const
122     { return reinterpret_cast<const unsigned char*>(data()->get_sequence_data(0)); }
123 
array()124   inline unsigned char* array()
125     { return reinterpret_cast<unsigned char*>(data()->get_sequence_data(0)); }
126 
allocate_set(unsigned flags,EntityID index)127   inline void allocate_set( unsigned flags, EntityID index )
128   {
129     unsigned char* const ptr = array() + index * SET_SIZE;
130     new (ptr) MeshSet(flags);
131   }
132 
deallocate_set(EntityID index)133   inline void deallocate_set( EntityID index )
134   {
135     MeshSet* set = reinterpret_cast<MeshSet*>(array() + SET_SIZE * index );
136     set->~MeshSet();
137   }
138 };
139 
get_set(EntityHandle h)140 inline MeshSet* MeshSetSequence::get_set( EntityHandle h )
141 {
142   return reinterpret_cast<MeshSet*>(array() + SET_SIZE*(h - data()->start_handle()));
143 }
get_set(EntityHandle h) const144 inline const MeshSet* MeshSetSequence::get_set( EntityHandle h ) const
145 {
146   return reinterpret_cast<const MeshSet*>(array() + SET_SIZE*(h - data()->start_handle()));
147 }
148 
149 } // namespace moab
150 
151 #endif
152