1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
 * MOAB, a Mesh-Oriented datABase, is a software component for creating,
 * storing and accessing finite element mesh data.
 *
 * Copyright 2004 Sandia Corporation.  Under the terms of Contract
 * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
 * retains certain rights in this software.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 */

/**\file MeshSetSequence.hpp
 *\author Jason Kraftcheck ([email protected])
 *\date 2007-04-30
 */

#ifndef MESH_SET_SEQUENCE_HPP
#define MESH_SET_SEQUENCE_HPP

#include "EntitySequence.hpp"
#include "MeshSet.hpp"
#include "SequenceData.hpp"

namespace moab
{

class SequenceManager;

class MeshSetSequence : public EntitySequence
{
  public:
    MeshSetSequence( EntityHandle start, EntityID count, const unsigned* flags, SequenceData* data );

    MeshSetSequence( EntityHandle start, EntityID count, unsigned flags, SequenceData* data );

    MeshSetSequence( EntityHandle start, EntityID count, const unsigned* flags, EntityID sequence_size );

    MeshSetSequence( EntityHandle start, EntityID count, unsigned flags, EntityID sequence_size );

    virtual ~MeshSetSequence();

    EntitySequence* split( EntityHandle here );<--- Function in derived class<--- Function in derived class<--- Function in derived class<--- Function in derived class

    SequenceData* create_data_subset( EntityHandle, EntityHandle ) const<--- Function in derived class<--- Function in derived class<--- Function in derived class<--- Function in derived class
    {
        return 0;
    }

    ErrorCode pop_back( EntityID count );<--- Function in derived class<--- Function in derived class<--- Function in derived class<--- Function in derived class
    ErrorCode pop_front( EntityID count );<--- Function in derived class<--- Function in derived class<--- Function in derived class<--- Function in derived class
    ErrorCode push_back( EntityID count, const unsigned* flags );
    ErrorCode push_front( EntityID count, const unsigned* flags );

    void get_const_memory_use( unsigned long& bytes_per_entity, unsigned long& size_of_sequence ) const;<--- Function in derived class<--- Function in derived class<--- Function in derived class<--- Function in derived class
    unsigned long get_per_entity_memory_use( EntityHandle first, EntityHandle last ) const;<--- Function in derived class<--- Function in derived class<--- Function in derived class<--- Function in derived class

    inline MeshSet* get_set( EntityHandle h );
    inline const MeshSet* get_set( EntityHandle h ) const;

    ErrorCode get_entities( EntityHandle set, std::vector< EntityHandle >& entities ) const;
    ErrorCode get_entities( SequenceManager const* seqman, EntityHandle set, Range& entities, bool recursive ) const;
    ErrorCode get_dimension( SequenceManager const* seqman,
                             EntityHandle set,
                             int dim,
                             std::vector< EntityHandle >& entities,
                             bool recursive ) const;
    ErrorCode get_dimension( SequenceManager const* seqman,
                             EntityHandle set,
                             int dim,
                             Range& entities,
                             bool recursive ) const;
    ErrorCode get_type( SequenceManager const* seqman,
                        EntityHandle set,
                        EntityType type,
                        std::vector< EntityHandle >& entities,
                        bool recursive ) const;
    ErrorCode get_type( SequenceManager const* seqman,
                        EntityHandle set,
                        EntityType type,
                        Range& entities,
                        bool recursive ) const;

    ErrorCode num_entities( SequenceManager const* seqman, EntityHandle set, int& count, bool recursive ) const;
    ErrorCode num_dimension( SequenceManager const* seqman,
                             EntityHandle set,
                             int dim,
                             int& count,
                             bool recursive ) const;
    ErrorCode num_type( SequenceManager const* seqman,
                        EntityHandle set,
                        EntityType type,
                        int& count,
                        bool recursive ) const;

    ErrorCode get_parents( SequenceManager const* seqman,
                           EntityHandle of,
                           std::vector< EntityHandle >& parents,
                           int num_hops ) const;
    ErrorCode get_children( SequenceManager const* seqman,
                            EntityHandle of,
                            std::vector< EntityHandle >& children,
                            int num_hops ) const;
    ErrorCode get_contained_sets( SequenceManager const* seqman,
                                  EntityHandle of,
                                  std::vector< EntityHandle >& contents,
                                  int num_hops ) const;
    ErrorCode num_parents( SequenceManager const* seqman, EntityHandle of, int& number, int num_hops ) const;
    ErrorCode num_children( SequenceManager const* seqman, EntityHandle of, int& number, int num_hops ) const;
    ErrorCode num_contained_sets( SequenceManager const* seqman, EntityHandle of, int& number, int num_hops ) const;

  private:
    enum SearchType
    {
        PARENTS,
        CHILDREN,
        CONTAINED
    };

    MeshSetSequence( MeshSetSequence& split_from, EntityHandle split_at ) : EntitySequence( split_from, split_at ) {}

    void initialize( const unsigned* set_flags );

    ErrorCode get_parent_child_meshsets( EntityHandle meshset,
                                         SequenceManager const* set_sequences,
                                         std::vector< EntityHandle >& results,
                                         int num_hops,
                                         SearchType link_type ) const;

    static ErrorCode recursive_get_sets( EntityHandle start_set,
                                         SequenceManager const* set_sequences,
                                         std::vector< const MeshSet* >* sets_out          = 0,
                                         Range* set_handles_out                           = 0,
                                         std::vector< EntityHandle >* set_handle_vect_out = 0 );
    static ErrorCode recursive_get_sets( EntityHandle start_set,
                                         SequenceManager* set_sequences,
                                         std::vector< MeshSet* >& sets_out );

    enum
    {
        SET_SIZE = sizeof( MeshSet )
    };

    inline const unsigned char* array() const
    {
        return reinterpret_cast< const unsigned char* >( data()->get_sequence_data( 0 ) );
    }

    inline unsigned char* array()
    {
        return reinterpret_cast< unsigned char* >( data()->get_sequence_data( 0 ) );
    }

    inline void allocate_set( unsigned flags, EntityID index )
    {
        unsigned char* const ptr = array() + index * SET_SIZE;
        new( ptr ) MeshSet( flags );
    }

    inline void deallocate_set( EntityID index )
    {
        MeshSet* set = reinterpret_cast< MeshSet* >( array() + SET_SIZE * index );
        set->~MeshSet();
    }
};

inline MeshSet* MeshSetSequence::get_set( EntityHandle h )
{
    return reinterpret_cast< MeshSet* >( array() + SET_SIZE * ( h - data()->start_handle() ) );
}
inline const MeshSet* MeshSetSequence::get_set( EntityHandle h ) const
{
    return reinterpret_cast< const MeshSet* >( array() + SET_SIZE * ( h - data()->start_handle() ) );
}

}  // namespace moab

#endif