void peano::integration::partitioncoupling::builtin::tests::PartitionCoupling4MovingSphereTest::run(){


  tarch::la::Vector<DIMENSIONS,double> hexahedronSize(1.0);
  tarch::la::Vector<DIMENSIONS,double> hexahedronOffset(0.0);
  peano::geometry::builtin::Hexahedron *hexahedron = new peano::geometry::builtin::Hexahedron(false,hexahedronSize,hexahedronOffset);

  tarch::la::Vector<DIMENSIONS,double> spherePosition(0.5);
  double sphereRadius = 1.0/6.0;
  double sphereDensity = 1.0;
  double sphereMass = sphereDensity*tarch::la::PI
#if (DIMENSIONS==2)
                      *sphereRadius*sphereRadius
#elif(DIMENSIONS==3)
                      *4.0/3.0*sphereRadius*sphereRadius*sphereRadius
#endif
                    ;

  int timestepsPerPlotting = 5;
  double dt = 0.01;

  tarch::la::Vector<DIMENSIONS,double> force(0.0);
  tarch::la::Vector<DIMENSIONS,double> forcePosition(0.0);
  tarch::la::Vector<DIMENSIONS,double> velocityPosition(0.0);

  std::vector<peano::integration::partitioncoupling::builtin::tests::PartitionCoupling4MovingSphereTest::TestScenario>
    testScenarios = getTestScenarios(spherePosition,sphereRadius,sphereMass,dt);

  for (unsigned int i = 0; i < testScenarios.size(); i++){
    tarch::la::Vector<DIMENSIONS,double> velocity(0.0);
    std::stringstream ss(std::stringstream::in | std::stringstream::out);
    ss << "PartitionCoupling4MovingSphereTest_Test_" << i << "_";

    // create receive-,send- and coupling object
    peano::integration::partitioncoupling::services::ReceiveDataService::getInstance().init(
      spherePosition,sphereRadius,tarch::la::Vector<3,double>(0.0),tarch::la::Vector<3,double>(0.0)
    );
    peano::integration::partitioncoupling::services::SendDataService::getInstance().init(spherePosition);

    PartitionCoupling4MovingSphere partitionCoupling(
      hexahedron,hexahedronSize,hexahedronOffset,spherePosition,sphereRadius,sphereDensity,
      timestepsPerPlotting,timestepsPerPlotting,ss.str()
    );
    partitionCoupling.initialize();
    // add force,advance in time
    peano::integration::partitioncoupling::services::SendDataService::getInstance().getSendData().sendForce(testScenarios[i].forcePosition,testScenarios[i].force);
    partitionCoupling.advance(dt);
    // get velocity and validate its components
    velocity = peano::integration::partitioncoupling::services::ReceiveDataService::getInstance().getReceiveData().getVelocity(testScenarios[i].velocityPosition);
    std::cout << "Velocity: " << velocity << ", expected: " << testScenarios[i].expectedVelocity << std::endl;
    validate(tarch::la::equals(
      tarch::la::dot(velocity-testScenarios[i].expectedVelocity,velocity-testScenarios[i].expectedVelocity),
      0.0
    ));
  }
}
Ejemplo n.º 2
0
void CollisionObject::correctPosition(const sf::Vector2f &position)
{
	if(m_maxtime == 0.f || m_time >= m_maxtime)
		forcePosition(position.x, position.y);
	else
	{
		m_position.x = position.x;
		m_position.y = position.y;
		/*
		//Continue interpolation from a different start position (disabling it makes the client more accurate, but the displayed data is less stable)
		//Linear 2-eq system solution
		m_direction = (m_desired - m_position) / (1.f - m_time / m_maxtime);
		m_start = m_desired - m_direction;
		*/
	}
}
Ejemplo n.º 3
0
void CollisionObject::forcePosition(const sf::Vector2f &position)
{
	forcePosition(position.x, position.y);
}