Exemplo n.º 1
0
void SetupSingleSolution::execute()
{
  RDM::RDSolver& mysolver = *solver().handle< RDM::RDSolver >();

  if(is_null(m_mesh))
    throw SetupError(FromHere(), "SetupSingleSolution has no configured mesh in [" + uri().string() + "]" );

  Mesh& mesh = *m_mesh;

  Group& fields = mysolver.fields();

  const Uint nbdofs = physical_model().neqs();

  // get the geometry field group

  SpaceFields& geometry = mesh.geometry_fields();

  const std::string solution_space = mysolver.options().option("solution_space").value<std::string>();

  // check that the geometry belongs to the same space as selected by the user

  Handle< SpaceFields > solution_group;

  if( solution_space == geometry.space() )
    solution_group = geometry.handle<SpaceFields>();
  else
  {
    // check if solution space already exists
    solution_group = find_component_ptr_with_name<SpaceFields>( mesh, RDM::Tags::solution() );
    if ( is_null(solution_group) )
    {
      solution_group = mesh.create_space_and_field_group( RDM::Tags::solution(), SpaceFields::Basis::POINT_BASED, "cf3.mesh."+solution_space).handle<SpaceFields>();
    }
    else // not null so check that space is what user wants
    {
      if( solution_space != solution_group->space() )
        throw NotImplemented( FromHere(), "Changing solution space not supported" );
    }
  }

  solution_group->add_tag( solution_space );

  // configure solution

  Handle< Field > solution = find_component_ptr_with_tag<Field>( *solution_group, RDM::Tags::solution() );
  if ( is_null( solution ) )
  {
    std::string vars;
    for(Uint i = 0; i < nbdofs; ++i)
    {
     vars += "u" + to_str(i) + "[1]";
     if( i != nbdofs-1 ) vars += ",";
    }

    solution = solution_group->create_field( RDM::Tags::solution(), vars ).handle<Field>();

    solution->add_tag(RDM::Tags::solution());
  }

  /// @todo here we should check if space() order is correct,
  ///       if not the change space() by enriching or other appropriate action

  // configure residual

  Handle< Field > residual = find_component_ptr_with_tag<Field>( *solution_group, RDM::Tags::residual());
  if ( is_null( residual ) )
  {
    residual = solution_group->create_field(Tags::residual(), solution->descriptor().description() ).handle<Field>();
    residual->descriptor().prefix_variable_names("rhs_");
    residual->add_tag(Tags::residual());
  }

  // configure wave_speed

  Handle< Field > wave_speed = find_component_ptr_with_tag<Field>( *solution_group, RDM::Tags::wave_speed());
  if ( is_null( wave_speed ) )
  {
    wave_speed = solution_group->create_field( Tags::wave_speed(), "ws[1]" ).handle<Field>();
    wave_speed->add_tag(Tags::wave_speed());
  }

  // place link to the fields in the Fields group

  if( ! fields.get_child( RDM::Tags::solution() ) )
    fields.create_component<Link>( RDM::Tags::solution()   )->link_to(*solution).add_tag(RDM::Tags::solution());
  if( ! fields.get_child( RDM::Tags::residual() ) )
    fields.create_component<Link>( RDM::Tags::residual()   )->link_to(*residual).add_tag(RDM::Tags::residual());
  if( ! fields.get_child( RDM::Tags::wave_speed() ) )
    fields.create_component<Link>( RDM::Tags::wave_speed() )->link_to(*wave_speed).add_tag(RDM::Tags::wave_speed());


  /// @todo apply here the bubble insertion if needed

  // parallelize the solution if not yet done

  solution->parallelize();

  std::vector<URI> sync_fields;
  sync_fields.push_back( solution->uri() );
  mysolver.actions().get_child("Synchronize")->options().configure_option("Fields", sync_fields);

}
Exemplo n.º 2
0
void loadPng(GImage* pImage, const unsigned char* pData, size_t nDataSize)
{
	// Check for the PNG signature
	if(nDataSize < 8 || png_sig_cmp((png_bytep)pData, 0, 8) != 0)
		throw Ex("not a png file");

	// Read all PNG data up until the image data chunk.
	GPNGReader reader(pData);
	png_set_read_fn(reader.m_pReadStruct, (png_voidp)&reader, (png_rw_ptr)readFunc);
	png_read_info(reader.m_pReadStruct, reader.m_pInfoStruct);

	// Get the image data
	int depth, color;
	png_uint_32 width, height;
	png_get_IHDR(reader.m_pReadStruct, reader.m_pInfoStruct, &width, &height, &depth, &color, NULL, NULL, NULL);
	GAssert(depth == 8); // unexpected depth
	pImage->setSize(width, height);

	// Set gamma correction
	double dGamma;
	if (png_get_gAMA(reader.m_pReadStruct, reader.m_pInfoStruct, &dGamma))
		png_set_gamma(reader.m_pReadStruct, 2.2, dGamma);
	else
		png_set_gamma(reader.m_pReadStruct, 2.2, 1.0 / 2.2); // 1.0 = viewing gamma, 2.2 = screen gamma

	// Update the 'info' struct with the gamma information
	png_read_update_info(reader.m_pReadStruct, reader.m_pInfoStruct);

	// Tell it to expand palettes to full channels
	png_set_expand(reader.m_pReadStruct);
	png_set_gray_to_rgb(reader.m_pReadStruct);

	// Allocate the row pointers
	unsigned long rowbytes = png_get_rowbytes(reader.m_pReadStruct, reader.m_pInfoStruct);
	unsigned long channels = rowbytes / width;
	ArrayHolder<unsigned char> hData(new unsigned char[rowbytes * height]);
	png_bytep pRawData = (png_bytep)hData.get();
	unsigned int i;
	{
		ArrayHolder<unsigned char> hRows(new unsigned char[sizeof(png_bytep) * height]);
		png_bytep* pRows = (png_bytep*)hRows.get();
		for(i = 0; i < height; i++)
			pRows[i] = pRawData + i * rowbytes;
		png_read_image(reader.m_pReadStruct, pRows);
	}

	// Copy to the GImage
	unsigned long nPixels = width * height;
	unsigned int* pRGBQuads = pImage->pixels();
	unsigned char *pBytes = pRawData;
	if(channels > 3)
	{
		GAssert(channels == 4); // unexpected number of channels
		for(i = 0; i < nPixels; i++)
		{
			*pRGBQuads = gARGB(pBytes[3], pBytes[0], pBytes[1], pBytes[2]);
			pBytes += channels;
			pRGBQuads++;
		}
	}
	else if(channels == 3)
	{
		for(i = 0; i < nPixels; i++)
		{
			*pRGBQuads = gARGB(0xff, pBytes[0], pBytes[1], pBytes[2]);
			pBytes += channels;
			pRGBQuads++;
		}
	}
	else
	{
		throw Ex("Sorry, loading ", to_str(channels), "-channel pngs not supported");
/*		GAssert(channels == 1); // unexpected number of channels
		for(i = 0; i < nPixels; i++)
		{
			*pRGBQuads = gARGB(0xff, pBytes[0], pBytes[0], pBytes[0]);
			pBytes += channels;
			pRGBQuads++;
		}*/
	}

	// Check for additional tags
	png_read_end(reader.m_pReadStruct, reader.m_pEndInfoStruct);
}
Exemplo n.º 3
0
void RegExpTest::word_segmentation_test()	{
	
	std::vector<std::string> tokens = {	
			"Other", 
			"CR", 
			"LF", 
			"Newline", 
			"Extend", 
			"Format", 
			"Katakana", 
			"ALetter", 
			"MidLetter", 
			"MidNum", 
			"MidNumLet", 
			"Numeric", 
			"ExtendNumLet"
		};		

// begin regular exp
	std::string Other_EF 		= "(Other.(Extend|Format)*)"; 
	std::string ALetter_EF 		= "(ALetter.(Extend|Format)*)"; 
	std::string Numeric_EF 		= "(Numeric.(Extend|Format)*)";
	std::string Katakana_EF  	= "(Katakana.(Extend|Format)*)";
	std::string ExtendNumLet_EF = "(ExtendNumLet.(Extend|Format)*)";
	std::string MidLetter_EF	= "(MidLetter.(Extend|Format)*)";
	std::string MidNumLet_EF	= "(MidNumLet.(Extend|Format)*)";
	std::string MidNum_EF 		= "(MidNum.(Extend|Format)*)";
	std::string MidLetter_MidNumLet_EF = "((MidLetter|MidNumLet).(Extend|Format)*)";
	std::string MidNum_MidNumLet_EF = "((MidNum|MidNumLet).(Extend|Format)*)";
	
//	std::string ALetter			= 	"(" + ALetter_EF + "+|(" + ALetter_EF + "+." + MidLetter_MidNumLet_EF + "." + ALetter_EF + "+))";
	std::string ALetter			= 	"((" + ALetter_EF + "|(" + ALetter_EF + "." + MidLetter_MidNumLet_EF + "." + ALetter_EF + "))+)";
	std::string Numeric			= 	"((" + Numeric_EF + "|(" + Numeric_EF + "+." + MidNum_MidNumLet_EF    + "." + Numeric_EF + "+))+)";
//	std::string Numeric			= 	"(" + Numeric_EF + "+|(" + Numeric_EF + "+." + MidNum_MidNumLet_EF + "." + Numeric_EF + "+))";

	std::string ALetter_Numeric =   	"((" + ALetter + "|" + Numeric + ")+)";

	//std::string Katakana = 			"((" + Katakana_EF + "+|" + ExtendNumLet_EF + "*)*)";
	//std::string Katakana = 				"(" + Katakana_EF + "+)";
	std::string Katakana_ExtendNumLet = "((" + Katakana_EF + "+|" + Katakana_EF + "+." + ExtendNumLet_EF + "+|" + ExtendNumLet_EF + "+." + Katakana_EF + "+)+)";
	std::string ALetter_Numeric_ExtendNumLet = "((" + ALetter_Numeric + "+|" + ALetter_Numeric + "+." + ExtendNumLet_EF + "+|" + ExtendNumLet_EF + "+." + ALetter_Numeric + "+)+)";

	std::string ExtendNumLet = "(" + ExtendNumLet_EF + "+)";

	std::string ALetter_Numeric_Katakana_1 =   "(" + ALetter_Numeric + "+." + ExtendNumLet_EF + "+." + Katakana_ExtendNumLet + "+)";
	std::string ALetter_Numeric_Katakana_2 =   "(" + Katakana_ExtendNumLet + "+." + ExtendNumLet_EF + "+." + ALetter_Numeric + "+)";

	std::stringstream ss;
//	ss << "("+ Other_EF + "|CR|LF|Newline|Extend|Format|Katakana|ALetter|" + MidLetter_EF + "|MidNum|" + MidNumLet_EF + "|Numeric|ExtendNumLet)";
	ss << "((Other|Extend|Format|Katakana|ALetter|MidLetter|MidNum|MidNumLet|Numeric|ExtendNumLet).(Extend|Format)*)";
	ss << "|(CR|LF|Newline)";
	ss << "|(CR.LF)";
	ss << "|((Extend|Format)*)";
	ss << "|" << ALetter_Numeric;
	ss << "|" << ALetter_Numeric_ExtendNumLet ;
	ss << "|" << Katakana_ExtendNumLet;
	ss << "|" << ALetter_Numeric_Katakana_1;
	ss << "|" << ALetter_Numeric_Katakana_2;
	ss << "|" << ExtendNumLet;
	ss << "|" << ALetter;
	
// end regular exp
	
	
	
	RegExpWithTokens<char> reg_exp(tokens, 'a');
	reg_exp.evaluate(ss.str());
	to_str(std::cout, reg_exp.dfa(), tokens, 'a');
	to_cpp(std::cout, reg_exp.dfa(), "word_states");

	std::string s0 = {};
	std::string s1 = {(char)PV::ALetter};
	std::string s2 = {(char)PV::ALetter, (char)PV::ALetter};
	std::string s3 = {(char)PV::ALetter, (char)PV::ALetter, (char)PV::ALetter};
	std::string s4 = {(char)PV::ALetter, (char)PV::Extend, (char)PV::ALetter, (char)PV::Numeric};
	std::string s5 = {(char)PV::Katakana};
	std::string s6 = {(char)PV::Katakana, (char)PV::Katakana};
	std::string s7 = {(char)PV::Katakana, (char)PV::Katakana, (char)PV::Katakana};
	
	std::string s8 = {(char)PV::Katakana, (char)PV::ExtendNumLet};
	std::string s9 = {(char)PV::Katakana, (char)PV::ExtendNumLet, (char)PV::ExtendNumLet, (char)PV::Katakana};
	std::string s10 = {(char)PV::Katakana, (char)PV::ExtendNumLet, (char)PV::Katakana, (char)PV::ExtendNumLet, (char)PV::Katakana};
	std::string s11 = {(char)PV::ExtendNumLet, (char)PV::Katakana, (char)PV::ExtendNumLet, (char)PV::Katakana};

	std::string s12 = {(char)PV::ALetter, (char)PV::Numeric, (char)PV::ALetter};
	std::string s13 = {(char)PV::ExtendNumLet};
	std::string s14 = {(char)PV::ExtendNumLet, (char)PV::ExtendNumLet};

	std::string s15 = {(char)PV::Katakana, (char)PV::ALetter};
	std::string s16 = {(char)PV::ALetter, (char)PV::Katakana};
	std::string s17 = {(char)PV::Katakana, (char)PV::Numeric};
	std::string s18 = {(char)PV::Numeric, (char)PV::Katakana};
	std::string s19 = {(char)PV::Other, (char)PV::Extend};
	std::string s20 = {(char)PV::MidNumLet, (char)PV::Format};
	std::string s21 = {(char)PV::ALetter, (char)PV::MidLetter, (char)PV::ALetter};

	
//	assert (check_aux(reg_exp.dfa(), s0, 'a')==false);
	assert (check_aux(reg_exp.dfa(), s1, 'a')==true);
	assert (check_aux(reg_exp.dfa(), s2, 'a')==true);
	assert (check_aux(reg_exp.dfa(), s3, 'a')==true);
	assert (check_aux(reg_exp.dfa(), s4, 'a')==true);
	assert (check_aux(reg_exp.dfa(), s5, 'a')==true);
	assert (check_aux(reg_exp.dfa(), s6, 'a')==true);
	assert (check_aux(reg_exp.dfa(), s7, 'a')==true);
	assert (check_aux(reg_exp.dfa(), s8, 'a')==true);
	assert (check_aux(reg_exp.dfa(), s9, 'a')==true);
	assert (check_aux(reg_exp.dfa(), s10, 'a')==true);
	assert (check_aux(reg_exp.dfa(), s11, 'a')==true);
	assert (check_aux(reg_exp.dfa(), s12, 'a')==true);
	assert (check_aux(reg_exp.dfa(), s13, 'a')==true);
	assert (check_aux(reg_exp.dfa(), s14, 'a')==true);
	assert (check_aux(reg_exp.dfa(), s15, 'a')==false);
	assert (check_aux(reg_exp.dfa(), s16, 'a')==false);
	assert (check_aux(reg_exp.dfa(), s17, 'a')==false);
	assert (check_aux(reg_exp.dfa(), s18, 'a')==false);
	assert (check_aux(reg_exp.dfa(), s19, 'a')==true);
	assert (check_aux(reg_exp.dfa(), s20, 'a')==true);
	assert (check_aux(reg_exp.dfa(), s21, 'a')==true);
	
/*	check_aux(reg_exp.dfa(), , true};
	check_aux(reg_exp.dfa(), , true},
	check_aux(reg_exp.dfa(), std::string({(char)PV::ALetter, (char)PV::Extend, (char)PV::ALetter, (char)PV::Numeric}, true}
	*/	
	
//	std::string target = {(char)PV::ALetter, (char)PV::Extend, };
	std::string target = {(char)PV::ALetter, (char)PV::Extend, (char)PV::ALetter, (char)PV::Numeric};
//	std::string target = {(char)PV::ALetter, (char)PV::Numeric};
//	CHECK(reg_exp.dfa(), target, true);
	std::cout << "end test5 " << std::endl;
		
}
Exemplo n.º 4
0
 static bool convert(const T& i, std::string& o)
 {
     return to_str(i, o);
 }
Exemplo n.º 5
0
	std::string & type_string::ref()
	{
		to_str();
		return string_value;
	}
Exemplo n.º 6
0
void route_val::print_val()
{
	set_str();
	rt_val_logdbg("%s", to_str());
}
Exemplo n.º 7
0
RazorAHRS::RazorAHRS(const string &port, DataCallbackFunc data_func, ErrorCallbackFunc error_func,
    int connect_timeout_ms, speed_t speed)
    : _input_pos(0)
    , _connect_timeout_ms(connect_timeout_ms)
    , data(data_func)
    , error(error_func)
    , _thread_id(0)
    , _stop_thread(false)
{  
  // check data type sizes
  assert(sizeof(char) == 1);
  assert(sizeof(float) == 4);

  // open serial port
  if (port == "")
    throw runtime_error("No port specified!");
  if (!_open_serial_port(port.c_str()))
    throw runtime_error("Could not open serial port!");  
      
  // get port attributes
  struct termios tio;
  if (int errorID = tcgetattr(_serial_port, &tio))
    throw runtime_error("Could not get serial port attributes! Error # " + to_str(errorID));
  
  /* see http://www.easysw.com/~mike/serial/serial.html */
  /* and also http://linux.die.net/man/3/tcsetattr */
  // basic raw/non-canonical setup
  cfmakeraw(&tio);
  
  // enable reading and ignore control lines
  tio.c_cflag |= CREAD | CLOCAL;

  // set 8N1
  tio.c_cflag &= ~PARENB; // no parity bit
  tio.c_cflag &= ~CSTOPB; // only one stop bit
  tio.c_cflag &= ~CSIZE;  // clear data bit number
  tio.c_cflag |= CS8;     // set 8 data bits
  
  // no hardware flow control
  tio.c_cflag &= ~CRTSCTS;
  // no software flow control  
  tio.c_iflag &= ~(IXON | IXOFF | IXANY);
  
  // poll() is broken on OSX, so we set VTIME and use read(), which is ok since
  // we're reading only one port anyway
  tio.c_cc[VMIN]  = 0;
  tio.c_cc[VTIME] = 10; // 10 * 100ms = 1s
  
  // set port speed
  if (int errorID = cfsetispeed(&tio, speed))
    throw runtime_error(" " + to_str(errorID)
        + ": Could not set new serial port input speed to "
        + to_str(speed) + ".");
  if (int errorID = cfsetospeed(&tio, speed))
    throw runtime_error(" " + to_str(errorID)
        + ": Could not set new serial port output speed to "
        + to_str(speed) + ".");

  // set port attributes
  // must be done after setting speed!
  if (int errorID = tcsetattr(_serial_port, TCSANOW, &tio))
  {
    throw runtime_error(" " + to_str(errorID)
        + ": Could not set new serial port attributes.");
  }

  // start input/output thread
  _start_io_thread();
}
Exemplo n.º 8
0
template<unsigned N> suite &operator <<( const char (&str)[N] ) { return xpr[1] += to_str(str),             *this; }
Exemplo n.º 9
0
		static const std::string to_str(const std::wstring &Data){return to_str(Data.c_str());}
Exemplo n.º 10
0
 template<          > inline std::string to_str( const timer::time_point &start ) {
     return to_str( double((timer::now() - start).count()) * timer::period::num / timer::period::den );
 }
Exemplo n.º 11
0
template<typename T> suite &operator <<( const T &t           ) { return xpr[1] += to_str(t),               *this; }
Exemplo n.º 12
0
XORER::XORER(int num_thread)
: num_thread(num_thread),
  num_mpi_procs(0), mpi_rank(0)
{
  log_(INFO, "constructed; \n" << to_str() )
}
Exemplo n.º 13
0
char* GTokenizer::nextArg(GCharSet& delimiters, char escapeChar)
{
	char c = m_pStream->peek();
	if(c == '"')
	{
		advance(1);
		nextUntil(charSet("\"\n"));
		if(peek() != '"')
			ThrowError("Expected matching double-quotes on line ", 
								 to_str(m_line), ", col ", to_str(col()));
		advance(1);
		return m_pBufStart;
	}
	else if(c == '\'')
	{
		advance(1);
		nextUntil(charSet("'\n"));
		if(peek() != '\'')
			ThrowError("Expected a matching single-quote on line ", to_str(m_line), 
								 ", col ", to_str(col()));
		advance(1);
		return m_pBufStart;
	}
	//else

	m_pBufPos = m_pBufStart;
	bool inEscapeMode = false;
	while(m_len > 0)
	{
		char c = m_pStream->peek();
		if(inEscapeMode)
		{
			if(c == '\n')
			{
				ThrowError("Error: '", to_str(escapeChar), "' character used as "
									 "last character on a line to attempt to extend string over "
									 "two lines on line" , to_str(m_line), ", col ", 
									 to_str(col()) );
			}
			c = get();
			bufferChar(c);
			inEscapeMode = false;			
		}
		else
		{
			if(c == '\n' || delimiters.find(c)){ break; }
			c = get();
			if(c == escapeChar)	{	inEscapeMode = true;	}
			else { bufferChar(c);	}
		}
	}

	if(m_pBufPos == m_pBufEnd)
	{
		growBuf();
	}
	*m_pBufPos = '\0';

	//	std::cerr << "nextArg: '" << m_pBufStart << "'\n"; //DEBUG
	return m_pBufStart;
}
Exemplo n.º 14
0
void ImposeCFL::execute()
{
  if (is_null(m_wave_speed))  throw SetupError(FromHere(), "wave_speed was not configured");
  if (is_null(m_time_step))   throw SetupError(FromHere(), "time_step Field was not set");
  if (is_null(m_time))        throw SetupError(FromHere(), "Time component was not set");

  Field& wave_speed = *m_wave_speed;
  Field& time_step = *m_time_step;

  std::vector<Real> args(3);
  args[0] = m_time->iter();
  args[1] = m_time->current_time();
  args[2] = m_cfl;
  m_cfl = m_cfl_function(args);

  if (options().value<bool>("time_accurate")) // global time stepping
  {
    Time& time = *m_time;

    cf3_assert_desc("Fields not compatible: "+to_str(time_step.size())+"!="+to_str(wave_speed.size()),time_step.size() == wave_speed.size());

    /// compute time step
    //  -----------------
    /// - take user-defined time step
    Real dt = time.options().value<Real>("time_step");
    if (dt==0.) dt = math::Consts::real_max();

    /// - Make time step stricter through the CFL number
    Real min_dt = dt;
    Real max_dt = 0.;
    for (Uint i=0; i<wave_speed.size(); ++i)
    {
      if (wave_speed[i][0] > 0.)
      {
        dt = m_cfl/wave_speed[i][0];

        min_dt = std::min(min_dt,dt);
        max_dt = std::max(max_dt,dt);
      }
    }

    Real glb_min_dt;
    PE::Comm::instance().all_reduce(PE::min(), &min_dt, 1, &glb_min_dt);
    dt = glb_min_dt;

    /// - Make sure we reach final simulation time
    Real tf = time.options().value<Real>("end_time");
    if( time.current_time() + dt*(1+sqrt(eps()))> tf )
      dt = tf - time.current_time();

    /// Calculate the time_step
    //  -----------------------
    /// For Forward Euler: time_step = @f$ \Delta t @f$.
    /// @f[ Q^{n+1} = Q^n + \Delta t \ R @f]
    for (Uint i=0; i<time_step.size(); ++i)
    {
      time_step[i][0] = dt ;
    }

    // Update the new time step
    time.dt() = dt;

// UNCOMMENTING THIS WILL FIX THE UPPER-LIMIT OF THE WAVESPEED FOREVER :(
// DUE TO LINE 88
//    // Fix wave-speed for visualization
//    Real glb_max_dt;
//    PE::Comm::instance().all_reduce(PE::min(), &max_dt, 1, &glb_max_dt);
//    for (Uint i=0; i<wave_speed.size(); ++i)
//    {
//      if (wave_speed[i][0] == 0.)
//      {
//        wave_speed[i][0] = cfl/glb_max_dt;
//      }
//    }
  }
  else // local time stepping
  {
    if (is_not_null(m_time))  m_time->dt() = 0.;

    // Check for a minimum value for the wave speeds
    Real min_wave_speed = math::Consts::real_max();
    for (Uint i=0; i<wave_speed.size(); ++i)
    {
      if (wave_speed[i][0] > 0.)
      {
        min_wave_speed = std::min(min_wave_speed,wave_speed[i][0]);
      }
    }
    PE::Comm::instance().all_reduce(PE::min(), &min_wave_speed, 1, &min_wave_speed);
    if (min_wave_speed == 0.)
      throw common::BadValue(FromHere(), "Minimum wave-speed cannot be zero!");

    // Calculate the time_stepicient = CFL/wave_speed
    for (Uint i=0; i<wave_speed.size(); ++i)
    {
      if (wave_speed[i][0] == 0.)
      {
        wave_speed[i][0] = min_wave_speed;
      }
      time_step[i][0] = m_cfl/wave_speed[i][0];
    }
  }
}
Exemplo n.º 15
0
void MainWindow::LoadDefaults()
{
	to_str( m_lastInputDir, QApplication::applicationDirPath() );
	to_str( m_settings.outputDir, QApplication::applicationDirPath() );
}
Exemplo n.º 16
0
			static void log_out(const char*FileName, int LineNo, const char*FunctionName, 
			ext_data levels_format_usage_data, bool endline, const T1 &Data1, const T2 &Data2, const T3 &Data3)
		{
			ezlogger_output_policy::get_log_stream() << ezlogger_format_policy::get_log_prefix_format(FileName, LineNo, FunctionName, levels_format_usage_data) << to_str(Data1) << ", "  << to_str(Data2) << ", "  << to_str(Data3);
			if (endline) ezlogger_output_policy::get_log_stream() << std::endl;
		}
Exemplo n.º 17
0
dst_entry_udp_mc::~dst_entry_udp_mc()
{
	dst_udp_mc_logdbg("%s", to_str().c_str());
}
Exemplo n.º 18
0
/*
backup in this order:

6 win
5 win/draw
4 draw if draw/loss
3 win/draw/loss
2 draw
1 draw/loss
0 lose
return true if fully solved, false if it's unknown or partially unknown
*/
bool Player::do_backup(Node * node, Node * backup, int toplay){
	int nodeoutcome = node->outcome;
	if(nodeoutcome >= 0) //already proven, probably by a different thread
		return true;

	if(backup->outcome == -3) //nothing proven by this child, so no chance
		return false;


	uint8_t proofdepth = backup->proofdepth;
	if(backup->outcome != toplay){
		uint64_t sims = 0, bestsims = 0, outcome = 0, bestoutcome = 0;
		backup = NULL;

		Node * child = node->children.begin(),
			 * end = node->children.end();

		for( ; child != end; child++){
			int childoutcome = child->outcome; //save a copy to avoid race conditions

			if(proofdepth < child->proofdepth+1)
				proofdepth = child->proofdepth+1;

			//these should be sorted in likelyness of matching, most likely first
			if(childoutcome == -3){ // win/draw/loss
				outcome = 3;
			}else if(childoutcome == toplay){ //win
				backup = child;
				outcome = 6;
				proofdepth = child->proofdepth+1;
				break;
			}else if(childoutcome == 3-toplay){ //loss
				outcome = 0;
			}else if(childoutcome == 0){ //draw
				if(nodeoutcome == toplay-3) //draw/loss
					outcome = 4;
				else
					outcome = 2;
			}else if(childoutcome == -toplay){ //win/draw
				outcome = 5;
			}else if(childoutcome == toplay-3){ //draw/loss
				outcome = 1;
			}else{
				logerr("childoutcome == " + to_str(childoutcome) + "\n");
				assert(false && "How'd I get here? All outcomes should be tested above");
			}

			sims = child->exp.num();
			if(bestoutcome < outcome){ //better outcome is always preferable
				bestoutcome = outcome;
				bestsims = sims;
				backup = child;
			}else if(bestoutcome == outcome && ((outcome == 0 && bestsims < sims) || bestsims > sims)){
				//find long losses or easy wins/draws
				bestsims = sims;
				backup = child;
			}
		}

		if(bestoutcome == 3) //no win, but found an unknown
			return false;
	}

	if(CAS(node->outcome, nodeoutcome, backup->outcome)){
		node->bestmove = backup->move;
		node->proofdepth = proofdepth;
	}else //if it was in a race, try again, might promote a partial solve to full solve
		return do_backup(node, backup, toplay);

	return (node->outcome >= 0);
}
Exemplo n.º 19
0
//This function prints a string that represent a row in the rule table as debug log.
void rule_val::print_val()
{
	set_str();
	rr_val_logdbg("%s", to_str());
}
Exemplo n.º 20
0
    del_pigsty_entry(pigsty);

CUTE_TEST_CASE_END

CUTE_TEST_CASE(to_int_tests)
    CUTE_CHECK("to_int() != 0", to_int(NULL) == 0);
    CUTE_CHECK("to_int() != 4", to_int("4") == 4);
    CUTE_CHECK("to_int() != 0xf", to_int("0xf") == 0xf);
    CUTE_CHECK("to_int() != 0x0f", to_int("0x0f") == 0xf);
    CUTE_CHECK("to_int() != 0xe0", to_int("0xe0") == 0xe0);
    CUTE_CHECK("to_int() == 0", to_int(NULL) == 0);
CUTE_TEST_CASE_END

CUTE_TEST_CASE(to_str_tests)
    char *retval = NULL;
    CUTE_CHECK("to_str() != NULL", to_str(NULL) == NULL);
    retval = to_str("\"\\n\\r\\t\"");
    CUTE_CHECK("to_str() != \"\\n\\r\\t\"", strcmp(retval, "\n\r\t") == 0);
    free(retval);
    retval = to_str("\"r\\nr\\nn\\ne\\n\"");
    CUTE_CHECK("to_str() != \"r\\nr\\nn\\ne\\n\"", strcmp(retval, "r\nr\nn\ne\n") == 0);
    free(retval);
    retval = to_str("\"\x61\x62\x63\"");
    CUTE_CHECK("to_str() != \"abc\"", strcmp(retval, "abc") == 0);
    free(retval);
    retval = to_str("\"\x61\x62\x6362\"");
    CUTE_CHECK("to_str() != \"abb\"", strcmp(retval, "abb") == 0);
    free(retval);
    retval = to_str("\"\x9tab!\"");
    CUTE_CHECK("to_str() != \"\\ttab!\"", strcmp(retval, "\ttab!") == 0);
    free(retval);
Exemplo n.º 21
0
Arquivo: class.c Projeto: takkaw/mruby
/*
  retrieve arguments from mrb_state.

  mrb_get_args(mrb, format, ...)

  returns number of arguments parsed.

  fortmat specifiers:

   o: Object [mrb_value]
   S: String [mrb_value]
   A: Array [mrb_value]
   H: Hash [mrb_value]
   s: String [char*,int]
   z: String [char*]
   a: Array [mrb_value*,mrb_int]
   f: Float [mrb_float]
   i: Integer [mrb_int]
   b: Binary [int]
   n: Symbol [mrb_sym]
   &: Block [mrb_value]
   *: rest argument [mrb_value*,int]
   |: optional
 */
int
mrb_get_args(mrb_state *mrb, const char *format, ...)
{
  char c;
  int i = 0;
  mrb_value *sp = mrb->stack + 1;
  va_list ap;
  int argc = mrb->ci->argc;
  int opt = 0;

  va_start(ap, format);
  if (argc < 0) {
    struct RArray *a = mrb_ary_ptr(mrb->stack[1]);

    argc = a->len;
    sp = a->ptr;
  }
  while ((c = *format++)) {
    switch (c) {
    case '|': case '*': case '&':
      break;
    default:
      if (argc <= i && !opt) {
        mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
      }
      break;
    }

    switch (c) {
    case 'o':
      {
        mrb_value *p;

        p = va_arg(ap, mrb_value*);
        if (i < argc) {
          *p = *sp++;
          i++;
        }
      }
      break;
    case 'S':
      {
        mrb_value *p;

        p = va_arg(ap, mrb_value*);
        if (i < argc) {
          *p = to_str(mrb, *sp++);
          i++;
        }
      }
      break;
    case 'A':
      {
        mrb_value *p;

        p = va_arg(ap, mrb_value*);
        if (i < argc) {
          *p = to_ary(mrb, *sp++);
          i++;
        }
      }
      break;
    case 'H':
      {
        mrb_value *p;

        p = va_arg(ap, mrb_value*);
        if (i < argc) {
          *p = to_hash(mrb, *sp++);
          i++;
        }
      }
      break;
    case 's':
      {
        mrb_value ss;
        struct RString *s;
        char **ps = 0;
        int *pl = 0;

        ps = va_arg(ap, char**);
        pl = va_arg(ap, int*);
        if (i < argc) {
          ss = to_str(mrb, *sp++);
          s = mrb_str_ptr(ss);
          *ps = s->ptr;
          *pl = s->len;
          i++;
        }
      }
      break;
    case 'z':
      {
        mrb_value ss;
        struct RString *s;
        char **ps;

        ps = va_arg(ap, char**);
        if (i < argc) {
          ss = to_str(mrb, *sp++);
          s = mrb_str_ptr(ss);
          if (strlen(s->ptr) != s->len) {
            mrb_raise(mrb, E_ARGUMENT_ERROR, "String contains NUL");
          }
          *ps = s->ptr;
          i++;
        }
      }
      break;
    case 'a':
      {
        mrb_value aa;
        struct RArray *a;
        mrb_value **pb;
        mrb_int *pl;

        pb = va_arg(ap, mrb_value**);
        pl = va_arg(ap, mrb_int*);
        if (i < argc) {
          aa = to_ary(mrb, *sp++);
          a = mrb_ary_ptr(aa);
          *pb = a->ptr;
          *pl = a->len;
          i++;
        }
      }
      break;
    case 'f':
      {
        mrb_float *p;

        p = va_arg(ap, mrb_float*);
        if (i < argc) {
          switch (mrb_type(*sp)) {
            case MRB_TT_FLOAT:
              *p = mrb_float(*sp);
              break;
            case MRB_TT_FIXNUM:
              *p = (mrb_float)mrb_fixnum(*sp);
              break;
            case MRB_TT_STRING:
              mrb_raise(mrb, E_TYPE_ERROR, "String can't be coerced into Float");
              break;
            default:
              {
                mrb_value tmp;

                tmp = mrb_convert_type(mrb, *sp, MRB_TT_FLOAT, "Float", "to_f");
                *p = mrb_float(tmp);
              }
              break;
          }
          sp++;
          i++;
        }
      }
      break;
    case 'i':
      {
        mrb_int *p;

        p = va_arg(ap, mrb_int*);
        if (i < argc) {
          switch (mrb_type(*sp)) {
            case MRB_TT_FIXNUM:
              *p = mrb_fixnum(*sp);
              break;
            case MRB_TT_FLOAT:
              {
                mrb_float f = mrb_float(*sp);

                if (!FIXABLE(f)) {
                  mrb_raise(mrb, E_RANGE_ERROR, "float too big for int");
                }
                *p = (mrb_int)f;
              }
              break;
            case MRB_TT_FALSE:
              *p = 0;
              break;
            default:
              {
                mrb_value tmp;

                tmp = mrb_convert_type(mrb, *sp, MRB_TT_FIXNUM, "Integer", "to_int");
                *p = mrb_fixnum(tmp);
              }
              break;
          }
          sp++;
          i++;
        }
      }
      break;
    case 'b':
      {
        int *boolp = va_arg(ap, int*);

        if (i < argc) {
          mrb_value b = *sp++;
          *boolp = mrb_test(b);
          i++;
        }
      }
      break;
    case 'n':
      {
        mrb_sym *symp;

        symp = va_arg(ap, mrb_sym*);
        if (i < argc) {
          mrb_value ss;

          ss = *sp++;
          if (mrb_type(ss) == MRB_TT_SYMBOL) {
            *symp = mrb_symbol(ss);
          }
          else if (mrb_string_p(ss)) {
            *symp = mrb_intern_str(mrb, to_str(mrb, ss));
          }
          else {
            mrb_value obj = mrb_funcall(mrb, ss, "inspect", 0);
            mrb_raisef(mrb, E_TYPE_ERROR, "%S is not a symbol", obj);
          }
          i++;
        }
      }
      break;

    case '&':
      {
        mrb_value *p, *bp;

        p = va_arg(ap, mrb_value*);
        if (mrb->ci->argc < 0) {
          bp = mrb->stack + 2;
        }
        else {
          bp = mrb->stack + mrb->ci->argc + 1;
        }
        *p = *bp;
      }
      break;
    case '|':
      opt = 1;
      break;

    case '*':
      {
        mrb_value **var;
        int *pl;

        var = va_arg(ap, mrb_value**);
        pl = va_arg(ap, int*);
        if (argc > i) {
          *pl = argc-i;
          if (*pl > 0) {
            *var = sp;
            i = argc;
          }
          i = argc;
          sp += *pl;
        }
        else {
          *pl = 0;
          *var = NULL;
        }
      }
      break;
    default:
      mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid argument specifier %S", mrb_str_new(mrb, &c, 1));
      break;
    }
  }
  if (!c && argc > i) {
    mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
  }
  va_end(ap);
  return i;
}
Exemplo n.º 22
0
constexpr auto to_str(T&& x, Args&&... args) {
    return to_str(std::forward<T>(x)) + to_str(std::forward<Args>(args)...);
}
Exemplo n.º 23
0
void RK::execute()
{
  RDSolver& mysolver = *solver().handle< RDSolver >();

  // get the current rk k step and order

  const Uint rkorder = mysolver.properties().value<Uint>("rkorder");
  const Uint step    = mysolver.iterative_solver().properties().value<Uint>("iteration");

  if (is_null(m_solution))
    m_solution = follow_link( mysolver.fields().get_child( RDM::Tags::solution() ) )->handle<Field>();
  if (is_null(m_residual))
    m_residual = follow_link( mysolver.fields().get_child( RDM::Tags::residual() ) )->handle<Field>();
  if (is_null(m_dual_area))
    m_dual_area = follow_link( mysolver.fields().get_child( RDM::Tags::dual_area() ) )->handle<Field>();

  // get the correct solution to update depending on which rk k step we are

  Handle< Field > csolution_k;
  if ( step == rkorder )
    csolution_k = m_solution;
  else
  {
    csolution_k = follow_link(mysolver.fields().get_child( std::string(RDM::Tags::solution()) + "-" + to_str(step) + "dt" ))->handle<Field>();
  }

  cf3_assert( is_not_null(csolution_k) );

  Field& solution_k   = *csolution_k;
  Field& dual_area    = *m_dual_area;
  Field& residual     = *m_residual;

  /// @todo should be used later to calculate automatically the \Delta t
     //const Real CFL = options().option("cfl").value<Real>();

  /// @todo maybe better to directly store dual_area inverse

  // implementation of the RungeKutta update step

  const Uint nbdofs = solution_k.size();
  const Uint nbvars = solution_k.row_size();
  for ( Uint i=0; i< nbdofs; ++i )
    for ( Uint j=0; j< nbvars; ++j )
      solution_k[i][j] += - residual[i][j] / dual_area[i][0];
}
Exemplo n.º 24
0
Arquivo: rc.c Projeto: galexcode/w3m
Buffer *
load_option_panel(void)
{
    Str src;
    struct param_ptr *p;
    struct sel_c *s;
#ifdef USE_M17N
    wc_ces_list *c;
#endif
    int x, i;
    Str tmp;
    Buffer *buf;

    if (optionpanel_str == NULL)
	optionpanel_str = Sprintf(optionpanel_src1, w3m_version,
			      html_quote(localCookie()->ptr), _(CMT_HELPER));
#ifdef USE_M17N
#ifdef ENABLE_NLS
    OptionCharset = SystemCharset;	/* FIXME */
#endif
    if (!OptionEncode) {
	optionpanel_str =
	    wc_Str_conv(optionpanel_str, OptionCharset, InnerCharset);
	for (i = 0; sections[i].name != NULL; i++) {
	    sections[i].name =
		wc_conv(_(sections[i].name), OptionCharset,
			InnerCharset)->ptr;
	    for (p = sections[i].params; p->name; p++) {
		p->comment =
		    wc_conv(_(p->comment), OptionCharset,
			    InnerCharset)->ptr;
		if (p->inputtype == PI_SEL_C
#ifdef USE_COLOR
			&& p->select != colorstr
#endif
			) {
		    for (s = (struct sel_c *)p->select; s->text != NULL; s++) {
			s->text =
			    wc_conv(_(s->text), OptionCharset,
				    InnerCharset)->ptr;
		    }
		}
	    }
	}
#ifdef USE_COLOR
	for (s = colorstr; s->text; s++)
	    s->text = wc_conv(_(s->text), OptionCharset,
			      InnerCharset)->ptr;
#endif
	OptionEncode = TRUE;
    }
#endif
    src = Strdup(optionpanel_str);

    Strcat_charp(src, "<table><tr><td>");
    for (i = 0; sections[i].name != NULL; i++) {
	Strcat_m_charp(src, "<h1>", sections[i].name, "</h1>", NULL);
	p = sections[i].params;
	Strcat_charp(src, "<table width=100% cellpadding=0>");
	while (p->name) {
	    Strcat_m_charp(src, "<tr><td>", p->comment, NULL);
	    Strcat(src, Sprintf("</td><td width=%d>",
				(int)(28 * pixel_per_char)));
	    switch (p->inputtype) {
	    case PI_TEXT:
		Strcat_m_charp(src, "<input type=text name=",
			       p->name,
			       " value=\"",
			       html_quote(to_str(p)->ptr), "\">", NULL);
		break;
	    case PI_ONOFF:
		x = atoi(to_str(p)->ptr);
		Strcat_m_charp(src, "<input type=radio name=",
			       p->name,
			       " value=1",
			       (x ? " checked" : ""),
			       ">YES&nbsp;&nbsp;<input type=radio name=",
			       p->name,
			       " value=0", (x ? "" : " checked"), ">NO", NULL);
		break;
	    case PI_SEL_C:
		tmp = to_str(p);
		Strcat_m_charp(src, "<select name=", p->name, ">", NULL);
		for (s = (struct sel_c *)p->select; s->text != NULL; s++) {
		    Strcat_charp(src, "<option value=");
		    Strcat(src, Sprintf("%s\n", s->cvalue));
		    if ((p->type != P_CHAR && s->value == atoi(tmp->ptr)) ||
			(p->type == P_CHAR && (char)s->value == *(tmp->ptr)))
			Strcat_charp(src, " selected");
		    Strcat_char(src, '>');
		    Strcat_charp(src, s->text);
		}
		Strcat_charp(src, "</select>");
		break;
#ifdef USE_M17N
	    case PI_CODE:
		tmp = to_str(p);
		Strcat_m_charp(src, "<select name=", p->name, ">", NULL);
		for (c = *(wc_ces_list **) p->select; c->desc != NULL; c++) {
		    Strcat_charp(src, "<option value=");
		    Strcat(src, Sprintf("%s\n", c->name));
		    if (c->id == atoi(tmp->ptr))
			Strcat_charp(src, " selected");
		    Strcat_char(src, '>');
		    Strcat_charp(src, c->desc);
		}
		Strcat_charp(src, "</select>");
		break;
#endif
	    }
	    Strcat_charp(src, "</td></tr>\n");
	    p++;
	}
	Strcat_charp(src,
		     "<tr><td></td><td><p><input type=submit value=\"OK\"></td></tr>");
	Strcat_charp(src, "</table><hr width=50%>");
    }
    Strcat_charp(src, "</table></form></body></html>");
    buf = loadHTMLString(src);
#ifdef USE_M17N
    if (buf)
	buf->document_charset = OptionCharset;
#endif
    return buf;
}
Exemplo n.º 25
0
	int64_t type_string::append(const std::string & str)
	{
		to_str();
		string_value += str;
		return string_value.size();
	}
Exemplo n.º 26
0
	Node::Node() : Spatial()
	{
		this->setName("node_" + to_str(++node_count));
	}
Exemplo n.º 27
0
void CMonsterData::LoadData(void)
{
    CJson jc = CJson::Load( "Monster" );

    theResDataMgr.insert(this);
    resource_clear(id_monster_map);
    int32 count = 0;
    const Json::Value aj = jc["Array"];
    for ( uint32 i = 0; i != aj.size(); ++i)
    {
        SData *pmonster                      = new SData;
        pmonster->id                              = to_uint(aj[i]["id"]);
        pmonster->local_id                        = to_uint(aj[i]["local_id"]);
        pmonster->class_id                        = to_uint(aj[i]["class_id"]);
        pmonster->name                            = to_str(aj[i]["name"]);
        pmonster->type                            = to_uint(aj[i]["type"]);
        pmonster->equip_type                      = to_uint(aj[i]["equip_type"]);
        pmonster->level                           = to_uint(aj[i]["level"]);
        pmonster->animation_name                  = to_str(aj[i]["animation_name"]);
        pmonster->music                           = to_str(aj[i]["music"]);
        pmonster->avatar                          = to_uint(aj[i]["avatar"]);
        pmonster->occupation                      = to_uint(aj[i]["occupation"]);
        pmonster->quality                         = to_uint(aj[i]["quality"]);
        uint32 packets;
        for ( uint32 j = 1; j <= 5; ++j )
        {
            std::string buff = strprintf( "packets%d", j);
            packets = to_uint(aj[i][buff]);
            pmonster->packets.push_back(packets);
        }
        pmonster->fight_value                     = to_uint(aj[i]["fight_value"]);
        pmonster->initial_rage                    = to_uint(aj[i]["initial_rage"]);
        pmonster->hp                              = to_uint(aj[i]["hp"]);
        pmonster->physical_ack                    = to_uint(aj[i]["physical_ack"]);
        pmonster->physical_def                    = to_uint(aj[i]["physical_def"]);
        pmonster->magic_ack                       = to_uint(aj[i]["magic_ack"]);
        pmonster->magic_def                       = to_uint(aj[i]["magic_def"]);
        pmonster->speed                           = to_uint(aj[i]["speed"]);
        pmonster->critper                         = to_uint(aj[i]["critper"]);
        pmonster->crithurt                        = to_uint(aj[i]["crithurt"]);
        pmonster->critper_def                     = to_uint(aj[i]["critper_def"]);
        pmonster->crithurt_def                    = to_uint(aj[i]["crithurt_def"]);
        pmonster->hitper                          = to_uint(aj[i]["hitper"]);
        pmonster->dodgeper                        = to_uint(aj[i]["dodgeper"]);
        pmonster->parryper                        = to_uint(aj[i]["parryper"]);
        pmonster->parryper_dec                    = to_uint(aj[i]["parryper_dec"]);
        pmonster->stun_def                        = to_uint(aj[i]["stun_def"]);
        pmonster->silent_def                      = to_uint(aj[i]["silent_def"]);
        pmonster->weak_def                        = to_uint(aj[i]["weak_def"]);
        pmonster->fire_def                        = to_uint(aj[i]["fire_def"]);
        pmonster->rebound_physical_ack            = to_uint(aj[i]["rebound_physical_ack"]);
        pmonster->rebound_magic_ack               = to_uint(aj[i]["rebound_magic_ack"]);
        S2UInt32 odds;
        for ( uint32 j = 1; j <= 7; ++j )
        {
            std::string buff = strprintf( "odds%d", j);
            std::string value_string = aj[i][buff].asString();
            if ( 2 != sscanf( value_string.c_str(), "%u%%%u", &odds.first, &odds.second ) )
                break;
            pmonster->odds.push_back(odds);
        }
        S2UInt32 skills;
        for ( uint32 j = 1; j <= 6; ++j )
        {
            std::string buff = strprintf( "skills%d", j);
            std::string value_string = aj[i][buff].asString();
            if ( 2 != sscanf( value_string.c_str(), "%u%%%u", &skills.first, &skills.second ) )
                break;
            pmonster->skills.push_back(skills);
        }
        pmonster->money                           = to_uint(aj[i]["money"]);
        pmonster->exp                             = to_uint(aj[i]["exp"]);
        pmonster->desc                            = to_str(aj[i]["desc"]);
        pmonster->hp_layer                        = to_uint(aj[i]["hp_layer"]);
        uint32 fight_monster;
        for ( uint32 j = 1; j <= 5; ++j )
        {
            std::string buff = strprintf( "fight_monster%d", j);
            fight_monster = to_uint(aj[i][buff]);
            pmonster->fight_monster.push_back(fight_monster);
        }
        pmonster->help_monster                    = to_uint(aj[i]["help_monster"]);
        pmonster->strength                        = to_uint(aj[i]["strength"]);
        pmonster->recover_critper                 = to_uint(aj[i]["recover_critper"]);
        pmonster->recover_critper_def             = to_uint(aj[i]["recover_critper_def"]);
        pmonster->recover_add_fix                 = to_uint(aj[i]["recover_add_fix"]);
        pmonster->recover_del_fix                 = to_uint(aj[i]["recover_del_fix"]);
        pmonster->recover_add_per                 = to_uint(aj[i]["recover_add_per"]);
        pmonster->recover_del_per                 = to_uint(aj[i]["recover_del_per"]);
        pmonster->rage_add_fix                    = to_uint(aj[i]["rage_add_fix"]);
        pmonster->rage_del_fix                    = to_uint(aj[i]["rage_del_fix"]);
        pmonster->rage_add_per                    = to_uint(aj[i]["rage_add_per"]);
        pmonster->rage_del_per                    = to_uint(aj[i]["rage_del_per"]);

        Add(pmonster);
        ++count;
        LOG_DEBUG("id:%u,local_id:%u,class_id:%u,name:%s,type:%u,equip_type:%u,level:%u,animation_name:%s,music:%s,avatar:%u,occupation:%u,quality:%u,fight_value:%u,initial_rage:%u,hp:%u,physical_ack:%u,physical_def:%u,magic_ack:%u,magic_def:%u,speed:%u,critper:%u,crithurt:%u,critper_def:%u,crithurt_def:%u,hitper:%u,dodgeper:%u,parryper:%u,parryper_dec:%u,stun_def:%u,silent_def:%u,weak_def:%u,fire_def:%u,rebound_physical_ack:%u,rebound_magic_ack:%u,money:%u,exp:%u,desc:%s,hp_layer:%u,help_monster:%u,strength:%u,recover_critper:%u,recover_critper_def:%u,recover_add_fix:%u,recover_del_fix:%u,recover_add_per:%u,recover_del_per:%u,rage_add_fix:%u,rage_del_fix:%u,rage_add_per:%u,rage_del_per:%u,", pmonster->id, pmonster->local_id, pmonster->class_id, pmonster->name.c_str(), pmonster->type, pmonster->equip_type, pmonster->level, pmonster->animation_name.c_str(), pmonster->music.c_str(), pmonster->avatar, pmonster->occupation, pmonster->quality, pmonster->fight_value, pmonster->initial_rage, pmonster->hp, pmonster->physical_ack, pmonster->physical_def, pmonster->magic_ack, pmonster->magic_def, pmonster->speed, pmonster->critper, pmonster->crithurt, pmonster->critper_def, pmonster->crithurt_def, pmonster->hitper, pmonster->dodgeper, pmonster->parryper, pmonster->parryper_dec, pmonster->stun_def, pmonster->silent_def, pmonster->weak_def, pmonster->fire_def, pmonster->rebound_physical_ack, pmonster->rebound_magic_ack, pmonster->money, pmonster->exp, pmonster->desc.c_str(), pmonster->hp_layer, pmonster->help_monster, pmonster->strength, pmonster->recover_critper, pmonster->recover_critper_def, pmonster->recover_add_fix, pmonster->recover_del_fix, pmonster->recover_add_per, pmonster->recover_del_per, pmonster->rage_add_fix, pmonster->rage_del_fix, pmonster->rage_add_per, pmonster->rage_del_per);
    }
    LOG_INFO("Monster.xls:%d", count);
}
Exemplo n.º 28
0
ostream &operator<<(ostream &out, const Nature& nature) {
    out << to_str(nature);
    return out;
}
Exemplo n.º 29
0
void IterativeSolver::execute()
{
  RDM::RDSolver& mysolver = solver().as_type< RDM::RDSolver >();

  /// @todo this configuration sould be in constructor but does not work there

  configure_option_recursively( "iterator", this->uri() );

  // access components (out of loop)

  CActionDirector& boundary_conditions =
      access_component( "cpath:../BoundaryConditions" ).as_type<CActionDirector>();

  CActionDirector& domain_discretization =
      access_component( "cpath:../DomainDiscretization" ).as_type<CActionDirector>();

  CAction& synchronize = mysolver.actions().get_child("Synchronize").as_type<CAction>();

  Component& cnorm = post_actions().get_child("ComputeNorm");
  cnorm.configure_option("Field", mysolver.fields().get_child( RDM::Tags::residual() ).follow()->uri() );

  // iteration loop

  Uint iter = 1; // iterations start from 1 ( max iter zero will do nothing )
  property("iteration") = iter;


  while( ! stop_condition() ) // non-linear loop
  {
    // (1) the pre actions - cleanup residual, pre-process something, etc

    pre_actions().execute();

    // (2) domain discretization

    domain_discretization.execute();

    // (3) apply boundary conditions

    boundary_conditions.execute();

    // (4) update

    update().execute();

    // (5) update

    synchronize.execute();

    // (6) the post actions - compute norm, post-process something, etc

    post_actions().execute();

    // output convergence info

    /// @todo move current rhs as a prpoerty of the iterate or solver components
    if( mpi::PE::instance().rank() == 0 )
    {
      Real rhs_norm = cnorm.properties().value<Real>("Norm");
      std::cout << "iter ["    << std::setw(4)  << iter << "]"
                << "L2(rhs) [" << std::setw(12) << rhs_norm << "]" << std::endl;

      if ( is_nan(rhs_norm) || is_inf(rhs_norm) )
        throw FailedToConverge(FromHere(),
                               "Solution diverged after "+to_str(iter)+" iterations");
    }

    // raise signal that iteration is done

    raise_iteration_done();

    // increment iteration

    property("iteration") = ++iter; // update the iteration number

  }
}
Exemplo n.º 30
0
 template <typename Iter> void value::_serialize(Iter oi, int indent) const {
   switch (type_) {
   case string_type:
     serialize_str(*u_.string_, oi);
     break;
   case array_type: {
     *oi++ = '[';
     if (indent != -1) {
       ++indent;
     }
     for (array::const_iterator i = u_.array_->begin();
          i != u_.array_->end();
          ++i) {
   if (i != u_.array_->begin()) {
     *oi++ = ',';
   }
       if (indent != -1) {
         _indent(oi, indent);
       }
   i->_serialize(oi, indent);
     }
     if (indent != -1) {
       --indent;
       if (! u_.array_->empty()) {
         _indent(oi, indent);
       }
     }
     *oi++ = ']';
     break;
   }
   case object_type: {
     *oi++ = '{';
     if (indent != -1) {
       ++indent;
     }
     for (object::const_iterator i = u_.object_->begin();
      i != u_.object_->end();
      ++i) {
   if (i != u_.object_->begin()) {
     *oi++ = ',';
   }
       if (indent != -1) {
         _indent(oi, indent);
       }
   serialize_str(i->first, oi);
   *oi++ = ':';
       if (indent != -1) {
         *oi++ = ' ';
       }
       i->second._serialize(oi, indent);
     }
     if (indent != -1) {
       --indent;
       if (! u_.object_->empty()) {
         _indent(oi, indent);
       }
     }
     *oi++ = '}';
     break;
   }
   default:
     copy(to_str(), oi);
     break;
   }
   if (indent == 0) {
     *oi++ = '\n';
   }
 }