LCOV - code coverage report
Current view: top level - src/io - ReadRTT.cpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 46 396 11.6 %
Date: 2020-12-16 07:07:30 Functions: 7 27 25.9 %
Branches: 40 982 4.1 %

           Branch data     Line data    Source code
       1                 :            : /**
       2                 :            :  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
       3                 :            :  * storing and accessing finite element mesh data.
       4                 :            :  *
       5                 :            :  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
       6                 :            :  * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
       7                 :            :  * retains certain rights in this software.
       8                 :            :  *
       9                 :            :  * This library is free software; you can redistribute it and/or
      10                 :            :  * modify it under the terms of the GNU Lesser General Public
      11                 :            :  * License as published by the Free Software Foundation; either
      12                 :            :  * version 2.1 of the License, or (at your option) any later version.
      13                 :            :  *
      14                 :            :  */
      15                 :            : 
      16                 :            : /**
      17                 :            :  * \class ReadRTT
      18                 :            :  * \brief ReadRTT based on ReadNASTRAN
      19                 :            :  *
      20                 :            :  * See:
      21                 :            :  *
      22                 :            :  * \author Andrew Davis
      23                 :            :  */
      24                 :            : 
      25                 :            : #include "ReadRTT.hpp"
      26                 :            : 
      27                 :            : #include <iostream>
      28                 :            : #include <sstream>
      29                 :            : #include <fstream>
      30                 :            : #include <vector>
      31                 :            : #include <cstdlib>
      32                 :            : #include <map>
      33                 :            : #include <assert.h>
      34                 :            : #include <cmath>
      35                 :            : 
      36                 :            : #include "moab/Interface.hpp"
      37                 :            : #include "moab/ReadUtilIface.hpp"
      38                 :            : #include "Internals.hpp"  // for MB_START_ID
      39                 :            : #include "moab/Range.hpp"
      40                 :            : #include "moab/FileOptions.hpp"
      41                 :            : #include "FileTokenizer.hpp"
      42                 :            : #include "MBTagConventions.hpp"
      43                 :            : #include "moab/CN.hpp"
      44                 :            : #include "moab/ErrorHandler.hpp"
      45                 :            : #include "moab/GeomTopoTool.hpp"
      46                 :            : 
      47                 :            : namespace moab
      48                 :            : {
      49                 :            : 
      50                 :          1 : ReaderIface* ReadRTT::factory( Interface* iface )
      51                 :            : {
      52         [ +  - ]:          1 :     return new ReadRTT( iface );
      53                 :            : }
      54                 :            : 
      55                 :            : // constructor
      56                 :          1 : ReadRTT::ReadRTT( Interface* impl )
      57         [ +  - ]:          1 :     : MBI( impl ), geom_tag( 0 ), id_tag( 0 ), name_tag( 0 ), category_tag( 0 ), faceting_tol_tag( 0 )
      58                 :            : {
      59         [ -  + ]:          1 :     assert( NULL != impl );
      60 [ +  - ][ +  - ]:          1 :     myGeomTool = new GeomTopoTool( impl );
      61         [ +  - ]:          1 :     MBI->query_interface( readMeshIface );
      62         [ -  + ]:          1 :     assert( NULL != readMeshIface );
      63                 :            : 
      64                 :            :     // this section copied from ReadCGM initalisation
      65                 :          1 :     int negone  = -1;
      66                 :          1 :     double zero = 0.;
      67                 :            :     ErrorCode rval;
      68                 :            :     rval = MBI->tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER, geom_tag, MB_TAG_SPARSE | MB_TAG_CREAT,
      69         [ +  - ]:          1 :                                 &negone );
      70         [ -  + ]:          1 :     assert( !rval );
      71         [ +  - ]:          1 :     id_tag = MBI->globalId_tag();
      72         [ +  - ]:          1 :     rval = MBI->tag_get_handle( NAME_TAG_NAME, NAME_TAG_SIZE, MB_TYPE_OPAQUE, name_tag, MB_TAG_SPARSE | MB_TAG_CREAT );
      73         [ -  + ]:          1 :     assert( !rval );
      74                 :            :     rval = MBI->tag_get_handle( CATEGORY_TAG_NAME, CATEGORY_TAG_SIZE, MB_TYPE_OPAQUE, category_tag,
      75         [ +  - ]:          1 :                                 MB_TAG_SPARSE | MB_TAG_CREAT );
      76         [ -  + ]:          1 :     assert( !rval );
      77                 :            :     rval =
      78         [ +  - ]:          1 :         MBI->tag_get_handle( "FACETING_TOL", 1, MB_TYPE_DOUBLE, faceting_tol_tag, MB_TAG_SPARSE | MB_TAG_CREAT, &zero );
      79         [ -  + ]:          1 :     assert( !rval );
      80                 :            : #ifdef NDEBUG
      81                 :            :     if( !rval ) {};  // Line to avoid compiler warning about variable set but not used
      82                 :            : #endif
      83                 :          1 : }
      84                 :            : 
      85                 :            : // destructor
      86                 :          3 : ReadRTT::~ReadRTT()
      87                 :            : {
      88         [ +  - ]:          1 :     if( readMeshIface )
      89                 :            :     {
      90                 :          1 :         MBI->release_interface( readMeshIface );
      91                 :          1 :         readMeshIface = 0;
      92                 :            :     }
      93                 :            : 
      94         [ +  - ]:          1 :     delete myGeomTool;
      95         [ -  + ]:          2 : }
      96                 :            : 
      97                 :          0 : ErrorCode ReadRTT::read_tag_values( const char* /*file_name*/, const char* /*tag_name*/, const FileOptions& /*opts*/,
      98                 :            :                                     std::vector< int >& /*tag_values_out*/, const SubsetList* /*subset_list*/ )
      99                 :            : {
     100                 :          0 :     return MB_NOT_IMPLEMENTED;
     101                 :            : }
     102                 :            : 
     103                 :            : // load the file as called by the Interface function
     104                 :          1 : ErrorCode ReadRTT::load_file( const char* filename, const EntityHandle*, const FileOptions&,
     105                 :            :                               const ReaderIface::SubsetList* subset_list, const Tag* /*file_id_tag*/ )
     106                 :            : {
     107                 :            :     ErrorCode rval;
     108                 :            : 
     109                 :            :     // at this time there is no support for reading a subset of the file
     110         [ -  + ]:          1 :     if( subset_list )
     111                 :            :     {
     112 [ #  # ][ #  # ]:          0 :         std::cout << "Subset reading not supported for RTT meshes" << std::endl;
     113                 :          0 :         return MB_UNSUPPORTED_OPERATION;
     114                 :            :     }
     115                 :            : 
     116                 :            :     // test to see if file exists
     117                 :          1 :     FILE* file = NULL;
     118         [ +  - ]:          1 :     file       = fopen( filename, "r" );
     119         [ -  + ]:          1 :     if( file == NULL ) return MB_FILE_DOES_NOT_EXIST;
     120                 :            :     // otherwise close the file
     121         [ +  - ]:          1 :     fclose( file );
     122                 :            : 
     123                 :            :     // read the header
     124         [ +  - ]:          1 :     rval = ReadRTT::read_header( filename );
     125         [ +  - ]:          1 :     if( rval != MB_SUCCESS ) return rval;
     126                 :            : 
     127                 :            :     // read the side_flag data
     128         [ #  # ]:          0 :     std::vector< side > side_data;
     129         [ #  # ]:          0 :     rval = ReadRTT::read_sides( filename, side_data );
     130         [ #  # ]:          0 :     if( rval != MB_SUCCESS ) return rval;
     131                 :            : 
     132                 :            :     // read the cell data
     133         [ #  # ]:          0 :     std::vector< cell > cell_data;
     134         [ #  # ]:          0 :     rval = ReadRTT::read_cells( filename, cell_data );
     135         [ #  # ]:          0 :     if( rval != MB_SUCCESS ) return rval;
     136                 :            : 
     137                 :            :     // read the node data
     138         [ #  # ]:          0 :     std::vector< node > node_data;
     139         [ #  # ]:          0 :     rval = ReadRTT::read_nodes( filename, node_data );
     140         [ #  # ]:          0 :     if( rval != MB_SUCCESS ) return rval;
     141                 :            : 
     142                 :            :     // read the facet data
     143         [ #  # ]:          0 :     std::vector< facet > facet_data;
     144         [ #  # ]:          0 :     rval = ReadRTT::read_facets( filename, facet_data );
     145         [ #  # ]:          0 :     if( rval != MB_SUCCESS ) return rval;
     146                 :            : 
     147                 :            :     // read the tetrahedra data
     148         [ #  # ]:          0 :     std::vector< tet > tet_data;
     149         [ #  # ]:          0 :     rval = ReadRTT::read_tets( filename, tet_data );
     150         [ #  # ]:          0 :     if( rval != MB_SUCCESS ) return rval;
     151                 :            : 
     152                 :            :     // make the map of surface number in the rttmesh to the surface meshset
     153         [ #  # ]:          0 :     std::map< int, EntityHandle > surface_map;  // corrsespondance of surface number to entity handle
     154 [ #  # ][ #  # ]:          0 :     rval = ReadRTT::generate_topology( side_data, cell_data, surface_map );
                 [ #  # ]
     155         [ #  # ]:          0 :     if( rval != MB_SUCCESS ) return rval;
     156                 :            : 
     157                 :            :     // generate the rest of the database, triangles to surface meshsets etc
     158 [ #  # ][ #  # ]:          0 :     rval = ReadRTT::build_moab( node_data, facet_data, tet_data, surface_map );
         [ #  # ][ #  # ]
                 [ #  # ]
     159         [ #  # ]:          0 :     if( rval != MB_SUCCESS ) return rval;
     160                 :            : 
     161                 :          1 :     return MB_SUCCESS;
     162                 :            : }
     163                 :            : 
     164                 :            : /*
     165                 :            :  * builds the topology of the problem
     166                 :            :  */
     167                 :          0 : ErrorCode ReadRTT::generate_topology( std::vector< side > side_data, std::vector< cell > cell_data,
     168                 :            :                                       std::map< int, EntityHandle >& surface_map )
     169                 :            : {
     170                 :            : 
     171                 :            :     ErrorCode rval;
     172 [ #  # ][ #  # ]:          0 :     std::vector< EntityHandle > entmap[4];
                 [ #  # ]
     173                 :            :     int num_ents[4];  // number of entities in each dimension
     174                 :            : 
     175                 :          0 :     const char geom_categories[][CATEGORY_TAG_SIZE] = { "Vertex\0", "Curve\0", "Surface\0", "Volume\0", "Group\0" };
     176                 :            : 
     177         [ #  # ]:          0 :     std::vector< int > surface_numbers;  // the surface numbers in the problem
     178                 :            : 
     179                 :            :     // corresponds to number of cad like surfaces and cad like volumes
     180                 :          0 :     num_ents[2] = side_data.size();
     181                 :          0 :     num_ents[3] = cell_data.size();
     182                 :            : 
     183                 :            :     // loop over surfaces & volumes
     184         [ #  # ]:          0 :     for( int dim = 2; dim <= 3; dim++ )
     185                 :            :     {
     186         [ #  # ]:          0 :         for( int i = 0; i != num_ents[dim]; i++ )
     187                 :            :         {
     188                 :            :             EntityHandle handle;
     189                 :            :             // create a meshset for each entity surface/volume
     190 [ #  # ][ #  # ]:          0 :             rval = MBI->create_meshset( dim == 1 ? MESHSET_ORDERED : MESHSET_SET, handle );
     191                 :            :             // if failure
     192         [ #  # ]:          0 :             if( rval != MB_SUCCESS ) return rval;
     193                 :            : 
     194                 :            :             // collect the entity handles into an
     195         [ #  # ]:          0 :             entmap[dim].push_back( handle );
     196                 :            : 
     197                 :            :             // set the dimension tag
     198         [ #  # ]:          0 :             rval = MBI->tag_set_data( geom_tag, &handle, 1, &dim );
     199                 :            :             // if fail
     200         [ #  # ]:          0 :             if( MB_SUCCESS != rval ) return rval;
     201                 :            :             // if we are a surface
     202         [ #  # ]:          0 :             if( dim == 2 )
     203                 :            :             {
     204                 :            :                 // tag the id onto the surface meshset
     205 [ #  # ][ #  # ]:          0 :                 rval = MBI->tag_set_data( id_tag, &handle, 1, &side_data[i].id );
     206                 :            :                 // inesert entity into the map
     207 [ #  # ][ #  # ]:          0 :                 surface_map[side_data[i].id] = handle;
     208                 :            :             }
     209                 :            :             else
     210                 :            :             {
     211                 :            :                 // otherwise we set the volume tag data, loop is only 2 & 3 dim
     212 [ #  # ][ #  # ]:          0 :                 rval = MBI->tag_set_data( id_tag, &handle, 1, &cell_data[i].id );
     213                 :            :             }
     214                 :            :             // if fail
     215         [ #  # ]:          0 :             if( MB_SUCCESS != rval ) return rval;
     216                 :            :             // set the category tag
     217         [ #  # ]:          0 :             rval = MBI->tag_set_data( category_tag, &handle, 1, &geom_categories[dim] );
     218         [ #  # ]:          0 :             if( MB_SUCCESS != rval ) return rval;
     219                 :            :         }
     220                 :            :     }
     221                 :            : 
     222                 :            :     // generate parent child links
     223                 :            :     // best to loop over the surfaces and assign them to volumes, we can then assign facets to
     224                 :            :     // to each surface
     225 [ #  # ][ #  # ]:          0 :     generate_parent_child_links( num_ents, entmap, side_data, cell_data );
                 [ #  # ]
     226                 :            : 
     227                 :            :     // set the surface senses
     228 [ #  # ][ #  # ]:          0 :     set_surface_senses( num_ents, entmap, side_data, cell_data );
                 [ #  # ]
     229                 :            : 
     230                 :            :     // set the group data
     231         [ #  # ]:          0 :     rval = setup_group_data( entmap );
     232                 :            : 
     233         [ #  # ]:          0 :     return MB_SUCCESS;
           [ #  #  #  # ]
     234                 :            : }
     235                 :            : 
     236                 :            : /*
     237                 :            :  * builds the moab representation of the mesh
     238                 :            :  */
     239                 :          0 : ErrorCode ReadRTT::build_moab( std::vector< node > node_data, std::vector< facet > facet_data,
     240                 :            :                                std::vector< tet > tet_data, std::map< int, EntityHandle > surface_map )
     241                 :            : {
     242                 :            : 
     243                 :            :     ErrorCode rval;         // reusable return value
     244                 :            :     EntityHandle file_set;  // the file handle
     245                 :            :     // create the file set
     246         [ #  # ]:          0 :     rval = MBI->create_meshset( MESHSET_SET, file_set );
     247         [ #  # ]:          0 :     if( MB_SUCCESS != rval ) return rval;
     248                 :            : 
     249                 :            :     // create the vertices
     250                 :            :     EntityHandle handle;
     251                 :          0 :     std::vector< node >::iterator it;  // iterate over the nodes
     252         [ #  # ]:          0 :     Range mb_coords;                   // range of coordinates
     253 [ #  # ][ #  # ]:          0 :     for( it = node_data.begin(); it != node_data.end(); ++it )
                 [ #  # ]
     254                 :            :     {
     255         [ #  # ]:          0 :         node tmp         = *it;
     256                 :          0 :         double coords[3] = { tmp.x, tmp.y, tmp.z };
     257         [ #  # ]:          0 :         rval             = MBI->create_vertex( coords, handle );
     258         [ #  # ]:          0 :         if( MB_SUCCESS != rval ) return rval;
     259         [ #  # ]:          0 :         mb_coords.insert( handle );  // inesert handle into the coordinate range
     260                 :            :     }
     261                 :            : 
     262                 :            :     // add verts to set
     263         [ #  # ]:          0 :     rval = MBI->add_entities( file_set, mb_coords );
     264                 :            : 
     265                 :            :     // create sense tag
     266                 :            :     Tag side_id_tag, surface_number_tag;
     267                 :            :     //  int zero = 0;
     268         [ #  # ]:          0 :     rval = MBI->tag_get_handle( "SIDEID_TAG", 1, MB_TYPE_INTEGER, side_id_tag, MB_TAG_SPARSE | MB_TAG_CREAT );
     269                 :            :     rval =
     270         [ #  # ]:          0 :         MBI->tag_get_handle( "SURFACE_NUMBER", 1, MB_TYPE_INTEGER, surface_number_tag, MB_TAG_SPARSE | MB_TAG_CREAT );
     271                 :            : 
     272                 :            :     // create the facets
     273                 :            :     EntityHandle triangle;
     274                 :          0 :     std::vector< facet >::iterator it_f;
     275                 :            :     // range of triangles
     276         [ #  # ]:          0 :     Range mb_tris;
     277                 :            :     // loop over the facet data
     278 [ #  # ][ #  # ]:          0 :     for( it_f = facet_data.begin(); it_f != facet_data.end(); ++it_f )
                 [ #  # ]
     279                 :            :     {
     280         [ #  # ]:          0 :         facet tmp = *it_f;
     281                 :            :         // get the nodes for the triangle
     282 [ #  # ][ #  # ]:          0 :         EntityHandle tri_nodes[3] = { mb_coords[tmp.connectivity[0] - 1], mb_coords[tmp.connectivity[1] - 1],
     283         [ #  # ]:          0 :                                       mb_coords[tmp.connectivity[2] - 1] };
     284                 :            :         // create a triangle element
     285         [ #  # ]:          0 :         rval = MBI->create_element( MBTRI, tri_nodes, 3, triangle );
     286                 :            :         // tag in side id on the triangle
     287         [ #  # ]:          0 :         rval = MBI->tag_set_data( side_id_tag, &triangle, 1, &tmp.side_id );
     288                 :            :         // tag the surface number on the triangle
     289         [ #  # ]:          0 :         rval = MBI->tag_set_data( surface_number_tag, &triangle, 1, &tmp.surface_number );
     290                 :            :         // insert vertices and triangles into the appropriate surface meshset
     291         [ #  # ]:          0 :         EntityHandle meshset_handle = surface_map[tmp.surface_number];
     292                 :            :         // also set surface tag
     293         [ #  # ]:          0 :         rval = MBI->tag_set_data( side_id_tag, &meshset_handle, 1, &tmp.side_id );
     294         [ #  # ]:          0 :         rval = MBI->tag_set_data( surface_number_tag, &meshset_handle, 1, &tmp.surface_number );
     295                 :            :         // add vertices to the mesh
     296         [ #  # ]:          0 :         rval = MBI->add_entities( meshset_handle, &( *tri_nodes ), 3 );
     297                 :            :         // add triangles to the meshset
     298         [ #  # ]:          0 :         rval = MBI->add_entities( meshset_handle, &triangle, 1 );
     299                 :            :         // ineter triangles into large run
     300         [ #  # ]:          0 :         mb_tris.insert( triangle );
     301                 :            :     }
     302                 :            :     // add tris to set to fileset
     303         [ #  # ]:          0 :     rval = MBI->add_entities( file_set, mb_tris );
     304                 :            : 
     305                 :            :     // create material number tag
     306                 :            :     Tag mat_num_tag;
     307                 :            :     //  int zero = 0;
     308         [ #  # ]:          0 :     rval = MBI->tag_get_handle( "MATERIAL_NUMBER", 1, MB_TYPE_INTEGER, mat_num_tag, MB_TAG_SPARSE | MB_TAG_CREAT );
     309                 :            : 
     310                 :            :     // create the tets
     311                 :            :     EntityHandle tetra;  // handle for a specific tet
     312                 :          0 :     std::vector< tet >::iterator it_t;
     313         [ #  # ]:          0 :     Range mb_tets;
     314                 :            :     // loop over all tets
     315 [ #  # ][ #  # ]:          0 :     for( it_t = tet_data.begin(); it_t != tet_data.end(); ++it_t )
                 [ #  # ]
     316                 :            :     {
     317         [ #  # ]:          0 :         tet tmp = *it_t;
     318                 :            :         // get the handles for the tet
     319 [ #  # ][ #  # ]:          0 :         EntityHandle tet_nodes[4] = { mb_coords[tmp.connectivity[0] - 1], mb_coords[tmp.connectivity[1] - 1],
     320 [ #  # ][ #  # ]:          0 :                                       mb_coords[tmp.connectivity[2] - 1], mb_coords[tmp.connectivity[3] - 1] };
     321                 :            :         // create the tet
     322         [ #  # ]:          0 :         rval           = MBI->create_element( MBTET, tet_nodes, 4, tetra );
     323                 :          0 :         int mat_number = tmp.material_number;
     324                 :            :         // tag the tet with the material number
     325         [ #  # ]:          0 :         rval = MBI->tag_set_data( mat_num_tag, &tetra, 1, &mat_number );
     326                 :            :         // set the tag data
     327         [ #  # ]:          0 :         mb_tets.insert( tetra );
     328                 :            :     }
     329                 :            :     // add tris to set
     330         [ #  # ]:          0 :     rval = MBI->add_entities( file_set, mb_tets );
     331                 :            : 
     332                 :          0 :     return MB_SUCCESS;
     333                 :            : }
     334                 :            : 
     335                 :            : /*
     336                 :            :  * read the header data from the filename pointed to
     337                 :            :  */
     338                 :          1 : ErrorCode ReadRTT::read_header( const char* filename )
     339                 :            : {
     340         [ +  - ]:          1 :     std::ifstream input_file( filename );  // filename for rtt file
     341                 :            :     // file ok?
     342 [ +  - ][ -  + ]:          1 :     if( !input_file.good() )
     343                 :            :     {
     344 [ #  # ][ #  # ]:          0 :         std::cout << "Problems reading file = " << filename << std::endl;
                 [ #  # ]
     345                 :          0 :         return MB_FAILURE;
     346                 :            :     }
     347                 :            : 
     348                 :            :     // if it works
     349         [ +  - ]:          2 :     std::string line;
     350                 :          1 :     moab::ErrorCode rval = MB_FAILURE;
     351 [ +  - ][ +  - ]:          1 :     if( input_file.is_open() )
     352                 :            :     {
     353 [ +  - ][ +  - ]:     261917 :         while( std::getline( input_file, line ) )
                 [ +  + ]
     354                 :            :         {
     355 [ +  - ][ -  + ]:     261916 :             if( line.compare( "header" ) == 0 ) { rval = get_header_data( input_file ); }
                 [ #  # ]
     356                 :            :         }
     357         [ +  - ]:          1 :         input_file.close();
     358                 :            :     }
     359                 :          1 :     return rval;
     360                 :            : }
     361                 :            : 
     362                 :            : /*
     363                 :            :  * reads the side data from the filename pointed to
     364                 :            :  */
     365                 :          0 : ErrorCode ReadRTT::read_sides( const char* filename, std::vector< side >& side_data )
     366                 :            : {
     367         [ #  # ]:          0 :     std::string line;                      // the current line being read
     368         [ #  # ]:          0 :     std::ifstream input_file( filename );  // filestream for rttfile
     369                 :            :     // file ok?
     370 [ #  # ][ #  # ]:          0 :     if( !input_file.good() )
     371                 :            :     {
     372 [ #  # ][ #  # ]:          0 :         std::cout << "Problems reading file = " << filename << std::endl;
                 [ #  # ]
     373                 :          0 :         return MB_FAILURE;
     374                 :            :     }
     375                 :            :     // if it works
     376 [ #  # ][ #  # ]:          0 :     if( input_file.is_open() )
     377                 :            :     {
     378 [ #  # ][ #  # ]:          0 :         while( std::getline( input_file, line ) )
                 [ #  # ]
     379                 :            :         {
     380 [ #  # ][ #  # ]:          0 :             if( line.compare( "  2 FACES\0" ) == 0 )
     381                 :            :             {
     382                 :            :                 // read lines until find end nodes
     383 [ #  # ][ #  # ]:          0 :                 while( std::getline( input_file, line ) )
                 [ #  # ]
     384                 :            :                 {
     385 [ #  # ][ #  # ]:          0 :                     if( line.compare( "end_side_flags\0" ) == 0 ) break;
     386 [ #  # ][ #  # ]:          0 :                     side data = ReadRTT::get_side_data( line );
     387         [ #  # ]:          0 :                     side_data.push_back( data );
     388                 :          0 :                 }
     389                 :            :             }
     390                 :            :         }
     391         [ #  # ]:          0 :         input_file.close();
     392                 :            :     }
     393         [ #  # ]:          0 :     if( side_data.size() == 0 ) return MB_FAILURE;
     394                 :          0 :     return MB_SUCCESS;
     395                 :            : }
     396                 :            : 
     397                 :            : /*
     398                 :            :  * reads the cell data from the filename pointed to
     399                 :            :  */
     400                 :          0 : ErrorCode ReadRTT::read_cells( const char* filename, std::vector< cell >& cell_data )
     401                 :            : {
     402         [ #  # ]:          0 :     std::string line;                      // the current line being read
     403         [ #  # ]:          0 :     std::ifstream input_file( filename );  // filestream for rttfile
     404                 :            :     // file ok?
     405 [ #  # ][ #  # ]:          0 :     if( !input_file.good() )
     406                 :            :     {
     407 [ #  # ][ #  # ]:          0 :         std::cout << "Problems reading file = " << filename << std::endl;
                 [ #  # ]
     408                 :          0 :         return MB_FAILURE;
     409                 :            :     }
     410                 :            :     // if it works
     411 [ #  # ][ #  # ]:          0 :     if( input_file.is_open() )
     412                 :            :     {
     413 [ #  # ][ #  # ]:          0 :         while( std::getline( input_file, line ) )
                 [ #  # ]
     414                 :            :         {
     415 [ #  # ][ #  # ]:          0 :             if( line.compare( "  1 REGIONS\0" ) == 0 )
     416                 :            :             {
     417                 :            :                 // read lines until find end nodes
     418 [ #  # ][ #  # ]:          0 :                 while( std::getline( input_file, line ) )
                 [ #  # ]
     419                 :            :                 {
     420 [ #  # ][ #  # ]:          0 :                     if( line.compare( "end_cell_flags\0" ) == 0 ) break;
     421 [ #  # ][ #  # ]:          0 :                     cell data = ReadRTT::get_cell_data( line );
     422         [ #  # ]:          0 :                     cell_data.push_back( data );
     423                 :          0 :                 }
     424                 :            :             }
     425                 :            :         }
     426         [ #  # ]:          0 :         input_file.close();
     427                 :            :     }
     428         [ #  # ]:          0 :     if( cell_data.size() == 0 ) return MB_FAILURE;
     429                 :          0 :     return MB_SUCCESS;
     430                 :            : }
     431                 :            : 
     432                 :            : /*
     433                 :            :  * Reads the node data fromt the filename pointed to
     434                 :            :  */
     435                 :          0 : ErrorCode ReadRTT::read_nodes( const char* filename, std::vector< node >& node_data )
     436                 :            : {
     437         [ #  # ]:          0 :     std::string line;                      // the current line being read
     438         [ #  # ]:          0 :     std::ifstream input_file( filename );  // filestream for rttfile
     439                 :            :     // file ok?
     440 [ #  # ][ #  # ]:          0 :     if( !input_file.good() )
     441                 :            :     {
     442 [ #  # ][ #  # ]:          0 :         std::cout << "Problems reading file = " << filename << std::endl;
                 [ #  # ]
     443                 :          0 :         return MB_FAILURE;
     444                 :            :     }
     445                 :            : 
     446                 :            :     // if it works
     447 [ #  # ][ #  # ]:          0 :     if( input_file.is_open() )
     448                 :            :     {
     449 [ #  # ][ #  # ]:          0 :         while( std::getline( input_file, line ) )
                 [ #  # ]
     450                 :            :         {
     451 [ #  # ][ #  # ]:          0 :             if( line.compare( "nodes\0" ) == 0 )
     452                 :            :             {
     453                 :            :                 // read lines until find end nodes
     454 [ #  # ][ #  # ]:          0 :                 while( std::getline( input_file, line ) )
                 [ #  # ]
     455                 :            :                 {
     456 [ #  # ][ #  # ]:          0 :                     if( line.compare( "end_nodes\0" ) == 0 ) break;
     457 [ #  # ][ #  # ]:          0 :                     node data = ReadRTT::get_node_data( line );
     458         [ #  # ]:          0 :                     node_data.push_back( data );
     459                 :            :                 }
     460                 :            :             }
     461                 :            :         }
     462         [ #  # ]:          0 :         input_file.close();
     463                 :            :     }
     464         [ #  # ]:          0 :     if( node_data.size() == 0 ) return MB_FAILURE;
     465                 :          0 :     return MB_SUCCESS;
     466                 :            : }
     467                 :            : 
     468                 :            : /*
     469                 :            :  * Reads the facet data fromt the filename pointed to
     470                 :            :  */
     471                 :          0 : ErrorCode ReadRTT::read_facets( const char* filename, std::vector< facet >& facet_data )
     472                 :            : {
     473         [ #  # ]:          0 :     std::string line;                      // the current line being read
     474         [ #  # ]:          0 :     std::ifstream input_file( filename );  // filestream for rttfile
     475                 :            :     // file ok?
     476 [ #  # ][ #  # ]:          0 :     if( !input_file.good() )
     477                 :            :     {
     478 [ #  # ][ #  # ]:          0 :         std::cout << "Problems reading file = " << filename << std::endl;
                 [ #  # ]
     479                 :          0 :         return MB_FAILURE;
     480                 :            :     }
     481                 :            : 
     482                 :            :     // if it works
     483 [ #  # ][ #  # ]:          0 :     if( input_file.is_open() )
     484                 :            :     {
     485 [ #  # ][ #  # ]:          0 :         while( std::getline( input_file, line ) )
                 [ #  # ]
     486                 :            :         {
     487 [ #  # ][ #  # ]:          0 :             if( line.compare( "sides\0" ) == 0 )
     488                 :            :             {
     489                 :            :                 // read lines until find end nodes
     490 [ #  # ][ #  # ]:          0 :                 while( std::getline( input_file, line ) )
                 [ #  # ]
     491                 :            :                 {
     492 [ #  # ][ #  # ]:          0 :                     if( line.compare( "end_sides\0" ) == 0 ) break;
     493 [ #  # ][ #  # ]:          0 :                     facet data = ReadRTT::get_facet_data( line );
     494         [ #  # ]:          0 :                     facet_data.push_back( data );
     495                 :            :                 }
     496                 :            :             }
     497                 :            :         }
     498         [ #  # ]:          0 :         input_file.close();
     499                 :            :     }
     500         [ #  # ]:          0 :     if( facet_data.size() == 0 ) return MB_FAILURE;
     501                 :          0 :     return MB_SUCCESS;
     502                 :            : }
     503                 :            : 
     504                 :            : /*
     505                 :            :  * Reads the facet data fromt the filename pointed to
     506                 :            :  */
     507                 :          0 : ErrorCode ReadRTT::read_tets( const char* filename, std::vector< tet >& tet_data )
     508                 :            : {
     509         [ #  # ]:          0 :     std::string line;                      // the current line being read
     510         [ #  # ]:          0 :     std::ifstream input_file( filename );  // filestream for rttfile
     511                 :            :     // file ok?
     512 [ #  # ][ #  # ]:          0 :     if( !input_file.good() )
     513                 :            :     {
     514 [ #  # ][ #  # ]:          0 :         std::cout << "Problems reading file = " << filename << std::endl;
                 [ #  # ]
     515                 :          0 :         return MB_FAILURE;
     516                 :            :     }
     517                 :            :     // if it works
     518 [ #  # ][ #  # ]:          0 :     if( input_file.is_open() )
     519                 :            :     {
     520 [ #  # ][ #  # ]:          0 :         while( std::getline( input_file, line ) )
                 [ #  # ]
     521                 :            :         {
     522 [ #  # ][ #  # ]:          0 :             if( line.compare( "cells\0" ) == 0 )
     523                 :            :             {
     524                 :            :                 // read lines until find end nodes
     525 [ #  # ][ #  # ]:          0 :                 while( std::getline( input_file, line ) )
                 [ #  # ]
     526                 :            :                 {
     527 [ #  # ][ #  # ]:          0 :                     if( line.compare( "end_cells\0" ) == 0 ) break;
     528 [ #  # ][ #  # ]:          0 :                     tet data = ReadRTT::get_tet_data( line );
     529         [ #  # ]:          0 :                     tet_data.push_back( data );
     530                 :            :                 }
     531                 :            :             }
     532                 :            :         }
     533         [ #  # ]:          0 :         input_file.close();
     534                 :            :     }
     535         [ #  # ]:          0 :     if( tet_data.size() == 0 ) return MB_FAILURE;
     536                 :          0 :     return MB_SUCCESS;
     537                 :            : }
     538                 :            : 
     539                 :            : /*
     540                 :            :  * given the open file handle read until we find
     541                 :            :  */
     542                 :          0 : ErrorCode ReadRTT::get_header_data( std::ifstream& input_file )
     543                 :            : {
     544         [ #  # ]:          0 :     std::string line;
     545 [ #  # ][ #  # ]:          0 :     while( std::getline( input_file, line ) )
                 [ #  # ]
     546                 :            :     {
     547                 :            : 
     548                 :            :         // tokenize the line
     549         [ #  # ]:          0 :         std::istringstream iss( line );
     550 [ #  # ][ #  # ]:          0 :         std::vector< std::string > split_string;
     551         [ #  # ]:          0 :         do
     552                 :            :         {
     553         [ #  # ]:          0 :             std::string sub_string;
     554         [ #  # ]:          0 :             iss >> sub_string;
     555         [ #  # ]:          0 :             split_string.push_back( sub_string );
     556         [ #  # ]:          0 :         } while( iss );
     557                 :            : 
     558                 :            :         // if we find version
     559 [ #  # ][ #  # ]:          0 :         if( line.find( "version" ) != std::string::npos )
     560                 :            :         {
     561 [ #  # ][ #  # ]:          0 :             if( split_string[1].find( "v" ) != std::string::npos &&
         [ #  # ][ #  # ]
                 [ #  # ]
     562 [ #  # ][ #  # ]:          0 :                 split_string[0].find( "version" ) != std::string::npos )
     563 [ #  # ][ #  # ]:          0 :             { header_data.version = split_string[1]; }
     564                 :            :         }
     565                 :            : 
     566 [ #  # ][ #  # ]:          0 :         if( line.find( "title" ) != std::string::npos ) { header_data.title = split_string[1]; }
         [ #  # ][ #  # ]
     567 [ #  # ][ #  # ]:          0 :         if( line.find( "date" ) != std::string::npos ) { header_data.date = split_string[1]; }
         [ #  # ][ #  # ]
     568 [ #  # ][ #  # ]:          0 :         if( line.find( "end_header" ) != std::string::npos ) { return MB_SUCCESS; }
                 [ #  # ]
     569                 :          0 :     }
     570                 :            : 
     571                 :            :     // otherwise we never found the end_header keyword
     572                 :          0 :     return MB_FAILURE;
     573                 :            : }
     574                 :            : 
     575                 :            : /*
     576                 :            :  * given the string sidedata, get the id number, senses and names of the sides
     577                 :            :  */
     578                 :          0 : ReadRTT::side ReadRTT::get_side_data( std::string sidedata )
     579                 :            : {
     580         [ #  # ]:          0 :     side new_side;
     581         [ #  # ]:          0 :     std::vector< std::string > tokens;
     582 [ #  # ][ #  # ]:          0 :     tokens = ReadRTT::split_string( sidedata, ' ' );
     583                 :            : 
     584                 :          0 :     std::vector< std::string >::iterator it;
     585                 :            :     // set the side id
     586 [ #  # ][ #  # ]:          0 :     if( tokens.size() != 2 ) { MB_SET_ERR_RET_VAL( "Error, too many tokens found from side_data", new_side ); }
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     587                 :            :     // create the new side
     588         [ #  # ]:          0 :     new_side.id = std::atoi( tokens[0].c_str() );
     589                 :            : 
     590 [ #  # ][ #  # ]:          0 :     std::vector< std::string > cell_names = ReadRTT::split_string( tokens[1], '/' );
                 [ #  # ]
     591                 :            :     // get the boundary
     592 [ #  # ][ #  # ]:          0 :     boundary new_bnd = ReadRTT::split_name( cell_names[0] );
                 [ #  # ]
     593                 :            :     // set the surface sense and name
     594                 :          0 :     new_side.senses[0] = new_bnd.sense;
     595         [ #  # ]:          0 :     new_side.names[0]  = new_bnd.name;
     596                 :            :     //
     597         [ #  # ]:          0 :     if( cell_names.size() > 1 )
     598                 :            :     {
     599 [ #  # ][ #  # ]:          0 :         boundary bnd       = ReadRTT::split_name( cell_names[1] );
                 [ #  # ]
     600                 :          0 :         new_side.senses[1] = bnd.sense;
     601         [ #  # ]:          0 :         new_side.names[1]  = bnd.name;
     602                 :            :     }
     603                 :            :     else
     604                 :            :     {
     605                 :          0 :         new_side.senses[1] = 0;
     606         [ #  # ]:          0 :         new_side.names[1]  = "\0";
     607                 :            :     }
     608                 :            : 
     609                 :          0 :     return new_side;
     610                 :            : }
     611                 :            : 
     612                 :            : /*
     613                 :            :  * given the string celldata, get the id number and name of each cell
     614                 :            :  */
     615                 :          0 : ReadRTT::cell ReadRTT::get_cell_data( std::string celldata )
     616                 :            : {
     617         [ #  # ]:          0 :     cell new_cell;
     618         [ #  # ]:          0 :     std::vector< std::string > tokens;
     619 [ #  # ][ #  # ]:          0 :     tokens = ReadRTT::split_string( celldata, ' ' );
     620                 :            : 
     621                 :          0 :     std::vector< std::string >::iterator it;
     622                 :            : 
     623                 :            :     // set the side id
     624 [ #  # ][ #  # ]:          0 :     if( tokens.size() != 2 ) { MB_SET_ERR_RET_VAL( "Error, too many tokens found from cell_data", new_cell ); }
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     625                 :            :     // create the new side
     626         [ #  # ]:          0 :     new_cell.id   = std::atoi( tokens[0].c_str() );
     627 [ #  # ][ #  # ]:          0 :     new_cell.name = tokens[1];
     628                 :            : 
     629                 :          0 :     return new_cell;
     630                 :            : }
     631                 :            : 
     632                 :            : /*
     633                 :            :  * given the string nodedata, get the id number and coordinates of the node
     634                 :            :  */
     635                 :          0 : ReadRTT::node ReadRTT::get_node_data( std::string nodedata )
     636                 :            : {
     637         [ #  # ]:          0 :     node new_node;
     638         [ #  # ]:          0 :     std::vector< std::string > tokens;
     639 [ #  # ][ #  # ]:          0 :     tokens = ReadRTT::split_string( nodedata, ' ' );
     640                 :            : 
     641                 :            :     // set the side id
     642 [ #  # ][ #  # ]:          0 :     if( tokens.size() != 5 ) { MB_SET_ERR_RET_VAL( "Error, too many tokens found from get_node_data", new_node ); }
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     643                 :          0 :     std::vector< std::string >::iterator it;
     644         [ #  # ]:          0 :     new_node.id = std::atoi( tokens[0].c_str() );
     645         [ #  # ]:          0 :     new_node.x  = std::atof( tokens[1].c_str() );
     646         [ #  # ]:          0 :     new_node.y  = std::atof( tokens[2].c_str() );
     647         [ #  # ]:          0 :     new_node.z  = std::atof( tokens[3].c_str() );
     648                 :          0 :     return new_node;
     649                 :            : }
     650                 :            : 
     651                 :            : /*
     652                 :            :  * given the string nodedata, get the id number, connectivity and sense data
     653                 :            :  */
     654                 :          0 : ReadRTT::facet ReadRTT::get_facet_data( std::string facetdata )
     655                 :            : {
     656         [ #  # ]:          0 :     facet new_facet;
     657         [ #  # ]:          0 :     std::vector< std::string > tokens;
     658 [ #  # ][ #  # ]:          0 :     tokens = ReadRTT::split_string( facetdata, ' ' );
     659                 :            : 
     660                 :            :     // set the side id
     661 [ #  # ][ #  # ]:          0 :     if( tokens.size() != 7 ) { MB_SET_ERR_RET_VAL( "Error, too many tokens found from get_facet_data", new_facet ); }
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     662                 :            : 
     663         [ #  # ]:          0 :     new_facet.id = std::atoi( tokens[0].c_str() );
     664                 :            :     // branch on the rtt version number
     665 [ #  # ][ #  # ]:          0 :     if( header_data.version == "v1.0.0" )
     666                 :            :     {
     667         [ #  # ]:          0 :         new_facet.connectivity[0] = std::atoi( tokens[1].c_str() );
     668         [ #  # ]:          0 :         new_facet.connectivity[1] = std::atoi( tokens[2].c_str() );
     669         [ #  # ]:          0 :         new_facet.connectivity[2] = std::atoi( tokens[3].c_str() );
     670         [ #  # ]:          0 :         new_facet.side_id         = std::atoi( tokens[4].c_str() );
     671         [ #  # ]:          0 :         new_facet.surface_number  = std::atoi( tokens[5].c_str() );
     672                 :            :     }
     673 [ #  # ][ #  # ]:          0 :     else if( header_data.version == "v1.0.1" )
     674                 :            :     {
     675         [ #  # ]:          0 :         new_facet.connectivity[0] = std::atoi( tokens[2].c_str() );
     676         [ #  # ]:          0 :         new_facet.connectivity[1] = std::atoi( tokens[3].c_str() );
     677         [ #  # ]:          0 :         new_facet.connectivity[2] = std::atoi( tokens[4].c_str() );
     678         [ #  # ]:          0 :         new_facet.side_id         = std::atoi( tokens[5].c_str() );
     679         [ #  # ]:          0 :         new_facet.surface_number  = std::atoi( tokens[6].c_str() );
     680                 :            :     }
     681                 :            :     else
     682                 :            :     {
     683 [ #  # ][ #  # ]:          0 :         MB_SET_ERR_RET_VAL( "Error, version number not understood", new_facet );
         [ #  # ][ #  # ]
                 [ #  # ]
     684                 :            :     }
     685                 :            : 
     686                 :          0 :     return new_facet;
     687                 :            : }
     688                 :            : 
     689                 :            : /*
     690                 :            :  * given the string tetdata, get the id number, connectivity and mat num of the tet
     691                 :            :  */
     692                 :          0 : ReadRTT::tet ReadRTT::get_tet_data( std::string tetdata )
     693                 :            : {
     694         [ #  # ]:          0 :     tet new_tet;
     695         [ #  # ]:          0 :     std::vector< std::string > tokens;
     696 [ #  # ][ #  # ]:          0 :     tokens = ReadRTT::split_string( tetdata, ' ' );
     697                 :            : 
     698                 :            :     // set the side id
     699 [ #  # ][ #  # ]:          0 :     if( tokens.size() != 7 ) { MB_SET_ERR_RET_VAL( "Error, too many tokens found from get_tet_data", new_tet ); }
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     700         [ #  # ]:          0 :     new_tet.id = std::atoi( tokens[0].c_str() );
     701                 :            :     // branch on the version number
     702 [ #  # ][ #  # ]:          0 :     if( header_data.version == "v1.0.0" )
     703                 :            :     {
     704         [ #  # ]:          0 :         new_tet.connectivity[0] = std::atoi( tokens[1].c_str() );
     705         [ #  # ]:          0 :         new_tet.connectivity[1] = std::atoi( tokens[2].c_str() );
     706         [ #  # ]:          0 :         new_tet.connectivity[2] = std::atoi( tokens[3].c_str() );
     707         [ #  # ]:          0 :         new_tet.connectivity[3] = std::atoi( tokens[4].c_str() );
     708         [ #  # ]:          0 :         new_tet.material_number = std::atoi( tokens[5].c_str() );
     709                 :            :     }
     710 [ #  # ][ #  # ]:          0 :     else if( header_data.version == "v1.0.1" )
     711                 :            :     {
     712         [ #  # ]:          0 :         new_tet.connectivity[0] = std::atoi( tokens[2].c_str() );
     713         [ #  # ]:          0 :         new_tet.connectivity[1] = std::atoi( tokens[3].c_str() );
     714         [ #  # ]:          0 :         new_tet.connectivity[2] = std::atoi( tokens[4].c_str() );
     715         [ #  # ]:          0 :         new_tet.connectivity[3] = std::atoi( tokens[5].c_str() );
     716         [ #  # ]:          0 :         new_tet.material_number = std::atoi( tokens[6].c_str() );
     717                 :            :     }
     718                 :            :     else
     719                 :            :     {
     720 [ #  # ][ #  # ]:          0 :         MB_SET_ERR_RET_VAL( "Error, version number not supported", new_tet );
         [ #  # ][ #  # ]
                 [ #  # ]
     721                 :            :     }
     722                 :            : 
     723                 :          0 :     return new_tet;
     724                 :            : }
     725                 :            : 
     726                 :            : /*
     727                 :            :  * splits string into sense and name, to later facilitate the building
     728                 :            :  * of sense data, strips off the tailing @ if it exists
     729                 :            :  */
     730                 :          0 : ReadRTT::boundary ReadRTT::split_name( std::string atilla_cellname )
     731                 :            : {
     732                 :          0 :     boundary new_boundary;
     733                 :            :     // default initialisation
     734                 :          0 :     new_boundary.sense = 0;
     735         [ #  # ]:          0 :     new_boundary.name  = "\0";
     736                 :            :     // +ve sense
     737 [ #  # ][ #  # ]:          0 :     if( atilla_cellname.find( "+" ) != std::string::npos )
     738                 :            :     {
     739                 :          0 :         new_boundary.sense = 1;
     740                 :            :         // look for the @# we do not want it
     741         [ #  # ]:          0 :         std::size_t found = atilla_cellname.find( "@" );
     742         [ #  # ]:          0 :         if( found != std::string::npos )
     743 [ #  # ][ #  # ]:          0 :             new_boundary.name = atilla_cellname.substr( 3, found );
     744                 :            :         else
     745 [ #  # ][ #  # ]:          0 :             new_boundary.name = atilla_cellname.substr( 3, atilla_cellname.length() );
     746                 :            :     }
     747 [ #  # ][ #  # ]:          0 :     else if( atilla_cellname.find( "-" ) != std::string::npos )
     748                 :            :     {
     749                 :            :         // negative sense
     750                 :          0 :         new_boundary.sense = -1;
     751 [ #  # ][ #  # ]:          0 :         new_boundary.name  = atilla_cellname.substr( 3, atilla_cellname.length() );
     752                 :            :     }
     753                 :          0 :     return new_boundary;
     754                 :            : }
     755                 :            : 
     756                 :            : /*
     757                 :            :  * splits a string in a vector of strings split by spaces
     758                 :            :  */
     759                 :          0 : std::vector< std::string > ReadRTT::split_string( std::string string_to_split, char split_char )
     760                 :            : {
     761         [ #  # ]:          0 :     std::istringstream ss( string_to_split );
     762         [ #  # ]:          0 :     std::vector< std::string > tokens;
     763 [ #  # ][ #  # ]:          0 :     while( !ss.eof() )
     764                 :            :     {
     765         [ #  # ]:          0 :         std::string x;                      // here's a nice, empty string
     766         [ #  # ]:          0 :         std::getline( ss, x, split_char );  // try to read the next field into it
     767         [ #  # ]:          0 :         tokens.push_back( x );
     768                 :          0 :     }
     769                 :            : 
     770                 :            :     // remove empty tokens
     771                 :          0 :     std::vector< std::string >::iterator it;
     772 [ #  # ][ #  # ]:          0 :     for( it = tokens.begin(); it != tokens.end(); )
     773                 :            :     {
     774 [ #  # ][ #  # ]:          0 :         std::string string = *it;
     775 [ #  # ][ #  # ]:          0 :         if( string.compare( "\0" ) == 0 )
     776         [ #  # ]:          0 :             it = tokens.erase( it );
     777                 :            :         else
     778         [ #  # ]:          0 :             ++it;
     779                 :          0 :     }
     780                 :          0 :     return tokens;
     781                 :            : }
     782                 :            : 
     783                 :            : /*
     784                 :            :  * Generate the parent-child links bwetween the cell and surface meshsets
     785                 :            :  */
     786                 :          0 : void ReadRTT::generate_parent_child_links( int num_ents[4], std::vector< EntityHandle > entity_map[4],
     787                 :            :                                            std::vector< side > side_data, std::vector< cell > cell_data )
     788                 :            : {
     789                 :            :     ErrorCode rval;  // return value
     790                 :            :     // loop over the number of surfaces
     791         [ #  # ]:          0 :     for( int i = 0; i < num_ents[2]; i++ )
     792                 :            :     {
     793                 :            :         // get the surface handle
     794                 :          0 :         EntityHandle surf_handle = entity_map[2][i];
     795                 :            :         // there are volumes that share this face
     796         [ #  # ]:          0 :         for( unsigned int shared = 0; shared <= 1; shared++ )
     797                 :            :         {
     798 [ #  # ][ #  # ]:          0 :             std::string parent_name = side_data[i].names[shared];
     799                 :            :             // find the @ sign
     800         [ #  # ]:          0 :             unsigned pos = parent_name.find( "@" );
     801 [ #  # ][ #  # ]:          0 :             parent_name  = parent_name.substr( 0, pos );
     802                 :            : 
     803                 :            :             // loop over tets looking for matching name
     804         [ #  # ]:          0 :             for( int j = 0; j < num_ents[3]; j++ )
     805                 :            :             {
     806                 :            :                 // if match found
     807 [ #  # ][ #  # ]:          0 :                 if( cell_data[j].name.compare( parent_name ) == 0 )
                 [ #  # ]
     808                 :            :                 {
     809         [ #  # ]:          0 :                     EntityHandle cell_handle = entity_map[3][j];
     810                 :            :                     // parent
     811         [ #  # ]:          0 :                     rval = MBI->add_parent_child( cell_handle, surf_handle );
     812 [ #  # ][ #  # ]:          0 :                     if( rval != MB_SUCCESS ) { std::cerr << "Failed to add parent child relationship" << std::endl; }
                 [ #  # ]
     813                 :            :                 }
     814                 :            :             }
     815                 :          0 :         }
     816                 :            :     }
     817                 :          0 :     return;
     818                 :            : }
     819                 :            : 
     820                 :            : /*
     821                 :            :  * sets the sense of the surfaces wrt to volumes using geom topo tool
     822                 :            :  */
     823                 :          0 : void ReadRTT::set_surface_senses( int num_ents[4], std::vector< EntityHandle > entity_map[4],
     824                 :            :                                   std::vector< side > side_data, std::vector< cell > cell_data )
     825                 :            : {
     826                 :            : 
     827                 :            :     ErrorCode rval;  // return value
     828                 :            :     // loop over the number of surfaces
     829         [ #  # ]:          0 :     for( int i = 0; i < num_ents[2]; i++ )
     830                 :            :     {
     831                 :          0 :         EntityHandle surf_handle = entity_map[2][i];
     832                 :            :         // there are 2 volumes that share this face
     833         [ #  # ]:          0 :         for( unsigned int shared = 0; shared <= 1; shared++ )
     834                 :            :         {
     835 [ #  # ][ #  # ]:          0 :             std::string parent_name = side_data[i].names[shared];
     836         [ #  # ]:          0 :             unsigned pos            = parent_name.find( "@" );
     837 [ #  # ][ #  # ]:          0 :             parent_name             = parent_name.substr( 0, pos );
     838                 :            :             // loop over tets looking for matching name
     839         [ #  # ]:          0 :             for( int j = 0; j < num_ents[3]; j++ )
     840                 :            :             {
     841                 :            :                 // if match found
     842 [ #  # ][ #  # ]:          0 :                 if( cell_data[j].name.compare( parent_name ) == 0 )
                 [ #  # ]
     843                 :            :                 {
     844         [ #  # ]:          0 :                     EntityHandle cell_handle = entity_map[3][j];
     845                 :            :                     // in rtt mesh +represents the inside and -represents outside
     846                 :            :                     // in moab reverse is outside and forward is inside
     847 [ #  # ][ #  # ]:          0 :                     if( side_data[i].senses[shared] == 1 )
     848         [ #  # ]:          0 :                         rval = myGeomTool->set_sense( surf_handle, cell_handle, SENSE_FORWARD );
     849 [ #  # ][ #  # ]:          0 :                     else if( side_data[i].senses[shared] == -1 )
     850         [ #  # ]:          0 :                         rval = myGeomTool->set_sense( surf_handle, cell_handle, SENSE_REVERSE );
     851                 :            :                     else
     852         [ #  # ]:          0 :                         rval = myGeomTool->set_sense( surf_handle, 0, SENSE_REVERSE );
     853                 :            : 
     854 [ #  # ][ #  # ]:          0 :                     if( rval != MB_SUCCESS ) { std::cerr << "Failed to set sense appropriately" << std::endl; }
                 [ #  # ]
     855                 :            :                 }
     856                 :            :             }
     857                 :          0 :         }
     858                 :            :     }
     859                 :          0 :     return;
     860                 :            : }
     861                 :            : 
     862                 :            : /*
     863                 :            :  * Add all entities that are to be part of the graveyard
     864                 :            :  */
     865                 :          0 : ErrorCode ReadRTT::setup_group_data( std::vector< EntityHandle > entity_map[4] )
     866                 :            : {
     867                 :            :     ErrorCode rval;  // error codes
     868                 :            :     EntityHandle handle;
     869 [ #  # ][ #  # ]:          0 :     handle = create_group( "graveyard_comp", 1 );
     870                 :            : 
     871                 :            :     // add any volume to group graveyard, it is ignored by dag
     872         [ #  # ]:          0 :     EntityHandle vol_handle = entity_map[3][0];
     873         [ #  # ]:          0 :     rval                    = MBI->add_entities( handle, &vol_handle, 1 );
     874                 :          0 :     return rval;
     875                 :            : }
     876                 :            : 
     877                 :            : /*
     878                 :            :  * create a new group of with the name group name and id
     879                 :            :  */
     880                 :          0 : EntityHandle ReadRTT::create_group( std::string group_name, int id )
     881                 :            : {
     882                 :            :     ErrorCode rval;
     883                 :            :     // category tags
     884                 :          0 :     const char geom_categories[][CATEGORY_TAG_SIZE] = { "Vertex\0", "Curve\0", "Surface\0", "Volume\0", "Group\0" };
     885                 :            : 
     886                 :            :     EntityHandle handle;
     887         [ #  # ]:          0 :     rval = MBI->create_meshset( MESHSET_SET, handle );
     888         [ #  # ]:          0 :     if( MB_SUCCESS != rval ) return rval;
     889                 :            : 
     890         [ #  # ]:          0 :     rval = MBI->tag_set_data( name_tag, &handle, 1, group_name.c_str() );
     891         [ #  # ]:          0 :     if( MB_SUCCESS != rval ) return MB_FAILURE;
     892                 :            : 
     893         [ #  # ]:          0 :     rval = MBI->tag_set_data( id_tag, &handle, 1, &id );
     894         [ #  # ]:          0 :     if( MB_SUCCESS != rval ) return MB_FAILURE;
     895                 :            : 
     896         [ #  # ]:          0 :     rval = MBI->tag_set_data( category_tag, &handle, 1, &geom_categories[4] );
     897         [ #  # ]:          0 :     if( MB_SUCCESS != rval ) return MB_FAILURE;
     898                 :            : 
     899                 :          0 :     return handle;
     900                 :            : }
     901                 :            : 
     902 [ +  - ][ +  - ]:        228 : }  // namespace moab

Generated by: LCOV version 1.11