Exemplo n.º 1
0
void
CSUmbrella::initialise(size_t nID)
{
  ID = nID;

  BOOST_FOREACH(const size_t& id, *range1)
    Sim->dynamics.getLiouvillean().updateParticle(Sim->particleList[id]);
  
  BOOST_FOREACH(const size_t& id, *range2)
    Sim->dynamics.getLiouvillean().updateParticle(Sim->particleList[id]);
  
  CPDData partdata(*Sim, *range1, *range2);

  ulevelcenter = int( - a * b * b / delU);

  double r = partdata.rij.nrm();

  if (!ulevelset)
    {
      ulevel = int(a * (r - b) * (r - b) / delU);
      if (r < b) ulevel *= -1;
      ulevelset = true;
    }
  
  recalculateTime();

  Sim->registerParticleUpdateFunc
    (magnet::function::MakeDelegate(this, &CSUmbrella::particlesUpdated));
}
Exemplo n.º 2
0
int recalculateTimeCommand(int argc, char* argv[])
{
	scheduler_mode = TIME_SLICE;
	recalculateTime();
	reorganizeQueue(&READY_QUEUE);
	dumpQueue(&READY_QUEUE);
	scheduler_mode = ROUND_ROBIN;
	reorganizeQueue(&READY_QUEUE);
	return 0;
}
Exemplo n.º 3
0
void 
CSUmbrella::particlesUpdated(const NEventData& PDat)
{
  BOOST_FOREACH(const ParticleEventData& pdat, PDat.L1partChanges)
    if (range1->isInRange(pdat.getParticle())
	|| range2->isInRange(pdat.getParticle()))
      {
	recalculateTime();
	Sim->ptrScheduler->rebuildSystemEvents();
	return;
      }

  BOOST_FOREACH(const PairEventData& pdat, PDat.L2partChanges)
    if (range1->isInRange(pdat.particle1_.getParticle())
	|| range2->isInRange(pdat.particle1_.getParticle())
	|| range1->isInRange(pdat.particle2_.getParticle())
	|| range2->isInRange(pdat.particle2_.getParticle()))
      {
	recalculateTime();
	Sim->ptrScheduler->rebuildSystemEvents();
	return;
      }
}
Exemplo n.º 4
0
  void
  SSleep::initialise(size_t nID)
  {
    ID = nID;

    Sim->_sigParticleUpdate.connect<SSleep, &SSleep::particlesUpdated>(this);

    recalculateTime();

    _lastData.resize(Sim->N());
    for (const Particle& part : Sim->particles)
      {
	_lastData[part.getID()].first = part.getPosition();
	_lastData[part.getID()].second = - HUGE_VAL;
      }
  }
Exemplo n.º 5
0
// **********************************************************************
// **********************************************************************
// scheduler
//
static int scheduler()
{
	int nextTask = peek(&READY_QUEUE);
	if(nextTask != -1)
	{
		if(scheduler_mode == TIME_SLICE)
		{
			if(tcb[nextTask].time == 0)
			{
				recalculateTime();
				reorganizeQueue(&READY_QUEUE);
				nextTask = peek(&READY_QUEUE);
			}

			tcb[nextTask].time = tcb[nextTask].time - 1;
		}
		nextTask = dequeue(&READY_QUEUE);
		enqueue(nextTask, &READY_QUEUE);
	}



	//	nextTask = ++curTask;
	//
	//	// mask sure nextTask is valid
	//	while (!tcb[nextTask].name)
	//	{
	//		if (++nextTask >= MAX_TASKS) nextTask = 0;
	//	}
	//	int i;
	//
	//		for(i = READY_QUEUE.size - 1; i >= 0; i--)
	//			if(!(tcb[READY_QUEUE.pq[i].taskid].signal & mySIGSTOP))
	//			{
	//				nextTask = READY_QUEUE.pq[i].taskid;
	//				takeout(READY_QUEUE.pq[i].taskid, &READY_QUEUE);
	//				enqueue(nextTask, tcb[i].priority, READY_QUEUE);
	//				printf("next task: %d", nextTask);
	//				return nextTask;
	//			}
	return nextTask;

} // end scheduler
Exemplo n.º 6
0
  void 
  SSleep::particlesUpdated(const NEventData& PDat)
  {
    BOOST_FOREACH(const PairEventData& pdat, PDat.L2partChanges)
      {
	const Particle& p1 = pdat.particle1_.getParticle();
	const Particle& p2 = pdat.particle2_.getParticle();
      
	//FC = Fixed collider, DP = Dynamic particle, SP = Static
	//particle, ODP = other dynamic particle, OSP = other static
	//particle

	//Check if either particle is static and should not move

	//[O?P-O?P]
	if (!_range->isInRange(p1) && !_range->isInRange(p2)) continue;

	//DP-[DP/ODP]
	if (p1.testState(Particle::DYNAMIC) && p2.testState(Particle::DYNAMIC)) continue; 
      
	//SP-[FC/SP/OSP]
#ifdef DYNAMO_DEBUG
	if (!p1.testState(Particle::DYNAMIC) && !p2.testState(Particle::DYNAMIC))
	  M_throw() << "Static particles colliding!";
#endif

	//We're guaranteed by the previous tests that
	//p1.testState(Particle::DYNAMIC) != p2.testState(Particle::DYNAMIC)
	//and that at least one particle is in the range

	//Sort the particles
	const Particle& dp = p1.testState(Particle::DYNAMIC) ? p1 : p2;
	const Particle& sp = p1.testState(Particle::DYNAMIC) ? p2 : p1;

	//Other variables
	Vector g(static_cast<const LNewtonianGravity&>(Sim->dynamics.getLiouvillean()).getGravityVector());

	if (!_range->isInRange(sp))  //DP-FC
	  {
	    //If the dynamic particle is going to fall asleep, mark its impulse as 0
	    if (sleepCondition(dp, g))
	      stateChange[dp.getID()] = Vector(0,0,0);
	    continue;
	  }

	if (!_range->isInRange(dp)) continue;

	//Final case
	//DP-SP
	//sp is in the range (a wakeable particle)

	//If the static particle sleeps
	if ((sleepCondition(sp, g)))
	  {
	    double massRatio = Sim->dynamics.getSpecies(sp).getMass(sp.getID()) 
	      / Sim->dynamics.getSpecies(dp).getMass(dp.getID());

	    stateChange[sp.getID()] = Vector(0,0,0);
	    stateChange[dp.getID()] = -sp.getVelocity() * massRatio;
	  
	    //Check if the sleep conditions match
	    if ((sleepCondition(dp, g, -sp.getVelocity() * massRatio)))
	      {
		stateChange[dp.getID()] = Vector(0,0,0);
		continue;
	      }

	    //We're not going to sleep the particle due to the standard
	    //rule, but here we try to catch anything that might cause a
	    //problem.

	    //Sometimes our relative velocity effectively goes to zero
	    //(in comparison to the other components). This means the
	    //particle will just keep having an event, we sleep it
	    //instead.
	    if ((pdat.dP.nrm() / Sim->dynamics.getSpecies(dp).getMass(dp.getID())) 
		< _sleepVelocity)
	      {
		stateChange[dp.getID()] = Vector(0,0,0);
		continue;
	      }
	    
	    continue;
	  }

	//Finally, just wake up the static particle
	stateChange[sp.getID()] = Vector(1,1,1);	
      }

    BOOST_FOREACH(const PairEventData& pdat, PDat.L2partChanges)
      {
	const Particle& p1 = pdat.particle1_.getParticle();
	_lastData[p1.getID()].first = p1.getPosition();
	_lastData[p1.getID()].second = Sim->dSysTime;

	const Particle& p2 = pdat.particle2_.getParticle();
	_lastData[p2.getID()].first = p2.getPosition();
	_lastData[p2.getID()].second = Sim->dSysTime;
      }

    if (!stateChange.empty())
      {
	recalculateTime();
	Sim->ptrScheduler->rebuildSystemEvents();
      }
  }
Exemplo n.º 7
0
	bool ControllerEdgeHide::addTime(Widget* _widget, float _time)
	{
		const IntSize& view_size = _widget->getParentSize();
		// do nothing if we have minimized window
		if (view_size.width <= 1 && view_size.height <= 1)
			return true;

		Widget* keyFocus = InputManager::getInstance().getKeyFocusWidget();
		Widget* mouseFocus = InputManager::getInstance().getMouseFocusWidget();

		while ((keyFocus != nullptr) && (_widget != keyFocus))
			keyFocus = keyFocus->getParent();
		while ((mouseFocus != nullptr) && (_widget != mouseFocus))
			mouseFocus = mouseFocus->getParent();

		// if our widget or its children have focus
		bool haveFocus = ((keyFocus != nullptr) || (mouseFocus != nullptr)) || (_widget->getVisible() == false);

		mElapsedTime += haveFocus ? -_time : _time;

		if (mElapsedTime >= mTime)
		{
			mElapsedTime = mTime;
		}
		if (mElapsedTime <= 0)
		{
			mElapsedTime = 0.0f;
			return true;
		}

		float k = sin(M_PI * mElapsedTime / mTime - M_PI / 2);
		if (k < 0) k = (-pow(-k, 0.7f) + 1) / 2;
		else k = (pow(k, 0.7f) + 1) / 2;

		MyGUI::IntCoord coord = _widget->getCoord();
		// if widget was moved
		if (coord != mLastCoord)
		{
			// if still moving - leave it alone
			if (haveFocus)
				return true;
			else
				recalculateTime(_widget);
		}

		bool nearBorder = false;

		if ((coord.left <= 0) && !(coord.right() >= view_size.width - 1))
		{
			coord.left = - int( float(coord.width - mRemainPixels - mShadowSize) * k);
			nearBorder = true;
		}
		if ((coord.top <= 0) && !(coord.bottom() >= view_size.height - 1))
		{
			coord.top = - int( float(coord.height - mRemainPixels - mShadowSize) * k);
			nearBorder = true;
		}
		if ((coord.right() >= view_size.width - 1) && !(coord.left <= 0))
		{
			coord.left = int(float(view_size.width - 1) - float(mRemainPixels) * k - float(coord.width) * (1.f - k));
			nearBorder = true;
		}
		if ((coord.bottom() >= view_size.height - 1) && !(coord.top <= 0))
		{
			coord.top = int(float(view_size.height - 1) - float(mRemainPixels) * k - float(coord.height) * (1.f - k));
			nearBorder = true;
		}

		if (nearBorder)
		{
			_widget->setCoord(coord);
		}
		else
		{
			mElapsedTime = 0;
		}
		mLastCoord = coord;

		eventUpdateAction(_widget, this);

		return true;
	}
Exemplo n.º 8
0
	void ControllerEdgeHide::prepareItem(Widget* _widget)
	{
		recalculateTime(_widget);
		// вызываем пользовательский делегат для подготовки
		eventPreAction(_widget, this);
	}