MOAB: Mesh Oriented datABase  (version 5.3.0)
SequenceManager.hpp
Go to the documentation of this file.
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, const EntityHandle entities[], size_t num_entities,
00097                                     bool root_set_okay = false ) const;
00098 
00099     /** Delete an entity.  Deletes sequence if only contained entity. */
00100     ErrorCode delete_entity( Error* error_handler, EntityHandle entity );
00101 
00102     /** Delete entities */
00103     ErrorCode delete_entities( Error* error_handler, const Range& entities );
00104 
00105     /** Allocate a vertex (possibly in an existing sequence) and
00106      *  assign it the passed coordinate values.
00107      */
00108     ErrorCode create_vertex( const double coords[3], EntityHandle& handle_out );
00109 
00110     /** Allocate a element (possibly in an existing sequence) and
00111      *  assign it the passed connectivity.
00112      */
00113     ErrorCode create_element( EntityType type, const EntityHandle* conn_array, unsigned num_vertices,
00114                               EntityHandle& handle_out );
00115 
00116     /** Allocate an entity set (possibly in an existing sequence) */
00117     ErrorCode create_mesh_set( unsigned flags, EntityHandle& handle_out );
00118     /** Allocate an entity set with the specified handle.
00119      *\return MB_ALREADY_ALLOCATED if handle is in use, MB_SUCCESS otherwise.
00120      */
00121     ErrorCode allocate_mesh_set( EntityHandle at_this_handle, unsigned flags );
00122 
00123     /**\brief Allocate a block of consecutive entity handles
00124      *
00125      * Allocate a block of consecutive entity handles.  Handles
00126      * may be appended or prepended to an existing entity sequence.
00127      *\param type The type of of entity for which to allocate handles
00128      *\param num_entities Number of entities to allocate
00129      *\param nodes_per_entity Number of nodes in connectivity for elements,
00130      *                    ignored MBVERTEX, MBPOLYGON, MBPOLYHEDRON, and
00131      *                    MBENTITYSET types.
00132      *\param start_id_hint Preferred ID portion for first handle.
00133      *                    May be ignored if not available.
00134      *\param first_handle_out First allocated handle.  Allocated handles
00135      *                    are [first_handle_out, first_handle_out+num_entities-1].
00136      *\param sequence_out The sequence in which the entities were allocated.
00137      *                    NOTE: first_handle_out may not be first handle in
00138      *                    sequence.
00139      *\param sequence_size If specified, allocate this sequence size instead of
00140      *DEFAULT_***_SEQUENCE_SIZE
00141      */
00142     ErrorCode create_entity_sequence( EntityType type, EntityID num_entities, int nodes_per_entity,
00143                                       EntityID start_id_hint, EntityHandle& first_handle_out,
00144                                       EntitySequence*& sequence_out, int sequence_size );
00145 
00146     /**\brief Allocate a block of consecutive mesh sets
00147      *
00148      * Allocate a block of consecutive entity handles.  Handles
00149      * may be appended or prepended to an existing entity sequence.
00150      *\param type The type of of entity for which to allocate handles
00151      *\param num_sets     Number of entities to allocate
00152      *\param start_id_hint Preferred ID portion for first handle.
00153      *                    May be ignored if not available.
00154      *\param processor_id Processor ID to embed in handles
00155      *\param flags        Array of length 'num_sets' containing entity set
00156      *                    creating flags.
00157      *\param first_handle_out First allocated handle.  Allocated handles
00158      *                    are [first_handle_out, first_handle_out+num_entities-1].
00159      *\param sequence_out The sequence in which the entities were allocated.
00160      *                    NOTE: first_handle_out may not be first handle in
00161      *                    sequence.
00162      */
00163     ErrorCode create_meshset_sequence( EntityID num_sets, EntityID start_id_hint, const unsigned* flags,
00164                                        EntityHandle& first_handle_out, EntitySequence*& sequence_out );
00165 
00166     /**\brief Allocate a block of consecutive mesh sets
00167      *
00168      * Alternate form that creates all mesh sets with same flags.
00169      */
00170     ErrorCode create_meshset_sequence( EntityID num_sets, EntityID start_id_hint, unsigned flags,
00171                                        EntityHandle& first_handle_out, EntitySequence*& sequence_out );
00172 
00173     /** Create structured mesh */
00174     ErrorCode create_scd_sequence( int imin, int jmin, int kmin, int imax, int jmax, int kmax, EntityType type,
00175                                    EntityID start_id_hint, EntityHandle& first_handle_out,
00176                                    EntitySequence*& sequence_out, int* is_periodic = NULL );
00177 
00178     /** Create structured mesh */
00179     ErrorCode create_scd_sequence( const HomCoord& coord_min, const HomCoord& coord_max, EntityType type,
00180                                    EntityID start_id_hint, EntityHandle& first_handle_out,
00181                                    EntitySequence*& sequence_out, int* is_periodic = NULL );
00182 
00183     /** Create swept mesh */
00184     ErrorCode create_sweep_sequence( int imin, int jmin, int kmin, int imax, int jmax, int kmax, int* Cq,
00185                                      EntityType type, EntityID start_id_hint, EntityHandle& first_handle_out,
00186                                      EntitySequence*& sequence_out );
00187 
00188     /** Create swept mesh */
00189     ErrorCode create_sweep_sequence( const HomCoord& coord_min, const HomCoord& coord_max, int* Cq, EntityType type,
00190                                      EntityID start_id_hint, EntityHandle& first_handle_out,
00191                                      EntitySequence*& sequence_out );
00192 
00193     /** Add a structured vertex sequence to this structured element sequence;
00194      * see comments in ScdElementData */
00195     ErrorCode add_vsequence( EntitySequence* vert_seq, EntitySequence* elem_seq, const HomCoord& p1, const HomCoord& q1,
00196                              const HomCoord& p2, const HomCoord& q2, const HomCoord& p3, const HomCoord& q3,
00197                              bool bb_input = false, const HomCoord* bb_min = NULL, const HomCoord* bb_max = NULL );
00198 
00199     /** Get data for a specific EntityType */
00200     TypeSequenceManager& entity_map( EntityType type )
00201     {
00202         return typeData[type];
00203     }
00204 
00205     /** Get data for a specific EntityType */
00206     const TypeSequenceManager& entity_map( EntityType type ) const
00207     {
00208         return typeData[type];
00209     }
00210 
00211     void get_memory_use( unsigned long long& total_entity_storage, unsigned long long& total_storage ) const;
00212 
00213     void get_memory_use( EntityType type, unsigned long long& total_entity_storage,
00214                          unsigned long long& total_storage ) const;
00215 
00216     void get_memory_use( const Range& entities, unsigned long long& total_entity_storage,
00217                          unsigned long long& total_amortized_storage ) const;
00218 
00219     /* Dense Tag Functions */
00220 
00221     /** Allocate a tag ID
00222      *\param tag_size The size of the tag value for each entity
00223      */
00224     ErrorCode reserve_tag_array( Error* error_handler, int tag_size, int& array_id_out );
00225 
00226     /** Release any storage assocociated with a tag ID, and optionally,
00227      *  release the reserved tag ID. */
00228     ErrorCode release_tag_array( Error* error_handler, int id, bool release_id );
00229 
00230     /**\brief Get default size of POLYGON and POLYHEDRON SequenceData */
00231     static EntityID default_poly_sequence_size( int entity_connectivity_length );
00232 
00233     /**\brief Size to allocate for new SquenceData
00234      * THIS FUNCTION SHOULD ONLY BE CALLED WHEN ALLOCATING FROM ReadUtil IN BULK
00235      * (since it will allocate lesser of requested_size and default_size)
00236      * If sequence_size != -1, will try to allocate that, unless there isn't available
00237      * space
00238      */
00239     EntityID new_sequence_size( EntityHandle start_handle, EntityID requested_size, int sequence_size ) const;
00240 
00241     /** \brief Interface to control memory allocation for sequences
00242      * Provide a factor that controls the size of the sequence that gets allocated.
00243      * This is typically useful in the parallel setting when a-priori, the number of ghost entities
00244      * and the memory required for them within the same sequence as the owned entities are unknown.
00245      * The default factor is 1.0 but this can be appropriately updated at runtime so that we do not
00246      * have broken sequences.
00247      */
00248     double get_sequence_multiplier() const
00249     {
00250         return sequence_multiplier;
00251     }
00252 
00253     /** \brief Interface to control memory allocation for sequences
00254      * Provide a factor that controls the size of the sequence that gets allocated.
00255      * This is typically useful in the parallel setting when a-priori, the number of ghost entities
00256      * and the memory required for them within the same sequence as the owned entities are unknown.
00257      * The default factor is 1.0 but this can be appropriately updated at runtime so that we do not
00258      * have broken sequences.
00259      *
00260      * \param meshset User specified multiplier (should be greater than 1.0)
00261      */
00262     void set_sequence_multiplier( double factor )
00263     {
00264         sequence_multiplier = factor;
00265     }
00266 
00267     /**\brief Default allocation size for vertices */
00268     static const EntityID DEFAULT_VERTEX_SEQUENCE_SIZE;
00269 
00270     /**\brief Default allocation size for elements */
00271     static const EntityID DEFAULT_ELEMENT_SEQUENCE_SIZE;
00272 
00273     /**\brief Default allocation size for poly's */
00274     static const EntityID DEFAULT_POLY_SEQUENCE_SIZE;
00275 
00276     /**\brief Default allocation size for meshsets */
00277     static const EntityID DEFAULT_MESHSET_SEQUENCE_SIZE;
00278 
00279   private:
00280     /**\brief Utility function for allocate_mesh_set (and similar)
00281      *
00282      * Given a block of available handles, determine the non-strict
00283      * subset at which to create a new EntitySequence.
00284      */
00285     void trim_sequence_block( EntityHandle start_handle, EntityHandle& end_handle_in_out,
00286                               unsigned maximum_sequence_size );
00287 
00288     /**\brief Get range of handles in which to create an entity sequence
00289      *
00290      * Get range of handles in whcih to place a new entity sequence.
00291      *\param type              The EntityType for the contents of the sequence
00292      *\param entity_count      The number of entities in the range
00293      *\param values_per_entity Vertices per element, zero for other types
00294      *\param start_id_hint     Preferred id of first handle
00295      *\param processor_rank    MPI processor ID
00296      *\param data_out  Output: Either NULL or an existing SequenceData
00297      *                         with a sufficiently large block to accomodate
00298      *                         the handle range.
00299      *\return zero if no available handle range, start handle otherwise.
00300      */
00301     EntityHandle sequence_start_handle( EntityType type, EntityID entity_count, int values_per_entity,
00302                                         EntityID start_id_hint, SequenceData*& data_out, EntityID& data_size );
00303 
00304     TypeSequenceManager typeData[MBMAXTYPE];
00305 
00306     std::vector< int > tagSizes;
00307 
00308     /**\brief The over-allocation factor for entities in a sequence (strictly >= 1.0) */
00309     double sequence_multiplier;
00310 };
00311 
00312 }  // namespace moab
00313 
00314 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines