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

Go to the source code of this file.

Enumerations

enum  { NO_ERROR = 0, SYNTAX_ERROR = 1, FILE_IO_ERROR = 2, INTERNAL_ERROR = 3 }

Functions

static void usage (const char *argv0)
static void check (ErrorCode rval)
static void tag_depth (Interface &moab, Tag tag)
int main (int argc, char *argv[])
static ErrorCode get_adjacent_elems (Interface &mb, const Range &verts, Range &elems)

Variables

const char * DEFAULT_TAG_NAME = "depth"

Enumeration Type Documentation

anonymous enum
Enumerator:
NO_ERROR 
SYNTAX_ERROR 
FILE_IO_ERROR 
INTERNAL_ERROR 

Definition at line 9 of file depth.cpp.


Function Documentation

static void check ( ErrorCode  rval) [static]

Definition at line 26 of file depth.cpp.

References INTERNAL_ERROR, and MB_SUCCESS.

Referenced by main(), tag_depth(), and moab::ParallelMergeMesh::TupleGreaterThan().

{
    if( MB_SUCCESS != rval )
    {
        std::cerr << "Internal error.  Aborting." << std::endl;
        exit( INTERNAL_ERROR );
    }
}
static ErrorCode get_adjacent_elems ( Interface mb,
const Range verts,
Range elems 
) [static]

Definition at line 117 of file depth.cpp.

References moab::Range::clear(), dim, ErrorCode, moab::Interface::get_adjacencies(), MB_SUCCESS, and moab::Interface::UNION.

Referenced by tag_depth().

{
    elems.clear();
    ErrorCode rval;
    for( int dim = 3; dim > 0; --dim )
    {
        rval = mb.get_adjacencies( verts, dim, false, elems, Interface::UNION );
        if( MB_SUCCESS != rval ) break;
    }
    return rval;
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 37 of file depth.cpp.

References check(), moab::Interface::create_meshset(), moab::DEFAULT_TAG_NAME, ErrorCode, FILE_IO_ERROR, moab::Interface::load_file(), mb, MB_SUCCESS, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_INTEGER, MESHSET_SET, NO_ERROR, output, moab::Interface::tag_delete(), tag_depth(), moab::Interface::tag_get_handle(), tagname, usage, and moab::Interface::write_file().

{
    const char *input = 0, *output = 0, *tagname = DEFAULT_TAG_NAME;
    bool expect_tag_name = false;
    for( int i = 1; i < argc; ++i )
    {
        if( expect_tag_name )
        {
            tagname         = argv[i];
            expect_tag_name = false;
        }
        else if( !strcmp( "-t", argv[i] ) )
            expect_tag_name = true;
        else if( input == 0 )
            input = argv[i];
        else if( output == 0 )
            output = argv[i];
        else
        {
            std::cerr << "Unexpected argument: '" << argv[i] << "'" << std::endl;
            usage( argv[0] );
        }
    }

    if( expect_tag_name )
    {
        std::cerr << "Expected argument following '-t'" << std::endl;
        usage( argv[0] );
    }
    if( !input )
    {
        std::cerr << "No input file" << std::endl;
        usage( argv[0] );
    }
    if( !output )
    {
        std::cerr << "No output file" << std::endl;
        usage( argv[0] );
    }

    Core moab;
    Interface& mb = moab;

    EntityHandle file;
    ErrorCode rval;
    rval = mb.create_meshset( MESHSET_SET, file );
    check( rval );
    rval = mb.load_file( input, &file );
    if( MB_SUCCESS != rval )
    {
        std::cerr << "Failed to load file: " << input << std::endl;
        return FILE_IO_ERROR;
    }

    int init_val = -1;
    Tag tag;
    bool created;
    rval = mb.tag_get_handle( tagname, 1, MB_TYPE_INTEGER, tag, MB_TAG_DENSE | MB_TAG_CREAT, &init_val, &created );
    if( !created )
    {
        rval = mb.tag_delete( tag );
        check( rval );
        rval = mb.tag_get_handle( tagname, 1, MB_TYPE_INTEGER, tag, MB_TAG_DENSE | MB_TAG_CREAT, &init_val, &created );
        check( rval );
    }

    tag_depth( mb, tag );

    rval = mb.write_file( output, 0, 0, &file, 1 );
    if( rval == MB_SUCCESS )
        std::cout << "Wrote file: " << output << std::endl;
    else
    {
        std::cerr << "Failed to write file: " << output << std::endl;
        return FILE_IO_ERROR;
    }

    return NO_ERROR;
}
void tag_depth ( Interface moab,
Tag  tag 
) [static]

Definition at line 129 of file depth.cpp.

References check(), moab::Range::clear(), dim, moab::Range::empty(), ErrorCode, moab::Skinner::find_skin(), moab::Interface::get_adjacencies(), get_adjacent_elems(), moab::Interface::get_entities_by_dimension(), moab::Range::insert(), moab::Range::rbegin(), moab::Range::rend(), moab::Range::size(), moab::Interface::tag_get_data(), moab::Interface::tag_set_data(), and moab::Interface::UNION.

Referenced by main().

{
    ErrorCode rval;
    int dim;

    Skinner tool( &mb );
    Range verts, elems;
    dim = 3;
    while( elems.empty() )
    {
        rval = mb.get_entities_by_dimension( 0, dim, elems );
        check( rval );
        if( --dim == 0 ) return;  // no elements
    }
    rval = tool.find_skin( 0, elems, 0, verts );
    check( rval );
    rval = get_adjacent_elems( mb, verts, elems );
    check( rval );

    std::vector< int > data;
    int val, depth = 0;
    while( !elems.empty() )
    {
        data.clear();
        data.resize( elems.size(), depth++ );
        rval = mb.tag_set_data( tag, elems, &data[0] );
        check( rval );

        verts.clear();
        rval = mb.get_adjacencies( elems, 0, false, verts, Interface::UNION );
        check( rval );

        Range tmp;
        rval = get_adjacent_elems( mb, verts, tmp );
        check( rval );
        elems.clear();
        for( Range::reverse_iterator i = tmp.rbegin(); i != tmp.rend(); ++i )
        {
            rval = mb.tag_get_data( tag, &*i, 1, &val );
            check( rval );
            if( val == -1 ) elems.insert( *i );
        }
    }

    std::cout << "Maximum depth: " << depth << std::endl;
}
static void usage ( const char *  argv0) [static]

Definition at line 19 of file depth.cpp.

References SYNTAX_ERROR.

{
    std::cerr << "Usage: " << argv0 << "[-t <tag name] <input_file> <output_file>" << std::endl
              << argv0 << "-h" << std::endl;
    exit( SYNTAX_ERROR );
}

Variable Documentation

const char* DEFAULT_TAG_NAME = "depth"

Definition at line 17 of file depth.cpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines