Exemple #1
0
void TextInputT::ReadConnectivity (const StringT& name, iArray2DT& connects)
{
  ifstreamT geo;
  OpenFile (geo, ".geo");

  if (!AdvanceToBlock (geo, name, "Connectivities")) throw ExceptionT::kDatabaseFail;

  StringT s;
  int numelms, numelnodes;
  iArrayT elms (connects.MinorDim());
  if (!geo.FindString ("Number of elements", s) ||
      !s.Tail ('=', numelms) ||
      !geo.FindString ("Number of element nodes", s) ||
      !s.Tail ('=', numelnodes) ||
      !geo.FindString ("element", s)) throw ExceptionT::kDatabaseFail;

  if (numelms != connects.MajorDim() ||
      numelnodes != connects.MinorDim()) throw ExceptionT::kSizeMismatch;

	for (int i=0; i < numelms; i++)
	{
		int elm_dex, elm_id; 
		geo >> elm_dex>> elm_id >> elms;
		connects.SetRow (i, elms);
	}
	connects--;
}
Exemple #2
0
void TextInputT::ReadGlobalElementSet (const StringT& name, iArrayT& set)
{
  if (set.Length() != fNumElements) throw ExceptionT::kSizeMismatch;

  ifstreamT geo;
  OpenFile (geo, ".geo");

  StringT s;
  int numelms;
  int count = 0;
  const int ID = atoi (name.Pointer());
  int found = -1;
  while (found != ID)
    {
      if (!geo.FindString ("Connectivities", s) ||
	  !geo.FindString ("Number of elements", s) ||
	  !s.Tail ('=', numelms) ||
	  !geo.FindString ("element", s)) throw ExceptionT::kDatabaseFail;

      count += numelms;
    }
  
  if (set.Length() != numelms) throw ExceptionT::kSizeMismatch;
  set.SetValueToPosition();
  set += count;
}
Exemple #3
0
void TextInputT::ReadGlobalElementMap (const StringT& name, iArrayT& elemmap)
{
  ifstreamT geo;
  OpenFile (geo, ".geo");

  StringT s;
  int numelms;
  char line [255];
  if (!AdvanceToBlock (geo, name, "Connectivities") ||
      !geo.FindString ("Number of elements", s) ||
      !s.Tail ('=', numelms)) throw ExceptionT::kDatabaseFail;
  if (elemmap.Length() != numelms) throw ExceptionT::kSizeMismatch;

	/* advance to the start of the connectivity block */
	if (!geo.FindString("index", s)) throw ExceptionT::kDatabaseFail;
	
	/* read map */
	elemmap = 0;
	for (int i=0; i < numelms; i++)
	{
		int index;
		geo >> index >> elemmap[i];
		geo.getline (line, 254);
    }
}
Exemple #4
0
void TextInputT::ReadAllElementMap (iArrayT& elemmap)
{
  if (elemmap.Length() != fNumElements) throw ExceptionT::kSizeMismatch;

  ifstreamT geo;
  OpenFile (geo, ".geo");

  StringT s;
  int numelms;
  int count = 0;
  char line [255];
  for (int i=0; i < fBlockID.Length(); i++)
    {
      if (!geo.FindString ("Connectivities", s) ||
	  !geo.FindString ("Number of elements", s) ||
	  !s.Tail ('=', numelms) ||
	  !geo.FindString ("element", s)) throw ExceptionT::kDatabaseFail;

      for (int i=0; i < numelms; i++)
	{
	  geo >> elemmap[count++];
	  geo.getline (line, 254);
	}
    }
}
Exemple #5
0
bool TextInputT::ScanResultsFile(ifstreamT& in)
{
	/* is old format */
	if (is_old_format(in.filename())) return ScanResultsFile_old(in);

	/* advance */
	StringT s;
	if (!in.FindString ("O U T P U T", s)) return false;

	/* first file name */
	StringT file;
	in >> file;
	if (!in.good()) return false;
	
	/* open first results file */
	StringT path, file_path;
	file_path.FilePath(in.filename());
	file_path.Append(file);
	ifstreamT dat(file_path);
	if (!dat.is_open()) {
		cout << "\n TextInputT::ScanResultsFile: error opening file: " << file_path << endl;
		return false;
	}

	/* get dimension from first file */
	if (!dat.FindString ("Group number", s)) return false;
	double t;
	if (!dat.FindString ("Time", s) || !s.Tail ('=', t)) return false;
	fTimeSteps.Append(t);
	if (!dat.FindString ("Number of blocks", s)) return false;

	/* scan nodal output labels */
	fNodeVariable.Free();
	int vals;
	if (!dat.FindString ("Nodal data", s) ||
        !dat.FindString ("Number of values", s) ||
        !s.Tail('=', vals)) {
		cout << "\n TextInputT::ScanResultsFile: error scanning nodal values" << endl;
		return false;
	}
	if (vals > 0) {
		dat >> s >> s; /* "index" and "node" */
		for (int v = 0; v < vals; v++) {
			dat >> s;
			fNodeVariable.Append(s);
		}
	}
Exemple #6
0
bool TextInputT::ScanGeometryFile (ifstreamT& in)
{
  StringT s;
  if (!in.FindString ("G E O M E T R Y", s)) return false;
  
	/* get number of element blocks */
	int num_blocks;
	if (!in.FindString ("Number of blocks", s) ||
	    !s.Tail ('=', num_blocks)) return false;

	/* coordinate data */
	if (!in.FindString ("Nodal coordinates", s)) return false;
	fNumNodes = 0;
	fNumDOF = 0;
	if (!in.FindString ("Number of nodal points", s) || !s.Tail ('=', fNumNodes)) 
		return false;
	if (!in.FindString ("Number of values", s) || !s.Tail ('=', fNumDOF)) 
		return false;
	
	/* scan block data */
	fNumElements = 0;
	if (!in.FindString ("Connectivities", s)) return false;
	for (int i = 0; i < num_blocks; i++)
	{
		StringT nid;
		if (!in.FindString ("Block ID", s) || !s.Tail ('=', nid)) 
			return false;
		fBlockID.Append(nid);
	
		int nel;
		if (!in.FindString ("Number of elements", s) || !s.Tail ('=', nel))
			return false;
		fBlockNumElem.Append(nel);
		fNumElements += nel;

		int nen;
		if (!in.FindString ("Number of element nodes", s) || !s.Tail ('=', nen))
			return false;
		fBlockNumElemNode.Append(nen);

		int icode;
		if (!in.FindString("Geometry code", s) || !s.Tail ('=', icode))
			return false;
		GeometryT::CodeT code = GeometryT::CodeT(icode);
		fBlockGeometry.Append(code);
	}

	/* return */
	if (fBlockID.Length() < 1) 
		return false;
	else
		return true;
}
Exemple #7
0
void TextInputT::ReadElementVariables(int step, const StringT& name, dArray2DT& evalues)
{
	const char caller[] = "TextInputT::ReadElementVariables";
		
	StringT toc_file(fFileRoot);
	toc_file.Append(".run");
	if (is_old_format(toc_file)) {
		ReadElementVariables_old(step, name, evalues);
		return;
	}

	/* resolve block index */
	int dex = fBlockID.PositionOf(name);
	if (dex == -1)
		ExceptionT::DatabaseFail(caller, "could not find block ID %s", name.Pointer());

	/* get file for specified step */
	StringT file;
	ResultsFile(toc_file, step, file);

	/* open results file */
	StringT results_file(fFilePath);
	results_file.Append(file);
  	ifstreamT run(results_file);
  	if (!run.is_open())
  		ExceptionT::GeneralFail(caller, "could not open file %s", results_file.Pointer());
	
	/* advance to the edge of the nodal data block */
	StringT s;
	if (!run.FindString ("Nodal data", s)) ExceptionT::DatabaseFail(caller);

	/* advance to block */
	for (int i = 0; i <= dex; i++)
		if (!run.FindString ("Element data", s)) 
			ExceptionT::DatabaseFail(caller);

	/* verify block */
	StringT block_ID;
	if (!run.FindString ("Block ID", s) ||
        !s.Tail('=', block_ID)) ExceptionT::DatabaseFail(caller);
	if (name != block_ID)
		ExceptionT::DatabaseFail(caller, "found block ID %s at position %d instead of ID %s",
			block_ID.Pointer(), dex, name.Pointer());

	/* read */
	iArrayT used (fElementVariable.Length()), ids;
	DataBlock(run, used, ids, evalues, false);	
}