Exemple #1
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 #2
0
/* collect global and local iterations info for each time step */
void MRSSKStV::GetIterationInfo(bool get_iters, int loc_iters)
{
	if(get_iters) {
		
		/* write data */
		const StringT& input_file = fSSMatSupport->InputFile();
	
		/* output filenames */
		StringT iterdata;
		iterdata.Root(input_file);
	
		iterdata.Append(".iterdata.", fSSMatSupport->StepNumber());
		
		/* open output streams */
		ofstreamT out_idata(iterdata);

		/* write */
		out_idata << "Time step number:       " << setw(kIntWidth) 
		          << fSSMatSupport->StepNumber() << endl;
		out_idata << "Global iteration number:" << setw(kIntWidth) 
		          << fSSMatSupport->GroupIterationNumber() << endl;
		out_idata << "Number of local iterations to converge:" << setw(kIntWidth) 
		          << loc_iters << endl;
		out_idata.close(); /* close */
		
	} // if(get_iters)
}
Exemple #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;
}
void NodeManagerPrimitive::RegisterOutput (OutputBaseT& output, MakeCSE_IOManager& input)
{
  // FUTURE: carry over node tags
  fOutputNodeMap.Dimension (fCoordinates.MajorDim());
  fOutputNodeMap.SetValueToPosition ();
  fOutputNodeMap ++;

  output.SetCoordinates (fCoordinates, &fOutputNodeMap);

  sArrayT blocktonodesets;
  input.BlockToNode (blocktonodesets);

  int nsetid = 1;
  
  for (int g=0; g < fNodeSetID.Length(); g++)
    if  (nsetid < atoi (fNodeSetID[g])) 
      nsetid = atoi (fNodeSetID[g]) + 1;

  iArrayT nodes;
  for (int i=0; i < blocktonodesets.Length(); i++)
    {
      StringT name;
      name.Append (nsetid + 1);
      out  << "\n Creating Node Set from Element Group ID . . . . = "
	   << blocktonodesets[i] << '\n';
      theBoss->NodesUsed (blocktonodesets[i], nodes);
      if (nodes.Length() > 0)
	AddNodeSet (name, nodes, CSEConstants::kSplit);
      else
	out << "\n     No nodes found...\n";
    }

  for (int n=0; n < fNodeSetData.Length(); n++)
    output.AddNodeSet (fNodeSetData[n], fNodeSetID[n]);
}
Exemple #5
0
void
read_s(
	StringT& str,
	void const* data,
	std::size_t const size
) {
	duct::IO::StreamContext ctx(FromU::id, duct::Endian::system);
	duct::IO::imemstream stream(data, size * FromU::char_size);
	std::printf(
		"stream size: %lu\n",
		static_cast<unsigned long>(duct::IO::size(stream))
	);
	DUCT_ASSERTE(stream.good());
	ctx.read_string(
		stream, str, static_cast<std::streamsize>(size), duct::CHAR_NULL
	);
	DUCT_ASSERTE(stream.good());
	print_states(stream);
	std::printf(
		"String [size: %lu bsize: %lu len: %lu]: |",
		static_cast<unsigned long>(size),
		static_cast<unsigned long>(size*FromU::char_size),
		static_cast<unsigned long>(str.size())
	);
	std::cout << str << "|\n";
	str.clear();
}
Exemple #6
0
/* generate database file name for the given ID */
void ExodusOutputT::FileName(int ID, StringT& filename) const
{
	/* root */
	filename = fOutroot;

	/* tack on sequence number */
	if (fSequence > 0) filename.Append(".sq", fSequence + 1);

	/* group number */
	//filename.Append(".gp", fElementSets[ID]->ID());
	//NOTE: it's hard to resolve the number of element groups from the
	//      number of io groups based solely on what's in the database,
	//      so skip it for now.	

	/* I/O ID */
	filename.Append(".io", ID);

	/* changing geometry */
	if (fElementSets[ID]->Changing())
		filename.Append(".ps", fElementSets[ID]->PrintStep(), 4);
			/* assuming no more than 1000 output steps */

	/* extension */
	filename.Append(".exo");
}
Exemple #7
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;
	}
Exemple #8
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 #9
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 #10
0
StringT ParaDynOutputT::CreateFileName (const StringT& Label) const
{
  StringT var (fOutroot);
  
  /* tack on extension */
  var.Append (".");
  var.Append (Label);
  return var;
}
Exemple #11
0
void add_dir_sep(StringT& str)
{
    if (
        str.IsEmpty() ||
        (str[str.GetLength() - 1] != tdir_sep::value)
    )
    {
        str += tdir_sep::value;
    }
}
Exemple #12
0
	Value * Compiler::lookup (Symbol * identifier) {
		StringT functionName = identifier->value();
		
		llvm::Function* code = m_engine->FindFunctionNamed(functionName.c_str());
		
		if (!code) {
			return NULL;
		}
		
		return new CompiledFunction(code);
	}
void __stdcall BlackConfigurator::Save(const StringT& filename)
{
    FILE* fp = NULL;    
    if (_tfopen_s(&fp, filename.c_str(), _T("wb+, ccs=UTF-8")) != 0) {
        SXLOG_INF(g_local_logger) << _X(" open file for write failed! filepath:") << filename.c_str() << LBT << END;
        return;
    }
    ConfItemDictFileWriter writer(this, fp, 0);
    writer.Write();
    fclose(fp);
}
Exemple #14
0
void generate_scalar_swap(StringT & source, std::string const & numeric_string)
{
  source.append("__kernel void swap( \n");
  source.append("          __global "); source.append(numeric_string); source.append(" * s1, \n");
  source.append("          __global "); source.append(numeric_string); source.append(" * s2) \n");
  source.append("{ \n");
  source.append("  "); source.append(numeric_string); source.append(" tmp = *s2; \n");
  source.append("  *s2 = *s1; \n");
  source.append("  *s1 = tmp; \n");
  source.append("} \n");
}
Exemple #15
0
		StringT unescape_string (const StringT & value) {
			StringStreamT buffer;
			
			StringT::const_iterator i = value.begin(), end = value.end();
			
			// Skip enclosing quotes
			++i;
			--end;
			
			for (; i < end; ++i) {
				if (*i == '\\') {
					++i;
					
					switch (*i) {
						case 't':
							buffer << '\t';
							continue;
						case 'r':
							buffer << '\r';
							continue;
						case 'n':
							buffer << '\n';
							continue;
						case '\\':
							buffer << '\\';
							continue;
						case '"':
							buffer << '"';
							continue;
						case '\'':
							buffer << '\'';
							continue;
						case 'x':
							if ((end - i) >= 2) {
								StringT::value_type value = Math::convert_to_digit(*(++i)) << 4;
								value |= Math::convert_to_digit(*(++i));
								buffer << (StringT::value_type)value;
								continue;
							} else {
								break;
							}
						case '.':
							continue;
					}
					
					throw std::runtime_error("Could not parse string escape!");
				} else {
					buffer << *i;
				}
			}
		
			return buffer.str();
		}
Exemple #16
0
		Token parse_constant(StringIteratorT begin, StringIteratorT end, const StringT & constant) {
			StringIteratorT s = begin;
			StringIteratorT c = constant.begin();
			
			while (s != end && c != constant.end() && *c == *s) s++, c++;
			
			if (c == constant.end()) {
				return Token(begin, s);
			} else {
				return Token();
			}
		}
bool __stdcall BlackConfigurator::Load(const StringT& filename)
{
    //Clear();
    FILE* fp = NULL;
    if (_tfopen_s(&fp, filename.c_str(), _T("rb+, ccs=UTF-8")) != 0) {
        SXLOG_INF(g_local_logger) << _X(" open file for read failed! filepath:") << filename.c_str() << LBT << END;
        return false;
    }
    ConfItemDictFileReader reader(fp);
    ConfItemDict* result_dict = reader.Read();
    return false;
}
Exemple #18
0
bool TextInputT::OpenFile (ifstreamT& in, const char* ext) const
{
  StringT file (fFileRoot);
  file.Append (ext);
  in.open (file);
  if (!in.is_open()) 
    {
      fout << "\nTextInputT::OpenFile unable to open " << file << "\n\n";
      return false;
    }
  return true;
}
Exemple #19
0
bool
RFindInReadable_Impl( const StringT& aPattern, IteratorT& aSearchStart, IteratorT& aSearchEnd, const Comparator& compare )
  {
    IteratorT patternStart, patternEnd, searchEnd = aSearchEnd;
    aPattern.BeginReading(patternStart);
    aPattern.EndReading(patternEnd);

      // Point to the last character in the pattern
    --patternEnd;
      // outer loop keeps searching till we run out of string to search
    while ( aSearchStart != searchEnd )
      {
          // Point to the end position of the next possible match
        --searchEnd;
    
          // Check last character, if a match, explore further from here
        if ( compare(patternEnd.get(), searchEnd.get(), 1, 1) == 0 )
          {  
              // We're at a potential match, let's see if we really hit one
            IteratorT testPattern(patternEnd);
            IteratorT testSearch(searchEnd);

              // inner loop verifies the potential match at the current position
            do
              {
                  // if we verified all the way to the end of the pattern, then we found it!
                if ( testPattern == patternStart )
                  {
                    aSearchStart = testSearch;  // point to start of match
                    aSearchEnd = ++searchEnd;   // point to end of match
                    return true;
                  }
    
                  // if we got to end of the string we're searching before we hit the end of the
                  //  pattern, we'll never find what we're looking for
                if ( testSearch == aSearchStart )
                  {
                    aSearchStart = aSearchEnd;
                    return false;
                  }
    
                  // test previous character for a match
                --testPattern;
                --testSearch;
              }
            while ( compare(testPattern.get(), testSearch.get(), 1, 1) == 0 );
          }
      }

    aSearchStart = aSearchEnd;
    return false;
  }
Exemple #20
0
void generate_fft_div_vec_scalar(StringT & source, std::string const & numeric_string)
{
  source.append("__kernel void fft_div_vec_scalar(__global "); source.append(numeric_string); source.append("2 *input1, \n");
  source.append("  unsigned int size, \n");
  source.append("  "); source.append(numeric_string); source.append(" factor) { \n");
  source.append("  for (unsigned int i = get_global_id(0); i < size; i += get_global_size(0))  \n");
  source.append("    input1[i] /= factor; \n");
  source.append("} \n");
}
Exemple #21
0
void generate_fft_complex_to_real(StringT & source, std::string const & numeric_string)
{
  source.append("__kernel void complex_to_real(__global "); source.append(numeric_string); source.append("2 *in, \n");
  source.append("  __global "); source.append(numeric_string); source.append("  *out, \n");
  source.append("  unsigned int size) { \n");
  source.append("  for (unsigned int i = get_global_id(0); i < size; i += get_global_size(0))  \n");
  source.append("    out[i] = in[i].x; \n");
  source.append("} \n");
}
Exemple #22
0
/* read initial stress from file */
void MRSSKStV::InitialStress(dSymMatrixT& Stress0)
{
	int ip = CurrIP();
	ElementCardT& element = CurrentElement();
	
	/* read data from file */
	const StringT& input_file = fSSMatSupport->InputFile();
	StringT InitialStressData;
	InitialStressData.Root(input_file);
	// read element by element, ip by ip
	// if data is generated by a program
	Stress0=0.;	
}
/* Batch file processing */
void ExecutionManagerT::RunBatch(ifstreamT& in, ostream& status)
{
	/* mark status */
	status << "\n Processing batch file: " << in.filename() << '\n';
	
	/* start day/date info */
	time_t starttime;
	time(&starttime);

	/* get 1st entry */
	StringT nextinfilename;
	in >> nextinfilename;
	
	/* repeat to end of file */
	while (in.good())
	{
		/* adjusting execution options */
		if (nextinfilename[0] == '-')
			AddCommandLineOption(nextinfilename);
		else /* execute regular file */
		{	
			/* file path format */
			nextinfilename.ToNativePathName();

			/* path to source file */
			StringT path;
			path.FilePath(in.filename());
	
			/* open new input stream */
			nextinfilename.Prepend(path);
			ifstreamT nextin('#', nextinfilename);
	
			/* process if valid */
			if (nextin.is_open())
				JobOrBatch(nextin, cout);
			else
				cout << " File not found: " << nextinfilename << '\n';
		}
			
		/* get next entry */
		in >> nextinfilename;
	}

	/* stop day/date info */
	time_t stoptime;
	time(&stoptime);
	cout << "\n Batch start time  : " << ctime(&starttime);
	cout <<   " Batch stop time   : " << ctime(&stoptime);
}
Exemple #24
0
/* describe the parameters needed by the interface */
void VectorParameterT::DefineParameters(ParameterListT& list) const
{
	/* inherited */
	ParameterInterfaceT::DefineParameters(list);

	/* define components */
	for (int i = 0; i < fVector.Length(); i++) {
		StringT v = "v_";
		v[0] = fVariable;
		v.Append(i+1);
		ParameterT v_i(ParameterT::Double, v);
		v_i.SetDefault(0.0);
		list.AddParameter(v_i);
	}
}
Exemple #25
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);	
}
    inline bool 
    handle_identifier(boost::wave::token_id prev, 
        boost::wave::token_id before, StringT const &value)
    {
        using namespace boost::wave;
        switch (static_cast<unsigned int>(prev)) {
        case T_IDENTIFIER:
        case T_NONREPLACABLE_IDENTIFIER:
        case T_COMPL_ALT:
        case T_OR_ALT:
        case T_AND_ALT:
        case T_NOT_ALT:
        case T_XOR_ALT:
        case T_ANDASSIGN_ALT:
        case T_ORASSIGN_ALT:
        case T_XORASSIGN_ALT:
        case T_NOTEQUAL_ALT:
        case T_FIXEDPOINTLIT:
            return true;

        case T_FLOATLIT:
        case T_INTLIT:
        case T_PP_NUMBER:
            return (value.size() > 1 || (value[0] != 'e' && value[0] != 'E'));
            
         // avoid constructing universal characters (\u1234)
        case TOKEN_FROM_ID('\\', UnknownTokenType):
            return would_form_universal_char(value);
        }
        return false;
    }
Exemple #27
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 #28
0
void generate_asbs_impl3(StringT & source, char sign_a, char sign_b, asbs_config const & cfg, bool mult_alpha, bool mult_beta)
{
  source.append("      *s1 "); source.append(cfg.assign_op); source.append(1, sign_a); source.append(" *s2 ");
  if (mult_alpha)
    source.append("* alpha ");
  else
    source.append("/ alpha ");
  if (cfg.b != VIENNACL_ASBS_NONE)
  {
    source.append(1, sign_b); source.append(" *s3 ");
    if (mult_beta)
      source.append("* beta");
    else
      source.append("/ beta");
  }
  source.append("; \n");
}
Exemple #29
0
		StringT escape_string (const StringT & value) {
			StringStreamT buffer;
			
			StringT::const_iterator i = value.begin(), end = value.end();
			buffer << '"';
			
			for (; i != end; ++i) {
				if (*i == '"') {
					buffer << "\\\"";
				} else {
					buffer << *i;
				}
			}
			
			buffer << '"';
			return buffer.str();
		}
Exemple #30
0
void generate_asbs_impl2(StringT & source, char sign_a, char sign_b, asbs_config const & cfg)
{
  source.append("    if (options2 & (1 << 1)) { \n");
  if (cfg.b != VIENNACL_ASBS_NONE)
  {
    source.append("     if (options3 & (1 << 1)) \n");
    generate_asbs_impl3(source, sign_a, sign_b, cfg, false, false);
    source.append("     else \n");
    generate_asbs_impl3(source, sign_a, sign_b, cfg, false, true);
  }
  else
    generate_asbs_impl3(source, sign_a, sign_b, cfg, false, true);
  source.append("    } else { \n");
  if (cfg.b != VIENNACL_ASBS_NONE)
  {
    source.append("     if (options3 & (1 << 1)) \n");
    generate_asbs_impl3(source, sign_a, sign_b, cfg, true, false);
    source.append("     else \n");
    generate_asbs_impl3(source, sign_a, sign_b, cfg, true, true);
  }
  else
    generate_asbs_impl3(source, sign_a, sign_b, cfg, true, true);
  source.append("    } \n");

}