MOAB: Mesh Oriented datABase  (version 5.4.1)
moab::ReadUtil Class Reference

#include <ReadUtil.hpp>

+ Inheritance diagram for moab::ReadUtil:
+ Collaboration diagram for moab::ReadUtil:

Public Member Functions

 ReadUtil (Core *mdb, Error *error_handler)
 Constructor takes Core pointer.
 ~ReadUtil ()
 Destructor.
ErrorCode get_node_coords (const int num_arrays, const int num_nodes, const int preferred_start_id, EntityHandle &actual_start_handle, std::vector< double * > &arrays, int sequence_size=-1)
 Get arrays for coordinate data from the MB.
ErrorCode get_element_connect (const int num_elements, const int verts_per_element, const EntityType mdb_type, const int preferred_start_id, EntityHandle &actual_start_handle, EntityHandle *&array, int sequence_size=-1)
 Get array for connectivity data from the MB.
ErrorCode gather_related_ents (Range &partition, Range &related_ents, EntityHandle *file_set=NULL)
 Gather entities related to those in the partition Gather entities related to those in the input partition. Related means down-adjacent to, contained in, etc.
ErrorCode create_entity_sets (EntityID num_sets, const unsigned *set_flags, EntityID preffered_start_id, EntityHandle &actual_start_handle)
ErrorCode update_adjacencies (const EntityHandle start_handle, const int number_elements, const int number_vertices_per_element, const EntityHandle *conn_array)
 Tell MB which elements have been added to the database.
ErrorCode get_ordered_vertices (EntityHandle *bound_ents, int *sense, int num_bound, int dim, EntityHandle *bound_verts, EntityType &etype)
ErrorCode assign_ids (Tag id_tag, const Range &ents, int start=0)
 Assign sequential IDS to entities in range and store IDs in tag.
ErrorCode assign_ids (Tag id_tag, const EntityHandle *ents, size_t num_ents, int start=0)
ErrorCode create_gather_set (EntityHandle &gather_set)
 Create a new gather set with tag GATHER_SET.
ErrorCode get_gather_set (EntityHandle &gather_set)
 Get entity handle of an existing gather set.

Private Attributes

CoremMB
 Pointer to the Core.

Detailed Description

Definition at line 31 of file ReadUtil.hpp.


Constructor & Destructor Documentation

moab::ReadUtil::ReadUtil ( Core mdb,
Error error_handler 
)

Constructor takes Core pointer.

Definition at line 38 of file ReadUtil.cpp.

: ReadUtilIface(), mMB( mdb ) {}

Destructor.

Definition at line 42 of file ReadUtil.hpp.

{}

Member Function Documentation

ErrorCode moab::ReadUtil::assign_ids ( Tag  id_tag,
const Range ents,
int  start = 0 
) [virtual]

Assign sequential IDS to entities in range and store IDs in tag.

Implements moab::ReadUtilIface.

Definition at line 314 of file ReadUtil.cpp.

References moab::check_int_tag(), moab::Range::clear(), ErrorCode, moab::Range::insert(), MB_SUCCESS, mMB, moab::Range::pair_begin(), moab::Range::pair_end(), and moab::Core::tag_set_data().

{
    ErrorCode rval = check_int_tag( mMB, id_tag );
    if( MB_SUCCESS != rval ) return rval;

    Range tmp_range;
    std::vector< int > data;
    for( Range::const_pair_iterator i = ents.pair_begin(); i != ents.pair_end(); ++i )
    {
        data.resize( i->second + 1 - i->first );
        for( std::vector< int >::iterator j = data.begin(); j != data.end(); ++j )
            *j = start++;
        tmp_range.clear();
        tmp_range.insert( i->first, i->second );
        rval = mMB->tag_set_data( id_tag, tmp_range, &data[0] );
        if( MB_SUCCESS != rval ) return rval;
    }

    return MB_SUCCESS;
}
ErrorCode moab::ReadUtil::assign_ids ( Tag  id_tag,
const EntityHandle ents,
size_t  num_ents,
int  start = 0 
) [virtual]

Assign to each entity in an array the ID that is its position in the array plus the value of 'start'. For any non-zero handles in the array, store the ID value in the passed tag.

Implements moab::ReadUtilIface.

Definition at line 335 of file ReadUtil.cpp.

References moab::check_int_tag(), ErrorCode, MB_SUCCESS, mMB, size, and moab::Core::tag_set_data().

{
    ErrorCode rval = check_int_tag( mMB, id_tag );
    if( MB_SUCCESS != rval ) return rval;

    std::vector< int > data;
    const EntityHandle* const end = ents + num_ents;
    const EntityHandle* i         = ents;
    while( i != end )
    {
        const EntityHandle* next = std::find( i, end, 0u );
        size_t size              = next - i;
        if( !size )
        {
            ++i;
            continue;
        }

        int id = start + ( i - ents );
        data.resize( size );
        for( std::vector< int >::iterator j = data.begin(); j != data.end(); ++j )
            *j = id++;

        rval = mMB->tag_set_data( id_tag, i, size, &data[0] );
        if( MB_SUCCESS != rval ) return rval;
    }

    return MB_SUCCESS;
}
ErrorCode moab::ReadUtil::create_entity_sets ( EntityID  num_sets,
const unsigned *  set_flags,
EntityID  preffered_start_id,
EntityHandle actual_start_handle 
) [virtual]

Implements moab::ReadUtilIface.

Definition at line 116 of file ReadUtil.cpp.

References moab::SequenceManager::create_meshset_sequence(), moab::EntitySequence::end_handle(), moab::error(), ErrorCode, MB_INDEX_OUT_OF_RANGE, MB_SUCCESS, mMB, moab::Core::sequence_manager(), and moab::EntitySequence::start_handle().

{
    if( num_sets < 1 )
    {
        start_handle = 0;
        return MB_INDEX_OUT_OF_RANGE;
    }

    ErrorCode error;
    EntitySequence* seq;
    error = mMB->sequence_manager()->create_meshset_sequence( num_sets, start_id, flags, start_handle, seq );
    if( MB_SUCCESS != error ) return error;

    if( seq->start_handle() > start_handle || seq->end_handle() < start_handle ||
        seq->end_handle() - start_handle + 1 < (EntityHandle)num_sets )
        return MB_FAILURE;

    return MB_SUCCESS;
}

Create a new gather set with tag GATHER_SET.

Implements moab::ReadUtilIface.

Definition at line 365 of file ReadUtil.cpp.

References moab::Core::create_meshset(), ErrorCode, MB_SUCCESS, MB_TAG_CREAT, MB_TAG_SPARSE, MB_TYPE_INTEGER, MESHSET_SET, mMB, moab::Core::tag_get_handle(), and moab::Core::tag_set_data().

{
    ErrorCode rval = mMB->create_meshset( MESHSET_SET, gather_set );
    if( MB_SUCCESS != rval ) return rval;

    Tag gather_set_tag;
    rval = mMB->tag_get_handle( "GATHER_SET", 1, MB_TYPE_INTEGER, gather_set_tag, MB_TAG_CREAT | MB_TAG_SPARSE );
    if( MB_SUCCESS != rval ) return rval;

    int gather_val = 1;
    rval           = mMB->tag_set_data( gather_set_tag, &gather_set, 1, &gather_val );
    if( MB_SUCCESS != rval ) return rval;

    return MB_SUCCESS;
}
ErrorCode moab::ReadUtil::gather_related_ents ( Range partition,
Range related_ents,
EntityHandle file_set = NULL 
) [virtual]

Gather entities related to those in the partition Gather entities related to those in the input partition. Related means down-adjacent to, contained in, etc.

Parameters:
partitionEntities for which to gather related entities
related_entsRelated entities
all_setsIf non-NULL, all sets in mesh instance are returned in the pointed-to range

Implements moab::ReadUtilIface.

Definition at line 162 of file ReadUtil.cpp.

References moab::Range::begin(), moab::Range::clear(), dim, moab::Range::empty(), moab::Range::end(), moab::Range::equal_range(), ErrorCode, moab::Range::find(), moab::Core::get_adjacencies(), moab::Core::get_child_meshsets(), moab::Core::get_entities_by_handle(), moab::Core::get_entities_by_type(), moab::Core::get_parent_meshsets(), moab::Range::insert(), moab::intersect(), MB_SUCCESS, MBENTITYSET, moab::Range::merge(), mMB, RR, moab::Range::size(), and moab::Interface::UNION.

{
    // Loop over any sets, getting contained ents
    std::pair< Range::const_iterator, Range::const_iterator > pair_it = partition.equal_range( MBENTITYSET );

    ErrorCode result = MB_SUCCESS;
    for( Range::const_iterator rit = pair_it.first; rit != pair_it.second; ++rit )
    {
        ErrorCode tmp_result = mMB->get_entities_by_handle( *rit, related_ents, Interface::UNION );
        if( MB_SUCCESS != tmp_result ) result = tmp_result;
    }
    RR;

    // Gather adjacent ents of other dimensions
    Range tmp_ents;
    for( int dim = 3; dim >= 0; dim-- )
    {
        tmp_ents.clear();
        ErrorCode tmp_result = mMB->get_adjacencies( related_ents, dim, false, tmp_ents, Interface::UNION );
        if( MB_SUCCESS != tmp_result )
            result = tmp_result;
        else
            related_ents.merge( tmp_ents );
    }
    RR;

    // Related ents includes the partition itself
    related_ents.merge( partition );

    // Get contains-related sets
    Range tmp_ents3, last_related;
    if( file_set )
        result = mMB->get_entities_by_type( *file_set, MBENTITYSET, tmp_ents3 );
    else
        result = mMB->get_entities_by_type( 0, MBENTITYSET, tmp_ents3 );RR;

    while( related_ents.size() != last_related.size() )
    {
        last_related = related_ents;
        for( Range::iterator rit = tmp_ents3.begin(); rit != tmp_ents3.end(); ++rit )
        {
            if( related_ents.find( *rit ) != related_ents.end() ) continue;

            tmp_ents.clear();
            result = mMB->get_entities_by_handle( *rit, tmp_ents, true );RR;
            Range tmp_ents2 = intersect( tmp_ents, related_ents );

            // If the intersection is not empty, set is related
            if( !tmp_ents2.empty() ) related_ents.insert( *rit );
        }
    }

    // Get child-related sets
    last_related.clear();
    while( related_ents.size() != last_related.size() )
    {
        last_related                                                      = related_ents;
        std::pair< Range::const_iterator, Range::const_iterator > it_pair = last_related.equal_range( MBENTITYSET );

        for( Range::const_iterator rit = it_pair.first; rit != it_pair.second; ++rit )
        {
            // Get all children and add to related ents
            tmp_ents.clear();
            result = mMB->get_child_meshsets( *rit, tmp_ents, 0 );RR;
            related_ents.merge( tmp_ents );
        }
    }

    // Get parent-related sets
    last_related.clear();
    while( related_ents.size() != last_related.size() )
    {
        last_related                                                      = related_ents;
        std::pair< Range::const_iterator, Range::const_iterator > it_pair = last_related.equal_range( MBENTITYSET );

        for( Range::const_iterator rit = it_pair.first; rit != it_pair.second; ++rit )
        {
            // Get all parents and add to related ents
            tmp_ents.clear();
            result = mMB->get_parent_meshsets( *rit, tmp_ents, 0 );RR;
            related_ents.merge( tmp_ents );
        }
    }

    return MB_SUCCESS;
}
ErrorCode moab::ReadUtil::get_element_connect ( const int  num_elements,
const int  verts_per_element,
const EntityType  mdb_type,
const int  preferred_start_id,
EntityHandle actual_start_handle,
EntityHandle *&  array,
int  sequence_size = -1 
) [virtual]

Get array for connectivity data from the MB.

Implements moab::ReadUtilIface.

Definition at line 76 of file ReadUtil.cpp.

References moab::SequenceManager::create_entity_sequence(), moab::EntitySequence::end_handle(), moab::error(), ErrorCode, MB_INDEX_OUT_OF_RANGE, MB_SUCCESS, mMB, moab::ElementSequence::nodes_per_element(), moab::Core::sequence_manager(), and moab::EntitySequence::start_handle().

{
    ErrorCode error;
    EntitySequence* seq;

    if( num_elements < 1 )
    {
        actual_start_handle = 0;
        array               = 0;
        return MB_INDEX_OUT_OF_RANGE;
    }

    // if (mdb_type <= MBVERTEX || mdb_type >= MBPOLYHEDRON || mdb_type == MBPOLYGON)
    // return MB_TYPE_OUT_OF_RANGE;

    // Make an entity sequence to hold these elements
    error =
        mMB->sequence_manager()->create_entity_sequence( mdb_type, num_elements, verts_per_element, preferred_start_id,
                                                         actual_start_handle, seq, sequence_size );
    if( MB_SUCCESS != error ) return error;

    if( seq->start_handle() > actual_start_handle || seq->end_handle() < actual_start_handle ||
        seq->end_handle() - actual_start_handle + 1 < (unsigned)num_elements )
        return MB_FAILURE;

    // Get an array for the connectivity
    array = static_cast< ElementSequence* >( seq )->get_connectivity_array();
    if( !array ) return MB_FAILURE;
    array +=
        ( actual_start_handle - seq->start_handle() ) * static_cast< ElementSequence* >( seq )->nodes_per_element();

    return error;
}

Get entity handle of an existing gather set.

Implements moab::ReadUtilIface.

Definition at line 381 of file ReadUtil.cpp.

References moab::Range::empty(), ErrorCode, moab::Core::get_entities_by_type_and_tag(), MB_ENTITY_NOT_FOUND, MB_SUCCESS, MB_TAG_SPARSE, MB_TYPE_INTEGER, MBENTITYSET, mMB, and moab::Core::tag_get_handle().

{
    Tag gather_set_tag;
    ErrorCode rval = mMB->tag_get_handle( "GATHER_SET", 1, MB_TYPE_INTEGER, gather_set_tag, MB_TAG_SPARSE );
    if( MB_SUCCESS != rval ) return rval;

    int gather_val = 1;
    void* vals[]   = { &gather_val };
    Range gather_sets;
    rval = mMB->get_entities_by_type_and_tag( 0, MBENTITYSET, &gather_set_tag, vals, 1, gather_sets );
    if( MB_SUCCESS != rval ) return rval;

    if( gather_sets.empty() ) return MB_ENTITY_NOT_FOUND;

    gather_set = gather_sets[0];

    return MB_SUCCESS;
}
ErrorCode moab::ReadUtil::get_node_coords ( const int  num_arrays,
const int  num_nodes,
const int  preferred_start_id,
EntityHandle actual_start_handle,
std::vector< double * > &  arrays,
int  sequence_size = -1 
) [virtual]

Get arrays for coordinate data from the MB.

Implements moab::ReadUtilIface.

Definition at line 40 of file ReadUtil.cpp.

References moab::SequenceManager::create_entity_sequence(), moab::EntitySequence::end_handle(), moab::error(), ErrorCode, MB_INDEX_OUT_OF_RANGE, MB_SUCCESS, MBVERTEX, mMB, moab::Core::sequence_manager(), and moab::EntitySequence::start_handle().

{
    ErrorCode error;
    EntitySequence* seq = 0;

    if( num_nodes < 1 )
    {
        actual_start_handle = 0;
        arrays.clear();
        return MB_INDEX_OUT_OF_RANGE;
    }

    // Create an entity sequence for these nodes
    error = mMB->sequence_manager()->create_entity_sequence( MBVERTEX, num_nodes, 0, preferred_start_id,
                                                             actual_start_handle, seq, sequence_size );

    if( error != MB_SUCCESS ) return error;

    if( seq->start_handle() > actual_start_handle || seq->end_handle() < actual_start_handle ||
        seq->end_handle() - actual_start_handle + 1 < (unsigned)num_nodes )
        return MB_FAILURE;

    arrays.resize( 3 );

    error = static_cast< VertexSequence* >( seq )->get_coordinate_arrays( arrays[0], arrays[1], arrays[2] );
    for( unsigned i = 0; i < arrays.size(); ++i )
        if( arrays[i] ) arrays[i] += ( actual_start_handle - seq->start_handle() );

    return error;
}
ErrorCode moab::ReadUtil::get_ordered_vertices ( EntityHandle bound_ents,
int *  sense,
int  num_bound,
int  dim,
EntityHandle bound_verts,
EntityType &  etype 
) [virtual]

Given an ordered list of bounding entities and the sense of those entities, return an ordered list of vertices

Implements moab::ReadUtilIface.

Definition at line 249 of file ReadUtil.cpp.

References moab::CN::Dimension(), ErrorCode, moab::Core::get_connectivity(), moab::MAX_SUB_ENTITY_VERTICES, MB_SUCCESS, MBEDGE, MBENTITYSET, MBMAXTYPE, mMB, moab::CN::NumSubEntities(), moab::CN::SubEntityVertexIndices(), t, moab::TYPE_FROM_HANDLE(), and moab::CN::VerticesPerEntity().

{
    // Get dimension of bounding entities
    int bound_dim = CN::Dimension( TYPE_FROM_HANDLE( bound_ents[0] ) );
    int indices[MAX_SUB_ENTITY_VERTICES];
    const EntityHandle* connect = NULL;
    std::vector< EntityHandle > tmp_connect;

    // Find the right entity type based on # bounding ents
    int numv = 0, num_connect = 0;
    ErrorCode result;
    for( EntityType t = MBEDGE; t < MBENTITYSET; t++ )
    {
        int nindex = CN::NumSubEntities( t, bound_dim );
        if( CN::Dimension( t ) != dim || nindex != bound_size ) continue;

        // Fill in vertices from bounding entity vertices
        int nverts = CN::VerticesPerEntity( t );
        std::fill( bound_verts, bound_verts + nverts, 0 );
        for( int index = 0; index < nindex; index++ )
        {
            result = mMB->get_connectivity( bound_ents[index], connect, num_connect, false, &tmp_connect );
            if( MB_SUCCESS != result ) return result;

            CN::SubEntityVertexIndices( t, bound_dim, index, indices );

            for( int c = 0; c < num_connect; c++ )
            {
                if( !bound_verts[indices[c]] )
                {
                    bound_verts[indices[c]] = ( sense[index] > 0 ) ? connect[c] : connect[num_connect - c - 1];
                    numv++;
                }
            }
            if( numv == nverts )
            {
                etype = t;
                return MB_SUCCESS;
            }
        }
    }

    // If we get here, we didn't get full connectivity
    etype = MBMAXTYPE;
    return MB_FAILURE;
}
ErrorCode moab::ReadUtil::update_adjacencies ( const EntityHandle  start_handle,
const int  number_elements,
const int  number_vertices_per_element,
const EntityHandle conn_array 
) [virtual]

Tell MB which elements have been added to the database.

Implements moab::ReadUtilIface.

Definition at line 139 of file ReadUtil.cpp.

References moab::Core::a_entity_factory(), MB_SUCCESS, mMB, moab::AEntityFactory::notify_create_entity(), and moab::AEntityFactory::vert_elem_adjacencies().

{
    EntityHandle tmp_hndl    = start_handle;
    AEntityFactory* adj_fact = mMB->a_entity_factory();

    // Iterate over the elements and update adjacency information
    if( adj_fact != NULL && adj_fact->vert_elem_adjacencies() )
    {
        int j = 0;
        for( int i = 0; i < number_elements; i++ )
        {
            adj_fact->notify_create_entity( tmp_hndl, ( conn_array + j ), number_vertices_per_element );
            tmp_hndl++;
            j += number_vertices_per_element;
        }
    }

    return MB_SUCCESS;
}

Member Data Documentation

List of all members.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines