LCOV - code coverage report
Current view: top level - src - SequenceManager.hpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 23 28 82.1 %
Date: 2020-12-16 07:07:30 Functions: 9 11 81.8 %
Branches: 10 20 50.0 %

           Branch data     Line data    Source code
       1                 :            : #ifndef SEQUENCE_MANAGER_HPP
       2                 :            : #define SEQUENCE_MANAGER_HPP
       3                 :            : 
       4                 :            : #include "TypeSequenceManager.hpp"
       5                 :            : #include "TagInfo.hpp"
       6                 :            : #include <vector>
       7                 :            : 
       8                 :            : namespace moab
       9                 :            : {
      10                 :            : 
      11                 :            : class HomCoord;
      12                 :            : class Error;
      13                 :            : 
      14                 :            : class SequenceManager
      15                 :            : {
      16                 :            :   public:
      17 [ +  - ][ +  + ]:       4849 :     SequenceManager( double default_seq_multiplier = 1.0 ) : sequence_multiplier( default_seq_multiplier ) {}
         [ +  - ][ #  #  
          #  #  #  #  #  
                      # ]
      18                 :            : 
      19                 :            :     ~SequenceManager();
      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                 :    7298435 :     ErrorCode find( EntityHandle handle, EntitySequence*& sequence_out )
      28                 :            :     {
      29                 :    7298435 :         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                 :   54166632 :     ErrorCode find( EntityHandle handle, const EntitySequence*& sequence_out ) const
      36                 :            :     {
      37                 :   54166632 :         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                 :      17517 :     void get_entities( EntityType type, Range& entities_out ) const
      43                 :            :     {
      44         [ +  + ]:      17517 :         if( type == MBMAXTYPE )
      45                 :        478 :             get_entities( entities_out );
      46                 :            :         else
      47                 :      17039 :             typeData[type].get_entities( entities_out );
      48                 :      17517 :     }
      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                 :        142 :     void get_entities( EntityType type, std::vector< EntityHandle >& entities_out ) const
      55                 :            :     {
      56         [ +  + ]:        142 :         if( type == MBMAXTYPE )
      57                 :          1 :             get_entities( entities_out );
      58                 :            :         else
      59                 :        141 :             typeData[type].get_entities( entities_out );
      60                 :        142 :     }
      61                 :            : 
      62                 :            :     void get_entities( std::vector< EntityHandle >& entities_out ) const;
      63                 :            : 
      64                 :            :     /** Count entities of a given EntityType */
      65                 :       2354 :     EntityID get_number_entities( EntityType type ) const
      66                 :            :     {
      67         [ +  + ]:       2354 :         return type == MBMAXTYPE ? get_number_entities() : typeData[type].get_number_entities();
      68                 :            :     }
      69                 :            : 
      70                 :            :     /** Count entities of a given EntityType */
      71                 :            :     EntityID get_number_entities() const;
      72                 :            : 
      73                 :            :     /** Get most recently accessed sequence for a given type */
      74                 :    5892279 :     const EntitySequence* get_last_accessed_sequence( EntityType type ) const
      75                 :            :     {
      76                 :    5892279 :         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                 :            :      */
      87                 :            :     ErrorCode replace_subsequence( EntitySequence* new_seq );
      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                 :            :      */
      96                 :            :     ErrorCode check_valid_entities( Error* error_handler, const EntityHandle entities[], size_t num_entities,
      97                 :            :                                     bool root_set_okay = false ) const;
      98                 :            : 
      99                 :            :     /** Delete an entity.  Deletes sequence if only contained entity. */
     100                 :            :     ErrorCode delete_entity( Error* error_handler, EntityHandle entity );
     101                 :            : 
     102                 :            :     /** Delete entities */
     103                 :            :     ErrorCode delete_entities( Error* error_handler, const Range& entities );
     104                 :            : 
     105                 :            :     /** Allocate a vertex (possibly in an existing sequence) and
     106                 :            :      *  assign it the passed coordinate values.
     107                 :            :      */
     108                 :            :     ErrorCode create_vertex( const double coords[3], EntityHandle& handle_out );
     109                 :            : 
     110                 :            :     /** Allocate a element (possibly in an existing sequence) and
     111                 :            :      *  assign it the passed connectivity.
     112                 :            :      */
     113                 :            :     ErrorCode create_element( EntityType type, const EntityHandle* conn_array, unsigned num_vertices,
     114                 :            :                               EntityHandle& handle_out );
     115                 :            : 
     116                 :            :     /** Allocate an entity set (possibly in an existing sequence) */
     117                 :            :     ErrorCode create_mesh_set( unsigned flags, EntityHandle& handle_out );
     118                 :            :     /** Allocate an entity set with the specified handle.
     119                 :            :      *\return MB_ALREADY_ALLOCATED if handle is in use, MB_SUCCESS otherwise.
     120                 :            :      */
     121                 :            :     ErrorCode allocate_mesh_set( EntityHandle at_this_handle, unsigned flags );
     122                 :            : 
     123                 :            :     /**\brief Allocate a block of consecutive entity handles
     124                 :            :      *
     125                 :            :      * Allocate a block of consecutive entity handles.  Handles
     126                 :            :      * may be appended or prepended to an existing entity sequence.
     127                 :            :      *\param type The type of of entity for which to allocate handles
     128                 :            :      *\param num_entities Number of entities to allocate
     129                 :            :      *\param nodes_per_entity Number of nodes in connectivity for elements,
     130                 :            :      *                    ignored MBVERTEX, MBPOLYGON, MBPOLYHEDRON, and
     131                 :            :      *                    MBENTITYSET types.
     132                 :            :      *\param start_id_hint Preferred ID portion for first handle.
     133                 :            :      *                    May be ignored if not available.
     134                 :            :      *\param first_handle_out First allocated handle.  Allocated handles
     135                 :            :      *                    are [first_handle_out, first_handle_out+num_entities-1].
     136                 :            :      *\param sequence_out The sequence in which the entities were allocated.
     137                 :            :      *                    NOTE: first_handle_out may not be first handle in
     138                 :            :      *                    sequence.
     139                 :            :      *\param sequence_size If specified, allocate this sequence size instead of
     140                 :            :      *DEFAULT_***_SEQUENCE_SIZE
     141                 :            :      */
     142                 :            :     ErrorCode create_entity_sequence( EntityType type, EntityID num_entities, int nodes_per_entity,
     143                 :            :                                       EntityID start_id_hint, EntityHandle& first_handle_out,
     144                 :            :                                       EntitySequence*& sequence_out, int sequence_size );
     145                 :            : 
     146                 :            :     /**\brief Allocate a block of consecutive mesh sets
     147                 :            :      *
     148                 :            :      * Allocate a block of consecutive entity handles.  Handles
     149                 :            :      * may be appended or prepended to an existing entity sequence.
     150                 :            :      *\param type The type of of entity for which to allocate handles
     151                 :            :      *\param num_sets     Number of entities to allocate
     152                 :            :      *\param start_id_hint Preferred ID portion for first handle.
     153                 :            :      *                    May be ignored if not available.
     154                 :            :      *\param processor_id Processor ID to embed in handles
     155                 :            :      *\param flags        Array of length 'num_sets' containing entity set
     156                 :            :      *                    creating flags.
     157                 :            :      *\param first_handle_out First allocated handle.  Allocated handles
     158                 :            :      *                    are [first_handle_out, first_handle_out+num_entities-1].
     159                 :            :      *\param sequence_out The sequence in which the entities were allocated.
     160                 :            :      *                    NOTE: first_handle_out may not be first handle in
     161                 :            :      *                    sequence.
     162                 :            :      */
     163                 :            :     ErrorCode create_meshset_sequence( EntityID num_sets, EntityID start_id_hint, const unsigned* flags,
     164                 :            :                                        EntityHandle& first_handle_out, EntitySequence*& sequence_out );
     165                 :            : 
     166                 :            :     /**\brief Allocate a block of consecutive mesh sets
     167                 :            :      *
     168                 :            :      * Alternate form that creates all mesh sets with same flags.
     169                 :            :      */
     170                 :            :     ErrorCode create_meshset_sequence( EntityID num_sets, EntityID start_id_hint, unsigned flags,
     171                 :            :                                        EntityHandle& first_handle_out, EntitySequence*& sequence_out );
     172                 :            : 
     173                 :            :     /** Create structured mesh */
     174                 :            :     ErrorCode create_scd_sequence( int imin, int jmin, int kmin, int imax, int jmax, int kmax, EntityType type,
     175                 :            :                                    EntityID start_id_hint, EntityHandle& first_handle_out,
     176                 :            :                                    EntitySequence*& sequence_out, int* is_periodic = NULL );
     177                 :            : 
     178                 :            :     /** Create structured mesh */
     179                 :            :     ErrorCode create_scd_sequence( const HomCoord& coord_min, const HomCoord& coord_max, EntityType type,
     180                 :            :                                    EntityID start_id_hint, EntityHandle& first_handle_out,
     181                 :            :                                    EntitySequence*& sequence_out, int* is_periodic = NULL );
     182                 :            : 
     183                 :            :     /** Create swept mesh */
     184                 :            :     ErrorCode create_sweep_sequence( int imin, int jmin, int kmin, int imax, int jmax, int kmax, int* Cq,
     185                 :            :                                      EntityType type, EntityID start_id_hint, EntityHandle& first_handle_out,
     186                 :            :                                      EntitySequence*& sequence_out );
     187                 :            : 
     188                 :            :     /** Create swept mesh */
     189                 :            :     ErrorCode create_sweep_sequence( const HomCoord& coord_min, const HomCoord& coord_max, int* Cq, EntityType type,
     190                 :            :                                      EntityID start_id_hint, EntityHandle& first_handle_out,
     191                 :            :                                      EntitySequence*& sequence_out );
     192                 :            : 
     193                 :            :     /** Add a structured vertex sequence to this structured element sequence;
     194                 :            :      * see comments in ScdElementData */
     195                 :            :     ErrorCode add_vsequence( EntitySequence* vert_seq, EntitySequence* elem_seq, const HomCoord& p1, const HomCoord& q1,
     196                 :            :                              const HomCoord& p2, const HomCoord& q2, const HomCoord& p3, const HomCoord& q3,
     197                 :            :                              bool bb_input = false, const HomCoord* bb_min = NULL, const HomCoord* bb_max = NULL );
     198                 :            : 
     199                 :            :     /** Get data for a specific EntityType */
     200                 :      14708 :     TypeSequenceManager& entity_map( EntityType type )
     201                 :            :     {
     202                 :      14708 :         return typeData[type];
     203                 :            :     }
     204                 :            : 
     205                 :            :     /** Get data for a specific EntityType */
     206                 :      73833 :     const TypeSequenceManager& entity_map( EntityType type ) const
     207                 :            :     {
     208                 :      73833 :         return typeData[type];
     209                 :            :     }
     210                 :            : 
     211                 :            :     void get_memory_use( unsigned long long& total_entity_storage, unsigned long long& total_storage ) const;
     212                 :            : 
     213                 :            :     void get_memory_use( EntityType type, unsigned long long& total_entity_storage,
     214                 :            :                          unsigned long long& total_storage ) const;
     215                 :            : 
     216                 :            :     void get_memory_use( const Range& entities, unsigned long long& total_entity_storage,
     217                 :            :                          unsigned long long& total_amortized_storage ) const;
     218                 :            : 
     219                 :            :     /* Dense Tag Functions */
     220                 :            : 
     221                 :            :     /** Allocate a tag ID
     222                 :            :      *\param tag_size The size of the tag value for each entity
     223                 :            :      */
     224                 :            :     ErrorCode reserve_tag_array( Error* error_handler, int tag_size, int& array_id_out );
     225                 :            : 
     226                 :            :     /** Release any storage assocociated with a tag ID, and optionally,
     227                 :            :      *  release the reserved tag ID. */
     228                 :            :     ErrorCode release_tag_array( Error* error_handler, int id, bool release_id );
     229                 :            : 
     230                 :            :     /**\brief Get default size of POLYGON and POLYHEDRON SequenceData */
     231                 :            :     static EntityID default_poly_sequence_size( int entity_connectivity_length );
     232                 :            : 
     233                 :            :     /**\brief Size to allocate for new SquenceData
     234                 :            :      * THIS FUNCTION SHOULD ONLY BE CALLED WHEN ALLOCATING FROM ReadUtil IN BULK
     235                 :            :      * (since it will allocate lesser of requested_size and default_size)
     236                 :            :      * If sequence_size != -1, will try to allocate that, unless there isn't available
     237                 :            :      * space
     238                 :            :      */
     239                 :            :     EntityID new_sequence_size( EntityHandle start_handle, EntityID requested_size, int sequence_size ) const;
     240                 :            : 
     241                 :            :     /** \brief Interface to control memory allocation for sequences
     242                 :            :      * Provide a factor that controls the size of the sequence that gets allocated.
     243                 :            :      * This is typically useful in the parallel setting when a-priori, the number of ghost entities
     244                 :            :      * and the memory required for them within the same sequence as the owned entities are unknown.
     245                 :            :      * The default factor is 1.0 but this can be appropriately updated at runtime so that we do not
     246                 :            :      * have broken sequences.
     247                 :            :      */
     248                 :          0 :     double get_sequence_multiplier() const
     249                 :            :     {
     250                 :          0 :         return sequence_multiplier;
     251                 :            :     }
     252                 :            : 
     253                 :            :     /** \brief Interface to control memory allocation for sequences
     254                 :            :      * Provide a factor that controls the size of the sequence that gets allocated.
     255                 :            :      * This is typically useful in the parallel setting when a-priori, the number of ghost entities
     256                 :            :      * and the memory required for them within the same sequence as the owned entities are unknown.
     257                 :            :      * The default factor is 1.0 but this can be appropriately updated at runtime so that we do not
     258                 :            :      * have broken sequences.
     259                 :            :      *
     260                 :            :      * \param meshset User specified multiplier (should be greater than 1.0)
     261                 :            :      */
     262                 :          0 :     void set_sequence_multiplier( double factor )
     263                 :            :     {
     264                 :          0 :         sequence_multiplier = factor;
     265                 :          0 :     }
     266                 :            : 
     267                 :            :     /**\brief Default allocation size for vertices */
     268                 :            :     static const EntityID DEFAULT_VERTEX_SEQUENCE_SIZE;
     269                 :            : 
     270                 :            :     /**\brief Default allocation size for elements */
     271                 :            :     static const EntityID DEFAULT_ELEMENT_SEQUENCE_SIZE;
     272                 :            : 
     273                 :            :     /**\brief Default allocation size for poly's */
     274                 :            :     static const EntityID DEFAULT_POLY_SEQUENCE_SIZE;
     275                 :            : 
     276                 :            :     /**\brief Default allocation size for meshsets */
     277                 :            :     static const EntityID DEFAULT_MESHSET_SEQUENCE_SIZE;
     278                 :            : 
     279                 :            :   private:
     280                 :            :     /**\brief Utility function for allocate_mesh_set (and similar)
     281                 :            :      *
     282                 :            :      * Given a block of available handles, determine the non-strict
     283                 :            :      * subset at which to create a new EntitySequence.
     284                 :            :      */
     285                 :            :     void trim_sequence_block( EntityHandle start_handle, EntityHandle& end_handle_in_out,
     286                 :            :                               unsigned maximum_sequence_size );
     287                 :            : 
     288                 :            :     /**\brief Get range of handles in which to create an entity sequence
     289                 :            :      *
     290                 :            :      * Get range of handles in whcih to place a new entity sequence.
     291                 :            :      *\param type              The EntityType for the contents of the sequence
     292                 :            :      *\param entity_count      The number of entities in the range
     293                 :            :      *\param values_per_entity Vertices per element, zero for other types
     294                 :            :      *\param start_id_hint     Preferred id of first handle
     295                 :            :      *\param processor_rank    MPI processor ID
     296                 :            :      *\param data_out  Output: Either NULL or an existing SequenceData
     297                 :            :      *                         with a sufficiently large block to accomodate
     298                 :            :      *                         the handle range.
     299                 :            :      *\return zero if no available handle range, start handle otherwise.
     300                 :            :      */
     301                 :            :     EntityHandle sequence_start_handle( EntityType type, EntityID entity_count, int values_per_entity,
     302                 :            :                                         EntityID start_id_hint, SequenceData*& data_out, EntityID& data_size );
     303                 :            : 
     304                 :            :     TypeSequenceManager typeData[MBMAXTYPE];
     305                 :            : 
     306                 :            :     std::vector< int > tagSizes;
     307                 :            : 
     308                 :            :     /**\brief The over-allocation factor for entities in a sequence (strictly >= 1.0) */
     309                 :            :     double sequence_multiplier;
     310                 :            : };
     311                 :            : 
     312                 :            : }  // namespace moab
     313                 :            : 
     314                 :            : #endif

Generated by: LCOV version 1.11