MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 #ifndef SEQUENCE_MANAGER_HPP 00002 #define SEQUENCE_MANAGER_HPP 00003 00004 #include "TypeSequenceManager.hpp" 00005 #include "TagInfo.hpp" 00006 #include <vector> 00007 00008 namespace moab 00009 { 00010 00011 class HomCoord; 00012 class Error; 00013 00014 class SequenceManager 00015 { 00016 public: 00017 SequenceManager( double default_seq_multiplier = 1.0 ) : sequence_multiplier( default_seq_multiplier ) {} 00018 00019 ~SequenceManager(); 00020 00021 /** Delete all contained data */ 00022 void clear(); 00023 00024 /** Find entity sequence containing specified handle. 00025 *\return MB_SUCCESS or MB_ENTITY_NOT_FOUND 00026 */ 00027 ErrorCode find( EntityHandle handle, EntitySequence*& sequence_out ) 00028 { 00029 return typeData[TYPE_FROM_HANDLE( handle )].find( handle, sequence_out ); 00030 } 00031 00032 /** Find entity sequence containing specified handle. 00033 *\return MB_SUCCESS or MB_ENTITY_NOT_FOUND 00034 */ 00035 ErrorCode find( EntityHandle handle, const EntitySequence*& sequence_out ) const 00036 { 00037 return typeData[TYPE_FROM_HANDLE( handle )].find( handle, sequence_out ); 00038 } 00039 00040 /** Get all entities of a given EntityType, return all entities 00041 * if type == MBMAXTYPE */ 00042 void get_entities( EntityType type, Range& entities_out ) const 00043 { 00044 if( type == MBMAXTYPE ) 00045 get_entities( entities_out ); 00046 else 00047 typeData[type].get_entities( entities_out ); 00048 } 00049 00050 void get_entities( Range& entities_out ) const; 00051 00052 /** Get all entities of a given EntityType, return all entities 00053 * if type == MBMAXTYPE */ 00054 void get_entities( EntityType type, std::vector< EntityHandle >& entities_out ) const 00055 { 00056 if( type == MBMAXTYPE ) 00057 get_entities( entities_out ); 00058 else 00059 typeData[type].get_entities( entities_out ); 00060 } 00061 00062 void get_entities( std::vector< EntityHandle >& entities_out ) const; 00063 00064 /** Count entities of a given EntityType */ 00065 EntityID get_number_entities( EntityType type ) const 00066 { 00067 return type == MBMAXTYPE ? get_number_entities() : typeData[type].get_number_entities(); 00068 } 00069 00070 /** Count entities of a given EntityType */ 00071 EntityID get_number_entities() const; 00072 00073 /** Get most recently accessed sequence for a given type */ 00074 const EntitySequence* get_last_accessed_sequence( EntityType type ) const 00075 { 00076 return typeData[type].get_last_accessed(); 00077 } 00078 00079 /**\brief Replace subset of existing sequence with new 00080 * sequence (splits existing sequence) 00081 * 00082 * Used for converting number of nodes for fixed-connectivity-length 00083 * elements. Input sequence must be a non-strict subset of an existing 00084 * sequence. Existing sequence will be removed, modified, or split 00085 * into two prevent it from overlapping the new sequence. 00086 */ 00087 ErrorCode replace_subsequence( EntitySequence* new_seq ); 00088 00089 /** Check if passed entity handles are valid */ 00090 ErrorCode check_valid_entities( Error* error_handler, const Range& entities ) const; 00091 00092 /** Check if passed entity handles are valid 00093 *\param root_set_okay If true, do not returnan error if the passed 00094 * array contains one or more zero-valued handles 00095 */ 00096 ErrorCode check_valid_entities( Error* error_handler, 00097 const EntityHandle entities[], 00098 size_t num_entities, 00099 bool root_set_okay = false ) const; 00100 00101 /** Delete an entity. Deletes sequence if only contained entity. */ 00102 ErrorCode delete_entity( Error* error_handler, EntityHandle entity ); 00103 00104 /** Delete entities */ 00105 ErrorCode delete_entities( Error* error_handler, const Range& entities ); 00106 00107 /** Allocate a vertex (possibly in an existing sequence) and 00108 * assign it the passed coordinate values. 00109 */ 00110 ErrorCode create_vertex( const double coords[3], EntityHandle& handle_out ); 00111 00112 /** Allocate a element (possibly in an existing sequence) and 00113 * assign it the passed connectivity. 00114 */ 00115 ErrorCode create_element( EntityType type, 00116 const EntityHandle* conn_array, 00117 unsigned num_vertices, 00118 EntityHandle& handle_out ); 00119 00120 /** Allocate an entity set (possibly in an existing sequence) */ 00121 ErrorCode create_mesh_set( unsigned flags, EntityHandle& handle_out ); 00122 /** Allocate an entity set with the specified handle. 00123 *\return MB_ALREADY_ALLOCATED if handle is in use, MB_SUCCESS otherwise. 00124 */ 00125 ErrorCode allocate_mesh_set( EntityHandle at_this_handle, unsigned flags ); 00126 00127 /**\brief Allocate a block of consecutive entity handles 00128 * 00129 * Allocate a block of consecutive entity handles. Handles 00130 * may be appended or prepended to an existing entity sequence. 00131 *\param type The type of of entity for which to allocate handles 00132 *\param num_entities Number of entities to allocate 00133 *\param nodes_per_entity Number of nodes in connectivity for elements, 00134 * ignored MBVERTEX, MBPOLYGON, MBPOLYHEDRON, and 00135 * MBENTITYSET types. 00136 *\param start_id_hint Preferred ID portion for first handle. 00137 * May be ignored if not available. 00138 *\param first_handle_out First allocated handle. Allocated handles 00139 * are [first_handle_out, first_handle_out+num_entities-1]. 00140 *\param sequence_out The sequence in which the entities were allocated. 00141 * NOTE: first_handle_out may not be first handle in 00142 * sequence. 00143 *\param sequence_size If specified, allocate this sequence size instead of 00144 *DEFAULT_***_SEQUENCE_SIZE 00145 */ 00146 ErrorCode create_entity_sequence( EntityType type, 00147 EntityID num_entities, 00148 int nodes_per_entity, 00149 EntityID start_id_hint, 00150 EntityHandle& first_handle_out, 00151 EntitySequence*& sequence_out, 00152 int sequence_size ); 00153 00154 /**\brief Allocate a block of consecutive mesh sets 00155 * 00156 * Allocate a block of consecutive entity handles. Handles 00157 * may be appended or prepended to an existing entity sequence. 00158 *\param type The type of of entity for which to allocate handles 00159 *\param num_sets Number of entities to allocate 00160 *\param start_id_hint Preferred ID portion for first handle. 00161 * May be ignored if not available. 00162 *\param processor_id Processor ID to embed in handles 00163 *\param flags Array of length 'num_sets' containing entity set 00164 * creating flags. 00165 *\param first_handle_out First allocated handle. Allocated handles 00166 * are [first_handle_out, first_handle_out+num_entities-1]. 00167 *\param sequence_out The sequence in which the entities were allocated. 00168 * NOTE: first_handle_out may not be first handle in 00169 * sequence. 00170 */ 00171 ErrorCode create_meshset_sequence( EntityID num_sets, 00172 EntityID start_id_hint, 00173 const unsigned* flags, 00174 EntityHandle& first_handle_out, 00175 EntitySequence*& sequence_out ); 00176 00177 /**\brief Allocate a block of consecutive mesh sets 00178 * 00179 * Alternate form that creates all mesh sets with same flags. 00180 */ 00181 ErrorCode create_meshset_sequence( EntityID num_sets, 00182 EntityID start_id_hint, 00183 unsigned flags, 00184 EntityHandle& first_handle_out, 00185 EntitySequence*& sequence_out ); 00186 00187 /** Create structured mesh */ 00188 ErrorCode create_scd_sequence( int imin, 00189 int jmin, 00190 int kmin, 00191 int imax, 00192 int jmax, 00193 int kmax, 00194 EntityType type, 00195 EntityID start_id_hint, 00196 EntityHandle& first_handle_out, 00197 EntitySequence*& sequence_out, 00198 int* is_periodic = NULL ); 00199 00200 /** Create structured mesh */ 00201 ErrorCode create_scd_sequence( const HomCoord& coord_min, 00202 const HomCoord& coord_max, 00203 EntityType type, 00204 EntityID start_id_hint, 00205 EntityHandle& first_handle_out, 00206 EntitySequence*& sequence_out, 00207 int* is_periodic = NULL ); 00208 00209 /** Create swept mesh */ 00210 ErrorCode create_sweep_sequence( int imin, 00211 int jmin, 00212 int kmin, 00213 int imax, 00214 int jmax, 00215 int kmax, 00216 int* Cq, 00217 EntityType type, 00218 EntityID start_id_hint, 00219 EntityHandle& first_handle_out, 00220 EntitySequence*& sequence_out ); 00221 00222 /** Create swept mesh */ 00223 ErrorCode create_sweep_sequence( const HomCoord& coord_min, 00224 const HomCoord& coord_max, 00225 int* Cq, 00226 EntityType type, 00227 EntityID start_id_hint, 00228 EntityHandle& first_handle_out, 00229 EntitySequence*& sequence_out ); 00230 00231 /** Add a structured vertex sequence to this structured element sequence; 00232 * see comments in ScdElementData */ 00233 ErrorCode add_vsequence( EntitySequence* vert_seq, 00234 EntitySequence* elem_seq, 00235 const HomCoord& p1, 00236 const HomCoord& q1, 00237 const HomCoord& p2, 00238 const HomCoord& q2, 00239 const HomCoord& p3, 00240 const HomCoord& q3, 00241 bool bb_input = false, 00242 const HomCoord* bb_min = NULL, 00243 const HomCoord* bb_max = NULL ); 00244 00245 /** Get data for a specific EntityType */ 00246 TypeSequenceManager& entity_map( EntityType type ) 00247 { 00248 return typeData[type]; 00249 } 00250 00251 /** Get data for a specific EntityType */ 00252 const TypeSequenceManager& entity_map( EntityType type ) const 00253 { 00254 return typeData[type]; 00255 } 00256 00257 void get_memory_use( unsigned long long& total_entity_storage, unsigned long long& total_storage ) const; 00258 00259 void get_memory_use( EntityType type, 00260 unsigned long long& total_entity_storage, 00261 unsigned long long& total_storage ) const; 00262 00263 void get_memory_use( const Range& entities, 00264 unsigned long long& total_entity_storage, 00265 unsigned long long& total_amortized_storage ) const; 00266 00267 /* Dense Tag Functions */ 00268 00269 /** Allocate a tag ID 00270 *\param tag_size The size of the tag value for each entity 00271 */ 00272 ErrorCode reserve_tag_array( Error* error_handler, int tag_size, int& array_id_out ); 00273 00274 /** Release any storage assocociated with a tag ID, and optionally, 00275 * release the reserved tag ID. */ 00276 ErrorCode release_tag_array( Error* error_handler, int id, bool release_id ); 00277 00278 /**\brief Get default size of POLYGON and POLYHEDRON SequenceData */ 00279 static EntityID default_poly_sequence_size( int entity_connectivity_length ); 00280 00281 /**\brief Size to allocate for new SquenceData 00282 * THIS FUNCTION SHOULD ONLY BE CALLED WHEN ALLOCATING FROM ReadUtil IN BULK 00283 * (since it will allocate lesser of requested_size and default_size) 00284 * If sequence_size != -1, will try to allocate that, unless there isn't available 00285 * space 00286 */ 00287 EntityID new_sequence_size( EntityHandle start_handle, EntityID requested_size, int sequence_size ) const; 00288 00289 /** \brief Interface to control memory allocation for sequences 00290 * Provide a factor that controls the size of the sequence that gets allocated. 00291 * This is typically useful in the parallel setting when a-priori, the number of ghost entities 00292 * and the memory required for them within the same sequence as the owned entities are unknown. 00293 * The default factor is 1.0 but this can be appropriately updated at runtime so that we do not 00294 * have broken sequences. 00295 */ 00296 double get_sequence_multiplier() const 00297 { 00298 return sequence_multiplier; 00299 } 00300 00301 /** \brief Interface to control memory allocation for sequences 00302 * Provide a factor that controls the size of the sequence that gets allocated. 00303 * This is typically useful in the parallel setting when a-priori, the number of ghost entities 00304 * and the memory required for them within the same sequence as the owned entities are unknown. 00305 * The default factor is 1.0 but this can be appropriately updated at runtime so that we do not 00306 * have broken sequences. 00307 * 00308 * \param meshset User specified multiplier (should be greater than 1.0) 00309 */ 00310 void set_sequence_multiplier( double factor ) 00311 { 00312 sequence_multiplier = factor; 00313 } 00314 00315 /**\brief Default allocation size for vertices */ 00316 static const EntityID DEFAULT_VERTEX_SEQUENCE_SIZE; 00317 00318 /**\brief Default allocation size for elements */ 00319 static const EntityID DEFAULT_ELEMENT_SEQUENCE_SIZE; 00320 00321 /**\brief Default allocation size for poly's */ 00322 static const EntityID DEFAULT_POLY_SEQUENCE_SIZE; 00323 00324 /**\brief Default allocation size for meshsets */ 00325 static const EntityID DEFAULT_MESHSET_SEQUENCE_SIZE; 00326 00327 private: 00328 /**\brief Utility function for allocate_mesh_set (and similar) 00329 * 00330 * Given a block of available handles, determine the non-strict 00331 * subset at which to create a new EntitySequence. 00332 */ 00333 void trim_sequence_block( EntityHandle start_handle, 00334 EntityHandle& end_handle_in_out, 00335 unsigned maximum_sequence_size ); 00336 00337 /**\brief Get range of handles in which to create an entity sequence 00338 * 00339 * Get range of handles in whcih to place a new entity sequence. 00340 *\param type The EntityType for the contents of the sequence 00341 *\param entity_count The number of entities in the range 00342 *\param values_per_entity Vertices per element, zero for other types 00343 *\param start_id_hint Preferred id of first handle 00344 *\param processor_rank MPI processor ID 00345 *\param data_out Output: Either NULL or an existing SequenceData 00346 * with a sufficiently large block to accomodate 00347 * the handle range. 00348 *\return zero if no available handle range, start handle otherwise. 00349 */ 00350 EntityHandle sequence_start_handle( EntityType type, 00351 EntityID entity_count, 00352 int values_per_entity, 00353 EntityID start_id_hint, 00354 SequenceData*& data_out, 00355 EntityID& data_size ); 00356 00357 TypeSequenceManager typeData[MBMAXTYPE]; 00358 00359 std::vector< int > tagSizes; 00360 00361 /**\brief The over-allocation factor for entities in a sequence (strictly >= 1.0) */ 00362 double sequence_multiplier; 00363 }; 00364 00365 } // namespace moab 00366 00367 #endif