Esempio n. 1
0
void Exo_Entity::internal_load_params()
{
  int name_size = ex_inquire_int(fileId, EX_INQ_MAX_READ_NAME_LENGTH);
  {
    std::vector<char> name(name_size + 1);
    ex_get_name(fileId, exodus_type(), id_, TOPTR(name));
    if (name[0] != '\0') {
      name_ = TOPTR(name);
      to_lower(name_);
    }
    else {
      name_ = short_label();
      name_ += "_";
      name_ += to_string(id_);
    }
  }
  numVars = get_num_variables(fileId, exodus_type(), label());
  if (numVars) {
    results_ = new double *[numVars];
    SMART_ASSERT(results_ != nullptr);
    for (int i    = 0; i < numVars; ++i)
      results_[i] = nullptr;
  }

  numAttr = get_num_attributes(fileId, exodus_type(), id_, label());
  if (numAttr) {
    attributes_.resize(numAttr);

    char **names = get_name_array(numAttr, name_size);
    int    err   = ex_get_attr_names(fileId, exodus_type(), id_, names);
    if (err < 0) {
      ERROR("ExoII_Read::Get_Init_Data(): Failed to get " << label()
                                                          << " attribute names!  Aborting...\n");
      exit(1);
    }

    for (int vg = 0; vg < numAttr; ++vg) {
      SMART_ASSERT(names[vg] != nullptr);
      if (std::strlen(names[vg]) == 0) {
        std::string name = "attribute_" + to_string(vg + 1);
        attributeNames.push_back(name);
      }
      else if ((int)std::strlen(names[vg]) > name_size) {
        std::cerr << trmclr::red << "exodiff: ERROR: " << label()
                  << " attribute names appear corrupt\n"
                  << "                A length is 0 or greater than "
                  << "name_size(" << name_size << ")\n"
                  << "                Here are the names that I received from"
                  << " a call to ex_get_attr_names(...):\n";
        for (int k = 1; k <= numAttr; ++k)
          std::cerr << "\t\t" << k << ") \"" << names[k - 1] << "\"\n";
        std::cerr << "                 Aborting...\n" << trmclr::normal;
        exit(1);
      }
      else {
        std::string n(names[vg]);
        to_lower(n);
        attributeNames.push_back(n);
      }
    }
    free_name_array(names, numAttr);
  }
}
Esempio n. 2
0
template <typename INT> void ExoII_Read<INT>::Get_Init_Data()
{
  SMART_ASSERT(Check_State());
  SMART_ASSERT(file_id >= 0);

  // Determine max size of entity and variable names on the database
  int name_length = ex_inquire_int(file_id, EX_INQ_DB_MAX_USED_NAME_LENGTH);
  ex_set_max_name_length(file_id, name_length);

  ex_init_params info;
  info.title[0] = '\0';

  int err = ex_get_init_ext(file_id, &info);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get init data!"
              << " Error number = " << err << ".  Aborting..." << '\n';
    exit(1);
  }

  dimension       = info.num_dim;
  num_nodes       = info.num_nodes;
  num_elmts       = info.num_elem;
  num_elmt_blocks = info.num_elem_blk;
  num_node_sets   = info.num_node_sets;
  num_side_sets   = info.num_side_sets;
  title           = info.title;

  if (err > 0 && !interface.quiet_flag)
    std::cout << "EXODIFF WARNING: was issued, number = " << err << '\n';
  if (dimension < 1 || dimension > 3 || num_elmt_blocks < 0 || num_node_sets < 0 ||
      num_side_sets < 0) {
    std::cout << "EXODIFF ERROR: Init data appears corrupt:" << '\n'
              << "         dimension = " << dimension << '\n'
              << "         num_nodes = " << num_nodes << '\n'
              << "         num_elmts = " << num_elmts << '\n'
              << "         num_elmt_blocks = " << num_elmt_blocks << '\n'
              << "         num_node_sets = " << num_node_sets << '\n'
              << "         num_side_sets = " << num_side_sets << '\n'
              << " ... Aborting..." << '\n';
    exit(1);
  }

  int num_qa   = ex_inquire_int(file_id, EX_INQ_QA);
  int num_info = ex_inquire_int(file_id, EX_INQ_INFO);

  if (num_qa < 0 || num_info < 0) {
    std::cout << "EXODIFF ERROR: inquire data appears corrupt:" << '\n'
              << "         num_qa = " << num_qa << '\n'
              << "         num_info = " << num_info << '\n'
              << " ... Aborting..." << '\n';
    exit(1);
  }

  //                   Coordinate Names...

  char **coords = get_name_array(3, name_length);
  err           = ex_get_coord_names(file_id, coords);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get coordinate"
              << " names!  Aborting..." << '\n';
    exit(1);
  }

  coord_names.clear();
  for (size_t i = 0; i < dimension; ++i) {
    coord_names.push_back(coords[i]);
  }
  free_name_array(coords, 3);

  //                 Element Block Data...

  if (eblocks)
    delete[] eblocks;
  eblocks = nullptr;
  if (num_elmt_blocks > 0) {
    eblocks = new Exo_Block<INT>[num_elmt_blocks];
    SMART_ASSERT(eblocks != nullptr);
    std::vector<INT> ids(num_elmt_blocks);

    err = ex_get_ids(file_id, EX_ELEM_BLOCK, TOPTR(ids));

    if (err < 0) {
      std::cout << "EXODIFF ERROR: Failed to get element"
                << " block ids!  Aborting..." << '\n';
      exit(1);
    }

    size_t e_count = 0;
    for (size_t b = 0; b < num_elmt_blocks; ++b) {
      if (ids[b] <= EX_INVALID_ID) {
        std::cout << "EXODIFF  WARNING:  Element block Id "
                  << "for block index " << b << " is " << ids[b]
                  << " which is negative. This was returned by call to ex_get_elem_blk_ids()."
                  << '\n';
      }

      eblocks[b].initialize(file_id, ids[b]);
      e_count += eblocks[b].Size();
    }

    if (e_count != num_elmts && !interface.quiet_flag) {
      std::cout << "EXODIFF WARNING: Total number of elements " << num_elmts
                << " does not equal the sum of the number of elements "
                << "in each block " << e_count << '\n';
    }

    // Gather the attribute names (even though not all attributes are on all blocks)
    std::set<std::string> names;
    for (size_t b = 0; b < num_elmt_blocks; ++b) {
      for (int a = 0; a < eblocks[b].attr_count(); a++) {
        names.insert(eblocks[b].Get_Attribute_Name(a));
      }
    }
    elmt_atts.resize(names.size());
    std::copy(names.begin(), names.end(), elmt_atts.begin());
  }

  //                     Node & Side sets...

  if (nsets)
    delete[] nsets;
  nsets = nullptr;
  if (num_node_sets > 0) {
    nsets = new Node_Set<INT>[num_node_sets];
    SMART_ASSERT(nsets != nullptr);
    std::vector<INT> ids(num_node_sets);

    err = ex_get_ids(file_id, EX_NODE_SET, TOPTR(ids));

    if (err < 0) {
      std::cout << "EXODIFF ERROR: Failed to get "
                << "nodeset ids!  Aborting..." << '\n';
      exit(1);
    }

    for (size_t nset = 0; nset < num_node_sets; ++nset) {
      if (ids[nset] <= EX_INVALID_ID) {
        std::cout << "EXODIFF  WARNING: Nodeset Id "
                  << "for nodeset index " << nset << " is " << ids[nset]
                  << " which is negative.  This was returned by call to ex_get_ids()." << '\n';
      }

      nsets[nset].initialize(file_id, ids[nset]);
    }
  }

  if (ssets)
    delete[] ssets;
  ssets = nullptr;
  if (num_side_sets) {
    ssets = new Side_Set<INT>[num_side_sets];
    SMART_ASSERT(ssets != nullptr);
    std::vector<INT> ids(num_side_sets);

    err = ex_get_ids(file_id, EX_SIDE_SET, TOPTR(ids));

    if (err < 0) {
      std::cout << "EXODIFF ERROR: Failed to get "
                << "sideset ids!  Aborting..." << '\n';
      exit(1);
    }

    for (size_t sset = 0; sset < num_side_sets; ++sset) {
      if (ids[sset] <= EX_INVALID_ID) {
        std::cout << "EXODIFF  WARNING:  Sideset Id "
                  << "for sideset index " << sset << " is " << ids[sset]
                  << " which is negative. This was returned by call to ex_get_ids()." << '\n';
      }
      ssets[sset].initialize(file_id, ids[sset]);
    }
  }

  //  **************  RESULTS info  ***************  //

  int num_global_vars, num_nodal_vars, num_elmt_vars, num_ns_vars, num_ss_vars;

  err = ex_get_variable_param(file_id, EX_GLOBAL, &num_global_vars);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get number of"
              << " global variables!  Aborting..." << '\n';
    exit(1);
  }

  err = ex_get_variable_param(file_id, EX_NODAL, &num_nodal_vars);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get number of"
              << " nodal variables!  Aborting..." << '\n';
    exit(1);
  }

  err = ex_get_variable_param(file_id, EX_ELEM_BLOCK, &num_elmt_vars);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get number of"
              << " element variables!  Aborting..." << '\n';
    exit(1);
  }

  err = ex_get_variable_param(file_id, EX_NODE_SET, &num_ns_vars);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get number of"
              << " nodeset variables!  Aborting..." << '\n';
    exit(1);
  }

  err = ex_get_variable_param(file_id, EX_SIDE_SET, &num_ss_vars);
  if (err < 0) {
    std::cout << "EXODIFF ERROR: Failed to get number of"
              << " sideset variables!  Aborting..." << '\n';
    exit(1);
  }

  if (num_global_vars < 0 || num_nodal_vars < 0 || num_elmt_vars < 0 || num_ns_vars < 0 ||
      num_ss_vars < 0) {
    std::cout << "EXODIFF ERROR: Data appears corrupt for"
              << " number of variables !" << '\n'
              << "\tnum global vars  = " << num_global_vars << '\n'
              << "\tnum nodal vars   = " << num_nodal_vars << '\n'
              << "\tnum element vars = " << num_elmt_vars << '\n'
              << " ... Aborting..." << '\n';
    exit(1);
  }

  read_vars(file_id, EX_GLOBAL, "Global", num_global_vars, global_vars);
  read_vars(file_id, EX_NODAL, "Nodal", num_nodal_vars, nodal_vars);
  read_vars(file_id, EX_ELEM_BLOCK, "Element", num_elmt_vars, elmt_vars);
  read_vars(file_id, EX_NODE_SET, "Nodeset", num_ns_vars, ns_vars);
  read_vars(file_id, EX_SIDE_SET, "Sideset", num_ss_vars, ss_vars);

  // Times:
  num_times = ex_inquire_int(file_id, EX_INQ_TIME);
  if (num_times < 0) {
    std::cout << "EXODIFF ERROR: Number of time steps came"
              << " back negative (" << num_times << ")!  Aborting..." << '\n';
    exit(1);
  }

  if ((num_global_vars > 0 || num_nodal_vars > 0 || num_elmt_vars > 0 || num_ns_vars > 0 ||
       num_ss_vars > 0) &&
      num_times == 0) {
    std::cout << "EXODIFF Consistency error -- The database contains transient variables, but no "
                 "timesteps!"
              << '\n';
    exit(1);
  }

  if (num_times) {
    times = new double[num_times];
    SMART_ASSERT(times != nullptr);
    err = ex_get_all_times(file_id, times);
  }

  if (num_nodal_vars) {
    if (num_times == 0) {
      std::cout << "EXODIFF Consistency error--The database contains " << num_nodal_vars
                << " nodal variables, but there are no time steps defined." << '\n';
    }
    if (num_times) {
      results = new double *[num_nodal_vars];
      for (int i   = 0; i < num_nodal_vars; ++i)
        results[i] = nullptr;
    }
  }

} // End of EXODIFF