Esempio n. 1
0
bool Scale::internal_execute(const Ioss::Field &field, void *data)
{
    size_t count      = field.transformed_count();
    int    components = field.transformed_storage()->component_count();

    if (field.get_type() == Ioss::Field::REAL) {
        double *rdata = static_cast<double *>(data);

        for (size_t i = 0; i < count * components; i++) {
            rdata[i] *= realMultiplier;
        }
    }
    else if (field.get_type() == Ioss::Field::INTEGER) {
        int *idata = static_cast<int *>(data);

        for (size_t i = 0; i < count * components; i++) {
            idata[i] *= intMultiplier;
        }
    }
    else if (field.get_type() == Ioss::Field::INT64) {
        int64_t *idata = static_cast<int64_t *>(data);

        for (size_t i = 0; i < count * components; i++) {
            idata[i] *= intMultiplier;
        }
    }
    else {
    }
    return true;
}
Esempio n. 2
0
int64_t Ioex::SuperElement::internal_get_field_data(const Ioss::Field& field,
				      void *data, size_t data_size) const
{
  size_t num_to_get = field.verify(data_size);
  assert(num_to_get == numDOF * numDOF);
  
  if (field.get_name() == "Kr") {
    int status = nc_get_array(filePtr, "Kr", (double*)data);
    if (status != 0) {
      std::ostringstream errmsg;
      errmsg << "ERROR: Could not load stiffness matrix field 'Kr' from file '"
	     << fileName << "'.";
      IOSS_ERROR(errmsg);
    }
  }
  else if (field.get_name() == "Mr") {
    int status = nc_get_array(filePtr, "Mr", (double*)data);
    if (status != 0) {
      std::ostringstream errmsg;
      errmsg << "ERROR: Could not load mass matrix field 'Mr' from file '"
	     << fileName << "'.";
      IOSS_ERROR(errmsg);
    }
  }
  else {
    std::cerr << "WARNING: " << type() << " '" << name()
	      << "'. Unknown input field '" << field.get_name() << "'";
    return -4;
  }
  return num_to_get;
}
Esempio n. 3
0
  bool Scale3D::internal_execute(const Ioss::Field &field, void *data)
  {
    size_t count = field.transformed_count();
    assert(field.transformed_storage()->component_count() == 3);
    
    if (field.get_type() == Ioss::Field::REAL) {
      double *rdata = static_cast<double*>(data);

      for (size_t i = 0; i < count*3; i+=3) {
	rdata[i+0] *= realScale[0];
	rdata[i+1] *= realScale[1];
	rdata[i+2] *= realScale[2];
      }
    } else if (field.get_type() == Ioss::Field::INTEGER) {
      int *idata = static_cast<int*>(data);

      for (size_t i = 0; i < count*3; i+=3) {
	idata[i+0] *= intScale[0];
	idata[i+1] *= intScale[1];
	idata[i+2] *= intScale[2];
      }
    } else {
    }
    return true;
  }
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
  MPI_Init(&argc, &argv);
#endif

  Ioss::StorageInitializer initialize_storage;

  std::string input_file = std::string(argv[argc-1]);
  if (input_file == "") {
    OUTPUT << "Error: No input file specified\n";
    return (EXIT_FAILURE);
  }

  std::string cwd = "";

  input_file = Ioss::Utils::local_filename(input_file, "text", cwd);

  Ioex::SuperElement se(input_file, "superelement");

  size_t numDOF = se.get_property("numDOF").get_int();
  size_t numEIG = se.get_property("numEIG").get_int();
  size_t numCon = se.get_property("numConstraints").get_int();

  std::cerr << "DOF count = " << numDOF << "\n";
  std::cerr << "EIG count = " << numEIG << "\n";
  std::cerr << "Constraint dof count = " << numCon << "\n";
  assert(numCon == numDOF - numEIG);

  // List the fields on the superelement...
  if (!se.field_exists("Kr")) {
    std::cerr << "ERROR: Stiffness matrix field 'Kr' not found\n";
  } else {
    Ioss::Field kr = se.get_field("Kr");
    assert(kr.raw_count() == numDOF * numDOF);
  }
  
  if (!se.field_exists("Mr")) {
    std::cerr << "ERROR: Mass matrix field 'Mr' not found\n";
  } else {
    Ioss::Field mr = se.get_field("Mr");
    assert(mr.raw_count() == numDOF * numDOF);
  }

  std::vector<double> stiff_mat(numDOF * numDOF);
  std::vector<double> mass_mat(numDOF * numDOF);
  size_t kr_size = se.get_field_data("Kr", stiff_mat);
  size_t mr_size = se.get_field_data("Mr", mass_mat);
  assert(kr_size == numDOF * numDOF);
  assert(mr_size == numDOF * numDOF);

  OUTPUT << "\nSIERRA execution successful." << std::endl;
#ifdef HAVE_MPI
  MPI_Finalize();
#endif
  return EXIT_SUCCESS;
}
Esempio n. 5
0
void Ioss::Map::map_implicit_data(void *data, const Ioss::Field &field, size_t count, size_t offset) const
{
  if (field.get_type() == Ioss::Field::INTEGER) {
    map_implicit_data_internal(static_cast<int*>(data), count, map, offset);
  } else {
    map_implicit_data_internal(static_cast<int64_t*>(data), count, map, offset);
  }
}
Esempio n. 6
0
  bool Tensor::internal_execute(const Ioss::Field &field, void *data)
  {
    assert(field.get_type() == Ioss::Field::REAL);
    double *r = static_cast<double*>(data);

    int count = field.raw_count();
    int components = field.raw_storage()->component_count();

    bool success = false;
    switch (type_) {
    case TRACE:
    case INVARIANT1:
      {
	int j = 0;
	for (int i=0; i < count*components; i+=components) {
	  r[j++] = r[i] + r[i+1] + r[i+2];
	}
      }
      success = true;
      break;
    case INVARIANT2:
      {
	int j = 0;
	for (int i=0; i < count*components; i+=components) {
	  r[j++] = r[i+3]*r[i+3] + r[i+4]*r[i+4] + r[i+5]*r[i+5] -
	    (r[i+0]*r[i+1] + r[i+1]*r[i+2] + r[i+0]*r[i+2]);
	}
      }
      success = true;
      break;
    case INVARIANT3:
    case MAGNITUDE:
    case DEVIATOR:
    case SPHERICAL:
    case INVARIANTS:
      success = false;
      break;
    default:
      success = false;
    }

    return success;
  }
Esempio n. 7
0
  bool VectorMagnitude::internal_execute(const Ioss::Field &field, void *data)
  {
    double *rdata = static_cast<double *>(data);

    size_t count = field.transformed_count();
    if (field.transformed_storage()->component_count() == 3) {
      int j = 0;
      for (size_t i = 0; i < count; i++) {
        rdata[i] = std::sqrt(rdata[j] * rdata[j] + rdata[j + 1] * rdata[j + 1] +
                             rdata[j + 2] * rdata[j + 2]);
        j += 3;
      }
    }
    else {
      int j = 0;
      for (size_t i = 0; i < count; i++) {
        rdata[i] = std::sqrt(rdata[j] * rdata[j] + rdata[j + 1] * rdata[j + 1]);
        j += 2;
      }
    }
    return true;
  }
// ========================================================================
void process_nodeblocks(Ioss::Region &region, stk::mesh::MetaData &meta)
{
    const Ioss::NodeBlockContainer& node_blocks = region.get_node_blocks();
    assert(node_blocks.size() == 1);

    Ioss::NodeBlock *nb = node_blocks[0];

    assert(nb->field_exists("mesh_model_coordinates"));
    Ioss::Field coordinates = nb->get_field("mesh_model_coordinates");
    int spatial_dim = coordinates.transformed_storage()->component_count();

    stk::mesh::Field<double,stk::mesh::Cartesian> & coord_field =
        meta.declare_field<stk::mesh::Field<double,stk::mesh::Cartesian> >(stk::topology::NODE_RANK, "coordinates");

    stk::mesh::put_field( coord_field, meta.universal_part(),
                          spatial_dim);

    /** \todo IMPLEMENT truly handle fields... For this case we are
     * just defining a field for each transient field that is present
     * in the mesh...
     */
    stk::io::define_io_fields(nb, Ioss::Field::TRANSIENT, meta.universal_part(),stk::topology::NODE_RANK);
}
Esempio n. 9
0
void Ioss::Map::map_data(void *data, const Ioss::Field &field, size_t count) const
{
  if (!is_sequential(map)) {
    if (field.get_type() == Ioss::Field::INTEGER) {
      int *datum = static_cast<int*>(data);
      for (size_t i=0; i < count; i++)
	datum[i] = map[datum[i]];
    } else {
      int64_t *datum = static_cast<int64_t*>(data);
      for (size_t i=0; i < count; i++)
	datum[i] = map[datum[i]];
    }
  }
}
Esempio n. 10
0
void Ioss::Map::reverse_map_data(void *data, const Ioss::Field &field, size_t count) const
{
  assert(!map.empty());
  if (!is_sequential(map)) {
    if (field.get_type() == Ioss::Field::INTEGER) {
      int* connect = static_cast<int*>(data);
      for (size_t i=0; i < count; i++) {
	int global_id = connect[i];
	connect[i] = global_to_local(global_id, true);
      }
    } else {
      int64_t* connect = static_cast<int64_t*>(data);
      for (size_t i=0; i < count; i++) {
	int64_t global_id = connect[i];
	connect[i] = global_to_local(global_id, true);
      }
    }
  }
}
Esempio n. 11
0
  int64_t DatabaseIO::put_field_internal(const Ioss::Region* region, const Ioss::Field& field,
				     void *data, size_t data_size) const
  {
    initialize(region);
    Ioss::Field::RoleType role = field.get_role();
    int64_t num_to_get = field.verify(data_size);

    if ((role == Ioss::Field::TRANSIENT || role == Ioss::Field::REDUCTION) &&
	num_to_get == 1) {

      int ncomp = field.transformed_storage()->component_count();

      if (legend_ != NULL && layout_ != NULL) {
	if (ncomp == 1) {
	  legend_->add_legend(field.get_name());
	}
	else {
	  const Ioss::VariableType *var_type = field.transformed_storage();
	  for (int i=0; i < ncomp; i++) {
	    std::string var_name = var_type->label_name(field.get_name(), i+1, '_');
	    legend_->add_legend(var_name);
	  }
	}
      }

      if (field.get_type() == Ioss::Field::STRING) {
	// Assume that if layout_ is NULL, then we want special one-line output.
	if (layout_ == NULL) {
	  Layout layout(false, 0, separator_, fieldWidth_);
	  layout.add_literal("-");
	  layout.add_literal(time_stamp(tsFormat));
	  layout.add_literal(" ");
	  layout.add_literal(*(std::string*)data);
	  if (logStream != NULL)
	    *logStream << layout << std::endl;
	} else {
	  layout_->add(field.get_name(), *(std::string*)data);
	}
      } else {
	if (layout_ == NULL) {
	  std::ostringstream errmsg;
	  errmsg << "INTERNAL ERROR: Unexpected NULL layout.\n";
	  IOSS_ERROR(errmsg);
	}
	if (field.get_type() == Ioss::Field::INTEGER) {
	  assert(field.transformed_count() == 1);

	  int *i_data = (int*)data;
	  std::vector<int> idata(ncomp);
	  for (int i=0; i < ncomp; i++) {
	    idata[i] = i_data[i];
	  }
	  layout_->add(field.get_name(), idata);
	} else {
	  std::vector<double> rdata(ncomp);
	  double *r_data = (double*)data;
	  for (int i=0; i < ncomp; i++) {
	    rdata[i] = r_data[i];
	  }
	  layout_->add(field.get_name(), rdata);
	}
      }
    } else {
      std::ostringstream errmsg;
      errmsg << "ERROR: Can not handle non-TRANSIENT or non-REDUCTION fields on regions.\n";
      IOSS_ERROR(errmsg);
    }
    return num_to_get;
  }
Esempio n. 12
0
int64_t Ioex::SuperElement::internal_get_field_data(const Ioss::Field &field, void *data,
                                                    size_t data_size) const
{
  size_t num_to_get = field.verify(data_size);

  if (field.get_name() == "cbmap") {
    assert(num_to_get == 2 * num_nodes * num_dim);
    int status = nc_get_array(filePtr, "cbmap", reinterpret_cast<double *>(data));
    if (status != 0) {
      std::ostringstream errmsg;
      errmsg << "ERROR: Could not load coodintate data field 'cbmap' from file '" << fileName
             << "'.";
      IOSS_ERROR(errmsg);
    }
  }
  else if (field.get_name() == "node_num_map") {
    assert(num_to_get == num_nodes);
    int status = nc_get_array(filePtr, "node_num_map", reinterpret_cast<double *>(data));

    if (status != 0) {
      std::ostringstream errmsg;
      errmsg << "ERROR: Could not load coodintate data field 'node_num_map' from file '" << fileName
             << "'.";
      IOSS_ERROR(errmsg);
    }
  }
  else if (field.get_name() == "coordx") {
    assert(num_to_get == num_nodes);
    int status = nc_get_array(filePtr, "coordx", reinterpret_cast<double *>(data));
    if (status != 0) {
      std::ostringstream errmsg;
      errmsg << "ERROR: Could not load coodintate data field 'coordx' from file '" << fileName
             << "'.";
      IOSS_ERROR(errmsg);
    }
  }
  else if (field.get_name() == "coordy") {
    assert(num_to_get == num_nodes);
    int status = nc_get_array(filePtr, "coordy", reinterpret_cast<double *>(data));
    if (status != 0) {
      std::ostringstream errmsg;
      errmsg << "ERROR: Could not load coodintate data field 'coordy' from file '" << fileName
             << "'.";
      IOSS_ERROR(errmsg);
    }
  }
  else if (field.get_name() == "coordz") {
    assert(num_to_get == num_nodes);
    int status = nc_get_array(filePtr, "coordz", reinterpret_cast<double *>(data));
    if (status != 0) {
      std::ostringstream errmsg;
      errmsg << "ERROR: Could not load coodintate data field 'coordz' from file '" << fileName
             << "'.";
      IOSS_ERROR(errmsg);
    }
  }
  else if (field.get_name() == "Kr") {
    assert(num_to_get == numDOF * numDOF);
    int status = nc_get_array(filePtr, "Kr", reinterpret_cast<double *>(data));
    if (status != 0) {
      std::ostringstream errmsg;
      errmsg << "ERROR: Could not load stiffness matrix field 'Kr' from file '" << fileName << "'.";
      IOSS_ERROR(errmsg);
    }
  }
  else if (field.get_name() == "Mr") {
    assert(num_to_get == numDOF * numDOF);
    int status = nc_get_array(filePtr, "Mr", reinterpret_cast<double *>(data));
    if (status != 0) {
      std::ostringstream errmsg;
      errmsg << "ERROR: Could not load mass matrix field 'Mr' from file '" << fileName << "'.";
      IOSS_ERROR(errmsg);
    }
  }
  else {
    std::cerr << "WARNING: " << type() << " '" << name() << "'. Unknown input field '"
              << field.get_name() << "'";
    return -4;
  }
  return num_to_get;
}