Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
gsets.cpp File Reference
#include <iostream>
#include <cstdlib>
#include "moab/Range.hpp"
#include "moab/Core.hpp"
#include "MBTagConventions.hpp"
#include "moab/GeomTopoTool.hpp"
+ Include dependency graph for gsets.cpp:

Go to the source code of this file.

Enumerations

enum  Link { NONE = 0, SOLID, DASHED }

Functions

static void usage (const char *name, bool brief=true)
static void write_dot (Link contained, Link children)
static void dot_nodes (std::ostream &s, Range &sets_out)
static void dot_children (std::ostream &s, const Range &sets, bool dashed)
static void dot_contained (std::ostream &s, const Range &sets, bool dashed)
int main (int argc, char *argv[])
static void dot_get_sets (Range &curr_sets, Range &result_sets, Tag tag, void *tag_val=0)
static void dot_write_node (std::ostream &s, EntityHandle h, const char *label, int *id=0)
static void dot_write_id_nodes (std::ostream &s, const Range &entites, Tag id_tag, const char *type_name)
static void dot_down_link (std::ostream &s, EntityHandle parent, EntityHandle child, bool dashed, const char *label=0)

Variables

Tag geomTag = 0
Tag blockTag = 0
Tag sideTag = 0
Tag nodeTag = 0
Tag nameTag = 0
Tag idTag = 0
bool printAnonSets = false
bool printSVSense = false
Core mb

Enumeration Type Documentation

enum Link
Enumerator:
NONE 
SOLID 
DASHED 

Definition at line 49 of file gsets.cpp.

{
    NONE = 0,
    SOLID,
    DASHED
};

Function Documentation

void dot_children ( std::ostream &  s,
const Range sets,
bool  dashed 
) [static]

Definition at line 285 of file gsets.cpp.

References moab::Range::begin(), dot_down_link(), moab::Range::end(), moab::Core::get_parent_meshsets(), moab::intersect(), mb, MB_SUCCESS, and printSVSense.

Referenced by write_dot().

{
    int sense;
    const char *fstr = "forward", *rstr = "reverse";
    for( Range::iterator i = sets.begin(); i != sets.end(); ++i )
    {
        Range parents;
        mb.get_parent_meshsets( *i, parents );
        parents = intersect( parents, sets );

        for( Range::iterator j = parents.begin(); j != parents.end(); ++j )
        {
            const char* linklabel = 0;
            if( printSVSense && MB_SUCCESS == geomTool.get_sense( *i, *j, sense ) )

                // check here only one sense, as before...
                linklabel = ( sense == (int)SENSE_FORWARD ) ? fstr : rstr;

            dot_down_link( s, *j, *i, dashed, linklabel );
        }
    }
}
void dot_contained ( std::ostream &  s,
const Range sets,
bool  dashed 
) [static]

Definition at line 308 of file gsets.cpp.

References moab::Range::begin(), dot_down_link(), moab::Range::end(), moab::Core::get_entities_by_type(), moab::intersect(), mb, and MBENTITYSET.

Referenced by write_dot().

{
    for( Range::iterator i = sets.begin(); i != sets.end(); ++i )
    {
        Range contained;
        mb.get_entities_by_type( *i, MBENTITYSET, contained );
        contained = intersect( contained, sets );

        for( Range::iterator j = contained.begin(); j != contained.end(); ++j )
            dot_down_link( s, *i, *j, dashed );
    }
}
static void dot_down_link ( std::ostream &  s,
EntityHandle  parent,
EntityHandle  child,
bool  dashed,
const char *  label = 0 
) [static]

Definition at line 269 of file gsets.cpp.

References moab::Core::id_from_handle(), and mb.

Referenced by dot_children(), and dot_contained().

{
    s << 's' << mb.id_from_handle( parent ) << " -> " << 's' << mb.id_from_handle( child );
    if( dashed && label )
        s << " [style = dashed label = \"" << label << "\"]";
    else if( dashed )
        s << " [style = dashed]";
    else if( label )
        s << " [label = \"" << label << "\"]";
    s << ';' << std::endl;
}
static void dot_get_sets ( Range curr_sets,
Range result_sets,
Tag  tag,
void *  tag_val = 0 
) [static]

Definition at line 191 of file gsets.cpp.

References moab::Range::clear(), moab::Core::get_entities_by_type_and_tag(), mb, MBENTITYSET, moab::Range::merge(), and moab::subtract().

Referenced by dot_nodes().

{
    if( !tag ) return;

    result_sets.clear();
    mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &tag, &tag_val, 1, result_sets );
    result_sets = subtract( result_sets, curr_sets );
    curr_sets.merge( result_sets );
}
void dot_nodes ( std::ostream &  s,
Range sets_out 
) [static]

Definition at line 215 of file gsets.cpp.

References moab::Range::begin(), blockTag, dim, dot_get_sets(), dot_write_id_nodes(), dot_write_node(), moab::Range::end(), geomTag, moab::Core::get_entities_by_type(), moab::Core::id_from_handle(), idTag, mb, MB_SUCCESS, MBENTITYSET, NAME_TAG_SIZE, nameTag, nodeTag, printAnonSets, sideTag, moab::subtract(), moab::Range::swap(), and moab::Core::tag_get_data().

Referenced by write_dot().

{
    Range vol_sets, surf_sets, curv_sets, vert_sets;
    Range block_sets, side_sets, node_sets;
    Range named_sets, other_sets;

    dot_get_sets( sets, named_sets, nameTag );

    int dim = 3;
    dot_get_sets( sets, vol_sets, geomTag, &dim );
    dim = 2;
    dot_get_sets( sets, surf_sets, geomTag, &dim );
    dim = 1;
    dot_get_sets( sets, curv_sets, geomTag, &dim );
    dim = 0;
    dot_get_sets( sets, vert_sets, geomTag, &dim );

    dot_get_sets( sets, block_sets, blockTag );
    dot_get_sets( sets, side_sets, sideTag );
    dot_get_sets( sets, node_sets, nodeTag );

    if( printAnonSets )
    {
        mb.get_entities_by_type( 0, MBENTITYSET, other_sets );
        Range xsect = subtract( other_sets, sets );
        sets.swap( other_sets );
        other_sets.swap( xsect );
    }

    dot_write_id_nodes( s, vol_sets, idTag, "Volume" );
    dot_write_id_nodes( s, surf_sets, idTag, "Surface" );
    dot_write_id_nodes( s, curv_sets, idTag, "Curve" );
    dot_write_id_nodes( s, vert_sets, idTag, "Vertex" );
    dot_write_id_nodes( s, block_sets, blockTag, "Block" );
    dot_write_id_nodes( s, side_sets, sideTag, "Neumann Set" );
    dot_write_id_nodes( s, node_sets, nodeTag, "Dirichlet Set" );

    Range::iterator i;
    char name[NAME_TAG_SIZE + 1];
    for( i = named_sets.begin(); i != named_sets.end(); ++i )
    {
        if( MB_SUCCESS == mb.tag_get_data( nameTag, &*i, 1, name ) )
        {
            name[NAME_TAG_SIZE] = '\0';
            dot_write_node( s, *i, name );
        }
    }
    for( i = other_sets.begin(); i != other_sets.end(); ++i )
    {
        int id = mb.id_from_handle( *i );
        dot_write_node( s, *i, "EntitySet ", &id );
    }
}
static void dot_write_id_nodes ( std::ostream &  s,
const Range entites,
Tag  id_tag,
const char *  type_name 
) [static]

Definition at line 208 of file gsets.cpp.

References moab::Range::begin(), dot_write_node(), moab::Range::end(), mb, MB_SUCCESS, and moab::Core::tag_get_data().

Referenced by dot_nodes().

{
    int id;
    for( Range::iterator i = entites.begin(); i != entites.end(); ++i )
        if( MB_SUCCESS == mb.tag_get_data( id_tag, &*i, 1, &id ) ) dot_write_node( s, *i, type_name, &id );
}
static void dot_write_node ( std::ostream &  s,
EntityHandle  h,
const char *  label,
int *  id = 0 
) [static]

Definition at line 201 of file gsets.cpp.

References moab::Core::id_from_handle(), and mb.

Referenced by dot_nodes(), and dot_write_id_nodes().

{
    s << 's' << mb.id_from_handle( h ) << " [label = \"" << label;
    if( id ) s << ' ' << *id;
    s << "\"];" << std::endl;
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 60 of file gsets.cpp.

References blockTag, children, DASHED, DIRICHLET_SET_TAG_NAME, GEOM_DIMENSION_TAG_NAME, geomTag, moab::Core::globalId_tag(), idTag, input_file, moab::Core::load_mesh(), MATERIAL_SET_TAG_NAME, mb, MB_SUCCESS, MB_TYPE_INTEGER, MB_TYPE_OPAQUE, NAME_TAG_NAME, NAME_TAG_SIZE, nameTag, NEUMANN_SET_TAG_NAME, nodeTag, NONE, printAnonSets, printSVSense, sideTag, SOLID, t, moab::Core::tag_get_handle(), usage, and write_dot().

{
    Link children = SOLID, contained = SOLID;
    bool printGeomSets     = true;
    bool printMeshSets     = true;
    bool printNamedSets    = true;
    const char* input_file = 0;
    bool geom_flag = false, mesh_flag = false, name_flag = false, all_flag = false;
    bool no_more_flags = false;
    for( int i = 1; i < argc; ++i )
    {
        if( no_more_flags || argv[i][0] != '-' )
        {
            if( input_file ) usage( argv[0] );
            input_file = argv[i];
            continue;
        }
        for( int j = 1; argv[i][j]; ++j )
        {
            switch( argv[i][j] )
            {
                case 'a':
                    all_flag = true;
                    break;
                case 'g':
                    geom_flag = true;
                    break;
                case 'm':
                    mesh_flag = true;
                    break;
                case 'n':
                    name_flag = true;
                    break;
                case 's':
                    printSVSense = true;
                    break;
                case 'P':
                    children = NONE;
                    break;
                case 'p':
                    children = DASHED;
                    break;
                case 'C':
                    contained = NONE;
                    break;
                case 'c':
                    contained = DASHED;
                    break;
                case '-':
                    no_more_flags = true;
                    break;
                case 'h':
                    usage( argv[0], false );
                    break;
                default:
                    std::cerr << "Unknown flag: '" << argv[i][j] << "'" << std::endl;
                    usage( argv[0] );
            }
        }
    }

    if( !input_file )
    {
        std::cerr << "No input file specified." << std::endl;
        usage( argv[0] );
    }

    if( all_flag )
    {
        printGeomSets = printMeshSets = printNamedSets = printAnonSets = true;
    }
    else if( geom_flag || mesh_flag || name_flag )
    {
        printGeomSets  = geom_flag;
        printMeshSets  = mesh_flag;
        printNamedSets = name_flag;
    }

    if( MB_SUCCESS != mb.load_mesh( input_file ) )
    {
        std::cerr << input_file << ": file read failed." << std::endl;
        return 1;
    }

    Tag t;
    if( printGeomSets )
    {
        if( MB_SUCCESS == mb.tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER, t ) )
        {
            geomTag = t;
        }
    }
    if( printMeshSets )
    {
        if( MB_SUCCESS == mb.tag_get_handle( MATERIAL_SET_TAG_NAME, 1, MB_TYPE_INTEGER, t ) )
        {
            blockTag = t;
        }
        if( MB_SUCCESS == mb.tag_get_handle( DIRICHLET_SET_TAG_NAME, 1, MB_TYPE_INTEGER, t ) )
        {
            nodeTag = t;
        }
        if( MB_SUCCESS == mb.tag_get_handle( NEUMANN_SET_TAG_NAME, 1, MB_TYPE_INTEGER, t ) )
        {
            sideTag = t;
        }
    }
    if( printNamedSets )
    {
        if( MB_SUCCESS == mb.tag_get_handle( NAME_TAG_NAME, NAME_TAG_SIZE, MB_TYPE_OPAQUE, t ) )
        {
            nameTag = t;
        }
    }
    idTag = mb.globalId_tag();

    write_dot( contained, children );
    return 0;
}
static void usage ( const char *  name,
bool  brief = true 
) [static]

Definition at line 22 of file gsets.cpp.

{
    std::ostream& str = brief ? std::cerr : std::cout;
    if( !brief )
        str << name << ": A tool to export entity set parent/child relations" << std::endl
            << "      for use as input to graphviz" << std::endl;
    str << "Usage: " << name << " [-a | [-g] [-m] [-n] ] <input_file>" << std::endl
        << "       " << name << " -h" << std::endl;
    if( brief ) exit( 1 );
    str << "  The default behavior is equivalent to \"-gmn\"." << std::endl
        << "  If any of the following options are used to specify which " << std::endl
        << "  sets to output, then there are no defaults.  Only the " << std::endl
        << "  indicated sets will be output." << std::endl
        << "  -a  : write all sets (default is only geom, mesh, and named)" << std::endl
        << "  -g  : write geometric topology sets" << std::endl
        << "  -m  : write material sets and boundary condition sets" << std::endl
        << "  -n  : write named sets" << std::endl
        << "  -s  : label surface-volume links with sense" << std::endl
        << "  The default link behavior is to both child links" << std::endl
        << "  and containment with solid lines." << std::endl
        << "  -P  : do not write child links" << std::endl
        << "  -p  : write child links with dashed lines" << std::endl
        << "  -C  : do not write containment links" << std::endl
        << "  -c  : write containment links with dashed lines" << std::endl;
    exit( 0 );
}
void write_dot ( Link  contained,
Link  children 
) [static]

Definition at line 180 of file gsets.cpp.

References DASHED, dot_children(), dot_contained(), and dot_nodes().

Referenced by main().

{
    Range sets;
    std::cout << "digraph {" << std::endl;
    dot_nodes( std::cout, sets );
    std::cout << std::endl;
    if( contained ) dot_contained( std::cout, sets, contained == DASHED );
    if( children ) dot_children( std::cout, sets, children == DASHED );
    std::cout << "}" << std::endl;
}

Variable Documentation

Definition at line 11 of file gsets.cpp.

Referenced by dot_nodes(), and main().

Tag geomTag = 0

Definition at line 10 of file gsets.cpp.

Referenced by dot_nodes(), FBiGeom_getEntSets(), FBiGeom_getNumEntSets(), and main().

Tag nameTag = 0

Definition at line 14 of file gsets.cpp.

Referenced by dot_nodes(), main(), and smoab::Interface::name().

Tag nodeTag = 0

Definition at line 13 of file gsets.cpp.

Referenced by dot_nodes(), and main().

bool printAnonSets = false

Definition at line 16 of file gsets.cpp.

Referenced by dot_nodes(), and main().

bool printSVSense = false

Definition at line 17 of file gsets.cpp.

Referenced by dot_children(), and main().

Tag sideTag = 0

Definition at line 12 of file gsets.cpp.

Referenced by dot_nodes(), and main().

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines