MOAB: Mesh Oriented datABase  (version 5.4.1)
ReadPartFile.cpp File Reference
#include "moab/Core.hpp"
#include <iostream>
#include <fstream>
+ Include dependency graph for ReadPartFile.cpp:

Go to the source code of this file.

Defines

#define MESH_DIR   "."

Functions

int main (int argc, char **argv)

Variables

string test_file_name = string( MESH_DIR ) + string( "/3k-tri-sphere.vtk" )
string part_file_name
int nparts

Define Documentation

#define MESH_DIR   "."

Definition at line 15 of file ReadPartFile.cpp.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 22 of file ReadPartFile.cpp.

References moab::Interface::add_entities(), moab::Range::begin(), moab::Interface::create_meshset(), moab::Interface::delete_entities(), moab::Range::end(), ErrorCode, moab::Interface::get_entities_by_dimension(), moab::Interface::get_entities_by_type(), moab::Interface::load_mesh(), mb, MB_CHK_ERR, MBENTITYSET, MESHSET_SET, nparts, part_file_name, moab::Range::size(), moab::Interface::tag_get_data(), moab::Interface::tag_get_handle(), moab::Interface::tag_set_data(), test_file_name, and moab::Interface::write_file().

{
    // Get MOAB instance
    Interface* mb = new( std::nothrow ) Core;
    if( NULL == mb ) return 1;

    // Need option handling here for input filename
    if( argc > 4 )
    {
        // User has input a mesh file
        test_file_name = argv[1];
        part_file_name = argv[2];
        nparts         = atoi( argv[3] );
    }
    else
    {
        cerr << " usage is " << argv[0] << " <input file> <part file> <#parts> <output file> \n";
        exit( 0 );
    }
    ifstream inFile;
    inFile.open( part_file_name.c_str() );
    if( !inFile )
    {
        cerr << "Unable to open file " << part_file_name << "\n";
        exit( 1 );  // call system to stop
    }
    // Load the mesh from file
    ErrorCode rval = mb->load_mesh( test_file_name.c_str() );MB_CHK_ERR( rval );

    // Get sets entities, by type
    Range sets;
    rval = mb->get_entities_by_type( 0, MBENTITYSET, sets );MB_CHK_ERR( rval );

    // Output the number of sets
    cout << "Number of sets is " << sets.size() << endl;
    // remove the sets that have a PARALLEL_PARTITION tag

    Tag tag;
    rval = mb->tag_get_handle( "PARALLEL_PARTITION", tag );MB_CHK_ERR( rval );

    int i                = 0;
    int num_deleted_sets = 0;
    for( Range::iterator it = sets.begin(); it != sets.end(); it++, i++ )
    {
        EntityHandle eh = *it;
        // cout << " set :" << mb->id_from_handle(eh) <<"\n";
        int val = -1;
        rval    = mb->tag_get_data( tag, &eh, 1, &val );
        if( val != -1 )
        {
            num_deleted_sets++;
            rval = mb->delete_entities( &eh, 1 );  // delete the set, we will have a new partition soon
        }
    }
    if( num_deleted_sets ) cout << "delete " << num_deleted_sets << " existing  partition sets, and create new ones \n";
    Range cells;  // get them by dimension 2!
    rval = mb->get_entities_by_dimension( 0, 2, cells );MB_CHK_ERR( rval );
    EntityHandle* psets = new EntityHandle[nparts];
    for( int i = 0; i < nparts; i++ )
    {
        rval = mb->create_meshset( MESHSET_SET, psets[i] );MB_CHK_ERR( rval );
        rval = mb->tag_set_data( tag, &( psets[i] ), 1, &i );MB_CHK_ERR( rval );
    }

    for( Range::iterator it = cells.begin(); it != cells.end(); it++ )
    {
        int part;
        EntityHandle eh = *it;
        inFile >> part;
        rval = mb->add_entities( psets[part], &eh, 1 );MB_CHK_ERR( rval );
    }
    mb->write_file( argv[4] );

    delete mb;

    return 0;
}

Variable Documentation

Examples:
ReadPartFile.cpp.

Definition at line 20 of file ReadPartFile.cpp.

Referenced by main().

string test_file_name = string( MESH_DIR ) + string( "/3k-tri-sphere.vtk" )

Definition at line 19 of file ReadPartFile.cpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines