Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
moab::ReadRTT Class Reference

#include <ReadRTT.hpp>

+ Inheritance diagram for moab::ReadRTT:
+ Collaboration diagram for moab::ReadRTT:

Classes

struct  boundary
struct  cell
struct  facet
struct  headerData
struct  node
struct  side
struct  tet

Public Member Functions

ErrorCode load_file (const char *file_name, const EntityHandle *file_set, const FileOptions &opts, const SubsetList *subset_list=0, const Tag *file_id_tag=0)
 Load mesh from a file.
 ReadRTT (Interface *impl=NULL)
virtual ~ReadRTT ()
ErrorCode read_tag_values (const char *file_name, const char *tag_name, const FileOptions &opts, std::vector< int > &tag_values_out, const SubsetList *subset_list=0)
 Read tag values from a file.

Static Public Member Functions

static ReaderIfacefactory (Interface *)

Private Member Functions

ErrorCode generate_topology (std::vector< side > side_data, std::vector< cell > cell_data, std::map< int, EntityHandle > &surface_map)
void generate_parent_child_links (int num_ents[4], std::vector< EntityHandle > entity_map[4], std::vector< side > side_data, std::vector< cell > cell_data)
void set_surface_senses (int num_ents[4], std::vector< EntityHandle > entity_map[4], std::vector< side > side_data, std::vector< cell > cell_data)
ErrorCode setup_group_data (std::vector< EntityHandle > entity_map[4])
EntityHandle create_group (std::string group_name, int id)
ErrorCode build_moab (std::vector< node > node_data, std::vector< facet > facet_data, std::vector< tet > tet_data, std::map< int, EntityHandle > surface_map)
ErrorCode read_header (const char *filename)
ErrorCode read_sides (const char *filename, std::vector< side > &side_data)
ErrorCode read_cells (const char *filename, std::vector< cell > &cell_data)
ErrorCode read_nodes (const char *filename, std::vector< node > &node_data)
ErrorCode read_facets (const char *filename, std::vector< facet > &facet_data)
ErrorCode read_tets (const char *filename, std::vector< tet > &tet_data)
ErrorCode get_header_data (std::ifstream &input_file)
cell get_cell_data (std::string celldata)
side get_side_data (std::string sidedata)
node get_node_data (std::string nodedata)
facet get_facet_data (std::string facetdata)
tet get_tet_data (std::string tetdata)
std::vector< std::string > split_string (std::string string_to_split, char split_char)
boundary split_name (std::string atilla_cellname)
int count_sides (std::vector< side > side_data, std::vector< int > &surface_numbers)

Private Attributes

headerData header_data
ReadUtilIfacereadMeshIface
InterfaceMBI
GeomTopoToolmyGeomTool
Tag geom_tag
Tag id_tag
Tag name_tag
Tag category_tag
Tag faceting_tol_tag

Detailed Description

Definition at line 112 of file ReadRTT.hpp.


Constructor & Destructor Documentation

ReadRTT::ReadRTT ( Interface impl = NULL)

Definition at line 56 of file ReadRTT.cpp.

References category_tag, CATEGORY_TAG_NAME, CATEGORY_TAG_SIZE, ErrorCode, faceting_tol_tag, GEOM_DIMENSION_TAG_NAME, geom_tag, moab::Interface::globalId_tag(), id_tag, MB_TAG_CREAT, MB_TAG_SPARSE, MB_TYPE_DOUBLE, MB_TYPE_INTEGER, MB_TYPE_OPAQUE, MBI, myGeomTool, name_tag, NAME_TAG_NAME, NAME_TAG_SIZE, moab::Interface::query_interface(), readMeshIface, and moab::Interface::tag_get_handle().

Referenced by factory().

    : MBI( impl ), geom_tag( 0 ), id_tag( 0 ), name_tag( 0 ), category_tag( 0 ), faceting_tol_tag( 0 )
{
    assert( NULL != impl );
    myGeomTool = new GeomTopoTool( impl );
    MBI->query_interface( readMeshIface );
    assert( NULL != readMeshIface );

    // this section copied from ReadCGM initalisation
    int negone  = -1;
    double zero = 0.;
    ErrorCode rval;
    rval = MBI->tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER, geom_tag, MB_TAG_SPARSE | MB_TAG_CREAT,
                                &negone );
    assert( !rval );
    id_tag = MBI->globalId_tag();
    rval = MBI->tag_get_handle( NAME_TAG_NAME, NAME_TAG_SIZE, MB_TYPE_OPAQUE, name_tag, MB_TAG_SPARSE | MB_TAG_CREAT );
    assert( !rval );
    rval = MBI->tag_get_handle( CATEGORY_TAG_NAME, CATEGORY_TAG_SIZE, MB_TYPE_OPAQUE, category_tag,
                                MB_TAG_SPARSE | MB_TAG_CREAT );
    assert( !rval );
    rval =
        MBI->tag_get_handle( "FACETING_TOL", 1, MB_TYPE_DOUBLE, faceting_tol_tag, MB_TAG_SPARSE | MB_TAG_CREAT, &zero );
    assert( !rval );
#ifdef NDEBUG
    if( !rval )
    {
    };  // Line to avoid compiler warning about variable set but not used
#endif
}

Member Function Documentation

ErrorCode ReadRTT::build_moab ( std::vector< node node_data,
std::vector< facet facet_data,
std::vector< tet tet_data,
std::map< int, EntityHandle surface_map 
) [private]

Builds the full MOAB representation of the data, making vertices from coordinates, triangles from vertices and tets from the same vertices. Tags appropriate to each dataset collection are applied, triangles are tagged with the surface id and side id they belong to, as well as tagging the surface with the same data. Tets are similarly tagged only with the Material number

Parameters:
node_datathe node data
facet_data,thetriangles in the problem
tet_data,thetets in the problem
surface_map,themap of surface meshset and id numbers
Returns:
moab::ErrorCode

Definition at line 248 of file ReadRTT.cpp.

References moab::Interface::add_entities(), moab::ReadRTT::facet::connectivity, moab::ReadRTT::tet::connectivity, moab::Interface::create_element(), moab::Interface::create_meshset(), moab::Interface::create_vertex(), ErrorCode, moab::Range::insert(), moab::ReadRTT::tet::material_number, MB_SUCCESS, MB_TAG_CREAT, MB_TAG_SPARSE, MB_TYPE_INTEGER, MBI, MBTET, MBTRI, MESHSET_SET, moab::ReadRTT::facet::side_id, moab::ReadRTT::facet::surface_number, moab::Interface::tag_get_handle(), moab::Interface::tag_set_data(), moab::ReadRTT::node::x, moab::ReadRTT::node::y, and moab::ReadRTT::node::z.

Referenced by load_file().

{

    ErrorCode rval;         // reusable return value
    EntityHandle file_set;  // the file handle
    // create the file set
    rval = MBI->create_meshset( MESHSET_SET, file_set );
    if( MB_SUCCESS != rval ) return rval;

    // create the vertices
    EntityHandle handle;
    std::vector< node >::iterator it;  // iterate over the nodes
    Range mb_coords;                   // range of coordinates
    for( it = node_data.begin(); it != node_data.end(); ++it )
    {
        node tmp         = *it;
        double coords[3] = { tmp.x, tmp.y, tmp.z };
        rval             = MBI->create_vertex( coords, handle );
        if( MB_SUCCESS != rval ) return rval;
        mb_coords.insert( handle );  // inesert handle into the coordinate range
    }

    // add verts to set
    rval = MBI->add_entities( file_set, mb_coords );

    // create sense tag
    Tag side_id_tag, surface_number_tag;
    //  int zero = 0;
    rval = MBI->tag_get_handle( "SIDEID_TAG", 1, MB_TYPE_INTEGER, side_id_tag, MB_TAG_SPARSE | MB_TAG_CREAT );
    rval =
        MBI->tag_get_handle( "SURFACE_NUMBER", 1, MB_TYPE_INTEGER, surface_number_tag, MB_TAG_SPARSE | MB_TAG_CREAT );

    // create the facets
    EntityHandle triangle;
    std::vector< facet >::iterator it_f;
    // range of triangles
    Range mb_tris;
    // loop over the facet data
    for( it_f = facet_data.begin(); it_f != facet_data.end(); ++it_f )
    {
        facet tmp = *it_f;
        // get the nodes for the triangle
        EntityHandle tri_nodes[3] = { mb_coords[tmp.connectivity[0] - 1], mb_coords[tmp.connectivity[1] - 1],
                                      mb_coords[tmp.connectivity[2] - 1] };
        // create a triangle element
        rval = MBI->create_element( MBTRI, tri_nodes, 3, triangle );
        // tag in side id on the triangle
        rval = MBI->tag_set_data( side_id_tag, &triangle, 1, &tmp.side_id );
        // tag the surface number on the triangle
        rval = MBI->tag_set_data( surface_number_tag, &triangle, 1, &tmp.surface_number );
        // insert vertices and triangles into the appropriate surface meshset
        EntityHandle meshset_handle = surface_map[tmp.surface_number];
        // also set surface tag
        rval = MBI->tag_set_data( side_id_tag, &meshset_handle, 1, &tmp.side_id );
        rval = MBI->tag_set_data( surface_number_tag, &meshset_handle, 1, &tmp.surface_number );
        // add vertices to the mesh
        rval = MBI->add_entities( meshset_handle, &( *tri_nodes ), 3 );
        // add triangles to the meshset
        rval = MBI->add_entities( meshset_handle, &triangle, 1 );
        // ineter triangles into large run
        mb_tris.insert( triangle );
    }
    // add tris to set to fileset
    rval = MBI->add_entities( file_set, mb_tris );

    // create material number tag
    Tag mat_num_tag;
    //  int zero = 0;
    rval = MBI->tag_get_handle( "MATERIAL_NUMBER", 1, MB_TYPE_INTEGER, mat_num_tag, MB_TAG_SPARSE | MB_TAG_CREAT );

    // create the tets
    EntityHandle tetra;  // handle for a specific tet
    std::vector< tet >::iterator it_t;
    Range mb_tets;
    // loop over all tets
    for( it_t = tet_data.begin(); it_t != tet_data.end(); ++it_t )
    {
        tet tmp = *it_t;
        // get the handles for the tet
        EntityHandle tet_nodes[4] = { mb_coords[tmp.connectivity[0] - 1], mb_coords[tmp.connectivity[1] - 1],
                                      mb_coords[tmp.connectivity[2] - 1], mb_coords[tmp.connectivity[3] - 1] };
        // create the tet
        rval           = MBI->create_element( MBTET, tet_nodes, 4, tetra );
        int mat_number = tmp.material_number;
        // tag the tet with the material number
        rval = MBI->tag_set_data( mat_num_tag, &tetra, 1, &mat_number );
        // set the tag data
        mb_tets.insert( tetra );
    }
    // add tris to set
    rval = MBI->add_entities( file_set, mb_tets );

    return MB_SUCCESS;
}
int moab::ReadRTT::count_sides ( std::vector< side side_data,
std::vector< int > &  surface_numbers 
) [private]

Count the number of unique surface numbers in the dataset, also get list of surface numbers

Parameters:
side_data,collectionof all the side data in the mesh
surface_numbers,collectionof surface numbers

returns the number of surface numbers

EntityHandle ReadRTT::create_group ( std::string  group_name,
int  id 
) [private]

create a group of a given name, mustkeep track of id

Parameters:
group_name,nameof the group
id,integerid number

returns the entity handle of the group

Definition at line 926 of file ReadRTT.cpp.

References category_tag, CATEGORY_TAG_SIZE, moab::Interface::create_meshset(), ErrorCode, id_tag, MB_SUCCESS, MBI, MESHSET_SET, name_tag, and moab::Interface::tag_set_data().

Referenced by setup_group_data().

{
    ErrorCode rval;
    // category tags
    const char geom_categories[][CATEGORY_TAG_SIZE] = { "Vertex\0", "Curve\0", "Surface\0", "Volume\0", "Group\0" };

    EntityHandle handle;
    rval = MBI->create_meshset( MESHSET_SET, handle );
    if( MB_SUCCESS != rval ) return rval;

    rval = MBI->tag_set_data( name_tag, &handle, 1, group_name.c_str() );
    if( MB_SUCCESS != rval ) return MB_FAILURE;

    rval = MBI->tag_set_data( id_tag, &handle, 1, &id );
    if( MB_SUCCESS != rval ) return MB_FAILURE;

    rval = MBI->tag_set_data( category_tag, &handle, 1, &geom_categories[4] );
    if( MB_SUCCESS != rval ) return MB_FAILURE;

    return handle;
}
ReaderIface * ReadRTT::factory ( Interface iface) [static]

Definition at line 50 of file ReadRTT.cpp.

References ReadRTT().

Referenced by moab::ReaderWriterSet::ReaderWriterSet().

{
    return new ReadRTT( iface );
}
void ReadRTT::generate_parent_child_links ( int  num_ents[4],
std::vector< EntityHandle entity_map[4],
std::vector< side side_data,
std::vector< cell cell_data 
) [private]

Generate parent child links to create DAGMC like structure of surface meshsets being children of parent cell meshsets. By looping over the surfaces (1->N), look in the description of the cells that are shared by that surface, and then make the surface the child of the parent volume. The appropriate sense data will be set later

Parameters:
num_ents[4],arraycontaining the number of surfaces, cells, groups etc
entity_map[4],vectorof maps containing data by dimension
side_data,vectorof all the side data in the problem
cell_data,vectorof the cell data in the problem

Definition at line 822 of file ReadRTT.cpp.

References moab::Interface::add_parent_child(), ErrorCode, MB_SUCCESS, and MBI.

Referenced by generate_topology().

{
    ErrorCode rval;  // return value
    // loop over the number of surfaces
    for( int i = 0; i < num_ents[2]; i++ )
    {
        // get the surface handle
        EntityHandle surf_handle = entity_map[2][i];
        // there are volumes that share this face
        for( unsigned int shared = 0; shared <= 1; shared++ )
        {
            std::string parent_name = side_data[i].names[shared];
            // find the @ sign
            unsigned pos = parent_name.find( "@" );
            parent_name  = parent_name.substr( 0, pos );

            // loop over tets looking for matching name
            for( int j = 0; j < num_ents[3]; j++ )
            {
                // if match found
                if( cell_data[j].name.compare( parent_name ) == 0 )
                {
                    EntityHandle cell_handle = entity_map[3][j];
                    // parent
                    rval = MBI->add_parent_child( cell_handle, surf_handle );
                    if( rval != MB_SUCCESS )
                    {
                        std::cerr << "Failed to add parent child relationship" << std::endl;
                    }
                }
            }
        }
    }
    return;
}
ErrorCode ReadRTT::generate_topology ( std::vector< side side_data,
std::vector< cell cell_data,
std::map< int, EntityHandle > &  surface_map 
) [private]

generates the topology of the problem from the already read input data, loops over the 2 and 3 dimension macrodata that exist from the rtt file, sides = dagmc surfaces, cells = dagmc cells, creates a meshset for each surface and tags with the id number, and similarly makes a meshset for dagmc cells and tags with the id number. The surfaces are added to the s surface map, where the key is the surface ID number (1->N) and (cells and surfaces are added to an dimesional entity map stored in the class

Parameters:
side_data,vectorof side data
cell_data,vectorof vector of cell data
surface_map,referenceto the surface map of data

Definition at line 175 of file ReadRTT.cpp.

References category_tag, CATEGORY_TAG_SIZE, moab::Interface::create_meshset(), dim, ErrorCode, generate_parent_child_links(), geom_tag, id_tag, MB_SUCCESS, MBI, MESHSET_SET, set_surface_senses(), setup_group_data(), and moab::Interface::tag_set_data().

Referenced by load_file().

{

    ErrorCode rval;
    std::vector< EntityHandle > entmap[4];
    int num_ents[4];  // number of entities in each dimension

    const char geom_categories[][CATEGORY_TAG_SIZE] = { "Vertex\0", "Curve\0", "Surface\0", "Volume\0", "Group\0" };

    std::vector< int > surface_numbers;  // the surface numbers in the problem

    // corresponds to number of cad like surfaces and cad like volumes
    num_ents[2] = side_data.size();
    num_ents[3] = cell_data.size();

    // loop over surfaces & volumes
    for( int dim = 2; dim <= 3; dim++ )
    {
        for( int i = 0; i != num_ents[dim]; i++ )
        {
            EntityHandle handle;
            // create a meshset for each entity surface/volume
            rval = MBI->create_meshset( dim == 1 ? MESHSET_ORDERED : MESHSET_SET, handle );
            // if failure
            if( rval != MB_SUCCESS ) return rval;

            // collect the entity handles into an
            entmap[dim].push_back( handle );

            // set the dimension tag
            rval = MBI->tag_set_data( geom_tag, &handle, 1, &dim );
            // if fail
            if( MB_SUCCESS != rval ) return rval;
            // if we are a surface
            if( dim == 2 )
            {
                // tag the id onto the surface meshset
                rval = MBI->tag_set_data( id_tag, &handle, 1, &side_data[i].id );
                // inesert entity into the map
                surface_map[side_data[i].id] = handle;
            }
            else
            {
                // otherwise we set the volume tag data, loop is only 2 & 3 dim
                rval = MBI->tag_set_data( id_tag, &handle, 1, &cell_data[i].id );
            }
            // if fail
            if( MB_SUCCESS != rval ) return rval;
            // set the category tag
            rval = MBI->tag_set_data( category_tag, &handle, 1, &geom_categories[dim] );
            if( MB_SUCCESS != rval ) return rval;
        }
    }

    // generate parent child links
    // best to loop over the surfaces and assign them to volumes, we can then assign facets to
    // to each surface
    generate_parent_child_links( num_ents, entmap, side_data, cell_data );

    // set the surface senses
    set_surface_senses( num_ents, entmap, side_data, cell_data );

    // set the group data
    rval = setup_group_data( entmap );

    return MB_SUCCESS;
}
ReadRTT::cell ReadRTT::get_cell_data ( std::string  celldata) [private]

Reads a single atomic cell data string and populates a cell struct

Parameters:
celldata,astring of read data and
Returns:
cell, the propulated cell struct

Definition at line 642 of file ReadRTT.cpp.

References moab::ReadRTT::cell::id, MB_SET_ERR_RET_VAL, moab::ReadRTT::cell::name, and split_string().

Referenced by read_cells().

{
    cell new_cell;
    std::vector< std::string > tokens;
    tokens = ReadRTT::split_string( celldata, ' ' );

    // set the side id
    if( tokens.size() != 2 )
    {
        MB_SET_ERR_RET_VAL( "Error, too many tokens found from cell_data", new_cell );
    }
    // create the new side
    new_cell.id   = std::atoi( tokens[0].c_str() );
    new_cell.name = tokens[1];

    return new_cell;
}
ReadRTT::facet ReadRTT::get_facet_data ( std::string  facetdata) [private]

Reads a single atomic facet data string and populates a facet struct

Parameters:
facetdata,astring of facet data and
Returns:
facet, the propulated facet struct

Definition at line 684 of file ReadRTT.cpp.

References moab::ReadRTT::facet::connectivity, header_data, moab::ReadRTT::facet::id, MB_SET_ERR_RET_VAL, moab::ReadRTT::facet::side_id, split_string(), moab::ReadRTT::facet::surface_number, and moab::ReadRTT::headerData::version.

Referenced by read_facets().

{
    facet new_facet;
    std::vector< std::string > tokens;
    tokens = ReadRTT::split_string( facetdata, ' ' );

    // set the side id
    if( tokens.size() != 7 )
    {
        MB_SET_ERR_RET_VAL( "Error, too many tokens found from get_facet_data", new_facet );
    }

    new_facet.id = std::atoi( tokens[0].c_str() );
    // branch on the rtt version number
    if( header_data.version == "v1.0.0" )
    {
        new_facet.connectivity[0] = std::atoi( tokens[1].c_str() );
        new_facet.connectivity[1] = std::atoi( tokens[2].c_str() );
        new_facet.connectivity[2] = std::atoi( tokens[3].c_str() );
        new_facet.side_id         = std::atoi( tokens[4].c_str() );
        new_facet.surface_number  = std::atoi( tokens[5].c_str() );
    }
    else if( header_data.version == "v1.0.1" )
    {
        new_facet.connectivity[0] = std::atoi( tokens[2].c_str() );
        new_facet.connectivity[1] = std::atoi( tokens[3].c_str() );
        new_facet.connectivity[2] = std::atoi( tokens[4].c_str() );
        new_facet.side_id         = std::atoi( tokens[5].c_str() );
        new_facet.surface_number  = std::atoi( tokens[6].c_str() );
    }
    else
    {
        MB_SET_ERR_RET_VAL( "Error, version number not understood", new_facet );
    }

    return new_facet;
}
ErrorCode ReadRTT::get_header_data ( std::ifstream &  input_file) [private]

Reads the header data into a class member structure

Parameters:
input_file,anopen filestream
Returns:
void

Definition at line 556 of file ReadRTT.cpp.

References moab::ReadRTT::headerData::date, header_data, MB_SUCCESS, split_string(), moab::ReadRTT::headerData::title, and moab::ReadRTT::headerData::version.

Referenced by read_header().

{
    std::string line;
    while( std::getline( input_file, line ) )
    {

        // tokenize the line
        std::istringstream iss( line );
        std::vector< std::string > split_string;
        do
        {
            std::string sub_string;
            iss >> sub_string;
            split_string.push_back( sub_string );
        } while( iss );

        // if we find version
        if( line.find( "version" ) != std::string::npos )
        {
            if( split_string[1].find( "v" ) != std::string::npos &&
                split_string[0].find( "version" ) != std::string::npos )
            {
                header_data.version = split_string[1];
            }
        }

        if( line.find( "title" ) != std::string::npos )
        {
            header_data.title = split_string[1];
        }
        if( line.find( "date" ) != std::string::npos )
        {
            header_data.date = split_string[1];
        }
        if( line.find( "end_header" ) != std::string::npos )
        {
            return MB_SUCCESS;
        }
    }

    // otherwise we never found the end_header keyword
    return MB_FAILURE;
}
ReadRTT::node ReadRTT::get_node_data ( std::string  nodedata) [private]

Reads a single atomic node data string and populates a node struct

Parameters:
sidedata,astring of read data and
Returns:
node, the propulated node struct

Definition at line 663 of file ReadRTT.cpp.

References moab::ReadRTT::node::id, MB_SET_ERR_RET_VAL, split_string(), moab::ReadRTT::node::x, moab::ReadRTT::node::y, and moab::ReadRTT::node::z.

Referenced by read_nodes().

{
    node new_node;
    std::vector< std::string > tokens;
    tokens = ReadRTT::split_string( nodedata, ' ' );

    // set the side id
    if( tokens.size() != 5 )
    {
        MB_SET_ERR_RET_VAL( "Error, too many tokens found from get_node_data", new_node );
    }
    new_node.id = std::atoi( tokens[0].c_str() );
    new_node.x  = std::atof( tokens[1].c_str() );
    new_node.y  = std::atof( tokens[2].c_str() );
    new_node.z  = std::atof( tokens[3].c_str() );
    return new_node;
}
ReadRTT::side ReadRTT::get_side_data ( std::string  sidedata) [private]

Reads a single atomic side data string and populates a side struct

Parameters:
sidedata,astring of read data and
Returns:
side, the propulated side struct

Definition at line 603 of file ReadRTT.cpp.

References moab::ReadRTT::side::id, MB_SET_ERR_RET_VAL, moab::ReadRTT::boundary::name, moab::ReadRTT::side::names, moab::ReadRTT::boundary::sense, moab::ReadRTT::side::senses, split_name(), and split_string().

Referenced by read_sides().

{
    side new_side;
    std::vector< std::string > tokens;
    tokens = ReadRTT::split_string( sidedata, ' ' );

    // set the side id
    if( tokens.size() != 2 )
    {
        MB_SET_ERR_RET_VAL( "Error, too many tokens found from side_data", new_side );
    }
    // create the new side
    new_side.id = std::atoi( tokens[0].c_str() );

    std::vector< std::string > cell_names = ReadRTT::split_string( tokens[1], '/' );
    // get the boundary
    boundary new_bnd = ReadRTT::split_name( cell_names[0] );
    // set the surface sense and name
    new_side.senses[0] = new_bnd.sense;
    new_side.names[0]  = new_bnd.name;
    //
    if( cell_names.size() > 1 )
    {
        boundary bnd       = ReadRTT::split_name( cell_names[1] );
        new_side.senses[1] = bnd.sense;
        new_side.names[1]  = bnd.name;
    }
    else
    {
        new_side.senses[1] = 0;
        new_side.names[1]  = "\0";
    }

    return new_side;
}
ReadRTT::tet ReadRTT::get_tet_data ( std::string  tetdata) [private]

Reads a single atomic tet data string and populates a tet struct

Parameters:
tetdata,astring of tet data and
Returns:
tet, the propulated tet struct

Definition at line 725 of file ReadRTT.cpp.

References moab::ReadRTT::tet::connectivity, header_data, moab::ReadRTT::tet::id, moab::ReadRTT::tet::material_number, MB_SET_ERR_RET_VAL, split_string(), and moab::ReadRTT::headerData::version.

Referenced by read_tets().

{
    tet new_tet;
    std::vector< std::string > tokens;
    tokens = ReadRTT::split_string( tetdata, ' ' );

    // set the side id
    if( tokens.size() != 7 )
    {
        MB_SET_ERR_RET_VAL( "Error, too many tokens found from get_tet_data", new_tet );
    }
    new_tet.id = std::atoi( tokens[0].c_str() );
    // branch on the version number
    if( header_data.version == "v1.0.0" )
    {
        new_tet.connectivity[0] = std::atoi( tokens[1].c_str() );
        new_tet.connectivity[1] = std::atoi( tokens[2].c_str() );
        new_tet.connectivity[2] = std::atoi( tokens[3].c_str() );
        new_tet.connectivity[3] = std::atoi( tokens[4].c_str() );
        new_tet.material_number = std::atoi( tokens[5].c_str() );
    }
    else if( header_data.version == "v1.0.1" )
    {
        new_tet.connectivity[0] = std::atoi( tokens[2].c_str() );
        new_tet.connectivity[1] = std::atoi( tokens[3].c_str() );
        new_tet.connectivity[2] = std::atoi( tokens[4].c_str() );
        new_tet.connectivity[3] = std::atoi( tokens[5].c_str() );
        new_tet.material_number = std::atoi( tokens[6].c_str() );
    }
    else
    {
        MB_SET_ERR_RET_VAL( "Error, version number not supported", new_tet );
    }

    return new_tet;
}
ErrorCode ReadRTT::load_file ( const char *  file_name,
const EntityHandle file_set,
const FileOptions opts,
const SubsetList subset_list = 0,
const Tag file_id_tag = 0 
) [virtual]

Load mesh from a file.

Method all readers must provide to import a mesh.

Parameters:
file_nameThe file to read.
file_setOptional pointer to entity set representing file. If this is not NULL, reader may optionally tag the pointed-to set with format-specific meta-data.
subset_listAn optional struct pointer specifying the tags identifying entity sets to be read.
file_id_tagIf specified, reader should store for each entity it reads, a unique integer ID for this tag.
Author:
Jason Kraftcheck

Implements moab::ReaderIface.

Definition at line 109 of file ReadRTT.cpp.

References build_moab(), ErrorCode, generate_topology(), MB_FILE_DOES_NOT_EXIST, MB_SUCCESS, MB_UNSUPPORTED_OPERATION, read_cells(), read_facets(), read_header(), read_nodes(), read_sides(), and read_tets().

{
    ErrorCode rval;

    // at this time there is no support for reading a subset of the file
    if( subset_list )
    {
        std::cout << "Subset reading not supported for RTT meshes" << std::endl;
        return MB_UNSUPPORTED_OPERATION;
    }

    // test to see if file exists
    FILE* file = NULL;
    file       = fopen( filename, "r" );
    if( file == NULL ) return MB_FILE_DOES_NOT_EXIST;
    // otherwise close the file
    fclose( file );

    // read the header
    rval = ReadRTT::read_header( filename );
    if( rval != MB_SUCCESS ) return rval;

    // read the side_flag data
    std::vector< side > side_data;
    rval = ReadRTT::read_sides( filename, side_data );
    if( rval != MB_SUCCESS ) return rval;

    // read the cell data
    std::vector< cell > cell_data;
    rval = ReadRTT::read_cells( filename, cell_data );
    if( rval != MB_SUCCESS ) return rval;

    // read the node data
    std::vector< node > node_data;
    rval = ReadRTT::read_nodes( filename, node_data );
    if( rval != MB_SUCCESS ) return rval;

    // read the facet data
    std::vector< facet > facet_data;
    rval = ReadRTT::read_facets( filename, facet_data );
    if( rval != MB_SUCCESS ) return rval;

    // read the tetrahedra data
    std::vector< tet > tet_data;
    rval = ReadRTT::read_tets( filename, tet_data );
    if( rval != MB_SUCCESS ) return rval;

    // make the map of surface number in the rttmesh to the surface meshset
    std::map< int, EntityHandle > surface_map;  // corrsespondance of surface number to entity handle
    rval = ReadRTT::generate_topology( side_data, cell_data, surface_map );
    if( rval != MB_SUCCESS ) return rval;

    // generate the rest of the database, triangles to surface meshsets etc
    rval = ReadRTT::build_moab( node_data, facet_data, tet_data, surface_map );
    if( rval != MB_SUCCESS ) return rval;

    return MB_SUCCESS;
}
ErrorCode ReadRTT::read_cells ( const char *  filename,
std::vector< cell > &  cell_data 
) [private]

Reads the full set of cell data from the file

Parameters:
filename,thefile to read all the side data from
celldata, a vector containing all the read cell data
Returns:
moab::ErrorCode

Definition at line 414 of file ReadRTT.cpp.

References get_cell_data(), input_file, and MB_SUCCESS.

Referenced by load_file().

{
    std::string line;                      // the current line being read
    std::ifstream input_file( filename );  // filestream for rttfile
    // file ok?
    if( !input_file.good() )
    {
        std::cout << "Problems reading file = " << filename << std::endl;
        return MB_FAILURE;
    }
    // if it works
    if( input_file.is_open() )
    {
        while( std::getline( input_file, line ) )
        {
            if( line.compare( "  1 REGIONS\0" ) == 0 )
            {
                // read lines until find end nodes
                while( std::getline( input_file, line ) )
                {
                    if( line.compare( "end_cell_flags\0" ) == 0 ) break;
                    cell data = ReadRTT::get_cell_data( line );
                    cell_data.push_back( data );
                }
            }
        }
        input_file.close();
    }
    if( cell_data.size() == 0 ) return MB_FAILURE;
    return MB_SUCCESS;
}
ErrorCode ReadRTT::read_facets ( const char *  filename,
std::vector< facet > &  facet_data 
) [private]

Reads the full set of facet data from the file

Parameters:
filename,thefile to read all the side data from
facetdata, a vector containing all the read facet data
Returns:
moab::ErrorCode

Definition at line 485 of file ReadRTT.cpp.

References get_facet_data(), input_file, and MB_SUCCESS.

Referenced by load_file().

{
    std::string line;                      // the current line being read
    std::ifstream input_file( filename );  // filestream for rttfile
    // file ok?
    if( !input_file.good() )
    {
        std::cout << "Problems reading file = " << filename << std::endl;
        return MB_FAILURE;
    }

    // if it works
    if( input_file.is_open() )
    {
        while( std::getline( input_file, line ) )
        {
            if( line.compare( "sides\0" ) == 0 )
            {
                // read lines until find end nodes
                while( std::getline( input_file, line ) )
                {
                    if( line.compare( "end_sides\0" ) == 0 ) break;
                    facet data = ReadRTT::get_facet_data( line );
                    facet_data.push_back( data );
                }
            }
        }
        input_file.close();
    }
    if( facet_data.size() == 0 ) return MB_FAILURE;
    return MB_SUCCESS;
}
ErrorCode ReadRTT::read_header ( const char *  filename) [private]

reads the full set of header data

Parameters:
filename,thefile to read the data from
Returns:
moab::Error code

Definition at line 349 of file ReadRTT.cpp.

References ErrorCode, get_header_data(), and input_file.

Referenced by load_file().

{
    std::ifstream input_file( filename );  // filename for rtt file
    // file ok?
    if( !input_file.good() )
    {
        std::cout << "Problems reading file = " << filename << std::endl;
        return MB_FAILURE;
    }

    // if it works
    std::string line;
    moab::ErrorCode rval = MB_FAILURE;
    if( input_file.is_open() )
    {
        while( std::getline( input_file, line ) )
        {
            if( line.compare( "header" ) == 0 )
            {
                rval = get_header_data( input_file );
            }
        }
        input_file.close();
    }
    return rval;
}
ErrorCode ReadRTT::read_nodes ( const char *  filename,
std::vector< node > &  node_data 
) [private]

Reads the full set of node data from the file

Parameters:
filename,thefile to read all the side data from
nodedata, a vector containing all the read node data
Returns:
moab::ErrorCode

Definition at line 449 of file ReadRTT.cpp.

References get_node_data(), input_file, and MB_SUCCESS.

Referenced by load_file().

{
    std::string line;                      // the current line being read
    std::ifstream input_file( filename );  // filestream for rttfile
    // file ok?
    if( !input_file.good() )
    {
        std::cout << "Problems reading file = " << filename << std::endl;
        return MB_FAILURE;
    }

    // if it works
    if( input_file.is_open() )
    {
        while( std::getline( input_file, line ) )
        {
            if( line.compare( "nodes\0" ) == 0 )
            {
                // read lines until find end nodes
                while( std::getline( input_file, line ) )
                {
                    if( line.compare( "end_nodes\0" ) == 0 ) break;
                    node data = ReadRTT::get_node_data( line );
                    node_data.push_back( data );
                }
            }
        }
        input_file.close();
    }
    if( node_data.size() == 0 ) return MB_FAILURE;
    return MB_SUCCESS;
}
ErrorCode ReadRTT::read_sides ( const char *  filename,
std::vector< side > &  side_data 
) [private]

Reads the full set of side data from the file

Parameters:
filename,thefile to read all the side data from
sidedata, a vector containing all the read side data
Returns:
moab::ErrorCode

Definition at line 379 of file ReadRTT.cpp.

References get_side_data(), input_file, and MB_SUCCESS.

Referenced by load_file().

{
    std::string line;                      // the current line being read
    std::ifstream input_file( filename );  // filestream for rttfile
    // file ok?
    if( !input_file.good() )
    {
        std::cout << "Problems reading file = " << filename << std::endl;
        return MB_FAILURE;
    }
    // if it works
    if( input_file.is_open() )
    {
        while( std::getline( input_file, line ) )
        {
            if( line.compare( "  2 FACES\0" ) == 0 )
            {
                // read lines until find end nodes
                while( std::getline( input_file, line ) )
                {
                    if( line.compare( "end_side_flags\0" ) == 0 ) break;
                    side data = ReadRTT::get_side_data( line );
                    side_data.push_back( data );
                }
            }
        }
        input_file.close();
    }
    if( side_data.size() == 0 ) return MB_FAILURE;
    return MB_SUCCESS;
}
ErrorCode ReadRTT::read_tag_values ( const char *  file_name,
const char *  tag_name,
const FileOptions opts,
std::vector< int > &  tag_values_out,
const SubsetList subset_list = 0 
) [virtual]

Read tag values from a file.

Read the list if all integer tag values from the file for a tag that is a single integer value per entity.

Parameters:
file_nameThe file to read.
tag_nameThe tag for which to read values
tag_values_outOutput: The list of tag values.
subset_listAn array of tag name and value sets specifying the subset of the file to read. If multiple tags are specified, the sets that match all tags (intersection) should be read.
subset_list_lengthThe length of the 'subset_list' array.

Implements moab::ReaderIface.

Definition at line 99 of file ReadRTT.cpp.

References MB_NOT_IMPLEMENTED.

{
    return MB_NOT_IMPLEMENTED;
}
ErrorCode ReadRTT::read_tets ( const char *  filename,
std::vector< tet > &  tet_data 
) [private]

Reads the full set of tet data from the file

Parameters:
filename,thefile to read all the side data from
tetdata, a vector containing all the read tet data
Returns:
moab::ErrorCode

Definition at line 521 of file ReadRTT.cpp.

References get_tet_data(), input_file, and MB_SUCCESS.

Referenced by load_file().

{
    std::string line;                      // the current line being read
    std::ifstream input_file( filename );  // filestream for rttfile
    // file ok?
    if( !input_file.good() )
    {
        std::cout << "Problems reading file = " << filename << std::endl;
        return MB_FAILURE;
    }
    // if it works
    if( input_file.is_open() )
    {
        while( std::getline( input_file, line ) )
        {
            if( line.compare( "cells\0" ) == 0 )
            {
                // read lines until find end nodes
                while( std::getline( input_file, line ) )
                {
                    if( line.compare( "end_cells\0" ) == 0 ) break;
                    tet data = ReadRTT::get_tet_data( line );
                    tet_data.push_back( data );
                }
            }
        }
        input_file.close();
    }
    if( tet_data.size() == 0 ) return MB_FAILURE;
    return MB_SUCCESS;
}
void ReadRTT::set_surface_senses ( int  num_ents[4],
std::vector< EntityHandle entity_map[4],
std::vector< side side_data,
std::vector< cell cell_data 
) [private]

Sets the appropriate surface senses for each surface in the problem. By looping through all the surfaces, we determine from the side_data vector, the volume id's that are shared, then using 1 to mean +ve sense and -1 to mean -ve sense wrt the volume.

Parameters:
num_ents[4],arraycontaining the number of surfaces, cells, groups etc
entity_map[4],vectorof maps containing data by dimension
side_data,vectorof all the side data in the problem
cell_data,vectorof the cell data in the problem

Definition at line 864 of file ReadRTT.cpp.

References ErrorCode, MB_SUCCESS, myGeomTool, SENSE_REVERSE, and moab::GeomTopoTool::set_sense().

Referenced by generate_topology().

{

    ErrorCode rval;  // return value
    // loop over the number of surfaces
    for( int i = 0; i < num_ents[2]; i++ )
    {
        EntityHandle surf_handle = entity_map[2][i];
        // there are 2 volumes that share this face
        for( unsigned int shared = 0; shared <= 1; shared++ )
        {
            std::string parent_name = side_data[i].names[shared];
            unsigned pos            = parent_name.find( "@" );
            parent_name             = parent_name.substr( 0, pos );
            // loop over tets looking for matching name
            for( int j = 0; j < num_ents[3]; j++ )
            {
                // if match found
                if( cell_data[j].name.compare( parent_name ) == 0 )
                {
                    EntityHandle cell_handle = entity_map[3][j];
                    // in rtt mesh +represents the inside and -represents outside
                    // in moab reverse is outside and forward is inside
                    if( side_data[i].senses[shared] == 1 )
                        rval = myGeomTool->set_sense( surf_handle, cell_handle, SENSE_FORWARD );
                    else if( side_data[i].senses[shared] == -1 )
                        rval = myGeomTool->set_sense( surf_handle, cell_handle, SENSE_REVERSE );
                    else
                        rval = myGeomTool->set_sense( surf_handle, 0, SENSE_REVERSE );

                    if( rval != MB_SUCCESS )
                    {
                        std::cerr << "Failed to set sense appropriately" << std::endl;
                    }
                }
            }
        }
    }
    return;
}
ErrorCode ReadRTT::setup_group_data ( std::vector< EntityHandle entity_map[4]) [private]

creates the group data requried for dagmc, reflecting planes, material assignments etc

Parameters:
entity_map,vectorof vector of entitiy handles for each dimension
Returns:
moab::ErrorCode

Definition at line 911 of file ReadRTT.cpp.

References moab::Interface::add_entities(), create_group(), ErrorCode, and MBI.

Referenced by generate_topology().

{
    ErrorCode rval;  // error codes
    EntityHandle handle;
    handle = create_group( "graveyard_comp", 1 );

    // add any volume to group graveyard, it is ignored by dag
    EntityHandle vol_handle = entity_map[3][0];
    rval                    = MBI->add_entities( handle, &vol_handle, 1 );
    return rval;
}
ReadRTT::boundary ReadRTT::split_name ( std::string  atilla_cellname) [private]

Splits an Attila cellname and populates a boundary structure

Parameters:
attila_cellname,stringcontaining the boundary information
Returns:
a boundary object

Definition at line 766 of file ReadRTT.cpp.

References moab::ReadRTT::boundary::name, and moab::ReadRTT::boundary::sense.

Referenced by get_side_data().

{
    boundary new_boundary;
    // default initialisation
    new_boundary.sense = 0;
    new_boundary.name  = "\0";
    // +ve sense
    if( atilla_cellname.find( "+" ) != std::string::npos )
    {
        new_boundary.sense = 1;
        // look for the @# we do not want it
        std::size_t found = atilla_cellname.find( "@" );
        if( found != std::string::npos )
            new_boundary.name = atilla_cellname.substr( 3, found );
        else
            new_boundary.name = atilla_cellname.substr( 3, atilla_cellname.length() );
    }
    else if( atilla_cellname.find( "-" ) != std::string::npos )
    {
        // negative sense
        new_boundary.sense = -1;
        new_boundary.name  = atilla_cellname.substr( 3, atilla_cellname.length() );
    }
    return new_boundary;
}
std::vector< std::string > ReadRTT::split_string ( std::string  string_to_split,
char  split_char 
) [private]

Splits a string into a vector of substrings delimited by split_char

Parameters:
string_to_split,thestring that needs splitting into chunks
split_char,thecharacter to split the string with
Returns:
a vector of strings that are delimited by split_char

Definition at line 795 of file ReadRTT.cpp.

Referenced by get_cell_data(), get_facet_data(), get_header_data(), get_node_data(), get_side_data(), and get_tet_data().

{
    std::istringstream ss( string_to_split );
    std::vector< std::string > tokens;
    while( !ss.eof() )
    {
        std::string x;                      // here's a nice, empty string
        std::getline( ss, x, split_char );  // try to read the next field into it
        tokens.push_back( x );
    }

    // remove empty tokens
    std::vector< std::string >::iterator it;
    for( it = tokens.begin(); it != tokens.end(); )
    {
        std::string string = *it;
        if( string.compare( "\0" ) == 0 )
            it = tokens.erase( it );
        else
            ++it;
    }
    return tokens;
}

Member Data Documentation

Definition at line 448 of file ReadRTT.hpp.

Referenced by create_group(), generate_topology(), and ReadRTT().

Definition at line 448 of file ReadRTT.hpp.

Referenced by ReadRTT().

Definition at line 448 of file ReadRTT.hpp.

Referenced by generate_topology(), and ReadRTT().

Definition at line 440 of file ReadRTT.hpp.

Referenced by get_facet_data(), get_header_data(), and get_tet_data().

Definition at line 448 of file ReadRTT.hpp.

Referenced by create_group(), generate_topology(), and ReadRTT().

Definition at line 446 of file ReadRTT.hpp.

Referenced by ReadRTT(), set_surface_senses(), and ~ReadRTT().

Definition at line 448 of file ReadRTT.hpp.

Referenced by create_group(), and ReadRTT().

Definition at line 442 of file ReadRTT.hpp.

Referenced by ReadRTT(), and ~ReadRTT().

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