コード例 #1
0
int main()
{
  const size_t npts = 10;
  const SS::GhostData ghost(0);
  const SS::BoundaryCellInfo bc = SS::BoundaryCellInfo::build<FieldT>();
  const SS::MemoryWindow mw( SS::IntVec( npts, 1, 1 ) );

  FieldT f( mw, bc, ghost, NULL );

  double x=0.1;
  for( FieldT::iterator ifld=f.begin(); ifld!=f.end(); ++ifld, x+=1.0 ){
    *ifld = x;
  }

  TestHelper status(true);

  FieldT::interior_iterator i2=f.interior_begin();
  for( FieldT::iterator i=f.begin(); i!=f.end(); ++i, ++i2 ){
    status( *i==*i2, "value" );
    status( &*i == &*i2, "address" );
  }

  {
    typedef SS::ConstValEval BCVal;
    typedef SS::BoundaryCondition<FieldT,BCVal> BC;

    BC bc1( SS::IntVec(2,1,1), BCVal(1.234) );
    BC bc2( SS::IntVec(4,1,1), BCVal(3.456) );
  
    bc1(f);
    bc2(f);
    status( f[2] == 1.234, "point BC 1" );
    status( f[4] == 3.456, "point BC 2" );
  }

  {
    std::vector<size_t> ix;
    ix.push_back(4);
    ix.push_back(2);
    SpatialOps::Point::FieldToPoint<FieldT> ftp(ix);
    SpatialOps::Point::PointToField<FieldT> ptf(ix);

    const SS::MemoryWindow mw2( SpatialOps::structured::IntVec(2,1,1) );
    FieldT f2( mw2, bc, ghost, NULL );
    ftp.apply_to_field( f, f2 );
    status( f2[0] == 3.456, "Field2Point Interp (1)" );
    status( f2[1] == 1.234, "Field2Point Interp (2)" );

    f2[0] = -1.234;
    f2[1] = -3.456;
    ptf.apply_to_field( f2, f );
    status( f[2] == -3.456, "Point2Field Interp (1)" );
    status( f[4] == -1.234, "Point2Field Interp (2)" );
  }


  if( status.ok() ) return 0;
  return -1;
}
コード例 #2
0
ファイル: vf16.c プロジェクト: ABratovic/open-watcom-v2
int main() {
    bc1( &x );
    bc2( &x );
    bc3( &x );
    bcd( &x );
    _PASS;
}
コード例 #3
0
ファイル: CommandAI.cpp プロジェクト: AlexDiede/spring
CCommandQueue::iterator CCommandAI::GetCancelQueued(const Command& c, CCommandQueue& q)
{
	CCommandQueue::iterator ci = q.end();

	while (ci != q.begin()) {
		--ci; //iterate from the end and dont check the current order
		const Command& c2 = *ci;
		const int cmdID = c.GetID();
		const int cmd2ID = c2.GetID();

		const bool attackAndFight = (cmdID == CMD_ATTACK && cmd2ID == CMD_FIGHT && c2.params.size() == 1);

		if (c2.params.size() != c.params.size())
			continue;

		if ((cmdID == cmd2ID) || (cmdID < 0 && cmd2ID < 0) || attackAndFight) {
			if (c.params.size() == 1) {
				// assume the param is a unit-ID or feature-ID
				if ((c2.params[0] == c.params[0]) &&
				    (cmd2ID != CMD_SET_WANTED_MAX_SPEED)) {
					return ci;
				}
			}
			else if (c.params.size() >= 3) {
				if (cmdID < 0) {
					BuildInfo bc1(c);
					BuildInfo bc2(c2);

					if (bc1.def == NULL) continue;
					if (bc2.def == NULL) continue;

					if (math::fabs(bc1.pos.x - bc2.pos.x) * 2 <= std::max(bc1.GetXSize(), bc2.GetXSize()) * SQUARE_SIZE &&
					    math::fabs(bc1.pos.z - bc2.pos.z) * 2 <= std::max(bc1.GetZSize(), bc2.GetZSize()) * SQUARE_SIZE) {
						return ci;
					}
				} else {
					// assume c and c2 are positional commands
					const float3& c1p = c.GetPos(0);
					const float3& c2p = c2.GetPos(0);

					if ((c1p - c2p).SqLength2D() >= (COMMAND_CANCEL_DIST * COMMAND_CANCEL_DIST))
						continue;
					if ((c.options & SHIFT_KEY) != 0 && (c.options & INTERNAL_ORDER) != 0)
						continue;

					return ci;
				}
			}
		}
	}
	return q.end();
}
コード例 #4
0
ファイル: q15_7.cpp プロジェクト: k-mi/Stroustrup_PPP
int main(){
	Simple_window win(Point(100, 100), 600, 400, "Bar_chart");

	Bar_chart bc1(Point(0, 0), win.x_max() / 2, win.y_max() / 2);
	bc1.add_data(100);
	bc1.add_data(600);
	bc1.add_data(300);
	bc1.add_data(700);
	bc1.add_data(200);

	Bar_chart bc2(Point(win.x_max() / 2, win.y_max() / 2), win.x_max() / 2, win.y_max() / 2);
	bc2.add_data(30, "7", Color::yellow);
	bc2.add_data(180, "1", Color::red);
	bc2.add_data(20, "8", Color::blue);
	bc2.add_data(150, "2", Color::yellow);
	bc2.add_data(70, "5", Color::yellow);
	bc2.add_data(40, "6", Color::yellow);
	bc2.add_data(130, "3", Color::yellow);
	bc2.add_data(90, "4", Color::yellow);

	win.attach(bc1);
	win.attach(bc2);
	win.wait_for_button();
}
コード例 #5
0
ファイル: test01.cpp プロジェクト: een5afr-public/gem5
void cover_sc_bit()
{
    sc_bit bdef;
    sc_bit bf(false);
    sc_bit bt(true);
    sc_bit b0(0);
    sc_bit b1(1);
    try {
	sc_bit foo(2);
    }
    catch (sc_report) {
	cout << "Caught exception for sc_bit(2)\n";
    }
    sc_bit bc0('0');
    sc_bit bc1('1');
    try {
	sc_bit foo('2');
    }
    catch (sc_report) {
	cout << "Caught exception for sc_bit('2')\n";
    }
    sc_bit blc0(sc_logic('0'));
    sc_bit blc1(sc_logic('1'));
    sc_bit blcx(sc_logic('X'));
    sc_bit bcop(bt);
    cout << bdef << bf << bt << b0 << b1 << bc0 << bc1 << blc0 << blc1
	 << blcx << bcop << endl;
    sc_bit b;
    b = bt;
    sc_assert(b);
    b = 0;
    sc_assert(!b);
    b = true;
    sc_assert(b.to_bool());
    b = '0';
    sc_assert(!b.to_bool());
    b = sc_logic('1');
    sc_assert(b.to_char() == '1');
    b = bf;
    sc_assert(~b);
    b |= bt;
    sc_assert(b);
    b &= bf;
    sc_assert(!b);
    b |= 1;
    sc_assert(b);
    b &= 0;
    sc_assert(!b);
    b |= '1';
    sc_assert(b);
    b &= '0';
    sc_assert(!b);
    b |= true;
    sc_assert(b);
    b &= false;
    sc_assert(!b);
    b ^= bt;
    sc_assert(b);
    b ^= 1;
    sc_assert(!b);
    b ^= '1';
    sc_assert(b);
    b ^= true;
    sc_assert(!b);

    sc_assert(b == bf);
    sc_assert(b == 0);
    sc_assert(b == '0');
    sc_assert(b == false);
    b = 1;
    sc_assert(b == bt);
    sc_assert(b == 1);
    sc_assert(b == '1');
    sc_assert(b == true);
    sc_assert(1 == b);
    sc_assert('1' == b);
    sc_assert(true == b);
    sc_assert(equal(b, bt));
    sc_assert(equal(b, 1));
    sc_assert(equal(b, '1'));
    sc_assert(equal(b, true));
    sc_assert(equal(1, b));
    sc_assert(equal('1', b));
    sc_assert(equal(true, b));
    b = 0;
    sc_assert(b != bt);
    sc_assert(b != 1);
    sc_assert(b != '1');
    sc_assert(b != true);
    sc_assert(1 != b);
    sc_assert('1' != b);
    sc_assert(true != b);
    sc_assert(not_equal(b, bt));
    sc_assert(not_equal(b, 1));
    sc_assert(not_equal(b, '1'));
    sc_assert(not_equal(b, true));
    sc_assert(not_equal(1, b));
    sc_assert(not_equal('1', b));
    sc_assert(not_equal(true, b));

    // the following assertion is incorrect, because the b_not() method
    // is destructive, i.e., it implements something like b ~= void.
    /// sc_assert(b == b_not(b.b_not()));
    b.b_not();
    sc_assert(b);
    sc_bit bx;
    b_not(bx, b0);
    sc_assert(bx);
    b_not(bx, b1);
    sc_assert(!bx);

    cout << (b0|b0) << (b0|b1) << (b1|b0) << (b1|b1) << endl;
    cout << (b0&b0) << (b0&b1) << (b1&b0) << (b1&b1) << endl;
    cout << (b0^b0) << (b0^b1) << (b1^b0) << (b1^b1) << endl;

    cout << (b0|0) << (b0|1) << (b1|0) << (b1|1) << endl;
    cout << (b0&0) << (b0&1) << (b1&0) << (b1&1) << endl;
    cout << (b0^0) << (b0^1) << (b1^0) << (b1^1) << endl;

    cout << (b0|'0') << (b0|'1') << (b1|'0') << (b1|'1') << endl;
    cout << (b0&'0') << (b0&'1') << (b1&'0') << (b1&'1') << endl;
    cout << (b0^'0') << (b0^'1') << (b1^'0') << (b1^'1') << endl;

    cout << (b0|true) << (b0|false) << (b1|true) << (b1|false) << endl;
    cout << (b0&true) << (b0&false) << (b1&true) << (b1&false) << endl;
    cout << (b0^true) << (b0^false) << (b1^true) << (b1^false) << endl;

    cout << (0|b0) << (0|b1) << (1|b0) << (1|b1) << endl;
    cout << (0&b0) << (0&b1) << (1&b0) << (1&b1) << endl;
    cout << (0^b0) << (0^b1) << (1^b0) << (1^b1) << endl;

    cout << ('0'|b0) << ('0'|b1) << ('1'|b0) << ('1'|b1) << endl;
    cout << ('0'&b0) << ('0'&b1) << ('1'&b0) << ('1'&b1) << endl;
    cout << ('0'^b0) << ('0'^b1) << ('1'^b0) << ('1'^b1) << endl;

    cout << (false|b0) << (false|b1) << (true|b0) << (true|b1) << endl;
    cout << (false&b0) << (false&b1) << (true&b0) << (true&b1) << endl;
    cout << (false^b0) << (false^b1) << (true^b0) << (true^b1) << endl;

    cout << b_or(b0,b0) << b_or(b0,b1) << b_or(b1,b0) << b_or(b1,b1) << endl;
    cout << b_and(b0,b0) << b_and(b0,b1) << b_and(b1,b0) << b_and(b1,b1)
         << endl;
    cout << b_xor(b0,b0) << b_xor(b0,b1) << b_xor(b1,b0) << b_xor(b1,b1)
         << endl;

    cout << b_or(b0,0) << b_or(b0,1) << b_or(b1,0) << b_or(b1,1) << endl;
    cout << b_and(b0,0) << b_and(b0,1) << b_and(b1,0) << b_and(b1,1) << endl;
    cout << b_xor(b0,0) << b_xor(b0,1) << b_xor(b1,0) << b_xor(b1,1) << endl;

    cout << b_or(b0,'0') << b_or(b0,'1') << b_or(b1,'0') << b_or(b1,'1')
         << endl;
    cout << b_and(b0,'0') << b_and(b0,'1') << b_and(b1,'0') << b_and(b1,'1')
         << endl;
    cout << b_xor(b0,'0') << b_xor(b0,'1') << b_xor(b1,'0') << b_xor(b1,'1')
         << endl;

    cout << b_or(b0,false) << b_or(b0,true) << b_or(b1,false) << b_or(b1,true)
         << endl;
    cout << b_and(b0,false) << b_and(b0,true) << b_and(b1,false)
         << b_and(b1,true) << endl;
    cout << b_xor(b0,false) << b_xor(b0,true) << b_xor(b1,false)
         << b_xor(b1,true) << endl;

    cout << b_or(0,b0) << b_or(0,b1) << b_or(1,b0) << b_or(1,b1) << endl;
    cout << b_and(0,b0) << b_and(0,b1) << b_and(1,b0) << b_and(1,b1) << endl;
    cout << b_xor(0,b0) << b_xor(0,b1) << b_xor(1,b0) << b_xor(1,b1) << endl;

    cout << b_or('0',b0) << b_or('0',b1) << b_or('1',b0) << b_or('1',b1)
         << endl;
    cout << b_and('0',b0) << b_and('0',b1) << b_and('1',b0) << b_and('1',b1)
         << endl;
    cout << b_xor('0',b0) << b_xor('0',b1) << b_xor('1',b0) << b_xor('1',b1)
         << endl;

    cout << b_or(false,b0) << b_or(false,b1) << b_or(true,b0) << b_or(true,b1)
         << endl;
    cout << b_and(false,b0) << b_and(false,b1) << b_and(true,b0)
         << b_and(true,b1) << endl;
    cout << b_xor(false,b0) << b_xor(false,b1) << b_xor(true,b0)
         << b_xor(true,b1) << endl;

    b_or(b, b0, b1);
    sc_assert(b);
    b_and(b, b0, b1);
    sc_assert(!b);
    b_xor(b, b0, b1);
    sc_assert(b);
}
コード例 #6
0
ファイル: block.cpp プロジェクト: 5708/BruteForce
template<typename MatrixType> void block(const MatrixType& m)
{
  typedef typename MatrixType::Index Index;
  typedef typename MatrixType::Scalar Scalar;
  typedef typename MatrixType::RealScalar RealScalar;
  typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
  typedef Matrix<Scalar, 1, MatrixType::ColsAtCompileTime> RowVectorType;
  typedef Matrix<Scalar, Dynamic, Dynamic> DynamicMatrixType;
  typedef Matrix<Scalar, Dynamic, 1> DynamicVectorType;
  
  Index rows = m.rows();
  Index cols = m.cols();

  MatrixType m1 = MatrixType::Random(rows, cols),
             m1_copy = m1,
             m2 = MatrixType::Random(rows, cols),
             m3(rows, cols),
             ones = MatrixType::Ones(rows, cols);
  VectorType v1 = VectorType::Random(rows);

  Scalar s1 = internal::random<Scalar>();

  Index r1 = internal::random<Index>(0,rows-1);
  Index r2 = internal::random<Index>(r1,rows-1);
  Index c1 = internal::random<Index>(0,cols-1);
  Index c2 = internal::random<Index>(c1,cols-1);

  //check row() and col()
  VERIFY_IS_EQUAL(m1.col(c1).transpose(), m1.transpose().row(c1));
  //check operator(), both constant and non-constant, on row() and col()
  m1 = m1_copy;
  m1.row(r1) += s1 * m1_copy.row(r2);
  VERIFY_IS_APPROX(m1.row(r1), m1_copy.row(r1) + s1 * m1_copy.row(r2));
  // check nested block xpr on lhs
  m1.row(r1).row(0) += s1 * m1_copy.row(r2);
  VERIFY_IS_APPROX(m1.row(r1), m1_copy.row(r1) + Scalar(2) * s1 * m1_copy.row(r2));
  m1 = m1_copy;
  m1.col(c1) += s1 * m1_copy.col(c2);
  VERIFY_IS_APPROX(m1.col(c1), m1_copy.col(c1) + s1 * m1_copy.col(c2));
  m1.col(c1).col(0) += s1 * m1_copy.col(c2);
  VERIFY_IS_APPROX(m1.col(c1), m1_copy.col(c1) + Scalar(2) * s1 * m1_copy.col(c2));

  //check block()
  Matrix<Scalar,Dynamic,Dynamic> b1(1,1); b1(0,0) = m1(r1,c1);

  RowVectorType br1(m1.block(r1,0,1,cols));
  VectorType bc1(m1.block(0,c1,rows,1));
  VERIFY_IS_EQUAL(b1, m1.block(r1,c1,1,1));
  VERIFY_IS_EQUAL(m1.row(r1), br1);
  VERIFY_IS_EQUAL(m1.col(c1), bc1);
  //check operator(), both constant and non-constant, on block()
  m1.block(r1,c1,r2-r1+1,c2-c1+1) = s1 * m2.block(0, 0, r2-r1+1,c2-c1+1);
  m1.block(r1,c1,r2-r1+1,c2-c1+1)(r2-r1,c2-c1) = m2.block(0, 0, r2-r1+1,c2-c1+1)(0,0);

  enum {
    BlockRows = 2,
    BlockCols = 5
  };
  if (rows>=5 && cols>=8)
  {
    // test fixed block() as lvalue
    m1.template block<BlockRows,BlockCols>(1,1) *= s1;
    // test operator() on fixed block() both as constant and non-constant
    m1.template block<BlockRows,BlockCols>(1,1)(0, 3) = m1.template block<2,5>(1,1)(1,2);
    // check that fixed block() and block() agree
    Matrix<Scalar,Dynamic,Dynamic> b = m1.template block<BlockRows,BlockCols>(3,3);
    VERIFY_IS_EQUAL(b, m1.block(3,3,BlockRows,BlockCols));

    // same tests with mixed fixed/dynamic size
    m1.template block<BlockRows,Dynamic>(1,1,BlockRows,BlockCols) *= s1;
    m1.template block<BlockRows,Dynamic>(1,1,BlockRows,BlockCols)(0,3) = m1.template block<2,5>(1,1)(1,2);
    Matrix<Scalar,Dynamic,Dynamic> b2 = m1.template block<Dynamic,BlockCols>(3,3,2,5);
    VERIFY_IS_EQUAL(b2, m1.block(3,3,BlockRows,BlockCols));
  }

  if (rows>2)
  {
    // test sub vectors
    VERIFY_IS_EQUAL(v1.template head<2>(), v1.block(0,0,2,1));
    VERIFY_IS_EQUAL(v1.template head<2>(), v1.head(2));
    VERIFY_IS_EQUAL(v1.template head<2>(), v1.segment(0,2));
    VERIFY_IS_EQUAL(v1.template head<2>(), v1.template segment<2>(0));
    Index i = rows-2;
    VERIFY_IS_EQUAL(v1.template tail<2>(), v1.block(i,0,2,1));
    VERIFY_IS_EQUAL(v1.template tail<2>(), v1.tail(2));
    VERIFY_IS_EQUAL(v1.template tail<2>(), v1.segment(i,2));
    VERIFY_IS_EQUAL(v1.template tail<2>(), v1.template segment<2>(i));
    i = internal::random<Index>(0,rows-2);
    VERIFY_IS_EQUAL(v1.segment(i,2), v1.template segment<2>(i));
  }

  // stress some basic stuffs with block matrices
  VERIFY(numext::real(ones.col(c1).sum()) == RealScalar(rows));
  VERIFY(numext::real(ones.row(r1).sum()) == RealScalar(cols));

  VERIFY(numext::real(ones.col(c1).dot(ones.col(c2))) == RealScalar(rows));
  VERIFY(numext::real(ones.row(r1).dot(ones.row(r2))) == RealScalar(cols));

  // now test some block-inside-of-block.
  
  // expressions with direct access
  VERIFY_IS_EQUAL( (m1.block(r1,c1,rows-r1,cols-c1).block(r2-r1,c2-c1,rows-r2,cols-c2)) , (m1.block(r2,c2,rows-r2,cols-c2)) );
  VERIFY_IS_EQUAL( (m1.block(r1,c1,r2-r1+1,c2-c1+1).row(0)) , (m1.row(r1).segment(c1,c2-c1+1)) );
  VERIFY_IS_EQUAL( (m1.block(r1,c1,r2-r1+1,c2-c1+1).col(0)) , (m1.col(c1).segment(r1,r2-r1+1)) );
  VERIFY_IS_EQUAL( (m1.block(r1,c1,r2-r1+1,c2-c1+1).transpose().col(0)) , (m1.row(r1).segment(c1,c2-c1+1)).transpose() );
  VERIFY_IS_EQUAL( (m1.transpose().block(c1,r1,c2-c1+1,r2-r1+1).col(0)) , (m1.row(r1).segment(c1,c2-c1+1)).transpose() );

  // expressions without direct access
  VERIFY_IS_EQUAL( ((m1+m2).block(r1,c1,rows-r1,cols-c1).block(r2-r1,c2-c1,rows-r2,cols-c2)) , ((m1+m2).block(r2,c2,rows-r2,cols-c2)) );
  VERIFY_IS_EQUAL( ((m1+m2).block(r1,c1,r2-r1+1,c2-c1+1).row(0)) , ((m1+m2).row(r1).segment(c1,c2-c1+1)) );
  VERIFY_IS_EQUAL( ((m1+m2).block(r1,c1,r2-r1+1,c2-c1+1).col(0)) , ((m1+m2).col(c1).segment(r1,r2-r1+1)) );
  VERIFY_IS_EQUAL( ((m1+m2).block(r1,c1,r2-r1+1,c2-c1+1).transpose().col(0)) , ((m1+m2).row(r1).segment(c1,c2-c1+1)).transpose() );
  VERIFY_IS_EQUAL( ((m1+m2).transpose().block(c1,r1,c2-c1+1,r2-r1+1).col(0)) , ((m1+m2).row(r1).segment(c1,c2-c1+1)).transpose() );

  // evaluation into plain matrices from expressions with direct access (stress MapBase)
  DynamicMatrixType dm;
  DynamicVectorType dv;
  dm.setZero();
  dm = m1.block(r1,c1,rows-r1,cols-c1).block(r2-r1,c2-c1,rows-r2,cols-c2);
  VERIFY_IS_EQUAL(dm, (m1.block(r2,c2,rows-r2,cols-c2)));
  dm.setZero();
  dv.setZero();
  dm = m1.block(r1,c1,r2-r1+1,c2-c1+1).row(0).transpose();
  dv = m1.row(r1).segment(c1,c2-c1+1);
  VERIFY_IS_EQUAL(dv, dm);
  dm.setZero();
  dv.setZero();
  dm = m1.col(c1).segment(r1,r2-r1+1);
  dv = m1.block(r1,c1,r2-r1+1,c2-c1+1).col(0);
  VERIFY_IS_EQUAL(dv, dm);
  dm.setZero();
  dv.setZero();
  dm = m1.block(r1,c1,r2-r1+1,c2-c1+1).transpose().col(0);
  dv = m1.row(r1).segment(c1,c2-c1+1);
  VERIFY_IS_EQUAL(dv, dm);
  dm.setZero();
  dv.setZero();
  dm = m1.row(r1).segment(c1,c2-c1+1).transpose();
  dv = m1.transpose().block(c1,r1,c2-c1+1,r2-r1+1).col(0);
  VERIFY_IS_EQUAL(dv, dm);
}
int main(int argc, char **argv)
{
	dest_x=0;
	dest_y=6000;
	v = 200;	
	numberofobjects = 2;
	v1 = 100;
	ra[0][5] = 400;
	ra[1][5] = 400;
	ra[2][5] = 400; 
	ra[3][5] = 400;
	//argv[1]="-rh";
	//argv[2]="10.2.36.7";
	//argc=3;
	BotConnector bc(argc, argv);
	if( bc.connect() )
	{
		printf( "Connected to Robot\n" );
	}
	else
	{
		printf( "Connection attempt to Robot failed, Sorry :(\n" );
		return EXIT_SUCCESS;
	}
	argv[1]="-rrtp";
	argv[2]="8102";
	argc=3;
	BotConnector bc1(argc, argv);
	if( bc1.connect() )
	{
		printf( "Connected to Robot1\n" );
	}
	else
	{
		printf( "Connection attempt to Robot failed, Sorry :(\n" );
		return EXIT_SUCCESS;
	}
//	bc.setRobotVelocity_idle(100,100); // initialising vr and vl
	bc.setRobotVelocity(100,100, 10000);
	bc.getAngles(0);// updating ra[][].
//	omnicx = ra[0][1]+ra[0][5]*cos(ra[0][0]);
//	omnicy = ra[0][2]+ra[0][5]*sin(ra[0][0]);
	//bc1.moveRobot(0,90);
//bc1.setRobotVelocity(100,100, 10000);
bc1.moveRobot(6000,90);
//bc1.setRobotVelocity(100,100, 30000);
bc1.moveRobot(0,180);
	argv[1]="-rrtp";
	argv[2]="8103";	
	argc=3;
	BotConnector bc2(argc, argv);
	if( bc2.connect() )
	{
		printf( "Connected to Robot2\n" );
	}
	else
	{
		printf( "Connection attempt to Robot failed, Sorry :(\n" );
		return EXIT_SUCCESS;
	}
bc2.moveRobot(2000,90);
//bc2.setRobotVelocity(100,100, 20000);
bc2.moveRobot(2000,-45);
//bc2.setRobotVelocity(200,200, 25000);
bc2.moveRobot(0,135);
/*	argv[1]="-rrtp";
  argv[2]="8104";
  argc=3;
  BotConnector bc3(argc, argv);
  if( bc3.connect() )
  {
          printf( "Connected to Robot\n" );
  }
  else
  {
          printf( "Connection attempt to Robot failed, Sorry :(\n" );
          return EXIT_SUCCESS;
  }
//bc.setVelocity1(-100,-100, 10000);
bc3.moveRobot(0,90);
bc3.setRobotVelocity(150,150, 30000);
bc3.moveRobot(0,-125);
bc3.setRobotVelocity(100,100, 20000);
bc3.moveRobot(0,180);*/
/*argv[1]="-rrtp";
  argv[2]="8105";
  argc=3;
  BotConnector bc4(argc, argv);
  if( bc4.connect() )
  {
          printf( "Connected to Robot\n" );
  }
  else
  {
          printf( "Connection attempt to Robot failed, Sorry :(\n" );
          return EXIT_SUCCESS;
  }
//bc.setVelocity1(-100,-100, 10000);
bc4.getAngles(4);
bc4.moveRobot(0,90);
bc4.setRobotVelocity(100,100, 40000);
bc4.moveRobot(0,0);
bc4.setRobotVelocity(200,200, 25000);
bc4.moveRobot(0,180);
argv[1]="-rrtp";
  argv[2]="8106";
  argc=3;
  BotConnector bc5(argc, argv);
  if( bc5.connect() )
  {
          printf( "Connected to Robot\n" );
  }
  else
  {
          printf( "Connection attempt to Robot failed, Sorry :(\n" );
          return EXIT_SUCCESS;
  }
//bc.setVelocity1(-100,-100, 10000);
bc5.getAngles(5);
bc5.moveRobot(0,90);
bc5.setRobotVelocity(200,200, 25000);
bc5.moveRobot(0,-80);
bc5.setRobotVelocity(300,300, 15000);
bc5.moveRobot(0,180);*/
bc.setRobotVelocity(-100,-100, 10000);
bc.moveRobot(0,90);
bc.getAngles(0);
bc1.getAngles(1);
bc2.getAngles(2);
omnicx = ra[0][1];
omnicy = ra[0][2]+300;
//bc3.getAngles(3);
/*bc4.getAngles(4);
bc5.getAngles(5);*/
 ArUtil::sleep(5000);
	
	int f;
	for(f=0;f<200;f++)
	{
			float dest,dest1;
			int j;
			dest = tan_inv((dest_y-omnicy),(dest_x-omnicx));
			j=update(dest);
			right_left();
		//	robot_motion();
 			bc.setRobotVelocity_idle(vright,vleft);
         		 bc1.setRobotVelocity_idle(100,100);
	  		bc2.setRobotVelocity_idle(100,100);
			// bc3.setRobotVelocity_idle(250,250);
          		/*bc4.setRobotVelocity_idle(250,250);
          		bc5.setRobotVelocity_idle(250,250);*/
			 ArUtil::sleep(300);
          		bc.getAngles(0);
          		bc1.getAngles(1);
         		 bc2.getAngles(2);
			//bc3.getAngles(3);
			omnicx = omnicx+ra[0][3]*0.3;
			omnicy = omnicy+ra[0][4]*0.3;
			/*bc.setRobotVelocity_idle(0,0);
         		 bc1.setRobotVelocity_idle(0,0);
	  		bc2.setRobotVelocity_idle(0,0);
			 bc3.setRobotVelocity_idle(0,0);*/
		//	omnicx = ra[0][1]+ra[0][5]*cos(ra[0][0]);
//omnicy = ra[0][2]+ra[0][5]*sin(ra[0][0]);
			printf("omnicx = %f, omnicy = %f\n",omnicx,omnicy);
			printf("x = %d",f);
		/*	bc3.getAngles(3);
			bc4.getAngles(4);
			bc5.getAngles(5);*/
	}
	return bc.disconnect();
}
コード例 #8
0
int main(int argc, char* argv[])
{
  // Initialize POOMA and Tester class.
  Pooma::initialize(argc, argv);
  Pooma::Tester tester(argc, argv);

  tester.out() << argv[0] << ": KillBC with expressions" << std::endl;
  tester.out() << "------------------------------------------------"
               << std::endl;

  // First create a Particles object with some Attributes for BC's to act upon.

  tester.out() << "Creating Particles object with DynamicArray attributes ..."
               << std::endl;
  UniformLayout pl(Pooma::contexts());
#if POOMA_MESSAGING
  MyParticles<MPRemoteDynamicUniform> P(pl);
#else
  MyParticles<MPDynamicUniform> P(pl);
#endif

  if (Pooma::context() == 0)
    P.create(10,0,false);
  P.sync(P.a1);

  // Initialize the arrays with scalars.
  // Block since we're starting scalar code.

  Pooma::blockAndEvaluate();
  
  tester.out() << "Initializing DynamicArray objects ..."
               << std::endl;
  int i;
  for (i=0; i < P.size(); ++i) {
    P.a1(i) = 0.1 * i;
    P.a2(i) = 0.25 * i - 1.5;
  }

  tester.out() << "Initialization complete:" << std::endl;
  tester.out() << "  a1 = " << P.a1 << std::endl;
  tester.out() << "  a2 = " << P.a2 << std::endl;
  tester.out() << "  a1*a1+a2*a2 = " << P.a1 * P.a1 + P.a2 * P.a2
               << std::endl;

  // Create a KillBC

  tester.out() << "Creating a Particle KillBC object ..."
               << std::endl;

  // For each BC, we construct the BCType with boundary values.
  // Then we add a ParticleBC with this type to our list, and we provide
  // the subject of the BC (and the object, if different).
  // For the KillBC, object must be the Particles object itself.

  KillBC<double> bc1(0.0, 0.8);
  P.addBoundaryCondition(P.a1 * P.a1 + P.a2 * P.a2, P, bc1);

  // Apply boundary condition and display the results

  tester.out() << "Applying the boundary conditions ..." << std::endl;
  tester.out() << "Before BC's, Particles = " << P << std::endl;
  P.applyBoundaryConditions();
  tester.out() << "After BC's, Particles = " << P << std::endl;
  P.performDestroy();
  Pooma::blockAndEvaluate();
  tester.out() << "Status after applying BC: " << std::endl;
  tester.out() << "  a1 = " << P.a1 << std::endl;
  tester.out() << "  a2 = " << P.a2 << std::endl;

  tester.check(P.size() == 5);

  // Let's also try a KillBC on a free-standing DynamicArray.

  tester.out() << "Creating a free-standing DynamicArray ..." << std::endl;
#if POOMA_MESSAGING
  DynamicArray< Vector<2,int>, MultiPatch< DynamicTag, Remote<Dynamic> > > a3;
#else
  DynamicArray< Vector<2,int>, MultiPatch<DynamicTag,Dynamic> > a3;
#endif

  Interval<1> empty;
  DynamicLayout layout(empty, Pooma::contexts());
  a3.initialize(layout);
  int npc = 20 / Pooma::contexts();
  int rem = 20 % Pooma::contexts();
  if (Pooma::context() < rem) npc++;
  a3.create(npc);
  a3.layout().sync();

  Pooma::blockAndEvaluate();
  for (i=0; i<a3.domain().size(); ++i)
    a3(i) = Vector<2,int>(i,2*i+1);

  tester.out() << "Initialization complete." << std::endl;
  tester.out() << "a3 = " << a3 << std::endl;

  // Now construct a KillBC for this DynamicArray and apply it

  tester.out() << "Creating a DynamicArray KillBC object ..." << std::endl;
  KillBC< Vector<2,int> > bc2(Vector<2,int>(2,2), Vector<2,int>(24,24));
  ParticleBCItem* killbc2 = bc2.create(a3);

  tester.out() << "Applying the boundary condition ..." << std::endl;
  killbc2->applyBoundaryCondition();
  a3.layout().sync();
  Pooma::blockAndEvaluate();
  tester.out() << "Status after applying BC:" << std::endl;
  tester.out() << "a3 = " << a3 << std::endl;

  tester.check(a3.domain().size() == 10);

  // Delete the ParticleBC that we created

  delete killbc2;

  // Return resulting error code and shut down POOMA.

  tester.out() << "------------------------------------------------"
               << std::endl;
  int retval = tester.results("KillBC with expression");
  Pooma::finalize();
  return retval;
}
コード例 #9
0
ファイル: main.cpp プロジェクト: blackvladimir/hermes
int main(int argc, char* argv[])
{
    // Load the mesh.
    Mesh mesh;
    H2DReader mloader;
    mloader.load("domain.mesh", &mesh);

    // Perform uniform mesh refinement.
    for(int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(2); // 2 is for vertical split.

    // Initialize boundary conditions
    DefaultEssentialBCConst bc1(BDY_PERFECT, 0.0);
    EssentialBCNonConst bc2(BDY_LEFT);
    EssentialBCs bcs(Hermes::vector<EssentialBoundaryCondition *>(&bc1, &bc2));

    // Create an H1 space with default shapeset.
    H1Space e_r_space(&mesh, &bcs, P_INIT);
    H1Space e_i_space(&mesh, &bcs, P_INIT);
    int ndof = Space::get_num_dofs(&e_r_space);
    info("ndof = %d", ndof);

    // Initialize the weak formulation
    // Weak forms for real and imaginary parts

    // Initialize the weak formulation.
    WeakFormHelmholtz wf(eps, mu, omega, sigma, beta, E0, h);

    // Initialize the FE problem.
    bool is_linear = true;
    DiscreteProblem dp(&wf, Hermes::vector<Space *>(&e_r_space, &e_i_space), is_linear);

    // Set up the solver, matrix, and rhs according to the solver selection.
    SparseMatrix* matrix = create_matrix(matrix_solver);
    Vector* rhs = create_vector(matrix_solver);
    Solver* solver = create_linear_solver(matrix_solver, matrix, rhs);

    // Initialize the solutions.
    Solution e_r_sln, e_i_sln;

    // Assemble the stiffness matrix and right-hand side vector.
    info("Assembling the stiffness matrix and right-hand side vector.");
    dp.assemble(matrix, rhs);

    // Solve the linear system and if successful, obtain the solutions.
    info("Solving the matrix problem.");
    if(solver->solve())
        Solution::vector_to_solutions(solver->get_solution(),
                                      Hermes::vector<Space *>(&e_r_space, &e_i_space),
                                      Hermes::vector<Solution *>(&e_r_sln, &e_i_sln));
    else
        error ("Matrix solver failed.\n");

    // Visualize the solution.
    ScalarView viewEr("Er [V/m]", new WinGeom(0, 0, 800, 400));
    viewEr.show(&e_r_sln);
    // viewEr.save_screenshot("real_part.bmp");

    ScalarView viewEi("Ei [V/m]", new WinGeom(0, 450, 800, 400));
    viewEi.show(&e_i_sln);
    // viewEi.save_screenshot("imaginary_part.bmp");

    // Wait for the view to be closed.
    View::wait();

    // Clean up.
    delete solver;
    delete matrix;
    delete rhs;

    return 0;
}
コード例 #10
0
ファイル: main.cpp プロジェクト: LukasKoudela/hermes-examples
int main(int argc, char* argv[])
{
    // Load the mesh.
  Mesh mesh;
  MeshReaderH2D mloader;
  mloader.load("domain.mesh", &mesh);

  // Perform uniform mesh refinement.
  // 2 is for vertical split.
  for(int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(2); 

  // Initialize boundary conditions
  DefaultEssentialBCConst<double> bc1("Bdy_perfect", 0.0);
  EssentialBCNonConst bc2("Bdy_left");
  DefaultEssentialBCConst<double> bc3("Bdy_left", 0.0);
  EssentialBCs<double> bcs(Hermes::vector<EssentialBoundaryCondition<double> *>(&bc1, &bc2));
  EssentialBCs<double> bcs_im(Hermes::vector<EssentialBoundaryCondition<double> *>(&bc1, &bc3));

  // Create an H1 space with default shapeset.
  H1Space<double> e_r_space(&mesh, &bcs, P_INIT);
  H1Space<double> e_i_space(&mesh, &bcs_im, P_INIT);
  int ndof = Space<double>::get_num_dofs(&e_r_space);
  Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof);

  // Initialize the weak formulation.
  WeakFormHelmholtz wf(eps, mu, omega, sigma, beta, E0, h);

  // Initialize the FE problem.
  DiscreteProblem<double> dp(&wf, Hermes::vector<const Space<double>*>(&e_r_space, &e_i_space));

  // Initialize the solutions.
  Solution<double> e_r_sln, e_i_sln;

  // Initial coefficient vector for the Newton's method.  
  ndof = Space<double>::get_num_dofs(Hermes::vector<const Space<double>*>(&e_r_space, &e_i_space));

  Hermes::Hermes2D::NewtonSolver<double> newton(&dp);
  try
  {
    newton.set_newton_tol(NEWTON_TOL);
    newton.set_newton_max_iter(NEWTON_MAX_ITER);
    newton.solve();
  }
  catch(Hermes::Exceptions::Exception e)
  {
    e.printMsg();
    throw Hermes::Exceptions::Exception("Newton's iteration failed.");
  };

  // Translate the resulting coefficient vector into Solutions.
  Solution<double>::vector_to_solutions(newton.get_sln_vector(), Hermes::vector<const Space<double>*>(&e_r_space, &e_i_space), 
      Hermes::vector<Solution<double>*>(&e_r_sln, &e_i_sln));

  // Visualize the solution.
  ScalarView viewEr("Er [V/m]", new WinGeom(0, 0, 800, 400));
  viewEr.show(&e_r_sln);
  // viewEr.save_screenshot("real_part.bmp");

  ScalarView viewEi("Ei [V/m]", new WinGeom(0, 450, 800, 400));
  viewEi.show(&e_i_sln);
  // viewEi.save_screenshot("imaginary_part.bmp");

  // Wait for the view to be closed.
  View::wait();

  return 0;
}