moab
moab::ReadSms Class Reference

#include <ReadSms.hpp>

Inheritance diagram for moab::ReadSms:
moab::ReaderIface

List of all members.

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.
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.
 ReadSms (Interface *impl=NULL)
 Constructor.
virtual ~ReadSms ()
 Destructor.

Static Public Member Functions

static ReaderIfacefactory (Interface *)
 factory method

Private Member Functions

ErrorCode add_entities (EntityHandle start, EntityHandle count, const Tag *file_id_tag)
ErrorCode load_file_impl (FILE *file, const Tag *file_id_tag)
ErrorCode get_set (std::vector< EntityHandle > *sets, int set_type, int set_id, Tag set_tag, EntityHandle &this_set, const Tag *file_id_tag)
ErrorCode read_parallel_info (FILE *file_ptr)

Private Attributes

ReadUtilIfacereadMeshIface
InterfacemdbImpl
 interface instance
Tag globalId
Tag paramCoords
Tag geomDimension
int setId

Detailed Description

Definition at line 14 of file ReadSms.hpp.


Constructor & Destructor Documentation

ReadSms::ReadSms ( Interface impl = NULL)

Constructor.

Definition at line 50 of file ReadSms.cpp.

ReadSms::~ReadSms ( ) [virtual]

Destructor.

Definition at line 56 of file ReadSms.cpp.


Member Function Documentation

ErrorCode ReadSms::add_entities ( EntityHandle  start,
EntityHandle  count,
const Tag file_id_tag 
) [private]

Definition at line 502 of file ReadSms.cpp.

{
  if (!count || !file_id_tag)
    return MB_FAILURE;

  Range range;
  range.insert( start, start + count - 1 );
  return readMeshIface->assign_ids( *file_id_tag, range, 1 );
}
ReaderIface * ReadSms::factory ( Interface iface) [static]

factory method

Definition at line 47 of file ReadSms.cpp.

  { return new ReadSms(iface); }
ErrorCode ReadSms::get_set ( std::vector< EntityHandle > *  sets,
int  set_type,
int  set_id,
Tag  set_tag,
EntityHandle this_set,
const Tag file_id_tag 
) [private]

Definition at line 422 of file ReadSms.cpp.

{
  ErrorCode result = MB_SUCCESS;
  
  if (set_dim < 0 || set_dim > 3)
    return MB_FILE_WRITE_ERROR;
  
  if ((int)sets[set_dim].size() <= set_id || 
      !sets[set_dim][set_id]) {
    if ((int)sets[set_dim].size() <= set_id) 
      sets[set_dim].resize(set_id+1, 0);
      
    if (!sets[set_dim][set_id]) {
      result = mdbImpl->create_meshset(MESHSET_SET, 
                                       sets[set_dim][set_id]);
      if (MB_SUCCESS != result) return result;
      result = mdbImpl->tag_set_data(globalId, 
                                     &sets[set_dim][set_id], 1,
                                     &set_id);
      if (MB_SUCCESS != result) return result;
      result = mdbImpl->tag_set_data(dim_tag,
                                     &sets[set_dim][set_id], 1,
                                     &set_dim);
      if (MB_SUCCESS != result) return result;
      
      if (file_id_tag) {
        result = mdbImpl->tag_set_data(*file_id_tag,
                                     &sets[set_dim][set_id], 1,
                                     &setId);
        ++setId;
      }
    }
  }

  this_set = sets[set_dim][set_id];

  return result;
}
ErrorCode ReadSms::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 74 of file ReadSms.cpp.

{
  if (subset_list) {
    readMeshIface->report_error( "Reading subset of files not supported for Sms." );
    return MB_UNSUPPORTED_OPERATION;
  }

  setId = 1;
    
    // Open file
  FILE* file_ptr = fopen( filename, "r" );
  if (!file_ptr)
  {
    readMeshIface->report_error( "%s: %s\n", filename, strerror(errno) );
    return MB_FILE_DOES_NOT_EXIST;
  }

  const ErrorCode result = load_file_impl( file_ptr, file_id_tag );
  fclose( file_ptr );

  return result;
}
ErrorCode ReadSms::load_file_impl ( FILE *  file,
const Tag file_id_tag 
) [private]

Definition at line 101 of file ReadSms.cpp.

{
  bool warned = false;
  double dum_params[] = {0.0, 0.0, 0.0};
  
  int zero = 0;
  ErrorCode result = mdbImpl->tag_get_handle( GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER,
                                              globalId, MB_TAG_DENSE|MB_TAG_CREAT, &zero);
  CHECK("Failed to create gid tag.");
    
  result = mdbImpl->tag_get_handle("PARAMETER_COORDS", 3, MB_TYPE_DOUBLE,
                                   paramCoords, MB_TAG_DENSE|MB_TAG_CREAT );
  CHECK("Failed to create param coords tag.");
    
  int negone = -1;
  result = mdbImpl->tag_get_handle(GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER,
                                   geomDimension, MB_TAG_SPARSE|MB_TAG_CREAT, &negone);
  CHECK("Failed to create geom dim tag.");

  int n;
  char line[256];
  int file_type;
  n = fscanf(file_ptr, "%s %d", line, &file_type);
  CHECKN(2);

  if (3 == file_type) {
    result = read_parallel_info(file_ptr);
    CHECK("Failed to read parallel info.");
  }

  int nregions, nfaces, nedges, nvertices, npoints;
  n = fscanf(file_ptr, "%d %d %d %d %d", &nregions, &nfaces, &nedges,
         &nvertices, &npoints);
  CHECKN(5);
  if (nregions < 0 || nfaces < 0 || nedges < 0 || nvertices < 0 || npoints < 0)
    return MB_FILE_WRITE_ERROR;

    // create the vertices
  std::vector<double*> coord_arrays;
  EntityHandle vstart = 0;
  result = readMeshIface->get_node_coords( 3, nvertices, MB_START_ID, 
                                           vstart, coord_arrays );
  CHECK("Failed to get node arrays.");
  if (MB_SUCCESS != result)
    return result;
    
  if (file_id_tag) {
    result = add_entities( vstart, nvertices, file_id_tag );
    if (MB_SUCCESS != result)
      return result;
  }
  
  EntityHandle this_gent, new_handle;
  std::vector<EntityHandle> gentities[4];
  int gent_id, dum_int;
  int gent_type, num_connections;
  
  for(int i = 0; i < nvertices; i++)
  {
    n = fscanf(file_ptr, "%d", &gent_id); 
    CHECKN(1);
    if (!gent_id) continue;

    n = fscanf(file_ptr,"%d %d %lf %lf %lf", &gent_type, &num_connections,
           coord_arrays[0]+i, coord_arrays[1]+i, coord_arrays[2]+i);
    CHECKN(5);
    
    result = get_set(gentities, gent_type, gent_id, geomDimension, this_gent, file_id_tag );
    if (MB_SUCCESS != result)
      return result;

    new_handle = vstart + i;
    result = mdbImpl->add_entities(this_gent, &new_handle, 1);
    CHECK("Adding vertex to geom set failed.");
    if (MB_SUCCESS != result) return result;
    
    switch(gent_type)
    {
      case 1:
          n = fscanf(file_ptr, "%le", dum_params);
          CHECKN(1);
          result = mdbImpl->tag_set_data(paramCoords, &new_handle, 1, dum_params);
          CHECK("Failed to set param coords tag for vertex.");
          if (MB_SUCCESS != result) return result;
          break;
      case 2:
          n = fscanf(file_ptr, "%le %le %d", dum_params, dum_params+1, &dum_int);
          CHECKN(3);
          dum_params[2] = dum_int;
          result = mdbImpl->tag_set_data(paramCoords, &new_handle, 1, dum_params);
          CHECK("Failed to set param coords tag for vertex.");
          if (MB_SUCCESS != result) return result;
          break;
          
      default: break;
    }
  } // end of reading vertices

// *******************************
//  Read Edges
// *******************************

  int vert1, vert2, num_pts;
  std::vector<EntityHandle> everts(2);
  EntityHandle estart, *connect;
  result = readMeshIface->get_element_connect(nedges, 2, MBEDGE, 1, estart, connect);
  CHECK("Failed to create array of edges.");
  if (MB_SUCCESS != result) return result;

  if (file_id_tag) {
    result = add_entities( estart, nedges, file_id_tag );
    if (MB_SUCCESS != result)
      return result;
  }
  
  for(int i = 0; i < nedges; i++)
  {
    n = fscanf(file_ptr,"%d",&gent_id);
    CHECKN(1);
    if (!gent_id) continue;

    n = fscanf(file_ptr, "%d %d %d %d %d", &gent_type, &vert1, &vert2, 
           &num_connections, &num_pts);
    CHECKN(5);
    if (vert1 < 1 || vert1 > nvertices)
      return MB_FILE_WRITE_ERROR;
    if (vert2 < 1 || vert2 > nvertices)
      return MB_FILE_WRITE_ERROR;
    
    connect[0] = vstart + vert1 - 1;
    connect[1] = vstart + vert2 - 1;
    if (num_pts > 1 && !warned) {
      std::cout << "Warning: num_points > 1 not supported; choosing last one." << std::endl;
      warned = true;
    }

    result = get_set(gentities, gent_type, gent_id, geomDimension, this_gent, file_id_tag);
    CHECK("Problem getting geom set for edge.");
    if (MB_SUCCESS != result)
      return result;

    new_handle = estart + i;
    result = mdbImpl->add_entities(this_gent, &new_handle, 1);
    CHECK("Failed to add edge to geom set.");
    if (MB_SUCCESS != result) return result;

    connect += 2;

    for(int j = 0; j < num_pts; j++) {
      switch(gent_type) {
        case 1: 
            n = fscanf(file_ptr, "%le", dum_params);
            CHECKN(1);
            result = mdbImpl->tag_set_data(paramCoords, &new_handle, 1, dum_params);
            CHECK("Failed to set param coords tag for edge.");
            if (MB_SUCCESS != result) return result;
            break;
        case 2: 
            n = fscanf(file_ptr, "%le %le %d", dum_params, dum_params+1, &dum_int);
            CHECKN(3);
            dum_params[2] = dum_int;
            result = mdbImpl->tag_set_data(paramCoords, &new_handle, 1, dum_params);
            CHECK("Failed to set param coords tag for edge.");
            if (MB_SUCCESS != result) return result;
            break;
        default: 
            break;
      }
    }

  }  // end of reading edges

// *******************************
//  Read Faces
// *******************************
  std::vector<EntityHandle> bound_ents, bound_verts, new_faces;
  int bound_id;
  Range shverts;
  new_faces.resize(nfaces);
  int num_bounding;
    
  for(int i = 0; i < nfaces; i++)
  {
    n = fscanf(file_ptr, "%d", &gent_id);
    CHECKN(1);
    if(!gent_id) continue;

    n = fscanf(file_ptr,"%d %d", &gent_type, &num_bounding);
    CHECKN(2);

    result = get_set(gentities, gent_type, gent_id, geomDimension, this_gent, file_id_tag);
    CHECK("Problem getting geom set for face.");
    if (MB_SUCCESS != result)
      return result;

    bound_ents.resize(num_bounding+1);
    bound_verts.resize(num_bounding);
    for(int j = 0; j < num_bounding; j++) {
      n = fscanf(file_ptr, "%d ", &bound_id);
      CHECKN(1);
      if (0 > bound_id) bound_id = abs(bound_id);
      assert(0 < bound_id && bound_id <= nedges);
      if (bound_id < 1 || bound_id > nedges)
        return MB_FILE_WRITE_ERROR;
      bound_ents[j] = estart + abs(bound_id) - 1;
    }

      // convert edge-based model to vertex-based one
    for (int j = 0; j < num_bounding; j++) {
      if (j == num_bounding-1) bound_ents[j+1] = bound_ents[0];
      result = mdbImpl->get_adjacencies(&bound_ents[j], 2, 0, false, shverts);
      CHECK("Failed to get vertices bounding edge.");
      if (MB_SUCCESS != result) return result;
      assert(shverts.size() == 1);
      bound_verts[j] = *shverts.begin();
      shverts.clear();
    }

    result = mdbImpl->create_element((EntityType)(MBTRI+num_bounding-3),
                                     &bound_verts[0], bound_verts.size(), 
                                     new_faces[i]);
    CHECK("Failed to create edge.");
    if (MB_SUCCESS != result) return result;

    result = mdbImpl->add_entities(this_gent, &new_faces[i], 1);
    CHECK("Failed to add edge to geom set.");
    if (MB_SUCCESS != result) return result;

    int num_read = fscanf(file_ptr, "%d", &num_pts);
    if(!num_pts || !num_read) continue;

    for(int j = 0; j < num_pts; j++) {
      switch(gent_type) {
        case 1: 
            n = fscanf(file_ptr, "%le", dum_params); CHECKN(1);
            result = mdbImpl->tag_set_data(paramCoords, &new_faces[i], 1, dum_params);
            CHECK("Failed to set param coords tag for face.");
            if (MB_SUCCESS != result) return result;
            break;
        case 2: 
            n = fscanf(file_ptr, "%le %le %d", dum_params, dum_params+1, &dum_int);
            CHECKN(3);
            dum_params[2] = dum_int;
            result = mdbImpl->tag_set_data(paramCoords, &new_faces[i], 1, dum_params);
            CHECK("Failed to set param coords tag for face.");
            if (MB_SUCCESS != result) return result;
            break;
        default: 
            break;
      }
    }

  } // end of reading faces
  
  if (file_id_tag) {
    result = readMeshIface->assign_ids( *file_id_tag, &new_faces[0], new_faces.size(), 1 );
    if (MB_SUCCESS != result)
      return result;
  }


// *******************************
//  Read Regions
// *******************************
  int sense[MAX_SUB_ENTITIES];
  bound_verts.resize(MAX_SUB_ENTITIES);

  std::vector<EntityHandle> regions;
  if (file_id_tag)
    regions.resize( nregions );
  for(int i = 0; i < nregions; i++)
  {
    n = fscanf(file_ptr, "%d", &gent_id); CHECKN(1);
    if (!gent_id) continue;
    result = get_set(gentities, 3, gent_id, geomDimension, this_gent, file_id_tag);
    CHECK("Couldn't get geom set for region.");
    if (MB_SUCCESS != result)
      return result;
    n = fscanf(file_ptr, "%d", &num_bounding); CHECKN(1);
    bound_ents.resize(num_bounding);
    for(int j = 0; j < num_bounding; j++) {
      n = fscanf(file_ptr, "%d ", &bound_id); CHECKN(1);
      assert(abs(bound_id) < (int)new_faces.size()+1 && bound_id);
      if (!bound_id || abs(bound_id) > nfaces)
        return MB_FILE_WRITE_ERROR;
      sense[j] = (bound_id < 0) ? -1 : 1;
      bound_ents[j] = new_faces[abs(bound_id)-1];
    }

    EntityType etype;
    result = readMeshIface->get_ordered_vertices(&bound_ents[0], sense, 
                                                 num_bounding,
                                                 3, &bound_verts[0], etype);
    CHECK("Failed in get_ordered_vertices.");
        
      // make the element
    result = mdbImpl->create_element(etype, &bound_verts[0], 
                                     CN::VerticesPerEntity(etype), new_handle);
    CHECK("Failed to create region.");
    if (MB_SUCCESS != result) return result;

    result = mdbImpl->add_entities(this_gent, &new_handle, 1);
    CHECK("Failed to add region to geom set.");
    if (MB_SUCCESS != result) return result;

    if (file_id_tag)
      regions[i] = new_handle;
  
    n = fscanf(file_ptr, "%d ", &dum_int); CHECKN(1);

  } // end of reading regions
  
  if (file_id_tag) {
    result = readMeshIface->assign_ids( *file_id_tag, &regions[0], regions.size(), 1 );
    if (MB_SUCCESS != result)
      return result;
  }

  return MB_SUCCESS;
}
ErrorCode ReadSms::read_parallel_info ( FILE *  file_ptr) [private]

Definition at line 465 of file ReadSms.cpp.

{
//  ErrorCode result;

    // read partition info
  int nparts, part_id, num_ifaces, num_corner_ents;
  int num_read = fscanf(file_ptr, "%d %d %d %d", &nparts, &part_id, &num_ifaces, &num_corner_ents);
  if (!num_read) return MB_FAILURE;
  
    // read interfaces
  int iface_id, iface_dim, iface_own, num_iface_corners;
//  EntityHandle this_iface;
  std::vector<int> *iface_corners;
  for (int i = 0; i < num_ifaces; i++) {
    num_read = fscanf(file_ptr, "%d %d %d %d", &iface_id, &iface_dim, &iface_own,
                      &num_iface_corners);
    if (!num_read) return MB_FAILURE;
    
//    result = get_set(sets, iface_dim, iface_id, dim_tag, iface_own, this_iface);
//    CHECK("Failed to make iface set.");
    
      // read the corner ids and store them on the set for now
    iface_corners = new std::vector<int>(num_iface_corners);
    for (int j = 0; j < num_iface_corners; j++) {
      num_read = fscanf(file_ptr, "%d", &(*iface_corners)[j]);
      if (!num_read) return MB_FAILURE;
    }

//    result = tag_set_data(ifaceCornerTag, &this_iface, 1,
//                          &iface_corners);
//    CHECK("Failed to set iface corner tag.");
  }

    // interface data has been read
  return MB_SUCCESS;
}
ErrorCode ReadSms::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 64 of file ReadSms.cpp.

{
  return MB_NOT_IMPLEMENTED;
}

Member Data Documentation

Definition at line 61 of file ReadSms.hpp.

Definition at line 61 of file ReadSms.hpp.

interface instance

Definition at line 59 of file ReadSms.hpp.

Definition at line 61 of file ReadSms.hpp.

Definition at line 56 of file ReadSms.hpp.

int moab::ReadSms::setId [private]

Definition at line 63 of file ReadSms.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines