コード例 #1
0
ファイル: WriteVtk.cpp プロジェクト: vijaysm/MOAB
ErrorCode WriteVtk::write_file(const char *file_name,
                               const bool overwrite,
                               const FileOptions& opts,
                               const EntityHandle *output_list,
                               const int num_sets,
                               const std::vector<std::string>& /* qa_list */,
                               const Tag* tag_list,
                               int num_tags,
                               int /* export_dimension */)
{
  ErrorCode rval;

  // Get precision for node coordinates
  int precision;
  if (MB_SUCCESS != opts.get_int_option("PRECISION", precision))
    precision = DEFAULT_PRECISION;

  if (MB_SUCCESS == opts.get_null_option("STRICT"))
    mStrict = true;
  else if (MB_SUCCESS == opts.get_null_option("RELAXED"))
    mStrict = false;
  else
    mStrict = DEFAULT_STRICT;

  // Get entities to write
  Range nodes, elems;
  rval = gather_mesh(output_list, num_sets, nodes, elems);
  if (MB_SUCCESS != rval)
    return rval;

  // Honor overwrite flag
  if (!overwrite) {
    rval = writeTool->check_doesnt_exist(file_name);
    if (MB_SUCCESS != rval)
      return rval;
  }

  // Create file
  std::ofstream file(file_name);
  if (!file) {
    MB_SET_ERR(MB_FILE_WRITE_ERROR, "Could not open file: " << file_name);
  }
  file.precision(precision);

  // Write file
  if ((rval = write_header(file              )) != MB_SUCCESS ||
      (rval = write_nodes( file, nodes       )) != MB_SUCCESS ||
      (rval = write_elems( file, nodes, elems)) != MB_SUCCESS ||
      (rval = write_tags ( file, true,  nodes, tag_list, num_tags)) != MB_SUCCESS ||
      (rval = write_tags ( file, false, elems, tag_list, num_tags)) != MB_SUCCESS) {
    file.close();
    remove(file_name);
    return rval;
  }

  return MB_SUCCESS;
}
コード例 #2
0
ファイル: ReadDamsel.cpp プロジェクト: chrismullins/moab
ErrorCode ReadDamsel::parse_options(const FileOptions &opts,
                                    bool &parallel) 
{
    // Handle parallel options
  std::string junk;
  bool use_mpio = (MB_SUCCESS == opts.get_null_option("USE_MPIO"));
  ErrorCode rval = opts.match_option("PARALLEL", "READ_PART");
  parallel = (rval != MB_ENTITY_NOT_FOUND);
  nativeParallel = (rval == MB_SUCCESS);
  if (use_mpio && !parallel) {
    readMeshIface->report_error( "'USE_MPIO' option specified w/out 'PARALLEL' option" );
    return MB_NOT_IMPLEMENTED;
  }

  return MB_SUCCESS;
}
コード例 #3
0
ファイル: ReadNC.cpp プロジェクト: obmun/moab
ErrorCode ReadNC::parse_options(const FileOptions& opts, std::vector<std::string>& var_names, std::vector<int>& tstep_nums,
                                std::vector<double>& tstep_vals)
{
  int tmpval;
  if (MB_SUCCESS == opts.get_int_option("DEBUG_IO", 1, tmpval)) {
    dbgOut.set_verbosity(tmpval);
    dbgOut.set_prefix("NC ");
  }

  ErrorCode rval = opts.get_strs_option("VARIABLE", var_names);
  if (MB_TYPE_OUT_OF_RANGE == rval)
    noVars = true;
  else
    noVars = false;

  opts.get_ints_option("TIMESTEP", tstep_nums);
  opts.get_reals_option("TIMEVAL", tstep_vals);

  rval = opts.get_null_option("NOMESH");
  if (MB_SUCCESS == rval)
    noMesh = true;

  rval = opts.get_null_option("SPECTRAL_MESH");
  if (MB_SUCCESS == rval)
    spectralMesh = true;

  rval = opts.get_null_option("NO_MIXED_ELEMENTS");
  if (MB_SUCCESS == rval)
    noMixedElements = true;

  rval = opts.get_null_option("NO_EDGES");
  if (MB_SUCCESS == rval)
    noEdges = true;

  if (2 <= dbgOut.get_verbosity()) {
    if (!var_names.empty()) {
      std::cerr << "Variables requested: ";
      for (unsigned int i = 0; i < var_names.size(); i++)
        std::cerr << var_names[i];
      std::cerr << std::endl;
    }

    if (!tstep_nums.empty()) {
      std::cerr << "Timesteps requested: ";
      for (unsigned int i = 0; i < tstep_nums.size(); i++)
        std::cerr << tstep_nums[i];
      std::cerr << std::endl;
    }

    if (!tstep_vals.empty()) {
      std::cerr << "Time vals requested: ";
      for (unsigned int i = 0; i < tstep_vals.size(); i++)
        std::cerr << tstep_vals[i];
      std::cerr << std::endl;
    }
  }

  rval = opts.get_int_option("GATHER_SET", 0, gatherSetRank);
  if (MB_TYPE_OUT_OF_RANGE == rval) {
    MB_SET_ERR(rval, "Invalid value for GATHER_SET option");
  }

  rval = opts.get_int_option("TIMESTEPBASE", 0, tStepBase);
  if (MB_TYPE_OUT_OF_RANGE == rval) {
    MB_SET_ERR(rval, "Invalid value for TIMESTEPBASE option");
  }

  rval = opts.get_int_option("TRIVIAL_PARTITION_SHIFT", 1, trivialPartitionShift);
  if (MB_TYPE_OUT_OF_RANGE == rval) {
    MB_SET_ERR(rval, "Invalid value for TRIVIAL_PARTITION_SHIFT option");
  }

#ifdef MOAB_HAVE_MPI
  isParallel = (opts.match_option("PARALLEL", "READ_PART") != MB_ENTITY_NOT_FOUND);

  if (!isParallel)
  // Return success here, since rval still has _NOT_FOUND from not finding option
  // in this case, myPcomm will be NULL, so it can never be used; always check for isParallel 
  // before any use for myPcomm
    return MB_SUCCESS;

  int pcomm_no = 0;
  rval = opts.get_int_option("PARALLEL_COMM", pcomm_no);
  if (MB_TYPE_OUT_OF_RANGE == rval) {
    MB_SET_ERR(rval, "Invalid value for PARALLEL_COMM option");
  }
  myPcomm = ParallelComm::get_pcomm(mbImpl, pcomm_no);
  if (0 == myPcomm) {
    myPcomm = new ParallelComm(mbImpl, MPI_COMM_WORLD);
  }
  const int rank = myPcomm->proc_config().proc_rank();
  dbgOut.set_rank(rank);

  int dum;
  rval = opts.match_option("PARTITION_METHOD", ScdParData::PartitionMethodNames, dum);
  if (MB_FAILURE == rval) {
    MB_SET_ERR(rval, "Unknown partition method specified");
  }
  else if (MB_ENTITY_NOT_FOUND == rval)
    partMethod = ScdParData::ALLJORKORI;
  else
    partMethod = dum;
#endif

  return MB_SUCCESS;
}
コード例 #4
0
ファイル: ReadSTL.cpp プロジェクト: obmun/moab
// Generic load function for both ASCII and binary. Calls
// pure-virtual function implemented in subclasses to read
// the data from the file.
ErrorCode ReadSTL::load_file(const char* filename,
                             const EntityHandle* /* file_set */,
                             const FileOptions& opts,
                             const ReaderIface::SubsetList* subset_list,
                             const Tag* file_id_tag)
{
  if (subset_list) {
    MB_SET_ERR(MB_UNSUPPORTED_OPERATION, "Reading subset of files not supported for STL");
  }

  ErrorCode result;

  std::vector<ReadSTL::Triangle> triangles;

  bool is_ascii = false, is_binary = false;
  if (MB_SUCCESS == opts.get_null_option("ASCII"))
    is_ascii = true;
  if (MB_SUCCESS == opts.get_null_option("BINARY"))
    is_binary = true;
  if (is_ascii && is_binary) {
    MB_SET_ERR(MB_FAILURE, "Conflicting options: BINARY ASCII");
  }

  bool big_endian = false, little_endian = false;
  if (MB_SUCCESS == opts.get_null_option("BIG_ENDIAN"))
    big_endian = true;
  if (MB_SUCCESS == opts.get_null_option("LITTLE_ENDIAN"))
    little_endian = true;
  if (big_endian && little_endian) {
    MB_SET_ERR(MB_FAILURE, "Conflicting options: BIG_ENDIAN LITTLE_ENDIAN");
  }
  ByteOrder byte_order =    big_endian ? STL_BIG_ENDIAN
                       : little_endian ? STL_LITTLE_ENDIAN
                       :                 STL_UNKNOWN_BYTE_ORDER;

  if (is_ascii)
    result = ascii_read_triangles(filename, triangles);
  else if (is_binary)
    result = binary_read_triangles(filename, byte_order, triangles);
  else {
    // Try ASCII first
    result = ascii_read_triangles(filename, triangles);
    if (MB_SUCCESS != result) 
      // ASCII failed, try binary
      result = binary_read_triangles(filename, byte_order, triangles);
  }
  if (MB_SUCCESS != result)
    return result;

  // Create a std::map from position->handle, and such
  // that all positions are specified, and handles are zero.
  std::map<Point, EntityHandle> vertex_map;
  for (std::vector<Triangle>::iterator i = triangles.begin(); i != triangles.end(); ++i) {
    vertex_map[i->points[0]] = 0;
    vertex_map[i->points[1]] = 0;
    vertex_map[i->points[2]] = 0;
  }

  // Create vertices
  std::vector<double*> coord_arrays;
  EntityHandle vtx_handle = 0;
  result = readMeshIface->get_node_coords(3, vertex_map.size(), MB_START_ID,
                                          vtx_handle, coord_arrays);
  if (MB_SUCCESS != result)
    return result;

  // Copy vertex coordinates into entity sequence coordinate arrays
  // and copy handle into vertex_map.
  double *x = coord_arrays[0], *y = coord_arrays[1], *z = coord_arrays[2];
  for (std::map<Point, EntityHandle>::iterator i = vertex_map.begin();
       i != vertex_map.end(); ++i) {
    i->second = vtx_handle; ++vtx_handle;
    *x = i->first.coords[0]; ++x;
    *y = i->first.coords[1]; ++y;
    *z = i->first.coords[2]; ++z;
  }

  // Allocate triangles
  EntityHandle elm_handle = 0;
  EntityHandle* connectivity;
  result = readMeshIface->get_element_connect(triangles.size(),
                                              3,
                                              MBTRI,
                                              MB_START_ID,
                                              elm_handle,
                                              connectivity);
  if (MB_SUCCESS != result)
    return result;

  // Use vertex_map to recover triangle connectivity from
  // vertex coordinates.
  EntityHandle *conn_sav = connectivity;
  for (std::vector<Triangle>::iterator i = triangles.begin(); i != triangles.end(); ++i) {
    *connectivity = vertex_map[i->points[0]]; ++connectivity;
    *connectivity = vertex_map[i->points[1]]; ++connectivity;
    *connectivity = vertex_map[i->points[2]]; ++connectivity;
  }

  // Notify MOAB of the new elements
  result = readMeshIface->update_adjacencies(elm_handle, triangles.size(),
                                             3, conn_sav);
  if (MB_SUCCESS != result)
    return result;

  if (file_id_tag) {
    Range vertices(vtx_handle, vtx_handle + vertex_map.size() - 1);
    Range elements(elm_handle, elm_handle + triangles.size() - 1);
    readMeshIface->assign_ids(*file_id_tag, vertices);
    readMeshIface->assign_ids(*file_id_tag, elements);
  }

  return MB_SUCCESS;
}