Mesh Oriented datABase  (version 5.5.0)
An array-based unstructured mesh library
SequenceManager.hpp
Go to the documentation of this file.
1 #ifndef SEQUENCE_MANAGER_HPP
2 #define SEQUENCE_MANAGER_HPP
3 
5 #include "TagInfo.hpp"
6 #include <vector>
7 
8 namespace moab
9 {
10 
11 class HomCoord;
12 class Error;
13 
15 {
16  public:
17  SequenceManager( double default_seq_multiplier = 1.0 ) : sequence_multiplier( default_seq_multiplier ) {}
18 
20 
21  /** Delete all contained data */
22  void clear();
23 
24  /** Find entity sequence containing specified handle.
25  *\return MB_SUCCESS or MB_ENTITY_NOT_FOUND
26  */
27  ErrorCode find( EntityHandle handle, EntitySequence*& sequence_out )
28  {
29  return typeData[TYPE_FROM_HANDLE( handle )].find( handle, sequence_out );
30  }
31 
32  /** Find entity sequence containing specified handle.
33  *\return MB_SUCCESS or MB_ENTITY_NOT_FOUND
34  */
35  ErrorCode find( EntityHandle handle, const EntitySequence*& sequence_out ) const
36  {
37  return typeData[TYPE_FROM_HANDLE( handle )].find( handle, sequence_out );
38  }
39 
40  /** Get all entities of a given EntityType, return all entities
41  * if type == MBMAXTYPE */
42  void get_entities( EntityType type, Range& entities_out ) const
43  {
44  if( type == MBMAXTYPE )
45  get_entities( entities_out );
46  else
47  typeData[type].get_entities( entities_out );
48  }
49 
50  void get_entities( Range& entities_out ) const;
51 
52  /** Get all entities of a given EntityType, return all entities
53  * if type == MBMAXTYPE */
54  void get_entities( EntityType type, std::vector< EntityHandle >& entities_out ) const
55  {
56  if( type == MBMAXTYPE )
57  get_entities( entities_out );
58  else
59  typeData[type].get_entities( entities_out );
60  }
61 
62  void get_entities( std::vector< EntityHandle >& entities_out ) const;
63 
64  /** Count entities of a given EntityType */
65  EntityID get_number_entities( EntityType type ) const
66  {
67  return type == MBMAXTYPE ? get_number_entities() : typeData[type].get_number_entities();
68  }
69 
70  /** Count entities of a given EntityType */
72 
73  /** Get most recently accessed sequence for a given type */
74  const EntitySequence* get_last_accessed_sequence( EntityType type ) const
75  {
76  return typeData[type].get_last_accessed();
77  }
78 
79  /**\brief Replace subset of existing sequence with new
80  * sequence (splits existing sequence)
81  *
82  * Used for converting number of nodes for fixed-connectivity-length
83  * elements. Input sequence must be a non-strict subset of an existing
84  * sequence. Existing sequence will be removed, modified, or split
85  * into two prevent it from overlapping the new sequence.
86  */
88 
89  /** Check if passed entity handles are valid */
90  ErrorCode check_valid_entities( Error* error_handler, const Range& entities ) const;
91 
92  /** Check if passed entity handles are valid
93  *\param root_set_okay If true, do not returnan error if the passed
94  * array contains one or more zero-valued handles
95  */
97  const EntityHandle entities[],
98  size_t num_entities,
99  bool root_set_okay = false ) const;
100 
101  /** Delete an entity. Deletes sequence if only contained entity. */
102  ErrorCode delete_entity( Error* error_handler, EntityHandle entity );
103 
104  /** Delete entities */
105  ErrorCode delete_entities( Error* error_handler, const Range& entities );
106 
107  /** Allocate a vertex (possibly in an existing sequence) and
108  * assign it the passed coordinate values.
109  */
110  ErrorCode create_vertex( const double coords[3], EntityHandle& handle_out );
111 
112  /** Allocate a element (possibly in an existing sequence) and
113  * assign it the passed connectivity.
114  */
115  ErrorCode create_element( EntityType type,
116  const EntityHandle* conn_array,
117  unsigned num_vertices,
118  EntityHandle& handle_out );
119 
120  /** Allocate an entity set (possibly in an existing sequence) */
121  ErrorCode create_mesh_set( unsigned flags, EntityHandle& handle_out );
122  /** Allocate an entity set with the specified handle.
123  *\return MB_ALREADY_ALLOCATED if handle is in use, MB_SUCCESS otherwise.
124  */
125  ErrorCode allocate_mesh_set( EntityHandle at_this_handle, unsigned flags );
126 
127  /**\brief Allocate a block of consecutive entity handles
128  *
129  * Allocate a block of consecutive entity handles. Handles
130  * may be appended or prepended to an existing entity sequence.
131  *\param type The type of of entity for which to allocate handles
132  *\param num_entities Number of entities to allocate
133  *\param nodes_per_entity Number of nodes in connectivity for elements,
134  * ignored MBVERTEX, MBPOLYGON, MBPOLYHEDRON, and
135  * MBENTITYSET types.
136  *\param start_id_hint Preferred ID portion for first handle.
137  * May be ignored if not available.
138  *\param first_handle_out First allocated handle. Allocated handles
139  * are [first_handle_out, first_handle_out+num_entities-1].
140  *\param sequence_out The sequence in which the entities were allocated.
141  * NOTE: first_handle_out may not be first handle in
142  * sequence.
143  *\param sequence_size If specified, allocate this sequence size instead of
144  *DEFAULT_***_SEQUENCE_SIZE
145  */
146  ErrorCode create_entity_sequence( EntityType type,
147  EntityID num_entities,
148  int nodes_per_entity,
149  EntityID start_id_hint,
150  EntityHandle& first_handle_out,
151  EntitySequence*& sequence_out,
152  int sequence_size );
153 
154  /**\brief Allocate a block of consecutive mesh sets
155  *
156  * Allocate a block of consecutive entity handles. Handles
157  * may be appended or prepended to an existing entity sequence.
158  *\param type The type of of entity for which to allocate handles
159  *\param num_sets Number of entities to allocate
160  *\param start_id_hint Preferred ID portion for first handle.
161  * May be ignored if not available.
162  *\param processor_id Processor ID to embed in handles
163  *\param flags Array of length 'num_sets' containing entity set
164  * creating flags.
165  *\param first_handle_out First allocated handle. Allocated handles
166  * are [first_handle_out, first_handle_out+num_entities-1].
167  *\param sequence_out The sequence in which the entities were allocated.
168  * NOTE: first_handle_out may not be first handle in
169  * sequence.
170  */
172  EntityID start_id_hint,
173  const unsigned* flags,
174  EntityHandle& first_handle_out,
175  EntitySequence*& sequence_out );
176 
177  /**\brief Allocate a block of consecutive mesh sets
178  *
179  * Alternate form that creates all mesh sets with same flags.
180  */
182  EntityID start_id_hint,
183  unsigned flags,
184  EntityHandle& first_handle_out,
185  EntitySequence*& sequence_out );
186 
187  /** Create structured mesh */
188  ErrorCode create_scd_sequence( int imin,
189  int jmin,
190  int kmin,
191  int imax,
192  int jmax,
193  int kmax,
194  EntityType type,
195  EntityID start_id_hint,
196  EntityHandle& first_handle_out,
197  EntitySequence*& sequence_out,
198  int* is_periodic = NULL );
199 
200  /** Create structured mesh */
201  ErrorCode create_scd_sequence( const HomCoord& coord_min,
202  const HomCoord& coord_max,
203  EntityType type,
204  EntityID start_id_hint,
205  EntityHandle& first_handle_out,
206  EntitySequence*& sequence_out,
207  int* is_periodic = NULL );
208 
209  /** Create swept mesh */
211  int jmin,
212  int kmin,
213  int imax,
214  int jmax,
215  int kmax,
216  int* Cq,
217  EntityType type,
218  EntityID start_id_hint,
219  EntityHandle& first_handle_out,
220  EntitySequence*& sequence_out );
221 
222  /** Create swept mesh */
223  ErrorCode create_sweep_sequence( const HomCoord& coord_min,
224  const HomCoord& coord_max,
225  int* Cq,
226  EntityType type,
227  EntityID start_id_hint,
228  EntityHandle& first_handle_out,
229  EntitySequence*& sequence_out );
230 
231  /** Add a structured vertex sequence to this structured element sequence;
232  * see comments in ScdElementData */
234  EntitySequence* elem_seq,
235  const HomCoord& p1,
236  const HomCoord& q1,
237  const HomCoord& p2,
238  const HomCoord& q2,
239  const HomCoord& p3,
240  const HomCoord& q3,
241  bool bb_input = false,
242  const HomCoord* bb_min = NULL,
243  const HomCoord* bb_max = NULL );
244 
245  /** Get data for a specific EntityType */
246  TypeSequenceManager& entity_map( EntityType type )
247  {
248  return typeData[type];
249  }
250 
251  /** Get data for a specific EntityType */
252  const TypeSequenceManager& entity_map( EntityType type ) const
253  {
254  return typeData[type];
255  }
256 
257  void get_memory_use( unsigned long long& total_entity_storage, unsigned long long& total_storage ) const;
258 
259  void get_memory_use( EntityType type,
260  unsigned long long& total_entity_storage,
261  unsigned long long& total_storage ) const;
262 
263  void get_memory_use( const Range& entities,
264  unsigned long long& total_entity_storage,
265  unsigned long long& total_amortized_storage ) const;
266 
267  /* Dense Tag Functions */
268 
269  /** Allocate a tag ID
270  *\param tag_size The size of the tag value for each entity
271  */
272  ErrorCode reserve_tag_array( Error* error_handler, int tag_size, int& array_id_out );
273 
274  /** Release any storage assocociated with a tag ID, and optionally,
275  * release the reserved tag ID. */
276  ErrorCode release_tag_array( Error* error_handler, int id, bool release_id );
277 
278  /**\brief Get default size of POLYGON and POLYHEDRON SequenceData */
279  static EntityID default_poly_sequence_size( int entity_connectivity_length );
280 
281  /**\brief Size to allocate for new SquenceData
282  * THIS FUNCTION SHOULD ONLY BE CALLED WHEN ALLOCATING FROM ReadUtil IN BULK
283  * (since it will allocate lesser of requested_size and default_size)
284  * If sequence_size != -1, will try to allocate that, unless there isn't available
285  * space
286  */
287  EntityID new_sequence_size( EntityHandle start_handle, EntityID requested_size, int sequence_size ) const;
288 
289  /** \brief Interface to control memory allocation for sequences
290  * Provide a factor that controls the size of the sequence that gets allocated.
291  * This is typically useful in the parallel setting when a-priori, the number of ghost entities
292  * and the memory required for them within the same sequence as the owned entities are unknown.
293  * The default factor is 1.0 but this can be appropriately updated at runtime so that we do not
294  * have broken sequences.
295  */
296  double get_sequence_multiplier() const
297  {
298  return sequence_multiplier;
299  }
300 
301  /** \brief Interface to control memory allocation for sequences
302  * Provide a factor that controls the size of the sequence that gets allocated.
303  * This is typically useful in the parallel setting when a-priori, the number of ghost entities
304  * and the memory required for them within the same sequence as the owned entities are unknown.
305  * The default factor is 1.0 but this can be appropriately updated at runtime so that we do not
306  * have broken sequences.
307  *
308  * \param meshset User specified multiplier (should be greater than 1.0)
309  */
310  void set_sequence_multiplier( double factor )
311  {
312  sequence_multiplier = factor;
313  }
314 
315  /**\brief Default allocation size for vertices */
317 
318  /**\brief Default allocation size for elements */
320 
321  /**\brief Default allocation size for poly's */
323 
324  /**\brief Default allocation size for meshsets */
326 
327  private:
328  /**\brief Utility function for allocate_mesh_set (and similar)
329  *
330  * Given a block of available handles, determine the non-strict
331  * subset at which to create a new EntitySequence.
332  */
333  void trim_sequence_block( EntityHandle start_handle,
334  EntityHandle& end_handle_in_out,
335  unsigned maximum_sequence_size );
336 
337  /**\brief Get range of handles in which to create an entity sequence
338  *
339  * Get range of handles in whcih to place a new entity sequence.
340  *\param type The EntityType for the contents of the sequence
341  *\param entity_count The number of entities in the range
342  *\param values_per_entity Vertices per element, zero for other types
343  *\param start_id_hint Preferred id of first handle
344  *\param processor_rank MPI processor ID
345  *\param data_out Output: Either NULL or an existing SequenceData
346  * with a sufficiently large block to accomodate
347  * the handle range.
348  *\return zero if no available handle range, start handle otherwise.
349  */
350  EntityHandle sequence_start_handle( EntityType type,
351  EntityID entity_count,
352  int values_per_entity,
353  EntityID start_id_hint,
354  SequenceData*& data_out,
355  EntityID& data_size );
356 
358 
359  std::vector< int > tagSizes;
360 
361  /**\brief The over-allocation factor for entities in a sequence (strictly >= 1.0) */
363 };
364 
365 } // namespace moab
366 
367 #endif