예제 #1
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);	
}
예제 #2
0
/* operator support */
ifstreamT& PartitionT::Read(ifstreamT& in)
{
	/* set comment marker */
	char old_marker = in.comment_marker();
	in.set_marker(CommentMarker());

	/* check version */
	StringT version;
	in >> version;
	if (version != sPartitionTVersion)
		ExceptionT::BadInputValue("operator>>PartitionT", 
			"file version %s is not the current %s", version.Pointer(), sPartitionTVersion);

	in >> fNumPartitions; // number of parts
	in >> fID;            // partition number
	in >> fScope;         // numbering scope
	in >> fDecompType;    // decomposition type

	int length;

	// read grid parameters for spatial decomposition
	if (fDecompType == PartitionT::kSpatial) {
		in >> length;
		fGridDims.Dimension(length);
		in >> fGridDims;
		fGridPosition.Dimension(length);
		in >> fGridPosition;
	}
예제 #3
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;
}
예제 #4
0
void TranslateIOManager::SetEcho (int s, const StringT& file)
{
	fEchoOut.open(file);
	if (!fEchoOut.is_open()) 
		ExceptionT::GeneralFail("TranslateIOManager::SetEcho","Cannot open file %s", file.Pointer());
  	fEcho = true;
  	if (fEcho)
  		fEchoOut << "%\n" << s << endl;
}
예제 #5
0
/* construct extracting length from the name */
VectorParameterT::VectorParameterT(const StringT& name_N, char variable):
	ParameterInterfaceT(name_N),
	fVariable(variable)
{
	const char caller[] = "VectorParameterT::VectorParameterT";
	const char msg[] = "could not extract length from \"%s\" in \"%s\"";

	/* resolve length */
	StringT suffix;
	suffix.Suffix(name_N, '_');
	if (suffix.StringLength() < 2 || !isdigit(suffix[1]))
		ExceptionT::GeneralFail(caller, msg, suffix.Pointer(), name_N.Pointer());
	int length = -1;
	length = atoi(suffix.Pointer(1));
	if (length < 0) 
		ExceptionT::GeneralFail(caller, msg, suffix.Pointer(), name_N.Pointer());

	/* initialize */
	fVector.Dimension(length);
	fVector = 0.0;
}
예제 #6
0
bool TextInputT::Open (const StringT& filename)
{
  /* create file root */
  StringT suffix;
  suffix.Suffix (filename.Pointer());
  if (strncmp (suffix.Pointer(), ".geo", 4) == 0 ||
      strncmp (suffix.Pointer(), ".run", 4) == 0 ||
      strncmp (suffix.Pointer(), ".in", 3) == 0)
  fFileRoot.Root (filename);
  fFilePath.FilePath(fFileRoot);

	/* scan geometry file */
	ifstreamT geo;
	if (!OpenFile (geo, ".geo")) {
		cout << "\n TextInputT::Open: error opening geometry file: " << geo.filename() << endl;
		return false;
	}
	if (!ScanGeometryFile (geo)) {
		cout << "\n TextInputT::Open: error scanning geometry file: " << geo.filename() << endl;
		return false;
	}

	/* scan results file */
	ifstreamT run;
	if (!OpenFile (run, ".run")) {
		cout << "\n TextInputT::Open: error opening results file: " << run.filename() << endl;
		return false;
	}
    if (!ScanResultsFile (run)) {
		cout << "\n TextInputT::Open: error scanning results file: " << run.filename() << endl;
		return false;
    }
      
	/* must be OK */
	return true;
}
예제 #7
0
void ExtractIOManager::OpenFile (ofstreamT& o, const StringT& name, bool append) const
{
  StringT filename (fOutputName);
  filename.Append ("_");
  for (int i=name.StringLength(); i < fNumDigits; i++)
    filename.Append ("0");
  filename.Append (name);
  filename.Append (".", fOutfileExtension);
  if (!append)
    {
      remove (filename); // remove any pre-existing file
      o.open (filename);
    }
  else
    o.open_append (filename);
  if (!o.is_open())
    ExceptionT::GeneralFail ("ExtractIOManager::OpenFile","Unable to open %s", filename.Pointer());
}
예제 #8
0
/* create results file */
void ExodusOutputT::CreateResultsFile(int ID, ExodusT& exo)
{
	/* database file name */
	StringT filename;
	FileName(ID, filename);

	/* set initialization parameters */
	int dim = fCoordinates->MinorDim();
	int num_nodes = fElementSets[ID]->NumNodes();
	int num_elem = fElementSets[ID]->NumElements();
	int num_blks = fElementSets[ID]->NumBlocks();
	int num_node_sets = 0;
	int num_side_sets = 0;
	
	/* create new file */
	ArrayT<StringT> info, qa;
	AssembleQA (qa);
	if (!exo.Create(filename, fTitle, info, qa, dim, num_nodes,
			num_elem, num_blks, num_node_sets, num_side_sets))
		ExceptionT::DatabaseFail("ExodusOutputT::WriteOutput",
			"could not create file \"%s\" for output ID %d",
			filename.Pointer(), ID);

	/* write geometry */
	iArrayT nodes_used;
	nodes_used.Alias(fElementSets[ID]->NodesUsed());
	WriteCoordinates (exo, nodes_used);
	WriteConnectivity (ID, exo, nodes_used);

	/* write nodal variable labels */
	const ArrayT<StringT>& node_labels = fElementSets[ID]->NodeOutputLabels();
	exo.WriteLabels(node_labels, ExodusT::kNode);

	/* write element variable labels */
	const ArrayT<StringT>& elem_labels = fElementSets[ID]->ElementOutputLabels();
	exo.WriteLabels(elem_labels, ExodusT::kElement);
}
예제 #9
0
void ParameterInterfaceT::DefineInlineSub(const StringT& name, ParameterListT::ListOrderT& order,
	SubListT& sub_lists) const
{
	/* check for definition in NewSub */
	ParameterInterfaceT* inline_sub = NewSub(name);
	if (inline_sub) /* define inline sub */ {
	
		/* set sequence or choice */
		order = inline_sub->ListOrder();
		
		/* there should be no parameters */
		ParameterListT params(inline_sub->Name());
		inline_sub->DefineParameters(params);
		if (params.NumParameters() > 0)
			ExceptionT::GeneralFail("ParameterInterfaceT::DefineInlineSub", 
				"%d parameters not allowed in inline sub \"%s\"", params.NumParameters(), name.Pointer());
		
		/* get subs */
		inline_sub->DefineSubs(sub_lists);
		
		/* clean up */
		delete inline_sub;
	}
}
예제 #10
0
/* parse the given file placing values into the given parameter tree */
void expat_ParseT::Parse(const StringT& file, ParameterListT& params)
{
	const char caller[] = "expat_ParseT::Parse";

	/* check stack */
	if (sListStack.Length() != 0) ExceptionT::GeneralFail(caller, "list stack is not empty");

	/* create parser */
	XML_Parser parser = XML_ParserCreate(NULL);

	/* disable parsing of external entities, i.e., the DTD */
	XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_NEVER);

	/* set element handlers */
	XML_SetElementHandler(parser, startElement, endElement);

	ExceptionT::CodeT error = ExceptionT::kNoError;
	FILE* fp = NULL;
	try {
	
	/* open a file */
	fp = fopen(file, "r");
	if (!fp) ExceptionT::GeneralFail(caller, "error opening file \"%s\"", file.Pointer());

	/* parse */
	sRoot = &params;
	int done;
	char buf[BUFSIZ]; /* BUFSIZE normally defined in stdio.h */
  	do {
		size_t len = fread(buf, 1, sizeof(buf), fp);
		done = len < sizeof(buf);

		/* handle error */
		if (XML_Parse(parser, buf, len, done) == XML_STATUS_ERROR) {

			/* get buffer */
			int offset = 0;
			int size = 0;
			const char* buffer = XML_GetInputContext(parser, &offset, &size);
			buffer += offset;

			/* report error message */
			printf(
				"\n expat error: \"%s\" at line %d near\n%s",
				XML_ErrorString(XML_GetErrorCode(parser)),
				XML_GetCurrentLineNumber(parser), buffer);

			ExceptionT::BadInputValue(caller, "error parsing file \"%s\"", file.Pointer());
    	}

	} while (!done);

	/* stack check */
	if (sListStack.Length() != 0)
		ExceptionT::GeneralFail(caller, "stack depth should be 0: %d", sListStack.Length());

	} /* end try */
	
	catch(ExceptionT::CodeT err) {
		error = err;
	}

	/* clean up */
	if (fp) fclose(fp);
	XML_ParserFree(parser);
	sListStack.Dimension(0);
	sRoot = NULL;
	
	/* error */
	if (error != ExceptionT::kNoError)
		ExceptionT::Throw(error, caller, "failed");
}
예제 #11
0
/* accept parameter list */
void ABAQUS_UMAT_SS_BaseT::TakeParameterList(const ParameterListT& list)
{
	const char caller[] = "ABAQUS_UMAT_SS_BaseT::TakeParameterList";

	/* inherited */
	SSIsotropicMatT::TakeParameterList(list);

	fDebug = list.GetParameter("debug");
	fUseUMATModulus = list.GetParameter("use_UMAT_modulus");
	fNumElasticIterations = list.GetParameter("elastic_iterations");

	/* dimension work space */
	int nsd = NumSD();
	fStress.Dimension(nsd);
	fIPCoordinates.Dimension(nsd);
	fmat_nsd.Dimension(nsd);
	fsym_mat_nsd.Dimension(dSymMatrixT::int2DimensionT(nsd));

	/* open UMAT parameters file */
	StringT path;
	path.FilePath(MaterialSupport().InputFile());
	StringT params = list.GetParameter("UMAT_parameter_file");
	params.ToNativePathName();
	params.Prepend(path);
	ifstreamT in('#', params);
	if (!in.is_open())
		ExceptionT::GeneralFail(caller, "could not open file \"%s\"",
			params.Pointer());

	/* read ABAQUS-format input */
	bool nonsym = false;	
	Read_ABAQUS_Input(in, fUMAT_name, fProperties, fDensity, nstatv, nonsym);
	if (nonsym)
		fTangentType = GlobalT::kNonSymmetric;

	/* notify */
	if (fThermal->IsActive())
		cout << "\n ABAQUS_UMAT_SS_BaseT::Initialize: thermal strains must\n"
		     <<   "    be handled within the UMAT\n" << endl;
	
	/* UMAT dimensions */
	ndi = 3; // always 3 direct components
	if (nsd == 2)
		nshr = 1;
	else if (nsd == 3)
		nshr = 3;
	else
		ExceptionT::GeneralFail(caller, "unexpected dimension %d", nsd);
	ntens = ndi + nshr;

	/* modulus storage */
	if (fTangentType == GlobalT::kDiagonal)
		fModulusDim = ntens;
	else if (fTangentType == GlobalT::kSymmetric)
	{
		if (nsd == 2) fModulusDim = 10;
		else if (nsd == 3) fModulusDim = 21;
		else ExceptionT::GeneralFail(caller);
	}
	else if (fTangentType == GlobalT::kNonSymmetric)
		fModulusDim = ntens*ntens;
	else
		ExceptionT::GeneralFail(caller);

	/* storage block size (per ip) */
	fBlockSize = 0;
	fBlockSize += ntens;       // fstress
	fBlockSize += ntens;       // fstrain
	fBlockSize += 3;           // fsse_pd_cd
	fBlockSize += nstatv;      // fstatv
	fBlockSize += fModulusDim; // fmodulus
	fBlockSize += ntens;       // fstress_last
	fBlockSize += ntens;       // fstrain_last
	fBlockSize += 3;           // fsse_pd_cd_last
	fBlockSize += nstatv;      // fstatv_last
	
	/* argument array */
	fArgsArray.Dimension(fBlockSize);

	/* assign pointers */
	doublereal* parg = fArgsArray.Pointer();
	fstress.Set(ntens, parg);        parg += ntens;
	fstrain.Set(ntens, parg);        parg += ntens;
	fsse_pd_cd.Set(3, parg);         parg += 3;
	fstatv.Set(nstatv, parg);        parg += nstatv;
	fmodulus.Set(fModulusDim, parg); parg += fModulusDim;
	fstress_last.Set(ntens, parg);   parg += ntens;
	fstrain_last.Set(ntens, parg);   parg += ntens;
	fsse_pd_cd_last.Set(3, parg);    parg += 3;
	fstatv_last.Set(nstatv, parg);

	/* UMAT array arguments */
	fddsdde.Dimension(ntens);
	fddsdde = 0.0;
	fdstran.Dimension(ntens);
	fdstran = 0.0;
	fdrot.Dimension(3);   // always 3
	fdrot.Identity();
	fdfgrd0.Dimension(3); // always 3
	fdfgrd0.Identity();
	fdfgrd1.Dimension(3); // always 3
	fdfgrd1.Identity();
	fcoords.Dimension(nsd);

	/* write properties */
	ofstreamT& out = MaterialSupport().Output();	
	out << " Number of ABAQUS UMAT internal variables. . . . = " << nstatv << '\n';
	out << " Number of ABAQUS UMAT properties. . . . . . . . = " << fProperties.Length() << '\n';
	PrintProperties(out);

	/* set material output variables/labels */
	SetOutputVariables(fOutputIndex, fOutputLabels);
}
예제 #12
0
void ExodusOutputT::WriteOutput(double time, int ID, const dArray2DT& n_values,
	const dArray2DT& e_values)
{
	/* inherited */
	OutputBaseT::WriteOutput(time, ID, n_values, e_values);

	/* ExodusII does not like empty files with no nodes */
	if (fElementSets[ID]->NumNodes() == 0) return;

	/* ExodusII database */
	ExodusT exo(cout);
	if (fElementSets[ID]->PrintStep() == 0 ||
	    fElementSets[ID]->Changing())
		/* create new file */
	        CreateResultsFile(ID, exo);
	else
	{
		/* database file name */
		StringT filename;
		FileName(ID, filename);
	
		/* append output to existing results */
		if (!exo.OpenWrite(filename))
			ExceptionT::DatabaseFail("ExodusOutputT::WriteOutput",
				"could not open file \"%s\" for output ID %d at time %g",
				filename.Pointer(), ID, time);
	}
	
	/* print step - changing implies 1 result per file */
	int print_step = (fElementSets[ID]->Changing()) ? 1 : fElementSets[ID]->PrintStep() + 1;

	/* write time */
	exo.WriteTime(print_step, time);

	/* write nodal data */
	if (n_values.Length() > 0)
	{
		/* separate values by variable */
		dArrayT values(n_values.MajorDim());
		for (int i = 0; i < n_values.MinorDim(); i++)
		{
			n_values.ColumnCopy(i, values);
			exo.WriteNodalVariable(print_step, i + 1, values);
		}
	}

	/* write element data */
	const ArrayT<StringT>& blockIDs = fElementSets[ID]->BlockID ();
	if (e_values.Length() > 0)
	{
		/* separate values by block */
		for (int b=0; b < blockIDs.Length(); b++)
	    {
			dArray2DT e_block (fElementSets[ID]->NumBlockElements(blockIDs[b]), 
					   e_values.MinorDim());
			ElementBlockValues (ID, b, e_values, e_block);
	      
			/* separate values by variable */
			dArrayT values(e_block.MajorDim());
			for (int i = 0; i < e_block.MinorDim(); i++)
			{
				e_block.ColumnCopy(i, values);
				exo.WriteElementVariable(print_step, fElementBlockIDs[ID][b], i + 1, values);
			}
	    }
	}
}
예제 #13
0
/* construct extracting dimensions from the name */
MatrixParameterT::MatrixParameterT(const StringT& name_NxM, char variable):
	ParameterInterfaceT(name_NxM),
	fVariable(variable),
	fCopySymmetric(false)
{
	const char caller[] = "MatrixParameterT::MatrixParameterT";
	const char msg[] = "could not extract %s dimensions from \"%s\" in \"%s\"";

	/* resolve suffix */
	StringT suffix;
	suffix.Suffix(name_NxM, '_');
	if (suffix.StringLength() < 4)
		ExceptionT::GeneralFail(caller, msg, "matrix", suffix.Pointer(), name_NxM.Pointer());
	
	/* resolve column dimensions */
	StringT num;
	num.Suffix(suffix, 'x');
	if (num.StringLength() < 2 || !isdigit(num[1]))
		ExceptionT::GeneralFail(caller, msg, "col", num.Pointer(), name_NxM.Pointer());
	int col = -1;
	col = atoi(num.Pointer(1));
	if (col < 0)
		ExceptionT::GeneralFail(caller, msg, "col", num.Pointer(), name_NxM.Pointer());
	
	/* resolve row dimensions */
	suffix.Root('x');
	if (suffix.StringLength() < 2 || !isdigit(suffix[1]))
		ExceptionT::GeneralFail(caller, msg, "row", suffix.Pointer(), name_NxM.Pointer());
	int row = -1;
	row = atoi(suffix.Pointer(1));
	if (row < 0)
		ExceptionT::GeneralFail(caller, msg, "row", suffix.Pointer(), name_NxM.Pointer());
	
	/* initialize */
	fMatrix.Dimension(row, col);
	fMatrix = 0.0;
}